﻿var ilMap = "none";
var nvMap = "none";
var mdMap = "none";
var flMap = "none";
var clMap = "none";
var errArr = new Array();

function changeCaptcha() {
	Contact.ChangeCaptcha(changeCaptcha_callback);
} //end changeCaptcha


function changeMoreInfo() {
	if (document.getElementById('moreInfo').value != "true") {
		document.getElementById('moreInfo').value = "true";
		document.getElementById('moreInfoImg').src = "/images/generic/input_checkBox_true.jpg";
	} else {
		document.getElementById('moreInfo').value = "false";
		document.getElementById('moreInfoImg').src = "/images/generic/input_checkBox_false.jpg";
	} //end if
} //end changeMoreInfo


function changeCaptcha_callback(res) {
	if (res.error != null) {
		document.getElementById('3').style.backgroundColor = "#FF0000";
		document.getElementById('3Error').innerHTML = "Server Error. Refresh Page; Try Again";
	} else if (res.value) {
		document.getElementById('captchaCell').innerHTML = "";
		document.getElementById('captchaCell').innerHTML = "<img src='/hidden/JpegImage.aspx?" + (new Date().getTime()) + "' alt='' />"
	} //end if
} //end changeCaptcha_callback


function switchMap(btnid) {
	var section = btnid.substring(0, btnid.indexOf('_'));
	var map = btnid.substring(btnid.indexOf('_') + 1, btnid.length);
	
	if (section == "corporate") {
		if (map == "overhead" && ilMap != "overhead") {
			document.getElementById(section).innerHTML = '<iframe width="655" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=3300+Washington+St,+Waukegan,+IL+60085&amp;sll=42.360256,-87.881109&amp;sspn=0.004305,0.008883&amp;ie=UTF8&amp;s=AARTsJocnt9yrof7A_nfs_sK0Vf6xNsrMg&amp;ll=42.367423,-87.878952&amp;spn=0.02061,0.056219&amp;z=14&amp;iwloc=addr&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=3300+Washington+St,+Waukegan,+IL+60085&amp;sll=42.360256,-87.881109&amp;sspn=0.004305,0.008883&amp;ie=UTF8&amp;ll=42.367423,-87.878952&amp;spn=0.02061,0.056219&amp;z=14&amp;iwloc=addr&amp;source=embed" style="text-align:left">View Larger Map</a></small>';
			ilMap = "overhead";
		} else if (map == "street" && ilMap != "street") {
			document.getElementById(section).innerHTML = '<iframe width="655" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/sv?cbp=1,381.2085752417057,,0,0.39743545095250693&amp;cbll=42.359567,-87.882853&amp;v=1&amp;panoid=tf6w8nrZtrEpRzdnvikrig&amp;gl=&amp;hl=en"></iframe><br /><small><a id="cbembedlink" href="http://maps.google.com/maps?cbp=1,381.2085752417057,,0,0.39743545095250693&cbll=42.359567,-87.882853&ll=42.359567,-87.882853&layer=c" style="text-align:left">View Larger Map</a></small>';
			ilMap = "street";
		} //end if
	} else if (section == "west") {
		if (map == "overhead" && nvMap != "overhead") {
			document.getElementById(section).innerHTML = '<iframe width="655" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=4040+Pioneer+Ave.+Las+Vegas,+NV+89102&amp;sll=36.135267,-115.254511&amp;sspn=0.004705,0.008883&amp;ie=UTF8&amp;s=AARTsJri7NXDIjivnaGs9kp4lMk5yAMxgQ&amp;ll=36.136072,-115.182896&amp;spn=0.022528,0.056219&amp;z=14&amp;iwloc=addr&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=4040+Pioneer+Ave.+Las+Vegas,+NV+89102&amp;sll=36.135267,-115.254511&amp;sspn=0.004705,0.008883&amp;ie=UTF8&amp;ll=36.136072,-115.182896&amp;spn=0.022528,0.056219&amp;z=14&amp;iwloc=addr&amp;source=embed" style="text-align:left">View Larger Map</a></small>';
			nvMap = "overhead";
		} else if (map == "street" && nvMap != "street") {
			document.getElementById(section).innerHTML = '<iframe width="655" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/sv?cbp=1,323.9211575670915,,0,3.9931485832676774&amp;cbll=36.128295,-115.193477&amp;v=1&amp;panoid=D4_dyvi-8cTu_odPvIXwRg&amp;gl=&amp;hl=en"></iframe><br /><small><a id="cbembedlink" href="http://maps.google.com/maps?cbp=1,323.9211575670915,,0,3.9931485832676774&cbll=36.128295,-115.193477&ll=36.128295,-115.193477&layer=c" style="text-align:left">View Larger Map</a></small>';
			nvMap = "street";
		} //end if
	} else if (section == "fl") {
	    if (map == "overhead" && flMap != "overhead") {
	        document.getElementById(section).innerHTML = '<iframe width="650" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=7548+Currency+Dr.+Orlando+FL&amp;sll=49.577527,15.938202&amp;sspn=0.009141,0.020578&amp;ie=UTF8&amp;ll=28.46107,-81.409292&amp;spn=0.024524,0.05579&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=7548+Currency+Dr.+Orlando+FL&amp;sll=49.577527,15.938202&amp;sspn=0.009141,0.020578&amp;ie=UTF8&amp;ll=28.46107,-81.409292&amp;spn=0.024524,0.05579&amp;z=14&amp;iwloc=A" style="text-align:left">View Larger Map</a></small>';
	        flMap = "overhead";
	    } else if (map == "street" && flMap != "street") {
	        document.getElementById(section).innerHTML = '<iframe width="655" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/sv?cbp=12,134.73,,0,-2.46&amp;cbll=28.45492,-81.409712&amp;v=1&amp;panoid=&amp;gl=&amp;hl=en"></iframe><br /><small><a id="cbembedlink" href="http://maps.google.com/maps?cbp=12,134.73,,0,-2.46&cbll=28.45492,-81.409712&ll=28.45492,-81.409712&layer=c" style="text-align:left">View Larger Map</a></small>';
	        flMap = "street";
	    } //end if
	} else if (section == "east") {
	    if (map == "overhead" && mdMap != "overhead") {
	        document.getElementById(section).innerHTML = '<iframe width="655" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=8919+McGaw+Ct.+Unit+%233+Columbia,+MD+21045&amp;aq=&amp;ie=UTF8&amp;hq=&amp;hnear=8919+McGaw+Ct+%233,+Columbia,+Maryland+21045&amp;t=m&amp;z=14&amp;vpsrc=0&amp;ll=39.188427,-76.824332&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=8919+McGaw+Ct.+Unit+%233+Columbia,+MD+21045&amp;aq=&amp;ie=UTF8&amp;hq=&amp;hnear=8919+McGaw+Ct+%233,+Columbia,+Maryland+21045&amp;t=m&amp;z=14&amp;vpsrc=0&amp;ll=39.188427,-76.824332" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
	        mdMap = "overhead";
	    } else if (map == "street" && mdMap != "street") {
			document.getElementById(section).innerHTML = '<iframe width="655" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/sv?cbp=12,139.77706759193362,,0,9.255910987482617&amp;cbll=39.126825,-76.82241&amp;v=1&amp;panoid=&amp;gl=us&amp;hl=en"></iframe><br /><small><a id="cbembedlink" href="http://maps.google.com/maps?cbp=12,139.77706759193362,,0,9.255910987482617&cbll=39.126825,-76.82241&ll=39.126825,-76.82241&layer=c" style="text-align:left">View Larger Map</a></small>';
			mdMap = "street";
	    } //end if
	} else if (section == "cl") {
		if (map == "overhead" && clMap != "overhead") {
			document.getElementById(section).innerHTML = '<iframe width="655" height="325" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=jose+ananias+104+macul+santiago+chile&amp;sll=-33.476735,-70.619109&amp;sspn=0.008627,0.016415&amp;ie=UTF8&amp;g=jose+ananias+104+macul+santiago+chile&amp;s=AARTsJpPhLdbAElaW_qav4BS0MEzf8SfXQ&amp;ll=-33.469898,-70.616426&amp;spn=0.025059,0.036478&amp;z=14&amp;iwloc=addr&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=jose+ananias+104+macul+santiago+chile&amp;sll=-33.476735,-70.619109&amp;sspn=0.008627,0.016415&amp;ie=UTF8&amp;g=jose+ananias+104+macul+santiago+chile&amp;ll=-33.469898,-70.616426&amp;spn=0.025059,0.036478&amp;z=14&amp;iwloc=addr&amp;source=embed" style="text-align:left">View Larger Map</a></small>';
			clMap = "overhead";
		} //end if
	} //end if
} //end switchMap


function sendMail() {
	triggerAlert(document.getElementById('contact_error'), "INFO", "Processing Request. Please Wait...");
	
	//clear any previous error DOM mutations
	for (var i = 0; i < errArr.length; i++) {
		var errorLoc = errArr[i].charAt(0);
		
		document.getElementById(errArr[i].charAt(0)).style.backgroundColor = "#FFFFFF";
		document.getElementById(errArr[i].charAt(0) + "Error").innerHTML = "";
	} //end for
	
	Contact.SendMail(
		document.getElementById('toSend').options[document.getElementById('toSend').selectedIndex].value,
		document.getElementById(nameID).value,
		document.getElementById(emailID).value,
		document.getElementById(organizationID).value,
		document.getElementById('address').value,
		document.getElementById('city').value,
		document.getElementById(phoneID).value, ValidatePhone(document.getElementById(phoneID)),
		document.getElementById('comments').value,
		document.getElementById('moreInfo').value,
		document.getElementById('captcha').value,
		sendMail_callback);
} //end sendMail


function sendMail_callback(res) {
	if (res.error != null) {
		triggerAlert(document.getElementById('contact_error'), "ERROR", "The Server was unable to complete your request. Please try again later. " + res.error);
	} else if (res.value[0] != null) {
		errArr = res.value;
		triggerAlert(document.getElementById('contact_error'), "WARNING", "Could Not Send Email. Please fix input errors before proceeding.");
		document.getElementById('captcha').value = "";
		changeCaptcha();
		
		for (var i = 0; i < res.value.length; i++) {
			var errorLoc = res.value[i].charAt(0);
			var errorMsg;
			
			errorMsg = res.value[i].substring(1, res.value[i].length);
			document.getElementById(errorLoc).style.backgroundColor = "#FFFE91";
			document.getElementById(errorLoc.toString() + "Error").innerHTML = errorMsg;
		} //end for
	} else {
		window.location = "/Default.aspx?msg=emailyes";
	} //end if
} //end sendMail_callback
