﻿function updateLocation(strLat, strLng, strZoomLevel){
	objTextboxLat = document.getElementById("textboxLat");
	objTextboxLng = document.getElementById("textboxLng");
	objTextboxZoomLevel = document.getElementById("textboxZoomLevel");
	objTextboxLat.value = strLat;
	objTextboxLng.value = strLng;
	objTextboxZoomLevel.value = strZoomLevel;
}
function init(){
    var strEnabled = document.getElementById("mapEnableCheckbox").checked.toString();
    var strLat = document.getElementById("textboxLat").value;
    var strLng = document.getElementById("textboxLng").value;
    var strZoomLevel = document.getElementById("textboxZoomLevel").value;
    if(strLat.length>0 && strLng.length>0 && strZoomLevel.length>0){
        frames["mapIFrame"].location.href = "/SetLocation.aspx?lat="+strLat+"&lng="+strLng+"&zoomLevel="+strZoomLevel+"&enabled="+strEnabled;
    }else{
        frames["mapIFrame"].location.href = "/SetLocation.aspx";
    }
    var objAddressTextBox = document.getElementById("txt_PostAds_P_Address");
    var objMapSearchTextBox = document.getElementById("mapSearch");
    if(objAddressTextBox && objMapSearchTextBox){
        objAddressTextBox.onchange = function(){
            document.getElementById("mapSearch").value = document.getElementById("txt_PostAds_P_Address").value;
        };
        if(objAddressTextBox.value.length > 0){
            objMapSearchTextBox.value = objAddressTextBox.value;
        }
    }
}
function initMapShowLocation(){
    var strEnabled = document.getElementById("hiddenEnabled").value;
    var strLat = document.getElementById("hiddenLat").value;
    var strLng = document.getElementById("hiddenLng").value;
    var strZoomLevel = document.getElementById("hiddenZoomLevel").value;
    if(strLat.length>0 && strLng.length>0 && strZoomLevel.length>0 && strEnabled.toLowerCase() == "true"){
        frames["mapIFrame"].location.href = "/ShowLocation.aspx?lat="+strLat+"&lng="+strLng+"&zoomLevel="+strZoomLevel+"&enabled="+strEnabled;
    }else{
        frames["mapIFrame"].location.href = "/ShowLocation.aspx";
    }
}

function callIframeSearch(){
    document.getElementById("mapIFrame").contentWindow.showAddress(); 
    return false;
}
function iFramePlace(dblLat, dblLng, strChosenAddress){
    document.getElementById("mapIFrame").contentWindow.place(dblLat, dblLng); 
    document.getElementById("mapSearch").value = strChosenAddress;
}



function fireDefaultButton(event, target) {//Refer to: http://dev.sentia.com.au/mt-search.cgi?tag=asp.net%20jquery&blog_id=1
	if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
		var defaultButton = document.getElementById(target);
		if (defaultButton && typeof(defaultButton.click) != "undefined") {
			defaultButton.click();
			event.cancelBubble = true;
			if (event.stopPropagation) event.stopPropagation();
				return false;
			}
		}
	return true;
}
