/**
 * getElementSafely(id)
 * Safely gets the element by id in all versions of NS and IE.  Also
 * sets element.css or element.style depending on the browser.  After
 * a call to this function you may reference the element's style 
 * properties with either element.css or element.style
 * @param id	The element you want to get by id
 * @return		Reference to the element you want
 */
function getElementSafely(id) {
  var element = (document.getElementById) ? document.getElementById(id) : 
				(document.all) ? document.all[id] :
				(document.layers) ? document.layers[id] : null;
  if (element)
	element.css = (element.style) ? element.style : element;
  return element;
}

function doHighlight(id, color) {
  var element=getElementSafely(id);
  element.css.textDecoration="underline";
  element.css.color=color;
}

function unHighlight(id, color) {
  var element=getElementSafely(id);
  element.css.textDecoration="none";
  element.css.color=color;
}

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// 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);
}

function ValidateForm(){
	var Phone=document.contactForm.txtPhone
	var emailAddy=document.contactForm.email
	var emailAddy2=document.contactForm.email2
	var fname=document.contactForm.firstname
	var lname=document.contactForm.lastname
	var address=document.contactForm.address
	var state=document.contactForm.state
	var city=document.contactForm.city
	var zip=document.contactForm.zip
	var country=document.contactForm.country
	var time=document.contactForm.available

	if (fname.value == ""){
		alert("Please Provide Your First Name")
		fname.focus()
		return false
	}
	
	if (lname.value == ""){
		alert("Please Provide Your Last Name")
		lname.focus()
		return false
	}
	
	if (address.value == ""){
		alert("Please Provide Your Address")
		address.focus()
		return false
	}
	
	if (city.value == ""){
		alert("Please Provide Your City")
		city.focus()
		return false
	}

	if (state.value == "" && country.value == "United States of America"){
		alert("Please Provide Your State or Province")
		state.focus()
		return false
	}
	
	if (zip.value == ""){
		alert("Please Provide Your Zip Code")
		zip.focus()
		return false
	}

	if (country.value == ""){
		alert("Please Provide Your Country")
		country.focus()
		return false
	}
	
	//E-mail	
	if (emailAddy.value == "" ||
		((emailAddy.value.indexOf ('@',0) == -1 ||
   			emailAddy.value.indexOf ('.',0) == -1) &&
	   		emailAddy.value != ""))
  	{
    	alert("Please Provide a Valid E-mail Address")
		email.value=""
		email.focus()
		return false
  	}
  	if (emailAddy.value != emailAddy2.value)
  	{
    	alert("Please Check your E-mail Address")
		email.focus()
		return false
  	}
  	
  	
	//Phone
	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.value=""
		Phone.focus()
		return false
	}
		
	if (time.value == ""){
		alert("Please Provide Your Phone Availability")
		time.focus()
		return false
	}

  	return true
 }
