/*
Rajasekaran the mad scientist behind this.
rajasekaran@sdi.la
http://rhinointernet.com
*/

//contact us form validations
function popupvalidate(){	
		
   	var focusname=false;
	var message='';
	if($('#fullname').attr('value')==''){
		message += 'The full name field is required. \n';
		$('#fullname').focus();
		focusname = true;
	}
	if($('#phone').attr('value')==''){
		message += 'The phone number field is required. \n';
		if(focusname==false) {
			focusname=true;
			$('#phone').focus();
		}
	} else if($('#phone').attr('value').length<10){
		message += 'The phone number field must be minimum 10 characters in length. \n';
		if(focusname==false) {
			focusname=true;
			$('#phone').focus();
		}

	}
	if($('#email').attr('value')==''){
		message += 'The email field is required. \n';
		if(focusname==false) {
			focusname=true;
			$('#email').focus();
		}
	}else {
		if(!isValidEmailAddress($('#email').attr('value'))){
			message += 'The email field must contain a valid email address. \n';
			if(focusname==false) {
				focusname=true;
				$('#email').focus();
			}
		}

	}
	if(message!=''){
		alert(message);
		return false;

	}
	
}

//email validations check
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}


//phone no and zipcode allow only digits
$(document).ready(function(){
	$('#zip').keypress(function (e)
		{
		  //if the letter is not digit then display error and don't type anything
		  if( e.which!=8 && e.which!=0 && e.which!=32 && (e.which<48 || e.which>57) && e.which!=13 && e.which!=45)
		  {
			//display error message
			$('#errmsg').html('Digits Only').show().fadeOut('slow');
			return false;
		  }
	});
});


//select particular regarding options
function selectRegarding(id) {
	$('#regarding')[0].selectedIndex = (id-1);
	return true;
}


//The following function used to load the contact form automatically
$(document).ready(function(){
	if($('#errorcontactus').length>0){
		$('.popupcontainer').css('display','block');		
//		$('#errorcontactus p').css('margin','0 0 0 0');
	}
});

function hidecontactuserror(){
	$('.popupcontainer').css('top','135px');
	$('#errorcontactus').css('display','none');
	
}
