///////////////////////////
////// Dropdown Menu //////
///////////////////////////

sfHover = function() {
	var sfEls = document.getElementById("mainNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/////////////////////////
////// Google Maps //////
/////////////////////////

window.onload = function (){
	load();
};
	
window.onunload = function (){
	GUnload();
};

var gmarkers = [];
var htmls = [];
var i = 0;
 
function createMarker(point,name,html) {
	var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
    	marker.openInfoWindowHtml(html);
 	});
    gmarkers[i] = marker;
   	htmls[i] = html;
    i++;
    return marker;
}
 
var map = null;
var geocoder = null;
 
function load() {
	if (GBrowserIsCompatible()) {
    	map = new GMap2(document.getElementById("gMap"));
       	map.setCenter(new GLatLng(39.117619, -75.557613), 9);
        map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
        showAddress();
	}
}
 
function showAddress() {
	geocoder.getLatLng('1154 Pulaski Highway Bear, DE 19701', function(point) {
    	var marker = createMarker(point,"This place","<br><h3>Halpern Eye Associates</h3><strong>Bear Location</strong><br />1154 Pulaski Highway<br /> Bear, DE 19701<br /><a href='http://maps.google.com/maps?&near=1154 Pulaski Highway Bear, DE 19701' target='_blank'>Get Directions</a><br /><br />")
 		map.addOverlay(marker);
                         
    });
	geocoder.getLatLng('885 S. Governors Ave, Dover DE 19904',function(point) {
    	var marker = createMarker(point,"This place","<br><h3>Halpern Eye Associates</h3><strong>Dover Location</strong><br />885 S. Governors Ave<br /> Dover DE 19904<br /><a href='http://maps.google.com/maps?&near=885 S. Governors Ave, Dover DE 19904' target='_blank'>Get Directions</a><br /><br />")
 		map.addOverlay(marker);
    });
	geocoder.getLatLng('223 E. Main St, Middletown DE 19709',function(point) {
   		var marker = createMarker(point,"This place","<br><h3>Halpern Eye Associates</h3><strong>Middltown Location</strong><br />223 E. Main St.<br/>Middletown DE 19709<br /><a href='http://maps.google.com/maps?&near=223 E. Main St, Middletown DE 19709' target='_blank'>Get Directions</a><br /><br />")
 			map.addOverlay(marker);
    });
	geocoder.getLatLng('771 E. Masten Circle, Milford DE 19963',function(point) {
   		var marker = createMarker(point,"This place","<br><h3>Halpern Eye Associates</h3><strong>Milford Location</strong><br />771 E. Masten Circle<br/> Milford DE 19963<br /><a href='http://maps.google.com/maps?&near=71 E. Masten Circle, Milford DE 19963' target='_blank'>Get Directions</a><br /><br />")
 			map.addOverlay(marker);
    });
	geocoder.getLatLng('1301 Bridgeville Highway, Seaford DE 19973',function(point) {
   		var marker = createMarker(point,"This place","<br><h3>Halpern Eye Associates</h3><strong>Seaford Location</strong><br />1301 Bridgeville Highway<br/> Seaford DE 19973<br /><a href='http://maps.google.com/maps?&near=1301 Bridgeville Highway, Seaford DE 19973' target='_blank'>Get Directions</a><br /><br />")
 			map.addOverlay(marker);
    });
	geocoder.getLatLng('201 Stadium Street, Smyrna DE 19977',function(point) {
   		var marker = createMarker(point,"This place","<br><h3>Halpern Eye Associates</h3><strong>Smyrna Location</strong><br />201 Stadium Street<br/> Smyrna DE 19977<br /><a href='http://maps.google.com/maps?&near=201 Stadium Street, Smyrna DE 19977' target='_blank'>Get Directions</a><br /><br />")
 			map.addOverlay(marker);
    });
	geocoder.getLatLng('142 Atlantic Avenue, Millville DE 19967',function(point) {
   		var marker = createMarker(point,"This place","<br><h3>Halpern Eye Associates</h3><strong>Millville Location</strong><br />142 Atlantic Avenue<br/> Millville DE 19967<br /><a href='http://maps.google.com/maps?&near=142 Atlantic Avenue, Millville DE 19967' target='_blank'>Get Directions</a><br /><br />")
 			map.addOverlay(marker);
    });
}

/////////////////////////
////// SWFObject 2 //////
/////////////////////////

var flashvars = {};
var params = {};
params.wmode = "transparent";
var attributes = {};
swfobject.embedSWF("swf/header.swf", "banner", "885", "191", "9.0.0", "expressInstall.swf", flashvars, params, attributes);


////////////////////////////////
//// Request an Appointment ////
////////////////////////////////

function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.requestappt.name.value=="" || document.requestappt.name.value=="First, Last") {
themessage = themessage + " - Name";
}
if (!(document.requestappt.Email.value.match(/(\w+[\w|\.]*\w+)(@\w+[\w|\.]*\w+\.\w{2,3})/)) || document.requestappt.Email.value=="username@hostname.com") {
themessage = themessage + " -  E-mail Address";
}
if (document.requestappt.comments.value=="") {
themessage = themessage + " -  Comments";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
