/* DESCRIPTION: Helpful functions */
/* AUTHOR: Michael Haderman */
/* Last Edited: 2008-02-01 by MDH */	

/* DESCRIPTION: disables an element and changes css class */	
/* AUTHOR: Michael Haderman */
/* Last Edited: 2008-02-01 by MDH */	
function disableElement( id ) {
	document.getElementById( id ).disabled = true;
	document.getElementById( id ).className = 'disabled';
}

/* DESCRIPTION: enables an element and changes css class */	
/* AUTHOR: Michael Haderman */
/* Last Edited: 2008-02-01 by MDH */
function enableElement( id ) {
	document.getElementById( id ).disabled = false;
	document.getElementById( id ).className = "";
}

/* DESCRIPTION: returns the selected value of a radio button set */	
/* AUTHOR: http://www.somacon.com/ */
/* Last Edited: 2008-02-01 by MDH */
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function showHideEle( id ) {
	if( $(id).style.display == 'none' )
		$(id).show();
	else
		$(id).hide();
}


function validZipCode( sZip ) {
	reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
    if (!reZip.test(sZip))
    	return false;
	return true;
}

// Validates Email Address
// Author: SmartWebby.com (http://www.smartwebby.com/dhtml/)
function isEmailValid( str ) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (str.indexOf(at)==-1)
	   return false;

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   return false;

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	    return false;

	 if (str.indexOf(at,(lat+1))!=-1)
	    return false;

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	    return false;

	 if (str.indexOf(dot,(lat+2))==-1)
	    return false;
	
	 if (str.indexOf(" ")!=-1)
	    return false;

		 return true;			
}

/* DESCRIPTION: used to create a random number */	
/* AUTHOR: Alan Healy */
/* Last Edited: 01-26-2010 by ANH */
function randomNumber()
{
	var d = new Date();
	return d.getTime();
}

// Check for policy confirmation
function CheckPolicyAgree() {
var s = document.getElementById('PolicySpan');
var e = document.getElementById('PolicyError'); 	
	if ( document.getElementById('PolicyAgree').checked == false ) {
		s.style.border  = '1px solid red';
		e.style.visibility = 'visible';
	}
	return document.getElementById('PolicyAgree').checked;
}


function validateForwardForm(){
	var sTo = document.getElementById("sTo");
	var sFrom = document.getElementById("sFrom");
	var sFirstName = document.getElementById("sFirstName");
	var sLastName = document.getElementById("sLastName");
	var infoDiv = document.getElementById("info");
	
	var errorDiv = document.getElementById("error");
	var emailError = document.getElementById("emailError");
	var firstNameError = document.getElementById("firstNameError");
	var lastNameError = document.getElementById("lastNameError");
	
	var success = true;
	
	if(infoDiv != null){
		infoDiv.style.display = "none";
	}
	
	
	if( !isEmailValid(sTo.value) || !isEmailValid(sFrom.value) ){
		emailError.style.display = "inline";
		if( !isEmailValid(sTo.value) ){
			sTo.style.border = "1px solid red";
		}
		else{
			sTo.style.border = "1px solid #a4b97f";
		}
		if( !isEmailValid(sFrom.value) ){
			sFrom.style.border = "1px solid red";
		}
		else{
			sFrom.style.border = "1px solid #a4b97f";
		}
		success = false;
	}
	else{
		emailError.style.display = "none";
		if( !isEmailValid(sTo.value) ){
			sTo.style.border = "1px solid red";
		}
		else{
			sTo.style.border = "1px solid #a4b97f";
		}
		if( !isEmailValid(sFrom.value) ){
			sFrom.style.border = "1px solid red";
		}
		else{
			sFrom.style.border = "1px solid #a4b97f";
		}
	}
	
	if( sFirstName.value == "" ){
		firstNameError.style.display = "inline";
		sFirstName.style.border = "1px solid red";
		success = false;
	}
	else{
		firstNameError.style.display = "none";
		sFirstName.style.border = "1px solid #a4b97f";
	}
	
	if( sLastName.value == "" ){
		lastNameError.style.display = "inline";
		sLastName.style.border = "1px solid red";
		success = false;
	}
	else{
		lastNameError.style.display = "none";
		sLastName.style.border = "1px solid #a4b97f";
	}
	
	if( success ){
		errorDiv.style.display = "none";
	}
	else{
		errorDiv.style.display = "block";
	}
	
	return success;
}

function displayErrorMessage(){

}
