﻿// JScript File

 function fnValidation()
 {   
        var errMsg="";
        var fv = {
           
		    Email:$("#ctl00_Main_txtEmail").val(),
		    Password:$("#ctl00_Main_txtPassword").val(),
		    FName:$("#ctl00_Main_txtFName").val(),
		    LName:$("#ctl00_Main_txtLName").val(),
		    HPhone:$("#ctl00_Main_txtHPhone").val(),
		    MPhone:$("#ctl00_Main_txtMPhone").val(),
		    Student:$("#ctl00_Main_rdoStudent").val(),
		    Media:$("#ctl00_Main_rdoBuy").val(),
		    Date:$("#ctl00_Main_txtDate").val(),
		    Matching:$("#ctl00_Main_rdoMatching").val(),
		    Buy:$("#ctl00_Main_rdoBuy").val()
		}
		
		var arrFldNames = new Array( "Email","Password","First Name","Last Name","Home Phone","Mobile Phone","Student","Advertising Media","Date Apartment Needed","Roommate matching service","Interested in buying your next home");//, "Short Name","River Name","Ln Degree","Ln Minute","Ln Second","Lt Degree","Lt Minute","Lt Second","Catchment Area","Warning Level","Base Of Guage" ,"Danger Level");
	    var arrFldValues = new Array(fv.Email,fv.Password,fv.FName,fv.LName,fv.HPhone,fv.MPhone,fv.Student,fv.Media,fv.Date,fv.Matching,fv.Buy);//, fv.ShortName,fv.RiverName,fv.LnDegree,fv.LnMinute,fv.LnSecond,fv.LtDegree,fv.LtMinute,fv.LtSecond,fv.CatchmentArea,fv.WarningLevel,fv.BaseOfGuage,fv.DangerLevel);
         
	    errMsg = SIPL.Validate.batchNull(arrFldNames,arrFldValues);
	    
	    var str = fnEmailValidation("ctl00_Main_txtEmail",0);
	    var str1 = fnEmailValidation("ctl00_Main_txtFAdditionalEmail",1);
	    var str2 = fnEmailValidation("ctl00_Main_txtSAdditionalEmail",1);
	    var str3 = fnEmailValidation("ctl00_Main_txtTAdditionalEmail",1);
	     
	    errMsg += str + str1 + str2 + str3
	    
	    if(document.getElementById('ctl00_Main_txtPassword').value != document.getElementById('ctl00_Main_txtCPassword').value)
	        errMsg += "  Password and Confirm Password does not match \n";
	    
	    if (errMsg != "")
	        SIPL.Debug.alertErr(errMsg);
	    if(errMsg == "")
	        return true;
	    else
            return false
 }

 function fnEmailValidation(ctrlName,val)
 {
        var errMsg = ''
        var fldvlu;
        fldvlu=document.getElementById(ctrlName).value;
        
        if(fldvlu!='')
        {
            var RegExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
            
            if (RegExp.test(fldvlu))
            {
                //return true;
            }
            else
            {
                if(val == 0)
                    errMsg =  '  Email Should be valid \n'
                else
                    errMsg =  '  Additional Roommates Email Should be valid \n'
                //alert('Enter Correct Email Address');
                //return false;
            }
        }
        return errMsg
 }
 
 
      function fnEnableButton()
      {
        if(document.getElementById('ctl00_Main_chkTerms').checked)
        {
            document.getElementById('ctl00_Main_btnSubmit').disabled = false;
            document.getElementById('ctl00_Main_btnSubmit').className = 'btn';
        }
        else
        {
            document.getElementById('ctl00_Main_btnSubmit').disabled = true;
            document.getElementById('ctl00_Main_btnSubmit').className = 'btn-disable';
        }
      }
      
      function fnCheckCollege(val)
      {
        if(val == 'yes')
        {
            document.getElementById('ctl00_Main_rdoStudent_0').checked = true
        }
        else
            document.getElementById('ctl00_Main_rdoStudent_1').checked = true   
        
        if(document.getElementById('ctl00_Main_rdoStudent_0').checked == true && document.getElementById('ctl00_Main_ddlCollege').value == 0)
        {
            document.getElementById('ctl00_Main_lblColl').innerHTML = 'Please select college'
        }
        else
             document.getElementById('ctl00_Main_lblColl').innerHTML = ' '   
             
        document.getElementById('ctl00_Main_RequiredFieldValidator7'). style.display = 'none'    
      }
      
      function fnCheck()
      {
        if(document.getElementById('ctl00_Main_ddlCollege').value != 0 && document.getElementById('ctl00_Main_rdoStudent_0').checked == true)
        {
            document.getElementById('ctl00_Main_lblColl').innerHTML = ' '
        }
        else if (document.getElementById('ctl00_Main_ddlCollege').value == 0 && document.getElementById('ctl00_Main_rdoStudent_0').checked == true)
            document.getElementById('ctl00_Main_lblColl').innerHTML = 'Please select college'
      } 
    
      
     function fnshowHide(layerid)
     {
       if (document.getElementById(layerid).style.visibility != "hidden"){
        document.getElementById(layerid).style.visibility = "hidden";
       }
       else{
        document.getElementById(layerid).style.visibility = "visible";
       }
       return false;
     }
     
           
     function fnCheck_Check(source, arguments){
        var date = document.getElementById('ctl00_Main_txtDate').value
        if(date == '')
            arguments.IsValid = false;
        else
            arguments.IsValid = true;
      }  
      
      function fnCheckLength(fldvlu)
      {
            if(fldvlu != "")
            {
                var re = new RegExp("[a-zA-Z]")
                var re1 = new RegExp("[0-9]")
                
                var len = chkIsChar(fldvlu)
                
                if(len >= 6 && re.test(fldvlu))
                {
                       if(re1.test(fldvlu))
                       {
                       
                       }
                       else
                       {
                            alert('You must use at least six (6) alphabetic characters and one (1) numeric character in when creating your password. Please try again');
                            document.getElementById('ctl00_Main_txtPassword').value = "";
                       } 
                }
                else
                {
                    alert('You must use at least six (6) alphabetic characters and one (1) numeric character in when creating your password. Please try again');
                    document.getElementById('ctl00_Main_txtPassword').value = "";
                }
                
                //var RegExp =  /^(\d|\w){6,13}$/ // /^(?=.*[A-Za-z])(?=.*[0-9])(?!.*[^A-Za-z0-9])(?!.*\s).{5,12}$/;///^\w{6,13}$/; 
                // /^((?=(.*?[a-z]){6})(?=(.*?[0-9]){1}).{7,20})$/;
            }
      }
      
      function chkIsChar(val)
      {
        var counter=0;  
        var total = 0;			
		//removing the leading and trailing spaces
		val = val.trim();
		
		var len = val.length;
		for (counter=0;counter < len; counter++){
			var char1 = val.charAt(counter) ;
			if (char1 < "0" || char1 > "9" )
				total = total + 1;
		}
		return total;
      }
      
      function chkNickName(val)
      {
        var re = new RegExp("^[ \t]+|[ \t]+$")
        var re1 = new RegExp("[^a-zA-Z0-9]+")
        
        var st = chkIsSpace(val)
        
       
        if(val.length < 5)
        {
            alert("At least five characters are required for Screen Name");
            return;
        }
        if(re.test(val)|| st != "0" || re1.test(val))
        {
            alert("Only alphabetic and numeric characters are allowed for Screen Name")
            document.getElementById('ctl00_Main_txtNickname').value = "";
        }
      }
      
      function chkIsSpace(val)
      {
        var counter=0;  
        var total = 0;			
		//removing the leading and trialing spaces
		val = val.trim();
		
		var len = val.length;
		for (counter=0;counter < len; counter++){
			var char1 = val.charAt(counter) ;
			if (char1 == " ")
			{
				total = "TAS"
	        }	
		}
		return total;
      }
      
      function isNonblankSpace (s) {
        var isNonblank_re    = "";
        return String (s).search (isNonblank_re) != -1
      }
      
      