/*

	/global/global.js
	===================================
	ShowImage
	
*/

// Global Constants

var vbCrLf = "\r\n";
var vbTab = "\t";
var keyEnter = 13;
var m_intMaxDistance = 10;
var m_blnFormSubmit = false;
var m_strSearchType = "";


// Global Functions

function ShowImage(strUrl, strTitle, strAlt) {
	if (strUrl.length > 0) {
		var intHeight = 200;
		var intWidth = 200;
		var intTop;
		var intLeft;
		var ImageViewer;
		var strImageViewerProperties;

		intTop = window.screen.height;
		intLeft = window.screen.width;
		strImageViewerProperties = "channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=yes,toolbar=no,top="+intTop+",left="+intLeft+",height="+intHeight+",width="+intWidth;

		ImageViewer = window.open("/picture.asp?url="+strUrl+"&title="+strTitle+"&alt="+strAlt, "ImageViewer", strImageViewerProperties);
		intTop = (window.screen.availHeight - intHeight)/2;
		intLeft = (window.screen.availWidth - intWidth)/2;

		ImageViewer.resizeTo(intWidth, intHeight);
		ImageViewer.moveTo(intLeft, intTop);
	}
}


function GetIntFromStr(str) {
	return parseInt(str.replace(/\D/g, ""));
}


function MileageLookup() {
	var strMileage = document.getElementById("txtMileage").value;
	if (strMileage.length > 0) {
		m_blnFormSubmit = true;
		document.getElementById("HiddenFrame").src = "/mileage.asp?miles=" + strMileage;
	} else {
		alert("Please enter your mileage.");
		document.getElementById("txtMileage").focus();
	}
}


function Mileage_enter(e) {
	var objKey = (window.event) ? window.event.keyCode : e.which;
	if (objKey == keyEnter) {
		MileageLookup();
	}
}


function eventPointGrabbed(arrPoint, strType) {
	if (arrPoint) {
		var strServiceValue = "";
		var lstServices = document.getElementById("lstServices");
		if (lstServices && strType != "zip") {
			if (lstServices.options[lstServices.selectedIndex].value.length == 0) {
				alert("Select a service to search for.");
				return false;
			} else {
				strServiceValue = "&service=" + lstServices.options[lstServices.selectedIndex].value;
			}
		}
		
		//document.getElementById("HiddenFrame").src = "/global/maps/blank.html";
		m_blnFormSubmit = true;
		location.href = "/proximitysearch.asp?lat=" + arrPoint[0] + "&lng=" + arrPoint[1] + "&max=" + m_intMaxDistance + strServiceValue + "&type=" + m_strSearchType;
	} else {
		alert("Invalid location, unable to return map coordinates.");
	}
}


function LocationSearch() {
	m_intMaxDistance = 20;
	m_strSearchType = "zip";
	var strZipCode = document.getElementById("txtLocation").value;
	strZipCode = strZipCode.replace(/\D/g, "");
	if (strZipCode.length == 5) {
		m_blnFormSubmit = true;
		document.getElementById("HiddenFrame").src = "/global/maps/coordinates.asp?address=" + strZipCode + "&type=zip";
	} else {
		alert("Please enter a valid zip code.");
		document.getElementById("txtLocation").focus();
	}
}


function Location_enter(e) {
	var objKey = (window.event) ? window.event.keyCode : e.which;
	if (objKey == keyEnter) {
		LocationSearch();
	}
}


function FindKwikKar() {
	var lstServices = document.getElementById("lstServices");
	if (lstServices) {
		if (lstServices.options[lstServices.selectedIndex].value.length == 0) {
			alert("Select a service to search for.");
			return false;
		}
	}

	var strFullAddress = "";
	var strAddress = document.getElementById("txtAddress").value;
	var strCity = document.getElementById("txtCity").value;
	var strState = document.getElementById("lstState").options[document.getElementById("lstState").selectedIndex].value;
	var strZip = document.getElementById("txtZip").value;
	var intDistance = document.getElementById("lstDistance").options[document.getElementById("lstDistance").selectedIndex].value;

	m_intMaxDistance = intDistance;
	if (strAddress.length > 0 && strCity.length > 0 && strState.length > 0) {
		strFullAddress = (strAddress.length > 0) ? strAddress + ", " : "";
		strFullAddress += strCity + ", " + strState;
		strFullAddress = (strZip.length > 0) ? strFullAddress + " " + strZip : strFullAddress;
		m_blnFormSubmit = true;
		document.getElementById("HiddenFrame").src = "/global/maps/coordinates.asp?address=" + strFullAddress;
	/*} else if (strZip.length > 0) {
		strFullAddress = (strAddress.length > 0) ? strAddress + ", " : "";
		strFullAddress += strZip;
		m_blnFormSubmit = true;
		document.getElementById("HiddenFrame").src = "/global/maps/coordinates.asp?address=" + strFullAddress;*/
	} else {
		alert("Please enter your complete address.");
		document.getElementById("txtAddress").focus();
	}
}


function LookupService() {
	var lstServices = document.getElementById("lstServices");
	var intServiceId = lstServices.options[lstServices.selectedIndex].value;
	var intLocationId = GetQueryString("id");
	if (m_strNickname.length > 0) {
		location.href = "/" + m_strNickname + "/services?sid=" + intServiceId;
	} else {
		location.href = "/content/service/?id=" + intLocationId + "&sid=" + intServiceId;
	}
}


function GetQueryString(strVariable) {
	if (document.location.search.length > 0) {
		var astrQueryString = document.location.search.substr(1).split("&");
		var astrValuePair;

		for (i=0;i<astrQueryString.length;i++) {
			astrValuePair = astrQueryString[i].split("=");
			if (astrValuePair[0] == strVariable) {
				return unescape(astrValuePair[1]);
			}
		}
	}
	return "";
}
