function formValidator(){	
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var Checkin = document.getElementById('Checkin');
	var Checkout = document.getElementById('Checkout');
	var rooms = document.getElementById('rooms');
	var children = document.getElementById('children');
	var adults = document.getElementById('adults');	

	var hid = document.getElementById('hid');
	
	

	
	// Check each input in the order that it appears in the form!
	if(isAlphanumeric(name, "Please enter your  name"))
	{
		if(document.getElementById('name').value == 'Your Name')
		{
			alert("Please enter your name");
			document.getElementById('name').focus();
		}
		else
		{
			if(emailValidator(email, "Please enter a valid email address"))
			{
				if(notEmpty(Checkin, "Please Enter checkin"))
				{
					if(document.getElementById('Checkin').value == 'Checkin')
					{
						alert("Please select Checkin date");
						document.getElementById('Checkin').focus();
					}
					 var datestring = document.getElementById("Checkin").value;
                     date1 = datestring.split("/");
                     var mydate = new Date(date1[1]+"/"+date1[0]+"/"+date1[2]);
                     var today_temp = new Date();
                     var today_dt = today_temp.getDate();
                     var today_mm = today_temp.getMonth()+1;
                     var today_yyyy = today_temp.getFullYear();
                     var today = new Date(today_mm+"/"+today_dt+"/"+today_yyyy)
                   
                    if(mydate < today)
                    {
                        alert("Checkin date can't be less than today.");
                        document.getElementById('Checkin').focus();
                        return false;
                    }
					else
					{
						if(notEmpty(Checkout, "Please Enter checkout"))
						{
							if(document.getElementById('Checkout').value == 'Checkout')
							{
								alert("Please select Checkout date");
								document.getElementById('Checkout').focus();
							}
							var datestring = document.getElementById("Checkout").value;
                            date1 = datestring.split("/");
                            var mydate = new Date(date1[1]+"/"+date1[0]+"/"+date1[2]);
                            var today_temp = new Date();
                            var today_dt = today_temp.getDate();
                            var today_mm = today_temp.getMonth()+1;
                            var today_yyyy = today_temp.getFullYear();
                            var today = new Date(today_mm+"/"+today_dt+"/"+today_yyyy)
                       
                            if(mydate < today)
                            {
                                alert("Checkout date can't be less than today.");
                                document.getElementById('Checkout').focus();
                                return false;
                            }
							else
							{
								if(notEmpty(rooms, "Please select rooms"))
								{
									if(notEmpty(children, "Please select childrens"))
									{
										if(notEmpty(adults, "Please select adults"))
										{
											if(document.getElementById('hid').value == 0 && document.getElementById('address').value == '')
											{
												alert("please enter your address");
												document.getElementById('address').focus();
												//return true;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	
	return false;
	
}






//Validation of second form
function formValidator1(){	
	var address = document.getElementById('address');
	var contactnumber = document.getElementById('contactnumber');
	var country = document.getElementById('country');
	var comment = document.getElementById('comment');

	
	

	
	// Check each input in the order that it appears in the form!
	if(isAlphanumeric(address, "Please enter your  address")){
		if(isNumeric(contactnumber, "Please Enter contactnumber")){
			if(notEmpty(country, "Please select your country")){
				if(notEmpty(comment, "Please enter comment")){
					return true;
				}
			}
		}
	}
	
	return false;
	
}


function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function validate_aspx()
{
    if(document.getElementById('address').value=="")
    {
        alert("Please enter your address.");
        document.getElementById('address').focus();
        return false;
    }
    if(document.getElementById('contact').value=="")
    {
        alert("Please enter your contact number.");
        document.getElementById('contact').focus();
        return false;
    }
    if(document.getElementById("country").selectedIndex==0)
    {
         alert("Please select your country.");
         document.getElementById('country').focus();
         return false;
    }
    if(document.getElementById('comment').value=="")
    {
        alert("Please enter your comment/message.");
        document.getElementById('comment').focus();
        return false;
    }
    return true;
}

//Function for remove blank space
function fun(thefield)
{ 
    var name=thefield.value; 
    thefield.value=name.replace(/^(?:\s)*/g,'').replace(/(?:\s)*$/g,'');
}
