/*Function to "break out" of framed pages*/
function brakeFrame(){
	if(top.location != self.location){
		top.location.href = document.location.href;
	}
}

function contactValidate(){
	//flag for first errors encountered. 
	var flagNum = 0;
	//flag for Name block errors
	var flagNameNum = 0;
	//flag for Address block errors
	var flagAddressNum = 0;
		
	//flag for blank email address
	var flagEmailAddressNum = 0;

	//flag for blank textarea
	//$flagQuestionNum = 0;
	var flagQuestionNum = 0;

	//for error message
	var errorText = "ERROR. Contact unsuccessful. Please enter\n\n";
	//for error messages based on blocks
	//Target email for form
	
	//***to change***
	//targetMail = 'info@petermount.au.com';
	
	//**********Name block****************
	//to make sure a first name is entered in input field
	//if (window.document.getElementById("dcccwebsitemail").firstname.value == "")
	//if (strlen($firstname) < 1){ 					//Must have first name
	if (window.document.getElementById("websitemail").firstname.value == ""){ //Must have first name
		errorText += "first name\n";
		flagNum++;
		flagNameNum++;
		}
	//to make sure a family name is entered in input field
	if (window.document.getElementById("websitemail").familyname.value == ""){
		errorText += "family name\n";
		flagNum++;
		flagNameNum++;
		}

	//*********Email block************
	//To see if an email address has been entered
	if((window.document.getElementById("websitemail").address.value == "") &&
	(window.document.getElementById("websitemail").email.value == ""))
	{
			errorText += "address or email address\n";
			flagNum++;
			flagEmailAddressNum++;
	}

	//In Javascript
	//To validate for valid email address
	var x=window.document.getElementById("websitemail") ;
	var Temp=x.email.value ;
	var EmailOk  = true ;
	var AtSym    = Temp.indexOf('@') ;
	var Period   = Temp.lastIndexOf('.') ;
	var Space    = Temp.indexOf(' ') ;
	var Length   = Temp.length - 1    ;
	if (((AtSym < 1) ||                     // '@' cannot be in first position
    	(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    	(Period == Length ) ||             // Must be atleast one valid char after '.'
    	(Space  != -1)) &&                  // No empty spaces permitted
		!(window.document.getElementById("websitemail").email.value == ""))

   	{  
		errorText += "valid e-mail\n";
		flagEmailAddressNum++;
		flagNum++;
   	}
	
	//To see if textarea has text in it
	if((window.document.getElementById("websitemail").question.value == ""))
	{
			errorText += "your question\n";
			flagNum++;
			flagQuestionNum++;
	}
	
	//To see if anything has been entered on the form
	if((window.document.getElementById("websitemail").firstname.value == "") &&
	(window.document.getElementById("websitemail").familyname.value == "") &&
	(window.document.getElementById("websitemail").email.value == "") &&
	(window.document.getElementById("websitemail").company.value == "") &&
	(window.document.getElementById("websitemail").address.value == "") &&
	(window.document.getElementById("websitemail").question.value == ""))
	{
		errorText = "ERROR. Contact unsuccessful.\n\nNothing entered on form";
		flagNum++;
	}	
	
	if(flagNum > 0)
	{
		window.alert(errorText);
	}
	
	//Return statements
	if(flagNum == 0)
		return true;
	return false;
}