jQuery.noConflict();
jQuery(document).ready(function($){ 
		adjustFooter();
		$(window).resize(adjustFooter);
		function adjustFooter(){
			if($("body").height()<$(window).height()){
				$("#footer").addClass("bottomFixed");
			}else{
				$("#footer").removeClass("bottomFixed"); 
			}
		} 
});


				
//===== contact form validation ==========//
String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};	

function validateForm(){
	var isValid = true;
	var _FirstName = document.getElementsByName('FirstName').item(0);
	var _LastName = document.getElementsByName('LastName').item(0);
	var _Company = document.getElementsByName('Company').item(0);
	var _Title = document.getElementsByName('Title').item(0);
	var _Phone = document.getElementsByName('Phone').item(0);
	var _Email = document.getElementsByName('Email').item(0);
	
	if(_FirstName.value.trim()==""){
		alert("Please Enter Your First Name");
		_FirstName.focus();
		isValid = false;
	}
	else if(!is_vaild_str(_FirstName.value)){
		alert("Only letters and spaces are allowed in the First Name field");
		_FirstName.focus();
		isValid = false;	
	}
	else if(_LastName.value.trim()==""){
		alert("Please Enter Your Last Name");
		_LastName.focus();
		isValid = false;
	}
	else if(!is_vaild_str(_LastName.value)){
		alert("Only letters and spaces are allowed in the Last Name field");
		_LastName.focus();
		isValid = false;
	}
	else if(!is_vaild_title(_Title.value)){
		alert("Only letters,spaces and periods are allowed in the Title field");
		_Title.focus();
		isValid = false;	
	}
	else if(!is_valid_phone(_Phone)){
		isValid = false;
	}
	else if(!is_valid_email(_Email.value)){
		alert("Please Enter Your Valid Email Address");
		_Email.focus();
		isValid = false;
	}
	var _ContactMe = document.getElementsByName('ContactMe').item(0).checked;
	
	return isValid;	
}

function is_vaild_str(strobj){
	   return  /^[a-zA-Z\s]+$/.test(strobj);
}	

function is_vaild_title(strobj){
	   return  /^[a-zA-Z\s\.]+$/.test(strobj);
}	   

function is_valid_email(email){
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

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 trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
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){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function is_valid_phone(Phone){	

	if ((trim(Phone.value)!="") && checkInternationalPhone(Phone.value)==false){
		alert("Please Enter A Valid Phone Number. Example 555-555-5555");
		Phone.focus();
		return false;
	}
	return true
 }
		
