



//*************************************************

// File Name     : JS/validation.js
// Created       : 5 Feb 2009 (LuYen) - New : Include all the JS function 
// Last Modified :

//*************************************************


function showVote(option)
{



    if(option =="RESULT")
		{
			document.getElementById('voteresult').style.display = "block";
			document.getElementById('voteques').style.display = "none";
			
    }
    if(option =="VOTE2")
    {

		document.getElementById('voteresult2').innerHTML='';
		document.getElementById('voteques').style.display = "block";
		document.getElementById('voteresult').style.display = "none";
		document.getElementById('votebtnresult2').style.display = "none";
		document.getElementById('errPoll').style.display="none";
    }

    for (var i=0; i<document.pollform.chkbox.length; i++)
	{
		document.pollform.chkbox[i].checked = false;
	}

}


function submitPoll()
{

   chkOption = -1;

    for (i=document.pollform.chkbox.length-1; i > -1; i--)
    {
        if (document.pollform.chkbox[i].checked)
        {
            chkOption = i;
            i = -1;

        }
    }
    if (chkOption == -1)
    {

        document.getElementById('errPoll').style.display="inline";
        return false;

    }


		 if(window.XMLHttpRequest)
		 {
				objRequest = new XMLHttpRequest();
		 }
		 else if(window.ActiveXObject)
		 {
				objRequest = new ActiveXObject("Microsoft.XMLHTTP");
		 }

		 objRequest.open("POST", "../update_process.asp", true);
		 objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 objRequest.send("act=submitPoll&pollid="+document.pollform.hiddenPollID.value +"&pollvalue=" +document.pollform.hiddenRadioVal.value);
         	 objRequest.onreadystatechange = UpdateCheckAvailability;
          	 document.getElementById('pollwaiting').innerHTML = '<img id="submitImage" name="submitImage" src="images/msgLoading.gif" alt="Waiting.." width="16px;" height="16px;"> Waiting..';


}


function UpdateCheckAvailability()
{


	if(objRequest.readyState == 4)
	{
		if(objRequest.status == 200)
		{
			 	var ab =objRequest.responseText;

			 	var absplit = ab.split("-");
				var ab1=absplit[0];
        		var ab2=absplit[1];

			 if(ab1==1)
    		 {

				 document.getElementById('voteresult2').innerHTML = ab2;
				 document.getElementById('voteques').style.display = "none";
				 document.getElementById('votebtnresult2').style.display = "block";
				 document.getElementById('pollwaiting').innerHTML='';

    		 }
		}
	}

}

function showResult()
{

	if(window.XMLHttpRequest)
	{
		objRequest = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		objRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
		objRequest.open("POST", "../update_process.asp", true);
		objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objRequest.send("act=showPoll");		
	        objRequest.onreadystatechange = UpdateCheckAvailability2;
	        document.getElementById('pollwaiting').innerHTML = '<img id="submitImage" name="submitImage" src="../images/msgLoading.gif" title="Waiting.." width="16px;" height="16px;"> Waiting..';
			
}

function UpdateCheckAvailability2()
{


	if(objRequest.readyState == 4)
	{
		if(objRequest.status == 200)
		{
			 	var ab =objRequest.responseText;
			 	var absplit = ab.split("-");
				var ab1=absplit[0];
				var ab2=absplit[1];
				
				
			 if(ab1==1)
			 {
			 	document.getElementById('voteresult2').innerHTML = ab2;
			 	document.getElementById('voteques').style.display = "none";
				document.getElementById('votebtnresult2').style.display = "block";
				document.getElementById('pollwaiting').innerHTML='';
			 }
			 	
		}
	}

}



function assignRadio(radioVal)
{
	document.pollform.hiddenRadioVal.value=radioVal;
	document.getElementById('errPoll').style.display="none";

}

function checkMail()
{
	document.getElementById('errEmail1').style.display="none";
	document.getElementById('errName').style.display="none";
	document.getElementById('errEmail2').style.display="none";
	document.getElementById("invalidemailformat").style.display = 'none';
	document.getElementById("invalidemailformat2").style.display = 'none';
	document.getElementById("sameEmail").style.display = 'none';
	
	var error= false;
	
   
   
	if(document.frm_recommend.recipientEmail.value =="")
	{
		document.getElementById('errEmail1').style.display="inline";
		document.frm_recommend.recipientEmail.focus();
		return false;
		error =true;
	}
	
	if(!checkEmail(document.frm_recommend.recipientEmail.value))
		{
			document.getElementById('invalidemailformat').style.display="inline";
			document.frm_recommend.recipientEmail.focus();
			return false;
			error =true;
		
		}

	
	

	if(document.frm_recommend.senderName.value =="")
	{
			document.getElementById('errName').style.display="inline";
			document.frm_recommend.senderName.focus();
			return false;
			error =true;
	}

	if(document.frm_recommend.senderEmail.value =="")
	{
			document.getElementById('errEmail2').style.display="inline";
			document.frm_recommend.senderEmail.focus();
			return false;
			error =true;
	}
	
	if(!checkEmail(document.frm_recommend.senderEmail.value))
	{
				document.getElementById('invalidemailformat2').style.display="inline";
				document.frm_recommend.senderEmail.focus();
				return false;
				error =true;
			
	}
	
	
   	 
   	 if(document.frm_recommend.recipientEmail.value == document.frm_recommend.senderEmail.value)
   	 {
   	 	document.getElementById("sameEmail").style.display = 'inline';
		document.frm_recommend.senderEmail.focus();
		error =true;
		return false;
   	 
   	 }
	
	if(error ==true);
	{
		document.getElementById('Submit').value='Sending..';
  		document.getElementById('Submit').disabled=true;
		document.frm_recommend.action ="update_process.asp?act=SENDFRIEND";
		//alert(document.frm_recommend.action)
		document.frm_recommend.submit();

	}
}


function CheckJoin()
{
	var error =false;
	document.getElementById('errEmptyUser').style.display="none";
	document.getElementById('errEmptyPassword').style.display="none";
	
	document.getElementById("errInvalidLogin").style.display = "none";
    	
	
	if (document.FrmJoinGroup.txtUserID.value =="")
	{
	
		document.getElementById('errEmptyUser').style.display="inline";
		document.FrmJoinGroup.txtUserID.focus();
		
		error =true;
	}
	
	else if(document.FrmJoinGroup.txtPassword.value =="")
	{
		document.getElementById('errEmptyPassword').style.display="inline";
		document.FrmJoinGroup.txtPassword.focus();
		
		error =true;
	}
	else if ((document.FrmJoinGroup.txtUserID.value!="") && (document.FrmJoinGroup.txtPassword.value!=""))	
	{
		if(window.XMLHttpRequest)
		{
			oRequest = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
			oRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		 
		oRequest.open("POST", "../update_process.asp", true);
           	oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
           	oRequest.send("act=JOIN&userid=" + document.FrmJoinGroup.txtUserID.value + "&password=" + document.FrmJoinGroup.txtPassword.value);
            	oRequest.onreadystatechange = UpdateCheckJoin;
            	//alert("act=LOGIN&userid=" + document.FrmJoinGroup.txtUserID.value + "&password=" + document.FrmJoinGroup.txtPassword.value);
		document.getElementById('waitingJoinImage').innerHTML = '<img src="images/msgloading.gif" alt="Waiting.." width="16px;" height="16px;"> Waiting..';

	}


}


function UpdateCheckJoin()
{


    document.getElementById("errInvalidLogin").style.display = "none";
    document.getElementById("errMemberExist").style.display="none";
    
  
    
    if(oRequest.readyState == 4)
    {
    if(oRequest.status == 200)
    {
         var ab =oRequest.responseText;
         var error =0;

        if(ab==1)
           {
                  error=0;
            }

         if(ab==2)
            {
                 document.getElementById("errInvalidLogin").style.display = 'inline';
                 document.getElementById('waitingJoinImage').innerHTML='';
                 error =1;
            }
         if(ab==4)
	  {
	            document.getElementById("errMemberExist").style.display = 'inline';
	            document.getElementById('waitingJoinImage').innerHTML='';
	            error =1;
          }
         if(ab==3)
	  {		window.location.href="../index.asp";	
	  	       //document.getElementById("ErrorNewMember").style.display = 'inline';
	  	       error =1;
          }
         

    }
    }
}


function ResetVal()
{
	document.FrmMemberLogin.txtUserID.value =="";
	document.FrmMemberLogin.txtPassword.value =="";
	document.getElementById('ErrorUserID').style.display="none";
	document.getElementById('ErrorNoPass').style.display="none";
	document.getElementById("invaliduserlogin").style.display = "none";
    	document.getElementById("ErrorNotGroupMember").style.display = 'none';
	

}


function CheckMemberLogin()
{
	var error =false;
	document.getElementById('ErrorUserID').style.display="none";
	document.getElementById('ErrorNoPass').style.display="none";
	document.getElementById("invaliduserlogin").style.display = "none";
	document.getElementById("ErrorNotGroupMember").style.display = "none";
	
	
	if (document.FrmMemberLogin.txtUserID.value =="")
	{

		document.getElementById('ErrorUserID').style.display="inline";
		document.FrmMemberLogin.txtUserID.focus();
		return false;
		error =true;
	}

	if(document.FrmMemberLogin.txtPassword.value =="")
	{
		document.getElementById('ErrorNoPass').style.display="inline";
		document.FrmMemberLogin.txtPassword.focus();
		return false;
		error =true;
	}
	if(error ==false)
	{
		
		if(window.XMLHttpRequest)
		{
		      oRequest = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
		      oRequest = new ActiveXObject("Microsoft.XMLHTTP");
             	}
		
		
		oRequest.open("POST", "update_process.asp", true);
		oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oRequest.send("act=MainLogin&strusername=" + document.FrmMemberLogin.txtUserID.value+ "&strpassword="+document.FrmMemberLogin.txtPassword.value);
		//alert("act=MainLogin&username=" + document.FrmMemberLogin.txtUserID.value+ "&password="+document.FrmMemberLogin.txtPassword.value);
           	oRequest.onreadystatechange = UpdateCheckAvailability3;
		
	}

}

function UpdateCheckAvailability3()
{
	document.getElementById('ErrorUserID').style.display="none";
	document.getElementById('ErrorNoPass').style.display="none";
	document.getElementById("invaliduserlogin").style.display = "none";
	document.getElementById("ErrorNotGroupMember").style.display = "none";
	
	
	if(oRequest.readyState == 4)
	 {
	    if(oRequest.status == 200)
	     {
				ab=oRequest.responseText;
				
				
				if(ab==1)
				{
					window.location.href=document.FrmMemberLogin.hiddenurl.value;
				                  error=0;
				 }
				 if(ab==2)
				            {
				                document.getElementById("invaliduserlogin").style.display = "inline";
				                document.getElementById('waitingLoginImage').innerHTML='';
				                 error =1;
				            }
				          if(ab==4)
							 {
				
							      document.getElementById("ErrorNotGroupMember").style.display = "inline";
							      document.getElementById('waitingLoginImage').innerHTML='';
							      error =1;
				            }


	      }
          
         }


}



function checkComment(option)
{
	document.getElementById('emptySenderName').style.display="none";
	document.getElementById('emptyMessage').style.display="none";
	var errorempty=false;

	if(document.frm_comment.txtSenderName.value=="")
	{
		document.getElementById('emptySenderName').style.display="inline";
		document.frm_comment.txtSenderName.focus();
		return false;
		errorempty=true;
	
	}
	if(document.getElementById('selMessage').value=="")
	{
	
		document.getElementById('emptyMessage').style.display="inline";
		document.getElementById('selMessage').focus();
		return false;
		errorempty=true;
	}
	if(errorempty==false)
	{
		if(option =="PhotoComment")
		{
			document.frm_comment.action="../update_process.asp?act=SubmitPhotoComment"
			document.frm_comment.submit();
		}
		if(option =="BlogComment")
		{
			document.frm_comment.action="../update_process.asp?act=SUBMITBLOGCOMMENT"
			document.frm_comment.submit();
		
		}
		if(option =="VideoComment")
		{
			document.frm_comment.action="../update_process.asp?act=SubmitVideoComment"
			document.frm_comment.submit();
				
		}
		
	
	}
}




function gotoLogout()
{
	
	window.location.href="logout.asp";	
	document.getElementById('logoutImage').innerHTML = '<img src="images/msgloading.gif" alt="Waiting.." width="16px;" height="16px;"> Waiting..';

}

function checkEmail(email) 
{
//var regExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
var regExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return regExp.test(email);
}