function clearText(thefield){
 if (thefield.defaultValue==thefield.value)
 thefield.value = ""
}

function setText(thefield){
 if (thefield.defaultValue=!thefield.value)
 thefield.value = thefield.defaultValue
} 

function XMLHTTPObject() {
    var xmlhttp=false;
    //If XMLHTTPReques is available
    if (XMLHttpRequest) {
        try {xmlhttp = new XMLHttpRequest();}
        catch(e) {xmlhttp = false;}
    } else if(typeof ActiveXObject != 'undefined') {
	//Use IE's ActiveX items to load the file.
        try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} 
        catch(e) {
            try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
            catch(E) {xmlhttp = false;}
        }
    } else  {
        xmlhttp = false; //Browser don't support Ajax
    }
    return xmlhttp;
}
var http = new XMLHTTPObject();


//This function will be called when the form is submited
function saveData() {
    var fname = document.getElementById("fname").value;
    var lname = document.getElementById("lname").value;
    var email = document.getElementById("email").value;
    var hphone = document.getElementById("hphone").value;
    var cphone = document.getElementById("cphone").value;
    var typeofcase = document.getElementById("typeofcase").value;
    //var disclaimer = document.getElementById("disclaimer").checked;
    
  	if ( fname=="First Name" || lname=="Last Name" || email=="Email" || hphone=="Main Phone" || typeofcase=="Type of Support" || fname=="" || lname=="" || email=="" || hphone=="" || typeofcase=="" ) 
	{
		alert('You must fill in First Name, Last Name, Main Phone, Email and Type of Support.');
		return false;
	}

/*
	if (disclaimer==false){
		alert('You must agree to the disclaimer before submitting this form!');
		return false;
	}
*/
    
    //By calling this file, we have saved the data.
    http.open("GET","/includes/small_form_send.php?fname=" + fname + "&lname=" + lname + "&email=" + email + "&hphone=" + hphone + "&cphone=" + cphone + "&typeofcase=" + typeofcase + "&return=confirm",true);
    
    http.onreadystatechange = function() {
        if(http.readyState == 4) {
            if(http.status == 200) {
                var result = http.responseText;
                var msg = ""
                result = result.substring(0,1);
                if(result == '1') {
                    //Display the thank you message.
                    msg = "<span class='text'>Thank you for your interest - we will respond as soon as possible.</span>";
                } else {
                    msg = "There was an error submitting this form, please try again later : " . result;
                }
                document.getElementById("form_elements").innerHTML = msg;
            }
        }
    }
    http.send(null);
    
    return false;//Prevent the form from being submited

}
function init() {
    if(http) {//If the browser supports Ajax functions
        //document.getElementById("contact_form").onsubmit = saveData; //The saveData function is attached to the submit action of the form.
    }
}
window.onload = init; //The 'init' function will be called when the page is loaded.
