//////////////////// Validate Query /////////////////////////
function validateQuery()
{
	// Make quick references to our fields
	var name = document.getElementById('name');
	var phone = document.getElementById('phone');	
	var email = document.getElementById('email');
	var city = document.getElementById('city');	
	var message = document.getElementById('message');
	// Check each input in the order that it appears in the form!
	if(isAlphabet(name, "Name sould not be blank"))
	{	
		if(isNumeric(phone, "Phone No should not be blank and only number"))
		{			
			if(emailValidator(email, "Please enter a valid email address"))
			{
				if(isAlphanumeric(city, "City should not be blank"))
				{
					if(isAlphanumeric(message, "Message should not be blank"))
					{
						return true;
					}
				}
			}
		}
	}
return false;
}



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

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


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

function isNumericport(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)){
		elem.style.borderColor='#00A2C6';
		return true;
	}else{
		elem.style.borderColor='#FF0000';
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){/[a-zA-Z0-9\.\,\/]/
	var alphaExp = /[0-9a-zA-Z\-^_.,<>?!@#$%&*()=}{"':;|><~`]+$/;
	if(elem.value.match(alphaExp)){
		elem.style.borderColor='#00A2C6';
		return true;
	}else{
		elem.style.borderColor='#FF0000';
		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 username between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function lengthRestrictionpass(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter password 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)){
		elem.style.borderColor='#00A2C6';
		return true;
	}else{
		elem.style.borderColor='#FF0000';
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function isValidIPAddress(ipaddr) {
   var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
   if (re.test(ipaddr)) {
      var parts = ipaddr.split(".");
      if (parseInt(parseFloat(parts[0])) == 0) { return false; }
      for (var i=0; i<parts.length; i++) {
         if (parseInt(parseFloat(parts[i])) > 255) { return false; }
      }
      return true;
   } else {
      return false;
   }
}





