var city='';var hdnuserloginstatus = false;
function callnewsiframe(){
 self.location="news.php";
}
function news(){
 setTimeout("callnewsiframe()",120000);
}

function nextlist(recordperpage,framename,pagename,startfield,numrowfield){
 var startvalue=document.getElementById(startfield).value;var numrowvalue=document.getElementById(numrowfield).value;
 startvalue=parseInt(startvalue);recordperpage=parseInt(recordperpage);startvalue=startvalue+recordperpage;
 if(startvalue>=numrowvalue) return;
 else document.getElementById(framename).src=pagename+"?start="+startvalue;
}
function previouslist(recordperpage,framename,pagename,startfield,numrowfield){
 var startvalue=document.getElementById(startfield).value;
 startvalue=parseInt(startvalue);recordperpage=parseInt(recordperpage);startvalue=startvalue-recordperpage;
 if(startvalue<0) return;
 else document.getElementById(framename).src=pagename+"?start="+startvalue;
}
function nextchlorvodlist(recordperpage,framename,startfield,numrowfield){
 var pagename=parent.document.getElementById('leftside2').src;var position=pagename.indexOf("?");
 if(position!=-1) pagename = pagename.substring(0,position);
 var startvalue=document.getElementById(startfield).value;var numrowvalue=document.getElementById(numrowfield).value;
 startvalue=parseInt(startvalue);recordperpage=parseInt(recordperpage);startvalue=startvalue+recordperpage;
 if(startvalue>=numrowvalue) return;
 else document.getElementById(framename).src = pagename+"?start="+startvalue;
}
function previouschlorvodlist(recordperpage,framename,startfield,numrowfield){
 var pagename=parent.document.getElementById('leftside2').src;var position=pagename.indexOf("?");
 if(position!=-1) pagename=pagename.substring(0,position);
 var startvalue=document.getElementById(startfield).value;startvalue=parseInt(startvalue);recordperpage=parseInt(recordperpage);startvalue=startvalue-recordperpage;
 if(startvalue<0) return;
 else document.getElementById(framename).src = pagename+"?start="+startvalue;
}
function ReadFromCookie(c_name){
 if(document.cookie.length>0){
  c_start=document.cookie.indexOf(c_name+"=");
  if(c_start!=-1){
   c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);
   if (c_end==-1) c_end=document.cookie.length;
   return unescape(document.cookie.substring(c_start,c_end));
  }
 }
 return "";
}
function delete_cookie(cookie_name)
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
function WriteToCookie(name,value){
 var nextyear=new Date();nextyear.setFullYear(nextyear.getFullYear()+1);
 document.cookie = name+"="+value+"; expires="+nextyear.toGMTString()+"; path=/";
}
function Checkuser(idval,flashfile,selectedchannel,channelnolength){
 var val=document.getElementById('tvplayer').style.visibility;
 if(val=="hidden") window.itv.document.getElementById('tv').style.visibility="hidden";
 var checkchannelno=ReadFromCookie('channelno');var tvplayerdivstatus=document.getElementById('tvplayer').style.visibility;
 if(checkchannelno==selectedchannel && tvplayerdivstatus=="visible") return;
 else{
  stopaaa();
  with(document){
   getElementById('Layer2').style.visibility="hidden";getElementById('Layer2').style.height="0px";
   getElementById('tvplayer').style.visibility="hidden";getElementById('tvplayer').style.height="0px";
   getElementById("Flash").style.visibility="hidden";getElementById("Flash").style.height="0px";
  }
  WriteToCookie('selectedchannelno',selectedchannel);//channelselected();
  var hdnloginstatus=parent.parent.document.getElementById('userloginstatus').value;
  var channelno=parseInt(selectedchannel);
  if(hdnloginstatus=='true'){
	var balance=ReadFromCookie('balance');
   if(balance=="yes"){
	 check(idval,flashfile);
   }
   else{
	 if(channelnolength=="4") alert("If you want to watch the paytv please check account your balance in www.rh-mbc.com or ask your dealer to top up for u to continue....");
	 else if(channelnolength=="5") alert("If you are a registered user and if you want to watch the Pay Per View please check account your balance in www.rh-mbc.com or ask your dealer to top up for you to continue....");
    document.getElementById("list").src="blankpage.html";
    var features = 'fullscreen=yes,dialog=no,scrollbars=yes,resizable=no,menubar=no,toolbar=no,titlebar=no,status=no,location=no,personalbar=no,border=0,left=0,top=0';
    //window.open("http://www.rh-mbc.com",'rhmbcwin',features);
   }
  }
  else document.getElementById("list").src="test.php?idval="+idval+"&flashfile="+flashfile+"&chllen="+channelnolength+"&channelno="+channelno;
 }
}
function callpage()
{
 var idval=document.getElementById('hdnidval').value;
 var flashfile=document.getElementById('hdnflashfile').value;
 parent.document.getElementById('list').src="login.php?val="+idval+"&flashfile="+flashfile;

}
function placeCursur(controlname){
 document.getElementById(controlname).focus();
}
function login(fieldname)
{
 var keypressvalue=event.keyCode;
 if(keypressvalue!=13){
  document.getElementById(fieldname).focus();return;
 }
 else{
  userNameAndPasswordCheck();return;
 }
}
function userNameAndPasswordCheck(){
 //var valid=true;
 var fieldvalue1=document.getElementById('Emailid').value;var fieldvalue2=document.getElementById('Password').value;
 //alert(fieldvalue1);alert(fieldvalue2);
 var valid=true;
 if(fieldvalue1==''||fieldvalue2=='')
 {
  valid=false;
  //alert("Please fill all the compulsory fields");
  if(fieldvalue1==''){
   alert("Email Address should not be blank!");
   document.getElementById('Emailid').focus();
  }
  else if(fieldvalue2==''){
   alert("Password should not be blank!");
   document.getElementById('Password').focus();
  }
  return;
  }
  if(fieldvalue1!=''){
   valid=false;
   if(!allValidChars(fieldvalue1)){
    alert("Please enter a valid "+fieldname1);return;
   }
   else if(fieldvalue1.indexOf("@")<1){
    alert("Please enter a valid "+fieldname1);return;
   }
   else if(fieldvalue1.lastIndexOf(".")<=fieldvalue1.indexOf("@")){
     alert("Please enter a valid "+fieldname1);return;
   }
   else if(fieldvalue1.indexOf("@")==fieldvalue1.length){
     alert("Please enter a valid "+fieldname1);return;
   }
   else if(fieldvalue1.indexOf("..") >=0){
     alert("Please enter a valid "+fieldname1);return;
   }
   else if (fieldvalue1.indexOf(".")==fieldvalue1.length){
    alert("Please enter a valid "+fieldname1);return;
   }
   else valid=true;
  }
 if(valid){
  document.loginfrm.action="validation.php";
  document.loginfrm.submit();
  return;
 }
}
function checkloginstatus(control,tvchannelid,userstatus,category,emailexistance,flashfile,channelno){
 var hdnloginstatus=parent.parent.document.getElementById('userloginstatus').value;
 if(hdnloginstatus=='false') emailexistance='';
 checkstatus=document.getElementById("loginval").value;
 var email=document.getElementById("email").value;
 if(checkstatus==1){
  placeCursur(control);
  alert("As you are not the registered user click ok for auto registration");
  document.loginfrm.action="validation.php";
  document.loginfrm.submit();
  return;
 }
 else if(checkstatus==2){
  parent.itv.document.getElementById('tv').style.visibility="hidden";
  placeCursur(control);
  WriteToCookie('email',email);
  WriteToCookie('userstatus',userstatus);
  WriteToCookie('balance','yes');
  parent.document.getElementById("list").src="blankpage.html";
  if((tvchannelid=='') && (flashfile=='')){
	tvchannelid="free";
   flashfile="evergreen.swf";
   parent.check(tvchannelid,flashfile);
  }
  else{
	parent.check(tvchannelid,flashfile);
  }
  parent.document.getElementById("iframe").src="top.php";
 }
 else if(checkstatus==3){
  WriteToCookie('email',email);
  WriteToCookie('userstatus',userstatus);
  parent.document.getElementById("list").src='userapproval.php';
  parent.parent.document.getElementById("iframe").src="top.php";
 }
 else if(checkstatus==4){
  WriteToCookie('email',email);
  WriteToCookie('userstatus',userstatus);
  WriteToCookie('balance','');
  parent.parent.document.getElementById("iframe").src="top.php";
  parent.document.getElementById("list").src="blankpage.html";
  var features = 'fullscreen=yes,dialog=no,scrollbars=yes,resizable=no,menubar=no,toolbar=no,titlebar=no,status=no,location=no,personalbar=no,border=0,left=0,top=0';
 }
 else if(checkstatus==5){
  WriteToCookie('email',email);
  WriteToCookie('userstatus',userstatus);
  WriteToCookie('balance','');
  parent.parent.document.getElementById("iframe").src="top.php";
  parent.document.getElementById("list").src="blankpage.html";
  parent.check('','');
 }
 else if(checkstatus==6){
  WriteToCookie('email',email);
  WriteToCookie('userstatus',userstatus);
  WriteToCookie('balance','yes');
  var returnvalue=payperviewconfirmation();
  if(returnvalue){
   parent.check(tvchannelid,flashfile);
   parent.document.getElementById("payperviewhdnframe").src="payperviewdeduct.php?channelno="+channelno;
  }
  else{
   parent.document.getElementById("startupdiv").style.zIndex = "10000";
   parent.document.getElementById("startupdiv").style.visibility = "visible";
   parent.document.getElementById("startupdiv").style.height = "350px";
  }
  parent.parent.document.getElementById("iframe").src="top.php";
  parent.document.getElementById("list").src="blankpage.html";
 }
 else if(checkstatus==7){
  WriteToCookie('email',email);
  WriteToCookie('userstatus',userstatus);
  WriteToCookie('balance','');
  alert("If you are a registered user and if you want to watch the Pay Per View please check account your balance in www.rh-mbc.com or ask your dealer to top up for you to continue....");
  var features = 'fullscreen=yes,dialog=no,scrollbars=yes,resizable=no,menubar=no,toolbar=no,titlebar=no,status=no,location=no,personalbar=no,border=0,left=0,top=0';
  parent.parent.document.getElementById("iframe").src="top.php";
  parent.document.getElementById("list").src="blankpage.html";
 }
}
function openpage(pagename){
 if(window.parent.document.getElementById("itv")){
 if(window.parent.document.getElementById("itv").src!="itvframe.php"){
  window.parent.document.getElementById("itv").src = "itvframe.php";
  window.parent.document.getElementById("itv").style.height="0px";
  }
 }
 parent.itv.stop();
 divlayer();
 parent.document.getElementById("list").src=pagename;
}
function register(fieldname2,fieldname1){
 var keypressvalue=event.keyCode;
 if(keypressvalue!=13){
  document.getElementById(fieldname2).focus();return;
 }
 else{
  Check(fieldname1,fieldname2);return;
 }
}
function Check(fieldname1,fieldname2){
 var fieldvalue1=document.getElementById(fieldname1).value;var fieldvalue2=document.getElementById(fieldname2).value;
 var valid=true;
 if(fieldvalue1==''||fieldvalue2=='')
 {
  valid=false;
  //alert("Please fill all the compulsory fields");
  if(fieldvalue1==''){
   alert("Email Address should not be blank!");
   document.getElementById(fieldname1).focus();
  }
  else if(fieldvalue2==''){
   alert("Password should not be blank!");
   document.getElementById(fieldname2).focus();
  }
  return;
  }
  if(fieldvalue1!=''){
   valid=false;
   if(!allValidChars(fieldvalue1)){
    alert("Please enter a valid "+fieldname1);return;
   }
   else if(fieldvalue1.indexOf("@")<1){
    alert("Please enter a valid "+fieldname1);return;
   }
   else if(fieldvalue1.lastIndexOf(".")<=fieldvalue1.indexOf("@")){
     alert("Please enter a valid "+fieldname1);return;
   }
   else if(fieldvalue1.indexOf("@")==fieldvalue1.length){
     alert("Please enter a valid "+fieldname1);return;
   }
   else if(fieldvalue1.indexOf("..") >=0){
     alert("Please enter a valid "+fieldname1);return;
   }
   else if (fieldvalue1.indexOf(".")==fieldvalue1.length){
    alert("Please enter a valid "+fieldname1);return;
   }
   else valid=true;
  }
  if(valid){
   document.registerfrm.action="register.php";
   document.registerfrm.submit();
   return;
  }
}
function allValidChars(fieldvalue1){
 var parsed=true;
 var validchars="abcdefghijklmnopqrstuvwxyz0123456789@.-_";
 for(var i=0;i<fieldvalue1.length;i++){
  var letter=fieldvalue1.charAt(i).toLowerCase();
  if(validchars.indexOf(letter)!=-1) continue;
  parsed=false;break;
 }
 return parsed;
}
function checkNredirect(tvchannelid){
 var isSubmit=false;
 var a=document.getElementById("hdn").value;
 if(a==1) isSubmit=true;
 else isSubmit=false;
 if(isSubmit){
  if(tvchannelid!='') parent.getid(tvchannelid);
  else self.location='login.php';
 }
}
function checkadminuser(uploadpage,loginpage){
 divlayer();
 var email=ReadFromCookie('email');var userstatus=ReadFromCookie('userstatus');
 if(email==''){
  alert("You have to login first");
  parent.document.getElementById("list").src = loginpage;
 }
 else if(email!=''){
  if(userstatus=='N') alert("You are not allowed to upload a video");
  else parent.document.getElementById("list").src=uploadpage;
 }
}
function showtime(controlname,actionpagename){
 var selectedtopic=document.getElementById(controlname).options[document.getElementById(controlname).selectedIndex].value;
 var now=new Date();
 var hours=now.getHours();var minutes=now.getMinutes();var seconds=now.getSeconds();
 var timeValue="";
 if(hours<10) hours = "0"+hours;
 timeValue+=hours;timeValue+=((minutes<10)?":0":":")+minutes;timeValue+=((seconds<10)?":0":":")+seconds;
 document.frm.hdn1.value=timeValue;
 if(selectedtopic==''){
  alert("Topic should not be blank");return;
 }
 else{
  document.frm.action= actionpagename;
  //if(selectedtopic=="news" || selectedtopic=="Features") document.getElementById('divmsg').innerHTML="Video URL uploading is going on.Please wait...";
  //else document.getElementById('divmsg').innerHTML="Video File uploading is going on.Please wait...";
  document.getElementById('divmsg').innerHTML="Video File uploading is going on.Please wait...";
  document.frm.submit();
 }
}
function playvideo(videoid,category,anchorid){
if(window.parent.document.getElementById("itv")){
 if(window.parent.document.getElementById("itv").src!="itvframe.php"){
  window.parent.document.getElementById("itv").src = "itvframe.php";
  window.parent.document.getElementById("itv").style.height="0px";
 }
}
 with(window.parent.document){
  getElementById('blackdiv').style.zIndex="7000";getElementById('blackdiv').style.visibility="visible";
  getElementById('startupdiv').style.visibility="hidden";getElementById('startupdiv').style.height="0px";
  getElementById('listdiv').style.zIndex="2500";
  getElementById('videoplayer').style.zIndex="4500";getElementById('videoplayer').style.visibility="visible";getElementById('videoplayer').style.height="350px";
  getElementById('Layer2').style.visibility="hidden";getElementById('Layer2').style.height="0px";
  getElementById('listdiv').style.visibility="hidden";getElementById('listdiv').style.height="0px";
  getElementById('tvplayer').style.visibility="hidden";getElementById('tvplayer').style.height="0px";
  getElementById("Flash").style.visibility="hidden";getElementById("Flash").style.height="0px";
 }
 parent.itv.stop();
 parent.videoplayeriframe.document.getElementById('container').style.visibility="hidden";
 parent.scrollTo(0,0);
 parent.stopaaa();

 if(category=="news" || category=="Features" || category=="Entertainment" || category=="HSK"){
  var position = anchorid.indexOf("watch");
  var checksitename = anchorid.substring(0,position);
  if(checksitename=='http://www.youtube.com/') parent.document.getElementById('videoplayeriframe').src="newsvideoplayer.php?idvalue="+videoid+"&category="+category+"&fileloc="+anchorid;
  else parent.document.getElementById('videoplayeriframe').src="videoplayer.php?idvalue="+videoid+"&category="+category;
 }
 else if(category=="city"){
  var position = anchorid.indexOf("watch");
  var checksitename = anchorid.substring(0,position);
  var position1 = checksitename.indexOf("http");
  var checksitename1 = checksitename.substring(position1,checksitename.length);
  if(checksitename1=='http://www.youtube.com/') parent.document.getElementById('videoplayeriframe').src="newsvideoplayer.php?idvalue="+videoid+"&category="+category+"&fileloc="+anchorid;
  else parent.document.getElementById('videoplayeriframe').src="videoplayer.php?idvalue="+videoid+"&category="+category;
 }
 else{
  parent.document.getElementById('videoplayeriframe').src="videoplayer.php?idvalue="+videoid+"&category="+category;
 }
}
function autocheck(){
 var tagval=document.getElementById('hdntag').value;
 if(tagval!='') document.getElementById("autocheckbox").checked=true;
}
function playtestadds(value1,value2){
 parent.document.getElementById('list').src="videoplayer.php?idvalue="+value1+"&tagval="+value2;
}
function opennewsite(sitename){
 var features='fullscreen=no,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,titlebar=yes,status=yes,location=yes,border=0,left=200,top=80,width='+(screen.width-400)+',height='+(screen.height-200);
 var mywindow=window.open(sitename,'mywin',features );
 if(sitename!="http://www.evergreeniptv.com/refer/"){
  with(document){
   getElementById('startupdiv').style.visibility="hidden";getElementById('startupdiv').style.height="0px";
   getElementById('blackdiv').style.zIndex="1";getElementById('blackdiv').style.visibility="hidden";
   getElementById('listdiv').style.zIndex="2800";getElementById('videoplayer').style.zIndex="2500";
   getElementById("Flash").style.visibility="hidden";getElementById("Flash").style.height="0";
   getElementById('videoplayer').style.visibility="hidden";getElementById('videoplayer').style.height="0px";
   getElementById('tvplayer').style.visibility="hidden";getElementById('tvplayer').style.height="0px";
   getElementById('listdiv').style.visibility="visible";getElementById('listdiv').style.height="350px";
   getElementById("list").src="blankpage.html";
  }
 }
}
function logout(){
 //parent.itv.stop();
 //parent.parent.document.getElementById("flashimg").src="blankpage.html";
 hdnuserloginstatus=false;parent.parent.document.getElementById("userloginstatus").value=hdnuserloginstatus;
 WriteToCookie('email','');WriteToCookie('userstatus','');WriteToCookie('balance','');
 delete_cookie('email');delete_cookie('userstatus');delete_cookie('balance');delete_cookie('selectedchannelno');
 self.location="showuser.php";
 with(window.parent.parent.document){
  //getElementById('startupdiv').style.visibility="hidden";getElementById('startupdiv').style.height="0px";
  //getElementById('blackdiv').style.zIndex="1";getElementById('blackdiv').style.visibility="hidden";
  //getElementById('listdiv').style.zIndex="2800";getElementById('videoplayer').style.zIndex="2500";
  //getElementById("Flash").style.visibility="hidden";getElementById("Flash").style.height="0";
  //getElementById('listdiv').style.visibility="visible";getElementById('listdiv').style.height="350px";
  //getElementById('videoplayer').style.visibility="hidden";getElementById('videoplayer').style.height="0px";
  //getElementById('tvplayer').style.visibility="hidden";getElementById('tvplayer').style.height="0px";
  getElementById("mainframe").src="logout.php";
 }
}
function checknull(email){
 if(email!=''){
  hdnuserloginstatus=true;parent.parent.document.getElementById('userloginstatus').value=hdnuserloginstatus;
  document.getElementById("user").style.visibility="visible";
 }
 else document.getElementById("user").style.visibility="hidden";
}
function showsponsorimage(image){
 with(window.parent.document){
  getElementById('blackdiv').style.zIndex="1";getElementById('blackdiv').style.visibility="hidden";getElementById('blackdiv').style.height="0px";
  getElementById('Layer2').style.visibility = "hidden";
  getElementById('listdiv').style.zIndex="2800";getElementById('videoplayer').style.zIndex="2500";
  getElementById("flashimg").src="blankpage.html";getElementById("list").src="blankpage.html";
  getElementById("Flash").style.visibility="hidden";getElementById("Flash").style.height="0";
  getElementById('listdiv').style.visibility="visible";getElementById('listdiv').style.height="350px";
  getElementById('videoplayer').style.visibility="hidden";getElementById('videoplayer').style.height="0px";
  getElementById('tvplayer').style.visibility="hidden";getElementById('tvplayer').style.height="0px";
  getElementById("list").src="showimage.php?imagename="+image;
 }
}
function displaysponsorimage(image){
 with(window.parent.document){getElementById('startupdiv').style.visibility="hidden";getElementById('startupdiv').style.height="0px";}
 var pageforothers=parent.document.getElementById("list").src;var position=pageforothers.indexOf(".");
 pageforothers=pageforothers.substring(0,position);
 var pagefortv= parent.document.getElementById("tvplayer").style.visibility;var pageforvideo = parent.document.getElementById("videoplayer").style.visibility;
 if(pageforothers!=''){
  if((pageforothers!="login")&&(pageforothers=="test")&&(pagefortv=="hidden")&&(pageforvideo=="hidden")) return;
  else if((pageforothers!="test")&&(pageforothers=="login")&&(pagefortv=="hidden")&&(pageforvideo=="hidden")) return;
  else if((pagefortv=="visible")&&(pageforvideo=="hidden")) return;
  else if((pagefortv=="hidden")&&(pageforvideo=="visible")) return;
  else showsponsorimage(image);
 }
 else return;
}
function openDiv(){
 document.getElementById('citydiv').style.visibility="visible";
}
function closeDiv(){
 document.getElementById('citydiv').style.visibility="hidden";
}
function opencity(cityname){
 city=cityname;
 closeDiv();
 setTimeout("opencityurl()",10);
}
function opencityurl(){
 var siteurl="http://www.evergreeniptv.com/mycity/"+city+"/";
 opennewsite(siteurl);
}
function setcolor(id){
 document.getElementById(id).style.background="#00CC00";
}
function changecolor(id){
document.getElementById(id).style.background="#339933";
}
function showsearchresult(){
 var ip=document.getElementById("ipsearchbox").value;var email=document.getElementById("emailsearchbox").value;var sdate=document.getElementById("startdatesearchbox").value;var edate=document.getElementById("enddatesearchbox").value;
 document.getElementById("newframe").src="showrecord.php?ip="+ip+"&email="+email+"&sdate="+sdate+"&edate="+edate;
}
function back(){
 self.location="index.php";
}
function callcheckPage(){
 var val=document.getElementById('hdn1').value;
 if(val=="1") self.location="channelowner.php";
 else return;
}
function Viewoption(uname){
 if(uname!=''){
 document.getElementById('user').style.visibility="visible";document.getElementById('logout').style.visibility="visible";
 }
 else self.location="index.php";
}
function adminlogout(pagename){
 document.getElementById('user').style.visibility="hidden";document.getElementById('logout').style.visibility="hidden";
 self.location=pagename+"?checkval=2";
}
function addchannel(){
 self.location="addchannel.php";
}
function calleditpage(val){
 self.location="editchannel.php?idval="+val;
}
function redirect(){
 self.location="index.php";
}
function showchnlresult(){
 var ip=document.getElementById("ipsearchbox").value;var email=document.getElementById("emailsearchbox").value;var sdate=document.getElementById("startdatesearchbox").value;var edate=document.getElementById("enddatesearchbox").value;var chnl=document.getElementById("chnl").value;
 document.getElementById("newframe").src = "showrecord.php?ip="+ip+"&email="+email+"&sdate="+sdate+"&edate="+edate+"&chnl="+chnl;
}
function settvvalue(channelno,swffile,checkval){
 if(checkval=='channel does not exist'){
  parent.check('','');
  return;
 }
 var hdnloginstatus=parent.parent.document.getElementById('userloginstatus').value;
 //var actualbalance=parent.document.getElementById('actualbalance').value;
 var channelnolength = channelno.length;
 var channelnumber=parseInt(channelno);
 if((channelnolength=="3") && (checkval=="free channel exist")){
  parent.check('free',swffile);
 }
 else if(channelnolength=='4'){
  if((channelnumber>=1000)&&(channelnumber<=4999)&&(hdnloginstatus=='true')&&(checkval=='2')) WriteToCookie('balance','yes');
  //else if((channelnumber>=1000)&&(channelnumber<=4999)&&(hdnloginstatus=='true')&&(actualbalance=='4')) WriteToCookie('balance','yes');
  else if((channelnumber>=5000)&&(channelnumber<=9999)&&(hdnloginstatus=='true')&&(checkval=='yes')) WriteToCookie('balance','yes');
  else if((channelnumber>=5000)&&(channelnumber<=9999)&&(hdnloginstatus=='true')&&(checkval=='no')) WriteToCookie('balance','');
  if((channelnumber>=1000)&&(channelnumber<=4999)) parent.Checkuser('registered',swffile,channelno,channelnolength);
  else if((channelnumber>=5000)&&(channelnumber<=9999)) parent.Checkuser('paytv',swffile,channelno,channelnolength);
 }
 else if(channelnolength=="5"){
  if((hdnloginstatus=='true')&&(checkval=='yes')){
	WriteToCookie('balance','yes');
   var returnvalue=payperviewconfirmation();
   if(returnvalue){
    parent.Checkuser('payperview',swffile,channelno,channelnolength);
    parent.document.getElementById("payperviewhdnframe").src="payperviewdeduct.php?channelno="+channelno;
   }
   else{
    parent.document.getElementById("startupdiv").style.zIndex = "10000";
    parent.document.getElementById("startupdiv").style.visibility = "visible";
    parent.document.getElementById("startupdiv").style.height = "350px";
   }
  }
  else if((hdnloginstatus=='true')&&(checkval=='no')){
   WriteToCookie('balance','');
   parent.Checkuser('payperview',swffile,channelno,channelnolength);
  }
  else parent.Checkuser('payperview',swffile,channelno,channelnolength);
 }
}
function payperviewconfirmation(){
 var agree=confirm('1RM will be deducted from your account if you view this channel');if (agree)return true ;else return false ;
}
function openselectedpage(pagename){
 self.location=pagename;
}
function addnewprogramme(){
 self.location="addprogramme.php";
}
function calladdprogrammecheckPage(){
 var val=document.getElementById('hdn1').value;
 if(val=="1") self.location="channelownertvprogramme.php";
 else return;
}
function showaddoreditprograme(controlname1,controlname2,controlname3,controlname4,controlname5,formname){
 if(formname=='frmaddprogramme'){
  var selectedchannel=document.getElementById(controlname1).options[document.getElementById(controlname1).selectedIndex].value;
  if(selectedchannel==''){
   alert("Channel number should not be blank");document.getElementById(controlname1).focus();return;
  }
 }
 var progdesc=document.getElementById(controlname2).value;
 progdesc=trim(progdesc);
 var progtime=document.getElementById(controlname3).value;
 progtime=trim(progtime);
 var progtimesuffix=document.getElementById(controlname4).options[document.getElementById(controlname4).selectedIndex].value;
 var progdate=document.getElementById(controlname5).value;
 var now=new Date();
 var hours=now.getHours();var minutes=now.getMinutes();var seconds=now.getSeconds();
 var timeValue="";
 if(hours<10) hours="0"+hours;
 timeValue+=hours;timeValue+=((minutes<10)?":0":":")+minutes;timeValue+=((seconds<10)?":0":":")+seconds;
 document.getElementById('hdn2').value=timeValue;
 if(progdesc==''){
  alert("Please put the Programme Description");document.getElementById(controlname2).focus();return;
 }
 else if(progtime==''){
  alert("Please put the Programme Time");document.getElementById(controlname3).focus();return;
 }
 else if(progtimesuffix==''){
  alert("Please select the Time Suffix");document.getElementById(controlname4).focus();return;
 }
 else if(progdate==''){
  alert("Please select the Programme Date");document.getElementById(controlname5).focus();return;
 }
 else{
  if(formname=='frmaddprogramme'){
   document.frmaddprogramme.submit();return;
  }
  else if(formname=='frmeditprogramme'){
   document.frmeditprogramme.submit();return;
  }
 }
}
function callprogrammeeditpage(val){
 self.location="editprogramme.php?idval="+val;
}
function setcontrolvalue(control1,control2){
 var val1=document.getElementById('hdn2').value;var val2=document.getElementById('hdn4').value;
 document.getElementById(control1).value=val1;document.getElementById(control2).value=val2;
}
function backtovod(pagename){
 document.getElementById("leftside2").src=pagename;
}
function setchannelcontrolvalue(control1){
 var val1=document.getElementById('hdn3').value;document.getElementById(control1).value=val1;
}
function precalltovod(){
 backtovod('videolist.php');return;
}
function openmmf(sitename){
 var features = 'fullscreen=yes,dialog=no,scrollbars=yes,resizable=no,menubar=no,toolbar=no,titlebar=no,status=no,location=no,personalbar=no,border=0,left=0,top=0';
 var mywindow = window.open(sitename,'mywin',features);
}
function divlayer(){
 with(window.parent.document){
  getElementById('blackdiv').style.zIndex="1";getElementById('blackdiv').style.visibility="hidden";
  //getElementById('startupdiv').style.visibility="hidden";getElementById('startupdiv').style.height="0px";
  getElementById('listdiv').style.zIndex="2800";
  //getElementById('videoplayer').style.zIndex="2500";
  getElementById("Flash").style.visibility="hidden";getElementById("Flash").style.height="0";
  getElementById('listdiv').style.visibility="visible";getElementById('listdiv').style.height="350px";
  //getElementById('videoplayer').style.visibility="hidden";getElementById('videoplayer').style.height="0px";
  getElementById('tvplayer').style.visibility="hidden";getElementById('tvplayer').style.height="0px";
 }
}
function openviewerregistrationpage(){
 self.location="selectviewer.php";
}
function opendealercategorypage(pagename){
 self.location=pagename;
}
function selectedregistrationpage(){
 var option=document.getElementById("selectcategory").options[document.getElementById("selectcategory").selectedIndex].value;
 if(option=='Viewer') document.getElementById("frame1").src="viewerregistration.php";
 else if(option=='Broadcuster') document.getElementById("frame1").src="broadcusterregistration.php";
}
function selectedmaintanancepage(){
 var option=document.getElementById("selectcategory").options[document.getElementById("selectcategory").selectedIndex].value;
 if(option=='Viewer') document.getElementById("frame1").src="viewermaintanance.php";
 else if(option=='Broadcuster') document.getElementById("frame1").src="broadcustermaintanance.php";
}
function callviewereditpage(val){
 self.location="vieweredit.php?idval="+val;
}
function callviewercheckPage(){
 var val=document.getElementById('hdn1').value;
 if(val=="1") self.location="viewermaintanance.php";
 else return;
}
function setcountryval(){
 var val=document.getElementById('countryval').value;
 document.getElementById("country").options.value=val;
}
function callbroadcustereditpage(val){
 self.location="broadcusteredit.php?idval="+val;
}
function callbroadcustercheckPage(){
 var val=document.getElementById('hdn1').value;
 if(val=="1") self.location="broadcustermaintanance.php";
 else return;
}
function setcountrycatdescriptionval(){
 var val1=document.getElementById('countryval').value;
 var val2=document.getElementById('categoryval').value;
 var val3=document.getElementById('chldescriptionval').value;
 document.getElementById("country").options.value=val1;
 document.getElementById("category").options.value=val2;
 document.getElementById("chldesc").value=val3;
}
function trim(str){
 var isTrimed=false;
 while((!isTrimed)&&(str!='')){
  if(str.charAt(0)==' '){
   str=str.substr(1);
  }
  else if(str.charAt(str.length-1)==' '){
   str=str.substr(0,str.length-1);
  }
  else{
   isTrimed=true;
  }
 }
 return str;
}
function checkinputforchannel(control1,control2,control3,control4,control5,control6,control7,formcontrol){
 var valid=true;
 var controlval1=document.getElementById(control1).value;
 var controlval2=document.getElementById(control2).value;
 var controlval3=document.getElementById(control3).value;
 var controlval4=document.getElementById(control4).value;
 var controlval5=document.getElementById(control5).value;
 var controlval6=document.getElementById(control6).value;
 var controlval7=document.getElementById(control7).options[document.getElementById(control7).selectedIndex].value;
 controlval2=trim(controlval2);
 controlval4=trim(controlval4);
 controlval5=trim(controlval5);
 controlval6=trim(controlval6);
 if(controlval1==''){
  if(formcontrol=='chlmaintainform'){
   alert('Please Select the Channel No');
   document.getElementById(control1).focus();
   valid=false;
   return;
  }
  else{
   controlval1=trim(controlval1);
	alert('Please put the Broadcaster IP');
   document.getElementById(control1).focus();
   valid=false;
   return;
  }
 }
 else if(controlval2==''){
  if(formcontrol=='chlmaintainform'){
   alert('Please put the Broadcaster IP');
   document.getElementById(control2).focus();
   valid=false;
   return;
  }
  else{
   alert('Please put the Broadcaster Port');
   document.getElementById(control2).focus();
   valid=false;
   return;
  }
 }
 else if(controlval3==''){
  if(formcontrol=='chlmaintainform'){
   controlval3=trim(controlval3);
	alert('Please put the Broadcaster Port');
   document.getElementById(control3).focus();
   valid=false;
   return;
  }
  else{
   alert('Please put the Channel No');
   document.getElementById(control3).focus();
   valid=false;
   return;
  }
 }
 else if(controlval4==''){
  alert('Please put the Channel Description');
  document.getElementById(control4).focus();
  valid=false;
  return;
 }
 else if(controlval5==''){
  alert('Please put the Broadcaster Username');
  document.getElementById(control5).focus();
  valid=false;
  return;
 }
 else if(controlval6==''){
  alert('Please put the Broadcaster Password');
  document.getElementById(control6).focus();
  valid=false;
  return;
 }
 else if(controlval7==''){
  alert('Please put the TV Broadcaster Group');
  document.getElementById(control7).focus();
  valid=false;
  return;
 }
 if(valid){
  addoreditnewchannel(formcontrol);
  return;
 }
 else return;
}
function addoreditnewchannel(formcontrol){
 if(formcontrol=='frmadd'){
  document.frmadd.submit();
  return;
 }
 else if(formcontrol=='frmedit'){
  document.frmedit.submit();
  return;
 }
 else if(formcontrol=='chlmaintainform'){
  document.chlmaintainform.submit();
  return;
 }
}
function checkchannelnoinput(control){
 var controlval=document.getElementById(control).options[document.getElementById(control).selectedIndex].value;
 controlval=trim(controlval);
 if(controlval==''){
  alert('Please Select the Channel No');
  document.getElementById(control).focus();
  return;
 }
 else return;
}
function adddealer(){
 self.location="adddealer.php";
}
function calladddealercheckPage(){
 var val=document.getElementById('hdn1').value;
 if(val=="1") self.location="administrativepage.php";
 else return;
}
function calldealereditpage(val){
 self.location="editdealer.php?idval="+val;
}
function setcountrystatusval(){
 var val1=document.getElementById('hdn2').value;
 var val2=document.getElementById('hdn3').value;
 document.getElementById("country").options.value=val1;
 document.getElementById("dealerstatus").options.value=val2;
}
function checkTvStreamingStatus(chllen,chlno){
 parent.itv.stop();
 var channelno=chlno;
 var chlnumber=parseInt(chlno);
 var idval=document.getElementById('hdnidval').value;
 var flashfile=document.getElementById('hdnflashfile').value;
 parent.document.getElementById('blackdiv').style.zIndex="1";parent.document.getElementById('blackdiv').style.visibility="hidden";
 if(chllen=="4"){
  if((chlnumber>=1000)&&(chlnumber<=4999)) alert("You need to be a registered user to enjoy watching these channels !");
  else if((chlnumber>=5000)&&(chlnumber<=9999)) alert("If you are a registered user please login and enjoy watching registered channels and if you want to watch the paytv please check account your balance in www.rh-mbc.com or ask your dealer to top up for u to continue....");
 }
 else if(chllen=="5") alert("You need to be a registered user to enjoy watching these channels !\nIf you are a registered user please login and enjoy watching registered channels and if you want to watch the Pay Per View please check account your balance in www.rh-mbc.com or ask your dealer to top up for you to continue....");
 parent.document.getElementById('list').src="login.php?val="+idval+"&flashfile="+flashfile+"&channelno="+channelno;
 return;
}
function openSiteByLinkClick(siteidentifier){
 if(document.getElementById("itv")){
 if(document.getElementById("itv").src!="itvframe.php"){
   document.getElementById("itv").src = "itvframe.php";
   document.getElementById("itv").style.height="0px";
  }
 }
 var switchingwindow;
 var features = 'fullscreen=yes,scrollbars=yes,resizable=no,status=no,addressbar=no,toolbar=no,titlebar=no,location=no,border=0,left=0,top=0';
 itv.stop();
 with(document){
   getElementById('startupdiv').style.visibility="hidden";getElementById('startupdiv').style.height="0px";
   getElementById('blackdiv').style.zIndex="1";getElementById('blackdiv').style.visibility="hidden";
   getElementById('Layer2').style.visibility = "hidden";
   getElementById('listdiv').style.zIndex="2800";getElementById('videoplayer').style.zIndex="2500";
   getElementById("Flash").style.visibility="hidden";getElementById("Flash").style.height="0";
   getElementById('videoplayer').style.visibility="hidden";getElementById('videoplayer').style.height="0px";
   getElementById("videoplayeriframe").src = "videoplayer.php";
   getElementById('tvplayer').style.visibility="hidden";getElementById('tvplayer').style.height="0px";
   getElementById('listdiv').style.visibility="visible";getElementById('listdiv').style.height="350px";
   getElementById("list").src="blankpage.html";
  }
 if(siteidentifier=="desktop"){
  itv.stop();
  with(document){
   getElementById('startupdiv').style.visibility="hidden";getElementById('startupdiv').style.height="0px";
   getElementById('blackdiv').style.zIndex="1";getElementById('blackdiv').style.visibility="hidden";
   getElementById('listdiv').style.zIndex="2800";getElementById('videoplayer').style.zIndex="2500";
   getElementById("Flash").style.visibility="hidden";getElementById("Flash").style.height="0";
   getElementById("flashimg").src="blankpage.html";
   getElementById('videoplayer').style.visibility="hidden";getElementById('videoplayer').style.height="0px";
   getElementById("videoplayeriframe").src = "videoplayer.php";
   getElementById('tvplayer').style.visibility="hidden";getElementById('tvplayer').style.height="0px";
   getElementById('listdiv').style.visibility="visible";getElementById('listdiv').style.height="350px";
   getElementById("list").src="blankpage.html";
  }
  var winleft = ReadFromCookie('winleft');
  var wintop =  ReadFromCookie('wintop');
  var winwidth = ReadFromCookie('winwidth');
  var winheight = ReadFromCookie('winheight');
  if((winleft != '')){
    switchingwindow = window.open ("desktop/indexpopup.php","mywindow","top="+wintop+",left="+winleft+",scrollbars=0,resizable=1,width="+winwidth+",height="+winheight);
  }else{
    switchingwindow = window.open ("desktop/indexpopup.php","mywindow","top=150,left=400,scrollbars=0,width=265,resizable=1,height=445");
  }
  return;
 }
 else if(siteidentifier=="couch"){
  switchingwindow=window.open("couch/","couch",features);
  return;
 }
}

function setuploadbox(controlname,controlname2){
 var selectedcat=document.getElementById(controlname).options[document.getElementById(controlname).selectedIndex].value;
 if(selectedcat=='news' || selectedcat=='Features'){
  document.getElementById("uploadtd").innerHTML='<input type="text" name="'+controlname2+'" id="'+controlname2+'" size="32">';
  document.getElementById("headingtd").innerHTML='Welcome To Video URL Uploading Page';
 }
 else{
  document.getElementById("uploadtd").innerHTML='<input type="file" name="'+controlname2+'" id="'+controlname2+'" >';
  document.getElementById("headingtd").innerHTML='Welcome To Video Uploading Page';
 }
}

function playitvforlogo(){
  if(content.blackdiv) content.ChangeChannel('618');
  else{
     document.getElementById('content').src='iframe2.php';
     setTimeout("playitvforlogo1()",10000);
  }
}
function playitvforlogo1(){
  if(content.blackdiv) content.ChangeChannel('618');
}
