﻿

$(document).ready(function() {
			// SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() }, 
			
			$("#frm").validationEngine();
			
			//$.validationEngine.loadValidation("#date")
			//alert($("#formID").validationEngine({returnIsValid:true}))
			//$.validationEngine.buildPrompt("#date","This is an example","error")	 		 // Exterior prompt build example								 // input prompt close example
			//$.validationEngine.closePrompt(".formError",true) 							// CLOSE ALL OPEN PROMPTS
		});
		
		// JUST AN EXAMPLE OF VALIDATIN CUSTOM FUNCTIONS : funcCall[validate2fields]
	
	function FormValidate()
	{
	    var Validate=true;
	    if(document.getElementById("txtEmailAddress").value=="")
	    {
	     $.validationEngine.buildPrompt('#txtEmailAddress','Cannot be left blank','error');	     
	     Validate=false;
	    }
	    if (document.getElementById("txtPassword") != null && document.getElementById("txtPassword").value == "")
	    {
	     $.validationEngine.buildPrompt('#txtPassword','Cannot be left blank','error');	     
	     Validate=false;
	    }
	    if(document.getElementById("txtConfirmPassword") != null && document.getElementById("txtConfirmPassword").value=="")
	    {
	     $.validationEngine.buildPrompt('#txtConfirmPassword','Cannot be left blank','error');	     
	     Validate=false;
	    }
	    
	    //dob
	    var DD = document.frm.txtDD.value;
        var YYYY = document.frm.txtYYYY.value;
        var Mnth = document.getElementById('ddlMM');
        
        var dtCurrent = new Date();    
	    var dtDOB = new Date(Mnth.value+"/"+DD+"/"+YYYY);
    	    
        if(Mnth.selectedIndex == 0)
	    {
	        $.validationEngine.buildPrompt('#ddlMM','Month is not selected','error');	        
	        Validate=false;
	    }
        if(DD == "DD" || DD == "dd" || DD == "")             
        {
            $.validationEngine.buildPrompt('#txtDD','Cannot be left blank','error');	        
	        Validate=false;	        
        }    
        if(YYYY == "YYYY" || YYYY == "yyyy" || YYYY == "")
        {
            $.validationEngine.buildPrompt('#txtYYYY','Cannot be left blank','error');	        
	        Validate=false;
        }
        if(isNaN(DD))
        {   
            $.validationEngine.buildPrompt('#txtDD','Please enter valid day & year','error');	        
	        Validate=false;
        }
        if(isNaN(YYYY))
        {   
            $.validationEngine.buildPrompt('#txtYYYY','Please enter valid day & year','error');	        
	        Validate=false;
        }        
        if(DD > 31 || DD < 1) // || YYYY < 1930)
        {
            $.validationEngine.buildPrompt('#txtDD','Please enter valid day & year','error');	        
	        Validate=false;
        }
        if((dtCurrent.getFullYear() - dtDOB.getFullYear()) < 18 || (dtCurrent.getFullYear() - dtDOB.getFullYear()) > 80 )
	    {		    
		    $.validationEngine.buildPrompt('#txtYYYY','Acceptable age: 18-80','error');	        
	        Validate=false;
	    }
	    
	    //Religion
	    if(document.getElementById("ddlReligion").selectedIndex==0)
	    {
	       $.validationEngine.buildPrompt('#ddlReligion','Religion must be selected','error');	       
	       Validate=false;
	    }
	    if(document.frm.ddlCountry.selectedIndex == 0 || document.frm.ddlCountry.selectedIndex == 7)
	    {
	       $.validationEngine.buildPrompt('#ddlCountry','Country must be selected','error');	       
	       Validate=false;
	    }
	    if (document.getElementById("txtImgText") != null) 
        {
           if (document.getElementById("txtImgText").value == "") 
           {
	           $.validationEngine.buildPrompt('#txtImgText', 'Cannot be left blank', 'error');
	           Validate = false;
	       }
	       if (isNaN(document.frm.txtImgText.value)) 
           {
	           $.validationEngine.buildPrompt('#txtImgText', 'Only numbers are accepted', 'error');
	           Validate = false;
	       }
	    }
	    return Validate;
	}

function FocusTxt(txt)
{

    if(txt == "dd")
    {
    
        var txtDD = document.getElementById('txtDD');
        if(txtDD.value == "DD")
            txtDD.value = "";
            
            
    }
    else if(txt == "yyyy")
    {
 
        var txtYYYY = document.getElementById('txtYYYY');
        if(txtYYYY.value == "YYYY")
            txtYYYY.value = "";
    }
}


function BlurTxt(txt, obj)
{   
    if(txt == "dd")
    {
        var txtDD = document.getElementById('txtDD');
        if(txtDD.value == "")
            txtDD.value = "DD";            
    }
    else if(txt == "yyyy")
    {
        var txtYYYY = document.getElementById('txtYYYY');
        if(txtYYYY.value == "")
            txtYYYY.value = "YYYY";                   
    }
    
    if(obj.id == "txtYYYY")
    {
        GetMatches('by_dob')
    }    
}

function RegCookies(obj)
 {
    var month,day,year,religion,country,email;
    var gender = "M";
    
    if(document.frm.rblGender[1].checked)
       gender="F";
    
    if(obj.id =='ddlMM')
       CreateCookies(gender,obj.value,"","","","","");
    else if(obj.id =='txtDD')
     {
       month = document.getElementById('ddlMM').selectedIndex;
       CreateCookies(gender,month,obj.value,"","","","");
     }
    else if(obj.id =='txtYYYY')
     {
       Gendr = document.getElementById('ddlMM').value;
       month = document.getElementById('ddlMM').selectedIndex;
       day = document.getElementById('txtDD').value;
       CreateCookies(gender,month,day,obj.value,"","","");
     }
    else if(obj.id =='ddlReligion')
     {
       Gendr = document.getElementById('ddlMM').value;
       month = document.getElementById('ddlMM').selectedIndex;
       day = document.getElementById('txtDD').value;
       year = document.getElementById('txtYYYY').value;
       CreateCookies(gender,month,day,year,obj.selectedIndex,"","");  
     }  
    else if(obj.id =='ddlCountry')
     {
       Gendr = document.getElementById('ddlMM').value;
       month = document.getElementById('ddlMM').selectedIndex;
       day = document.getElementById('txtDD').value;
       year = document.getElementById('txtYYYY').value;
       religion = document.getElementById('ddlMM').selectedIndex;       
       CreateCookies(gender,month,day,year,religion,obj.selectedIndex,"");  
     }  
    else if(obj.id =='txtEmailAddress')
     {
       Gendr = document.getElementById('ddlMM').value;
       month = document.getElementById('ddlMM').selectedIndex;
       day = document.getElementById('txtDD').value;
       year = document.getElementById('txtYYYY').value;
       religion = document.getElementById('ddlReligion').selectedIndex;
       country = document.getElementById('ddlCountry').selectedIndex;
       CreateCookies(gender,month,day,year,religion,country,obj.value);  
     }    
 }
 
 function CreateCookies(gender,month,day,year,religion,living,email)
  { 
    if(window.navigator.cookieEnabled)
    {  
       var cookies = gender + "_" + month + "_" + day + "_" + year + "_" + religion + "_" +living + "_" + email;
       setCookie("c_reg",cookies,60);
    }
  }

function setCookie(c_name,value,expiredays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie= c_name + "=" +value + ((expiredays==null) ? "" : ";expires="+exdate.toUTCString()) + "; path=/";
}
