﻿// JScript File
   /* country state JS */
    function CountryDDLChange(ctrlCountry, ctrlState, ctrlOtherState, vldddlStateReq, vldOtherStateCus)
        {
            var ddlCountry = document.getElementById(ctrlCountry);
            var ddlState = document.getElementById(ctrlState);
            var txtOtherState = document.getElementById(ctrlOtherState);
            
            if(parseInt(ddlCountry.value) == 0)
            {            
                ddlState.options[0].selected = true;
                ddlState.disabled = true;
                txtOtherState.disabled = true;
                txtOtherState.value = '';
                CheckValidator(document.getElementById(vldddlStateReq), false);            
                CheckValidator(document.getElementById(vldOtherStateCus), false);
            }
            else if(parseInt(ddlCountry.value) == 1) // if Country is US
            {            
                ddlState.disabled = false;
                txtOtherState.disabled = true;
                txtOtherState.value = '';
                
                // Load States of US
                LoadUSState(ddlState);
                                
                CheckValidator(document.getElementById(vldddlStateReq), true);                
                CheckValidator(document.getElementById(vldOtherStateCus), false);
            }
            else if(parseInt(ddlCountry.value) == 198) // if Country is UK
            {   
                ddlState.disabled = false;
                txtOtherState.disabled = true;
                txtOtherState.value = '';
                
                // Load States of UK
                LoadUKState(ddlState);
                
                CheckValidator(document.getElementById(vldddlStateReq), true);            
                CheckValidator(document.getElementById(vldOtherStateCus), false);
            }
            else if(parseInt(ddlCountry.value) != 1)
            {   
                ddlState.options.length = 0;
                ddlState.options.add(new Option('--Select--','0'));        
                ddlState.options[0].selected = true;                
                ddlState.disabled = true;
                txtOtherState.disabled = false; 
                txtOtherState.value = '';
                CheckValidator(document.getElementById(vldddlStateReq), false);            
                CheckValidator(document.getElementById(vldOtherStateCus), true);            
            }
                    
            document.getElementById('ctl00_UM_hdnStateID').value = ddlState.value;
            document.getElementById('ctl00_UM_hdnCountryID').value = ddlCountry.value;            
        }
        
        function LoadUSState(ddlState)
        {            
            ddlState.options.length = 0;
            var USStatesList = document.getElementById('ctl00_UM_txtUSStatesList');
            
            if(USStatesList.value != '')
            {
                var arlStates = USStatesList.value.split(',');
                
                for(i=0;i<arlStates.length;i++)
                {
                    var nStateID = arlStates[i].toString().substring(0,arlStates[i].toString().indexOf('|')); 
                    var nStateName = arlStates[i].toString().substring(arlStates[i].toString().indexOf('|')+1); 
                    ddlState.options[i] = new Option(nStateName,nStateID);
                    
                    if(document.getElementById('ctl00_UM_hdnStateID') != null)
                    {
                        if(parseInt(document.getElementById('ctl00_UM_hdnStateID').value) == parseInt(nStateID))
                            ddlState.selectedIndex = i;                          
                     }      
                }
            }
            
            if(ddlState.options.length > 0)
                ddlState.options.add(new Option('--Select--','0'),0);
            else
                ddlState.options.add(new Option('--Select--','0'));
                
            ddlState.options.add(new Option('Other','-1'));
            
            if(document.getElementById('ctl00_UM_hdnStateID') != null)
             {
                if(parseInt(document.getElementById('ctl00_UM_hdnStateID').value) == -1)                      
                    ddlState.selectedIndex = ddlState.options.length -1 ;                  
              }  
        }
        
        function LoadUKState(ddlState)
        {            
            ddlState.options.length = 0;        
            var UKStatesList = document.getElementById('ctl00_UM_txtUKStatesList');
            
            if(UKStatesList.value != '')
            {
                var arlStates = UKStatesList.value.split(',');
                for(i=0;i<arlStates.length;i++)
                {
                    var nStateID = arlStates[i].toString().substring(0,arlStates[i].toString().indexOf('|')); 
                    var nStateName = arlStates[i].toString().substring(arlStates[i].toString().indexOf('|')+1); 
                    ddlState.options[i] = new Option(nStateName,nStateID);
                    
                    if(document.getElementById('ctl00_UM_hdnStateID') != null)
                    {
                        if(parseInt(document.getElementById('ctl00_UM_hdnStateID').value) == parseInt(nStateID))
                            ddlState.selectedIndex = i;                      
                      }      
                }
            }
            
            if(ddlState.options.length > 0)
                ddlState.options.add(new Option('--Select--','0'),0);
            else
                ddlState.options.add(new Option('--Select--','0'));
                
            ddlState.options.add(new Option('Other','-1'));
            
            if(document.getElementById('ctl00_UM_hdnStateID') != null)
              {
                if(parseInt(document.getElementById('ctl00_UM_hdnStateID').value) == -1)                      
                   ddlState.selectedIndex = ddlState.options.length-1 ;
              }    
        }
        
        function StateDDLChange(ctrlCountry,ctrlState,ctrlOtherState,vldddlStateReq,vldOtherStateCus)
        {               
            var ddlCountry = document.getElementById(ctrlCountry);
            var ddlState = document.getElementById(ctrlState);
            var txtOtherState = document.getElementById(ctrlOtherState);
            var hdnStateID = document.getElementById('ctl00_UM_hdnStateID');              
            
            if((parseInt(ddlCountry.value) == 1 || parseInt(ddlCountry.value) == 198) && parseInt(ddlState.value) == 0) // --Select--
            {   
                txtOtherState.disabled = true;
                txtOtherState.value = '';
                CheckValidator(document.getElementById(vldOtherStateCus), false);
            }
            else if((parseInt(ddlCountry.value) == 1 || parseInt(ddlCountry.value) == 198) && parseInt(ddlState.value) == -1)// --Other--
            {   
                txtOtherState.disabled = false;
                txtOtherState.value = '';
                CheckValidator(document.getElementById(vldOtherStateCus), true);
            }
            else // US states 
            {
                txtOtherState.disabled = true;
                txtOtherState.value = '';
                CheckValidator(document.getElementById(vldOtherStateCus), false);
            }
            hdnStateID.value = ddlState.value;                                    
        }  
 
  function CheckState(oSrc,args) 
    {         
	    if (document.getElementById("ctl00_UM_ddlState") != null)
	    {
		    if(document.getElementById("ctl00_UM_ddlState").disabled == false && (parseInt(document.getElementById("ctl00_UM_ddlState").value) == 0 || document.getElementById("ctl00_UM_ddlState").value == ''))
		    {    			
			    args.IsValid=false;
		    }
		    else
		    {
			    args.IsValid=true;
		    }
	    }
	    else
	    {
		    args.IsValid = true;
	    }	    
    }         

     function CheckOtherState(oSrc,args)
    {
        if (document.getElementById("ctl00_UM_txtOtherState") != null)
	            {
		            if(document.getElementById("ctl00_UM_txtOtherState").disabled == false && trim(document.getElementById("ctl00_UM_txtOtherState").value)=='')
		            {    			
			            args.IsValid = false;
		            }
		            else
		            {
			            args.IsValid = true;
		            }
	            }
	            else
	            {
		            args.IsValid = true;
	            }	    
    }	
function LoadStates1()
{
    document.getElementById('ctl00_UM_dvState').style.display = 'none';
    if (document.getElementById('ctl00_UM_trOtherState') != null)
        document.getElementById('ctl00_UM_trOtherState').style.display = 'none';
    //document.getElementById('ctl00_UM_dvMsg1').style.display = '';    
 }		              
   
      if (document.getElementById('ctl00_UM_lblWordCount1')!= null)
        {  
     
         document.getElementById('ctl00_UM_lblWordCount1').innerHTML = 4000 - document.getElementById('ctl00_UM_txtMessage').value.length
        }
function ValidEventDate(oSrc,args)
	{   	    
		var str_date=document.getElementById('ctl00_UM_txtEventDate').value;
		var date_format = "mm/dd/yyyy";	
		if(str_date=="")
			return true;
		var i,j;		
		var RE_NUM = /^\-?\d+$/;
		var NUM_CENTYEAR = 30;
		
		var arr_date = str_date.split('/');
		
		if (arr_date.length != 3) 
		{   
			args.IsValid=false;
			return false;
		}
		i = date_format!="mm/dd/yyyy" ? 1 : 0;
		
		j = i > 0 ? 0 : 1;
		if (!arr_date[j]){ args.IsValid=false; return  false;} //;spacer + " - Invalid date format: '" + str_date + "'.\n" + spacer + " - No day of month value can be found.\n";
		if (!RE_NUM.exec(arr_date[j])) { args.IsValid=false; return  false;} //spacer + " - Invalid day of month value: '" + arr_date[j] + "'.\n" + spacer + " - Allowed values are unsigned integers.\n";
		if (!arr_date[i]) { args.IsValid=false; return  false;} //spacer + " - Invalid date format: '" + str_date + "'.\n" + spacer + " - No month value can be found.\n";
		if (!RE_NUM.exec(arr_date[i])) { args.IsValid=false; return  false;}//spacer + " - Invalid month value: '" + arr_date[i] + "'.\n" + spacer + " - Allowed values are unsigned integers.\n";
		if (!arr_date[2]) { args.IsValid=false; return  false;} //spacer + " - Invalid date format: '" + str_date + "'.\n" + spacer + " - No year value can be found.\n";
		if (!RE_NUM.exec(arr_date[2])) { args.IsValid=false; return  false;} //spacer + " - Invalid year value: '" + arr_date[2] + "'.\n" + spacer + " - Allowed values are unsigned integers.\n";
	
		var dt_date = new Date();
		dt_date.setDate(1);
	
		if (arr_date[i] < 1 || arr_date[i] > 12) 
		{
				args.IsValid=false;
				return false;
		} 
		dt_date.setMonth(arr_date[i]-1);
		 
		if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
		dt_date.setFullYear(arr_date[2]);
	
		var dt_numdays = new Date(arr_date[2], arr_date[i], 0);
		dt_date.setDate(arr_date[j]);
		if (dt_date.getMonth() != (arr_date[i]-1)) 
		{
			args.IsValid=false;
			return false;
		}
		//return (dt_date)
		args.IsValid=true;
		return true;
	}
	function CountWords(objtext,objlbl)
    {    
        if(objlbl != null)
        {           
            if (objtext.value.length < 4000)
            {
                objlbl.innerHTML = 250- objtext.value.length;     
            }
            else
            {               
                objlbl.innerHTML=0;
                var str = objtext.value;
                objtext.value = str.substring(0,str.length - 1);//set maximum 250 character not allowed more
            }
        }
    } 
    
    


