﻿//---------------------------------------------------------------------------------------------------------------
//ONLOAD - Event:
if (window.onload){
	var funWindowLoad = window.onload;
	window.onload = new Function("funWindowLoad(); Window_OnLoad();");
}
else
	window.onload = Window_OnLoad;
	
//---------------------------------------------------------------------------------------------------------------
function Window_OnLoad(){		

    //Check to see if the _form has been set yet, it could have been set in uof.js:
    if (_form == null) _form = document.frmMain;    
		
}
//---------------------------------------------------------------------------------------------------------------
function SendEmail(){	    
	
	//Make sure required fields are filled in:
	if (Trim(_form.txtFirstName.value) == ""){	
		alert("Please enter your first name.");
		_form.txtFirstName.focus();
		return;		
	}	
	
	if (Trim(_form.txtFirstName.value).length < 2 ){	
		alert("Please enter a valid first name.");
		_form.txtFirstName.focus();
		return;		
	}	
		
	if (Trim(_form.txtLastName.value) == ""){	
		alert("Please enter your last name.");
		_form.txtLastName.focus();
		return;		
	}	
	
	if (Trim(_form.txtLastName.value).length < 2 ){	
		alert("Please enter a valid last name.");
		_form.txtFirstName.focus();
		return;		
	}	
		
	if (Trim(_form.txtEmailFrom.value) == ""){	
		alert("Please enter your email address.");
		_form.txtEmailFrom.focus();
		return;		
	}
	if (!IsEmail(Trim(_form.txtEmailFrom.value))){	
		alert("Please enter a valid email address.");
		_form.txtEmailFrom.focus();		
		return;		
	}		
	if (Trim(_form.txtVerifyEmail.value) == ""){	
		alert("Please verify your email address.");
		_form.txtVerifyEmail.focus();
		return;
	}
	if (Trim(_form.txtEmailFrom.value) != Trim(_form.txtVerifyEmail.value)){	
		alert("The second entry of your email address must match your first entry.");
		_form.txtVerifyEmail.focus();
		return;		
	}		
	
	if (Trim(_form.txtComments.value) == ""){	
		alert("Please enter your question/comment.");
		_form.txtComments.focus();
		return;		
	}
	
	if (Trim(_form.txtComments.value).length < 2 ){	
		alert("Please enter your question/comment.");
		_form.txtFirstName.focus();
		return;		
	}	
	
	//Search for spam words and stop email if any are found:
    var wordsToSearch = /search engine|white hat|google ranking|increase traffic|online leads/;   
    var matchWords = _form.txtComments.value.toLowerCase().search(wordsToSearch);
    
    if(matchWords != -1){
	    alert("Your email was successfully sent.");	 
	    document.location.href = "default.aspx";
	    return;   
    }		
	
	//Disable the button:
	_form.cmdSendEmail.disabled = true;
	
	//Call the callback method:
	resultArray = cbSendEmail(
	                        escape(document.getElementById("tblContactForm").getAttribute("source")),
	                        escape((_form.txtAgentEmail == null?"":_form.txtAgentEmail.value)),
                            escape(_form.txtFirstName.value),
                            escape(_form.txtLastName.value),
                            escape(_form.txtEmailFrom.value),
                            escape(document.getElementById("divSubject").innerHTML),
                            escape(_form.txtComments.value)
	                         ).split("<cb_col>");
	                         
	//Evaluate result:                     
	if (resultArray[0] == "0"){	    
	
	    alert("Your email was successfully sent.");
	    document.location.href = "default.aspx";
	    	
	}
	else {
	
	    //Show the error:
	    alert(resultArray[1]);
	
	}	
	
	//Enable the button:
	_form.cmdSendEmail.disabled = false;	
	             
}
//---------------------------------------------------------------------------------------------------------------
