﻿// JScript File

function validateDOB()
{
    var tdMsg,drpMonth, drpDate, drpYear;
    var txtClientID = document.getElementById("RegClientID").value;
    
    drpMonth=document.getElementById(txtClientID+"drpMonth");
    //alert("drpMonth:"+drpMonth);
    drpDate=document.getElementById(txtClientID+"drpDate");
    //alert("drpDate:"+drpDate);
    drpYear=document.getElementById(txtClientID+"drpYear");
    
    if(drpMonth.value==0)
    {
        tdMsgDOB.innerHTML="Month is Required"
        drpMonth.focus();
        return false;
    }
    
    if(drpDate.value==0)
    {
        tdMsgDOB.innerHTML="Day is Required"
        drpDate.focus();
        return false;
    }
    
    if(drpYear.value==0)
    {
        tdMsgDOB.innerHTML="Year is Required"
        drpYear.focus();
        return false;
    }
     
    if(drpMonth.value==2 || drpMonth.value==4 || drpMonth.value==6 || drpMonth.value==9 || drpMonth.value==11)
    {
        if(drpDate.value>30)
        {
            tdMsgDOB.innerHTML="Invalid Date"
            drpDate.focus();
            return false;
        }
        if( drpMonth.value==2 && drpDate.value>28)
        {
            tdMsgDOB.innerHTML="Invalid Date"
            drpDate.focus();
            return false;
        }
    }
 }
  


function Registration()
{
    var txtUsrName, txtPass, txtConfirmPass, drpSecurityQue, txtAns,  drpMonth, drpDate, drpYear,txtZip,txtHumanVer,Chkterms;
    var txtProfileUrl;
    var tdMsg, tdMsgEmail,tdMsgPswd,tdMsgPswdConfirm,tdMsgDisplayName,tdMsgQuestion,tdMsgAnswer,tdMsgDOB,tdMsgZip,tdMsgVerCode,tdMsgTerms;
    var tdMsgConfirm, tdMsgVerify;
    var txtClientID = document.getElementById("RegClientID").value;

    txtUsrName=document.getElementById(txtClientID+"txtUsrName");
    //alert("txtUsrName:"+txtUsrName);
    txtPass=document.getElementById(txtClientID+"txtPass");
    //alert("txtPass:"+txtPass);
    txtConfirmPass=document.getElementById(txtClientID+"txtConfirmPass");
    //alert("txtConfrimPass:"+txtConfirmPass);
    drpSecurityQue=document.getElementById(txtClientID+"drpSecurityQue");
    //alert("drpSecurityQue:"+drpSecurityQue);
    txtAns=document.getElementById(txtClientID+"txtAns");
    //alert("txtAns:"+txtAns);
    drpMonth=document.getElementById(txtClientID+"drpMonth");
    //alert("drpMonth:"+drpMonth);
    drpDate=document.getElementById(txtClientID+"drpDate");
    //alert("drpDate:"+drpDate);
    drpYear=document.getElementById(txtClientID+"drpYear");
    //alert("drpYear:"+drpYear);
    txtZip=document.getElementById(txtClientID+"txtZip");
    //alert("txtZip:"+txtZip);
    txtHumanVer=document.getElementById(txtClientID+"txtHumanVer");
    //alert("txtHumanVer:"+txtHumanVer);
    Chkterms=document.getElementById(txtClientID+"Chkterms");
    //alert("Chkterms:"+Chkterms);
    tdMsg=document.getElementById("tdMsg");
    //alert("tdMsg:"+tdMsg);
    tdMsgEmail=document.getElementById("tdMsgEmail");
    //alert("tdMsgEmail:"+tdMsgEmail);
    tdMsgPswd=document.getElementById("tdMsgPswd");
    //alert("tdMsgPswd:"+tdMsgPswd);
    tdMsgConfirm=document.getElementById("tdMsgConfirm"); 
    tdMsgPswdConfirm=document.getElementById("tdMsgPswdConfirm"); 
    //alert("tdMsgPswdConfirm:"+tdMsgPswdConfirm);
    tdMsgDisplayName=document.getElementById("tdMsgDisplayName"); 
    //alert("tdMsgDisplayName:"+tdMsgDisplayName);
    tdMsgQuestion=document.getElementById("tdMsgQuestion"); 
    //alert("tdMsgQuestion:"+tdMsgQuestion);
    tdMsgAnswer=document.getElementById("tdMsgAnswer"); 
    //alert("tdMsgAnswer:"+tdMsgAnswer);
    tdMsgDOB=document.getElementById("tdMsgDOB"); 
    //alert("tdMsgDOB:"+tdMsgDOB);
    tdMsgZip=document.getElementById("tdMsgZip"); 
    //alert("tdMsgZip:"+tdMsgZip);
    tdMsgVerCode=document.getElementById("tdMsgVerCode");
    tdMsgVerify=document.getElementById("tdMsgVerify");
    //alert("tdMsgVerCode:"+tdMsgVerCode);
    tdMsgTerms=document.getElementById("tdMsgTerms");  
    //alert("tdMsgTerms:"+tdMsgTerms);
    txtProfileUrl=document.getElementById(txtClientID+"txtProfileUrl");
    //alert("txtProfileUrl:"+txtProfileUrl);

    tdMsg.innerHTML="";
    tdMsgEmail.innerHTML="";
    tdMsgPswd.innerHTML="";
    tdMsgConfirm.innerHTML="";
    tdMsgPswdConfirm.innerHTML="&nbsp;";
    tdMsgDisplayName.innerHTML="";
    tdMsgQuestion.innerHTML="";
    tdMsgAnswer.innerHTML="";
    tdMsgZip.innerHTML="";
    if(tdMsgDOB != null){ //if the user is MODIFING his/her account this will be NULL
        tdMsgDOB.innerHTML="";
        tdMsgVerCode.innerHTML="";
        tdMsgVerify.innerHTML="&nbsp;";
        tdMsgTerms.innerHTML="";
    }
//    txtProfileUrl.innerHTML="";

  	if (txtUsrName.value=="")
	{		 
		tdMsgEmail.innerHTML="Required"
		txtUsrName.focus();
		return false;
	}

	var str = txtUsrName.value;   
	if (str.length<=5)
	{
		tdMsgEmail.innerHTML="Invalid Format"
		txtUsrName.focus();
		return false;
	}
	
	var mail = txtUsrName.value;
	if (mail == "")
	{
		tdMsgEmail.innerHTML="Required"
		txtUsrName.focus();
		return false;
	}

	if (mail.indexOf("@")== -1)
	{
		tdMsgEmail.innerHTML="Invalid Format"
		txtUsrName.select();
		txtUsrName.focus();
		return false;
	}

	if (mail.indexOf(".")== -1)
	{
		tdMsgEmail.innerHTML="Invalid Format"
		txtUsrName.select();
		txtUsrName.focus();
		return false;
	}

	var aa=0;
	var bb=0;
	var cc=0;
	var td="";
	for (j =0 ; j<mail.length ;j++)
	{
		if(mail.charAt(j) =="@")
		{
		    aa=j;
		    cc=cc+1;
			    if ((aa==0) || (cc>1)){
				    tdMsgEmail.innerHTML="Invalid Format"
				    txtUsrName.select();
				    txtUsrName.focus();
				    return false;
			    }
		}else if(mail.charAt(j)==".")
		{
		    bb=j;
		    td=td+mail.charAt(j);
			    if(td=="..")
			    {
				    tdMsgEmail.innerHTML="Invalid Format"
				    txtUsrName.select();
				    txtUsrName.focus();
				    return false;
			    }
			    if (bb==0)
			    {
				    tdMsgEmail.innerHTML="Invalid Format"
				    txtUsrName.select();
				    txtUsrName.focus();
				    return false;
			    }
		}else
		{
			td="";
		}
	} //end for loop
	if (aa == mail.length-1)
	{
	    tdMsgEmail.innerHTML="Invalid Format"
		txtUsrName.select();
		txtUsrName.focus();
		return false;
	}
	if (bb == mail.length-1)
	{
		tdMsgEmail.innerHTML="Invalid Format"
		txtUsrName.select();
		txtUsrName.focus();
		return false;
	}	
	if(aa >= (bb-1))
	{
		tdMsgEmail.innerHTML="Invalid Format"
		txtUsrName.select();
		txtUsrName.focus();
		return false;
	}
	
	if (txtPass.value=="")
	{
		tdMsgPswd.innerHTML="Required"
		txtPass.focus();
		return false;
	}

	var str = txtPass.value;   
	if (str.length<=5)
	{
	    tdMsgPswd.innerHTML="Too short"
		txtPass.focus();
		return false;
	}
	
	if (txtConfirmPass.value=="")
	{
		tdMsgConfirm.innerHTML="Required"
		txtConfirmPass.focus();
		return false;
	}
	
	if (txtPass.value!=txtConfirmPass.value)
	{
		tdMsgPswdConfirm.innerHTML="Password and Confirm Password do not match"
		txtConfirmPass.focus();
		return false;
	}
	
	 if(txtProfileUrl)
    {
	    if (txtProfileUrl.value=="")
	    {
		    tdMsgDisplayName.innerHTML="Required"
		    txtProfileUrl.focus();
		    return false;
	    }
	
	    if (/[^a-zA-Z-_0-9]/.test(txtProfileUrl.value)) 
        {
            tdMsgDisplayName.innerHTML="Invalid Format"
            txtProfileUrl.focus();
            return false;
        }
	}
//	else
//	{
//	     txtDisplayNameR=document.getElementById(txtClientID+"txtDisplayNameR") 
//	     if(txtDisplayNameR.value=="")
//	     {
//	        tdMsg.innerHTML="Display Name should not be blank."
//		    txtDisplayNameR.focus();
//		    return false;
//		}
//		
//		if (/[^a-zA-Z-_0-9]/.test(txtDisplayNameR.value)) 
//         {
//             tdMsg.innerHTML="Space and special characters are not allowed in the display name."
//             txtDisplayNameR.focus();
//             return false;
//         }
//   
//	}
	
	 if(drpSecurityQue.value==0)
    {
        tdMsgQuestion.innerHTML="Required"
        drpSecurityQue.focus();
        return false;
    }
    
    if(txtAns.value=="")
    {
        tdMsgAnswer.innerHTML="Required"
        txtAns.focus();
        return false;
    }
     
//    if(txtFName.value=="")
//    {
//      tdMsg.innerHTML="Please enter your first name."
//      txtFName.focus();
//      return false;
//    }
//    
//    if(txtLName.value=="")
//    {
//      tdMsg.innerHTML="Please enter your last name."
//      txtLName.focus();
//      return false;
//    }
    if(tdMsgDOB != null){ //if the user is MODIFING his/her account this will be NULL
        if(drpMonth.value==0)
        {
            tdMsgDOB.innerHTML="Month is Required"
            drpMonth.focus();
            return false;
        }
        
        if(drpDate.value==0)
        {
            tdMsgDOB.innerHTML="Day is Required"
            drpDate.focus();
            return false;
        }
        
        if(drpYear.value==0)
        {
            tdMsgDOB.innerHTML="Year is Required"
            drpYear.focus();
            return false;
        }
         
        if(drpMonth.value==2 || drpMonth.value==4 || drpMonth.value==6 || drpMonth.value==9 || drpMonth.value==11)
        {
            if(drpDate.value>30)
            {
                tdMsgDOB.innerHTML="Invalid Date"
                drpDate.focus();
                return false;
            }
            if( drpMonth.value==2 && drpDate.value>28)
            {
                tdMsgDOB.innerHTML="Invalid Date"
                drpDate.focus();
                return false;
            }
        }
        
        if(txtHumanVer.value=="")
        {
            tdMsgVerCode.innerHTML="Required"
            txtHumanVer.focus();
            return false;
        }
    	 
	     if(Chkterms.checked==false)
	     {
	        tdMsgTerms.innerHTML="Required"
	        return false;
	     }
    }
      
    if(txtZip.value=="")
    {
         tdMsgZip.innerHTML="Required"
         txtZip.focus();
         return false;
    }

    var len=txtZip.value;
	if(len.length<=4)
	{
        tdMsgZip.innerHTML="Invalid Format"
        txtZip.focus();
        return false;
	}

	if (isNaN(txtZip.value))
	{
		tdMsgZip.innerHTML="Invalid Format"
		txtZip.focus();
		return false;
	}
	
	
	 	  
}

function PasswordUpdate()
{
    var txtPass, txtConfirmPass;
    var txtClientID = document.getElementById("RegClientID").value;
    txtPass=document.getElementById(txtClientID+"txtPass");
    txtConfirmPass=document.getElementById(txtClientID+"txtConfirmPass");
    tdMsgPswd.innerHTML="";
    tdMsgConfirm.innerHTML="";
    tdMsgPswdConfirm.innerHTML="&nbsp;";
	if (txtPass.value=="")
	{
		tdMsgPswd.innerHTML="Required"
		txtPass.focus();
		return false;
	}
	var str = txtPass.value;   
	if (str.length<=5)
	{
	    tdMsgPswd.innerHTML="Too short"
		txtPass.focus();
		return false;
	}
	if (txtConfirmPass.value=="")
	{
		tdMsgConfirm.innerHTML="Required"
		txtConfirmPass.focus();
		return false;
	}
	if (txtPass.value!=txtConfirmPass.value)
	{
		tdMsgPswdConfirm.innerHTML="Password and Confirm Password do not match"
		txtConfirmPass.focus();
		return false;
	}
}

function EmailUpdate()
{
    var txtEmail, txtConfirmEmail;
    var txtClientID = document.getElementById("RegClientID").value;
    txtEmail=document.getElementById(txtClientID+"txtEmail");
    txtConfirmEmail=document.getElementById(txtClientID+"txtConfirmEmail");
    tdMsgEmail.innerHTML="";
    tdMsgConfirm.innerHTML="";
    tdMsgEmailConfirm.innerHTML="&nbsp;";
	if (txtEmail.value=="")
	{
		tdMsgEmail.innerHTML="Required"
		txtEmail.focus();
		return false;
	}
	if (txtConfirmEmail.value=="")
	{
		tdMsgConfirm.innerHTML="Required"
		txtConfirmEmail.focus();
		return false;
	}
	if (txtEmail.value!=txtConfirmEmail.value)
	{
		tdMsgEmailConfirm.innerHTML="Email and Confirm Email do not match"
		txtConfirmEmail.focus();
		return false;
	}
}

