/* 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 initialize a google map */	
/* AUTHOR: Alan Healy */
/* Last Edited: 01-26-2010 by ANH */
function initialize(websiteURL) 
{
	if (GBrowserIsCompatible()) 
  	{
  		map = new GMap2(document.getElementById("map_canvas")); 
    	map.setCenter(new GLatLng(38,-96), 4); 
    	map.addControl(new GMapTypeControl());
    	map.addControl(new GLargeMapControl());
    	map.enableScrollWheelZoom();
    	map.addMapType(G_PHYSICAL_MAP);
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.setMapType(G_PHYSICAL_MAP);

		layer0 = new GGeoXml(websiteURL + "/KML/enviroflashCities.kmz?id="+randomNumber());//Default onload layer
		
		// Show the default onload layer
		map.addOverlay(layer0);
	}
	else 
	{
		document.getElementById("map_canvas").style.backgroundColor = '#E6F1F5';
		document.getElementById("map_canvas").innerHTML = "<div style='margin: 180px 110px;'>Sorry, your browser does not appear to be compatible with Google maps.</div>";
	}
}	

/* 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;
}
