
nowid = new Array();
allid = new Array();

function   showdiv(allnumber,currentid,divname)
{
       var  currentdivname;
       for (fromid=1;fromid<=allnumber;fromid++)
	   {
	       currentdivname = divname + fromid;
		   currenthrefname = divname + "a" +fromid;
		  
		   if (fromid==currentid)
		   {
		  
			 document.getElementById(currentdivname).style.display="";
		  	 var tmp =  document.getElementById(currenthrefname);  
			
			 tmp.setAttribute("className", "p_curpage") ;
			  tmp.setAttribute("class", "p_curpage") ;
			}
		   else
		   {
		      document.getElementById(currentdivname).style.display="none";
			  var tmp =  document.getElementById(currenthrefname);  
			 tmp.setAttribute("className", "p_num");  	
			 tmp.setAttribute("class", "p_num"); 
		   }
		  
	   }
	   
	  nowid[divname]=currentid;
} 


function  pagenext(divname)
{
    
    if  (parseInt(nowid[divname])< parseInt(allid[divname]))
	
	{
	   
	  var currentid = parseInt(nowid[divname]) + 1;
	
	   showdiv( allid[divname],currentid,divname)
	}
	

}

function  pagepre(divname)
{

 if  (parseInt(nowid[divname])>1)
	
	{
	  var  currentid = parseInt(nowid[divname]) - 1;
	   showdiv( allid[divname],currentid,divname)
	}
	
	
}

function  showpages(allnumber,divname)
{

  // alert("aa");
      document.write('<a class="p_redirect"  style="cursor:pointer"  onclick="pagepre('+ "'"+ divname + "'" +')">&laquo;</a>');
      document.write('<a  style="cursor:pointer"  id="'+divname+ 'a1"  onclick="showdiv('+allnumber+',1,' + "'"+divname+ "'"+ ')" class="p_curpage">1</a>');
       for (fromid=2;fromid<=allnumber;fromid++)
 
   {
    
       document.write('<a  style="cursor:pointer" id="'+divname+ 'a' +fromid+ '"   onclick="showdiv('+allnumber+','+ fromid +','+"'"+divname+"'"+')" class="p_num">'+fromid+'</a>');
   }
   
    document.write('<a  style="cursor:pointer" class="p_redirect" onclick="pagenext('+ "'"+ divname + "'" +')" >&raquo;</a>');

    nowid[divname]=1;
	allid[divname]=allnumber;
	 
	
} 

function checkdata()
{
	
	
	  //   alert("aa")
	
	     var process_request = "Operation in process...";
         var username_empty = "Username can not be empty.";
         var realname_empty = "Real name can not be empty.";
        var username_shorter = "Please input a username with at least three characters.";
        var username_invalid = "Username is formed by English letters, numbers and underline only.";
        var password_empty = "Password can not be empty.";
        var password_shorter = "Password is too short, please input a password with at least six characters.";
        var confirm_password_invalid = "Passwords you input are inconsistent.";
        var email_empty = "Email address can not be empty.";
        var email_invalid = "Invalid Email address";
        var msg_un_blank = "* Username can not be empty.";
        var msg_un_length = "* Please input a username with 14 characters at most.";
        var msg_un_format = "* Sorry, username contains illegal characters.";
        var msg_un_registered = "* This username has been taken, please choose another one.";
        var msg_email_blank = "* Email address can not be empty.";
        var msg_email_registered = "* This email address is already in use, please choose another one.";
        var msg_email_format = "* Invalid Email address";

  var frm  = document.forms['register'];
  var username  =(frm.elements['username_register'].value);
  var email  = (frm.elements['email_register'].value);
  var password  = (frm.elements['password_register'].value);
  var confirm_password =(frm.elements['confirmpassword_register'].value);
  var msg = "";
  var msg = '';
   if (email.length == 0)
   {
    msg += email_empty + '\n';
   }
  else  
  {
       var regmm = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
       var ismail  = false;
	   ismail=regmm.test( email )
	   if (ismail==false)
	   {
	     // msg += email_invalid + '\n';
	   }
  }
  
  if (username.length == 0)
  {
    msg += username_empty + '\n';
  } 
  else if (username.match(/^\s*$|^c:\\con\\con$|[%,\'\*\"\s\t\<\>\&\\]/))
  {
    msg += username_invalid + '\n';
  }
  else if (username.length < 3)
  {
    msg += username_shorter + '\n';
  }

  if (password.length == 0)
  {
    msg += password_empty + '\n';
  }
  else if (password.length < 6)
  {
    msg += password_shorter + '\n';
  }
  if (confirm_password != password )
  {
    msg += confirm_password_invalid + '\n';
  }

  if (msg.length > 0)
  {
    alert(msg);
    return false;
  }
  else
  {
    return true;
  }
}
 function  getvote(movie)
{
      var url =  "/getstars.php?code=5|"+movie;
	
      sendurl(url,"processReqsub")
	 //sendurl(url2,"processReqsub1")
   
 }


function sendurl(url,subname)
{
	if (window.XMLHttpRequest){  
		xmlhttp   =   new   XMLHttpRequest();  
		xmlhttp.onreadystatechange   =   eval(subname);  
		xmlhttp.open("GET",   url,   true);
		xmlhttp.send(null);
	}   else   if   (window.ActiveXObject)   {
		isIE   =   true;  
		xmlhttp   =   new   ActiveXObject("Microsoft.XMLHTTP");  
		if   (xmlhttp){  
		xmlhttp.onreadystatechange   =   eval(subname);  
		xmlhttp.open("GET",   url,   true);  
		xmlhttp.send();  
		}  
	}   
}



 
 function  processReqsub()   {
	var error = '';
	//alert(xmlhttp.readyState);
	if  (xmlhttp.readyState   ==   4)   {  
	//alert(xmlhttp.responseText);
		if   (xmlhttp.status   ==   200)   {  
			error = xmlhttp.responseText;
			
			
			rs =  error.split('|')
			
			
				 
			 document.getElementById("votestars").innerHTML =rs[3];
		     document.getElementById("votenumber").innerHTML =rs[2];
			
		}
	}  
 }
 
 
 function  showdv(dv1,dv2)
{
	document.getElementById(dv1).style.display="";  
	document.getElementById(dv2).style.display="none";  
}
function  dovotethink(num)
{
   for( i=1 ;i<=num;i++ )
   {
        var cc= "img"+i;
		//alert(cc);
		document.getElementById(cc).src="/templates/default/images/vote1.png";
   }
   t =num+1
   
   for( i=t ;i<=5;i++ )
   {
	  // alert(cc);
        var cc= "img"+i;
		document.getElementById(cc).src="/templates/default/images/vote3.png";
   }
   
}


function vote(num,movid,username)



 {
	   if (username=="")
	   {
		    alert("Please sign in");     
	   }
	   else
	  {
    	var url = '/getstars.php?action=send&votepoint='+num+'&movid='+movid+'&username='+username;
		
		sendurl(url,"dovote");
      }
 }
 
 function  dovote()   {
	var error = '';
	
	if  (xmlhttp.readyState   ==   4)   {  
	
		if   (xmlhttp.status   ==   200)   {  
			error = xmlhttp.responseText;
			
			rs =  error.split('|')
			
			if (rs[0] == 201)
			{
				  document.getElementById("votenumber").innerHTML =rs[2];
				  document.getElementById("votestars").innerHTML =rs[3];
				  alert('Rating succeeded, thanks for your participation!');
			}
			else if (rs[0] == 500)
			{
				
				alert('You have rated this movie, thanks for your participation!');
				//document.getElementById('vodcms').style.display = 'none'
			}
			
		}
	}  
 } 
 function submitcomment(movid,username)
 {
	var  amt = document.getElementById("content").value;
	//alert(amt);
	if (amt=="" || amt.length<3 || amt.length>500 )
	{
	   alert("The length of comments must be 3 to 500 charaters.");	
	   return false;
	}
	
	document.getElementById("content").value="";
	var url ='/getcomment.php?action=send&content='+amt+'&movid='+movid+'&username='+username;
	sendurl(url,"savecomment");
 }
 
 function  savecomment()   {
	var error = '';
     
	if  (xmlhttp.readyState   ==   4)   {  
	
		if   (xmlhttp.status   ==   200)   {  
			error = xmlhttp.responseText;
            if (error==202)
			{
				  alert("Please sign in");
			}
			else
			{
			rs =  error.split('%=+=%')
			//alert(error);
			if (rs[0] == 201)
			
			  {
                var tmp ='<table width="100%" cellpadding="0" cellspacing="0">';
				var num  =  rs.length;
				//alert(num);
				for(i=3;i<num-1;i++)
				{
				    var us=rs[i].split('*|=*');
				   
                   tmp =  tmp + '<tr><td><table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" style=" border:1px dotted #CCCCCC" class="s"><tr><td valign="middle" bgcolor="#F7F7F7"><strong> '+ us[1] +'</strong>&nbsp;&nbsp;'+ us[3] +'</td><td width="7%" bgcolor="#F7F7F7">#'+ us[4] +'</td></tr><tr><td colspan="2" valign="middle" bgcolor="#FFFFFF">'+ us[2] +'</td></tr></table></td></tr>';
                }
				tmp =  tmp + '</table>';
				//alert(tmp);
                  //document.getElementById("comttt").innerHTML = "aa";
				 document.getElementById("clist").innerHTML =tmp;
				 document.getElementById("pg").innerHTML =rs[1];
				  document.getElementById("ctotal").innerHTML = '<STRONG>Comments</STRONG>(<span style="color:red">'+rs[2] +'</span>)';
				pg = "ok";
				
			  }
			}
		}
	}  
 } 
 
 function gopage(page,movid)
 {
	
	var url ='/getcomment.php?page='+page+'&movid='+movid;
	sendurl(url,"savecomment");
 }
  function dopage(movid)
 {
      page = document.getElementById("custompage").value;
	  //alert(page+"--"+movid);
      gopage(page,movid);
 }
 
 function  dopage(movid)
 {
     gopage(1,movid);
     dowait(movid)
 }
 function dowait(movid)
			{
			  
				   if(pg=="ok")
				   { 
				       getvote(movid);
				   }
				   else
				   {
				       setTimeout("dowait("+movid+") ",100);
				   }
			}
			
function  addwishlist(movid)
{
	var url='/addwishlist.php?action=send&movid='+movid;
	sendurl(url,"dowishlist");
	
}

function  dowishlist()   {
	var error = '';
	
	if  (xmlhttp.readyState   ==   4)   {  
		if   (xmlhttp.status   ==   200)   {  
			error = xmlhttp.responseText;
			rs =  error.split('|')
			
			if (rs[0] == 201)
			{
				alert('Succeeded!');
			}
			else if (rs[0] == 500)
			{
				
				alert('Already subscribed!');
			
			}
			else if (error==202)
			{
				  alert("Please log in");
			}
			
		}
	}  
 } 
 function   reporterr(movid)
 
{
	window.open('/reporterr.php?movid='+movid);
	
	}
