var ie4 = false; 
if(document.all) { ie4 = true; }
function getObject(id) { 
  if (ie4) { return document.all[id]; } 
  else { return document.getElementById(id); } 
}

//Create a boolean variable to check for a valid MS instance.
var xmlhttp = false;

//Check if we are using IE.
try { //If the javascript version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) { //If not, then use the older active x object.
	try { //If we are using IE.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) { //Else we must be using a non-IE browser.
		xmlhttp = false;
	}
}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

function myAjax(source, destination) {
  var obj = getObject(destination);
  xmlhttp.open("GET", source);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      obj.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
}

function toggleDiv(divID) {
    obj = getObject(divID);
	if (obj.style.display != "none") {
	  new Effect.Fade(divID, {duration:0.5});
	} else {
	  new Effect.Appear(divID, {duration:0.8});
	}
	return false;
}

  function validPhone(field, alertTxt) {
    if (getObject(field)) {
      var phone = getObject(field).value.replace(/[^0-9]/g, '');
      if (phone.length < 7) {
        alert(alertTxt);
        getObject(field).focus();
        getObject(field).select();
        return false;
      } else {
        return true;
      }
    }
	return false;
  }  
  
  function validEmail(field,alertTxt) {
    if (getObject(field)) {
      var apos = getObject(field).value.indexOf("@");
      var dotpos = getObject(field).value.lastIndexOf(".");
      if ( apos < 1 || dotpos - apos < 2) {
	    alert(alertTxt);
	    getObject(field).focus();
	    getObject(field).select();
	    return false;
	  } else {
	    return true;
	  }
    }
	return false;
  }
  
  function validNonBlank(field, alertTxt) {
    if (getObject(field)) {
	  if (getObject(field).value.length < 1) {
	    alert(alertTxt);
	    getObject(field).focus();
	    getObject(field).select();
	    return false;
	  } else {
	    return true;
	  }
	}
  }
  
  function validateForm(which) {
	if (!validNonBlank(which+"-name", "Please enter your name.")) return false;
    if (!validPhone(which+"-phone","Please enter a valid Phone Number.")) return false;
	//if (!validEmail(which+"-email","Please enter a valid Email Address.")) return false;
	return true;
  }
  

