window.onload = function(){
	ie = false;
	w3c = false;
	
	if (document.all) {
	    ie = true;
	}else if (document.getElementById) {
	    w3c = true;
	}
	
	//try catch for the index page
	try{ 
		myTextArea = document.getElementById("otherTextArea");
		myForm = document.getElementById("requestATitle");
		
		if(ie){
   	    	myTextArea.attachEvent("focus",clearText);
			myForm.attachEvent("submit", checkForm);
    	}

		if(w3c){ 
        	myTextArea.addEventListener("focus",clearText,false);
			myForm.addEventListener("submit",checkForm,false);
    	}
	}catch(e){
		//do nothing I know it will break on sites because it has two html files pointing to the same js
	}
	
	//try catch for the contact page
	try{ 
		myContactForm = document.getElementById("contact");
		
		if(ie){
			myContactForm.attachEvent("submit",checkContactForm,false);
    	}

		if(w3c){ 
			myContactForm.addEventListener("submit",checkContactForm,false);
    	}
	}catch(e){
		//do nothing I know it will break on sites because it has two html files pointing to the same js
	}
}



function checkForm(e){
	myClientName = document.getElementById("clientName");
	myClientPhone = document.getElementById("clientPhone");
	myPropName = document.getElementById("propName");
	myPropAddy = document.getElementById("propAddy");
	myRundownType = document.getElementById("requestATitle");
	myOtherTextArea = document.getElementById("otherTextArea");
	
    error = "";
    if(myClientName.value == ""){
		error = "Please enter the Client Name.\n";
    }
    if(myClientPhone.value == "") {
      	error += "Please enter the Client Contact Number.\n";
    }
    if(myPropName.value == ""){
      	error += "Please enter the Parcel Owners Name.\n";
    }
    if(myPropAddy.value == ""){
      	error += "Please enter the address of the parcel.\n";
    }
    
	//right here we are going to go through and see if there is a rundown type
	rundownTypeValue = "";
	
	for (i=0;i<myRundownType.rundownType.length;i++){
		if (myRundownType.rundownType[i].checked){
			rundownTypeValue = myRundownType.rundownType[i].value;
		}
	}
	if(rundownTypeValue == ""){
		error += "Please enter a rundown type.\n";
	}
	
	if(rundownTypeValue == "other"){
		if(myOtherTextArea.value == "" || myOtherTextArea.value == "Enter details here if you selected other."){
			error += "Please describe the rundown type for other.";
		}
	}

    if(error != ""){
		if (e && e.preventDefault){
			alert(error);
			e.preventDefault(); // DOM style
		}else{
			alert(error);
			return false; // IE style\
		}
    }
  	return true;
}

function checkContactForm(e){
	myContactName = document.getElementById("contactName");
	myContactPhone = document.getElementById("contactEmail");
	myContactMessage = document.getElementById("contactMessage");
	
    error = "";
    if(myContactName.value == ""){
		error = "Please enter your name.\n";
    }
    if(myContactPhone.value == "") {
      	error += "Please enter your email address.\n";
    }
    if(myContactMessage.value == ""){
      	error += "Please enter your message.\n";
    }
    if(error != ""){
		if (e && e.preventDefault){
			alert(error);
			e.preventDefault(); // DOM style
		}else{
			alert(error);
			return false; // IE style\
		}
    }
  	return true;
}


function clearText(){
	myTextArea = document.getElementById("otherTextArea");
	if(myTextArea.value == "Enter details here if you selected other."){
		myTextArea.value = "";
	}
}
