// Phone Number Validation
	// Declaring required variables
		var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
		var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
		var minDigitsInIPhoneNumber = 10;

	function isInteger(s)
	{   var i;
	    for (i = 0; i < s.length; i++)
	    {   
	        // Check that current character is number.
	        var c = s.charAt(i);
	        if (((c < "0") || (c > "9"))) return false;
	    }
	    // All characters are numbers.
	    return true;
	}
	
	function stripCharsInBag(s, bag)
	{   var i;
	    var returnString = "";
	    // Search through string's characters one by one.
	    // If character is not in bag, append to returnString.
	    for (i = 0; i < s.length; i++)
	    {   
	        // Check that current character isn't whitespace.
	        var c = s.charAt(i);
	        if (bag.indexOf(c) == -1) returnString += c;
	    }
	    return returnString;
	}
	
	function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}




// Email address 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 Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}






	
	function ValidateForm(){
		var Phone=document.form.phonenumber;
		var fname=document.form.fname;
		var lname=document.form.lname;
		var emailID=document.form.emailaddress;
		var address=document.form.address;
		var city=document.form.city;
		var state=document.form.state;
		var zipcode=document.form.zipcode;
		var terms=document.form.terms;

		if ((fname.value == "") || (fname.value ==null)) {
			alert("Please Enter your First Name")
			fname.focus()
			return false
			}

		if ((lname.value == "") || (lname.value ==null)) {
			alert("Please Enter your Last Name")
			lname.focus()
			return false
			}
		
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email Address")
			emailID.focus()
			return false
		}
		if (echeck(emailID.value)==false){
			emailID.focus()
			return false
		}

		
		if ((Phone.value==null)||(Phone.value=="")){
			alert("Please Enter your Phone Number")
			Phone.focus()
			return false
		}
		if (checkInternationalPhone(Phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			Phone.focus()
			return false
		}

		if ((address.value == "") || (address.value ==null)) {
			alert("Please Enter your Address")
			address.focus()
			return false
			}

		if ((city.value == "") || (city.value ==null)) {
			alert("Please Enter your City")
			city.focus()
			return false
			}

		if ((state.value == "") || (state.value ==null)) {
			alert("Please Enter your State")
			state.focus()
			return false
			}

		if ((zipcode.value == "") || (zipcode.value ==null)) {
			alert("Please Enter your Zipcode")
			zipcode.focus()
			return false
			}

		if (!terms.checked == true) { 
   			alert("Please acknowledge that you've read and agree to the terms and conditions"); 
   			form.terms.focus( ); 
   			return false; 
   			}


		document.form.submit();
	 }



	
	function ValidateForm2(){
		var month_in=document.form.month_in;
		var day_in=document.form.day_in;
		var year_in=document.form.year_in;
		var month_out=document.form.month_out;
		var day_out=document.form.day_out;
		var year_out=document.form.year_out;

		if ((month_in.value == "") || (month_in.value ==null)) {
			alert("Please Enter your First Choice of Dates")
			month_in.focus()
			return false
			}

		if ((day_in.value == "") || (day_in.value ==null)) {
			alert("Please Enter your First Choice of Dates")
			day_in.focus()
			return false
			}

		if ((year_in.value == "") || (year_in.value ==null)) {
			alert("Please Enter your First Choice of Dates")
			year_in.focus()
			return false
			}

		if ((month_out.value == "") || (month_out.value ==null)) {
			alert("Please Enter your Second Choice of Dates")
			month_out.focus()
			return false
			}

		if ((day_out.value == "") || (day_out.value ==null)) {
			alert("Please Enter your Second Choice of Dates")
			day_out.focus()
			return false
			}

		if ((year_out.value == "") || (year_out.value ==null)) {
			alert("Please Enter your Second Choice of Dates")
			year_out.focus()
			return false
			}

		document.form.submit();
	 }


