﻿function doClick(clientID, uniqueID, e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which;              //FF
    if (key == 13) {

        ////ClientID
        //var btn = document.getElementById(clientID);
        //if (btn != null) {
        //btn.click();
        //event.keyCode = 0
        //}

        //UniqueID
        __doPostBack('' + uniqueID + '', '');
    }
}

function makeMaxWin(url) {
    var vheight = screen.height - 200;
    var vwidth = screen.width - 100;
    makeWin(url, vheight, vwidth)
}

function makeWin(tUrl, strheight, strwidth) {
    agent = navigator.userAgent;
    windowName = "DefinitionWindow";

    var vwidth = strwidth;
    var vheight = strheight;
    var vtop = ((screen.height - vheight) / 2);
    var vleft = ((screen.width - vwidth) / 2);
    params = "";
    params += "toolbar=0,";
    params += "location=0,";
    params += "directories=0,";
    params += "status=0,";
    params += "menubar=0,";
    params += "scrollbars=1,";
    params += "resizable=1,";
    params += "width=" + vwidth + ",";
    params += "height=" + vheight + ",";
    params += "top=" + vtop + ",";
    params += "left=" + vleft;

    win = window.open(tUrl, windowName, params);
    if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1) {
        win = window.open(url, windowName, params);
    }
    if (!win.opener) {
        win.opener = window;
    }
}

function showHideDiv(Layer) {
    if (document.getElementById(Layer) != null) {
        if (document.getElementById(Layer).style.display == "" ||
            document.getElementById(Layer).style.display == "block")
            document.getElementById(Layer).style.display = "none";
        else
            document.getElementById(Layer).style.display = "block";
    }
}

function showItemLayer(Layer) {
    //Hide all
    for (i = 1; i < 21; i++) {
        if (document.getElementById('divItem' + i) != null) {
            document.getElementById('divItem' + i).style.display = "none";
            //Turn off class
            if (document.getElementById('liItem' + i) != null)
                document.getElementById('liItem' + i).className = "";
        }
        else
            break;
    }

    //Show 1 layer and set class to "highlight"
    if (document.getElementById('div' + Layer) != null)
        document.getElementById('div' + Layer).style.display = "block";
    if (document.getElementById('li' + Layer) != null)
        document.getElementById('li' + Layer).className = "highlight";
}


var mapCounter = 0;

function showLocation(latitude, longitude, description) {
    showLocation(latitude, longitude, description, "/Common/Images/custom/pushpin.gif");
}

function showLocation(latitude, longitude, description, pushPin) {
    var icon = new GIcon();
    icon.image = pushPin;
    icon.iconSize = new GSize(47, 24);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

    var point = new GLatLng(latitude, longitude);
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "click",
        function() {
            marker.openInfoWindowHtml(description);
        }
    );
    map.addOverlay(marker);
    if (mapCounter == 0)
        marker.openInfoWindowHtml(description);
    mapCounter++;
}

function centerAndDisplayLocation(latitude, longitude, description) {
    centerAndDisplayLocation(latitude, longitude, description, "/Common/Images/custom/pushpin.gif");
}

function centerAndDisplayLocation(latitude, longitude, description, pushPin) {
    var icon = new GIcon();
    icon.image = pushPin;
    icon.iconSize = new GSize(47, 24);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

    var point = new GLatLng(latitude, longitude);
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "click",
        function() {
            marker.openInfoWindowHtml(description);
        }
    );
    map.addOverlay(marker);
    marker.openInfoWindowHtml(description);
    map.setCenter(new GLatLng(latitude, longitude), 13);
}

function centerAndDisplayLocationZoom(latitude, longitude, description, pushPin, zoom) {
    var icon = new GIcon();
    icon.image = pushPin;
    icon.iconSize = new GSize(47, 24);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

    var point = new GLatLng(latitude, longitude);
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "click",
        function() {
            marker.openInfoWindowHtml(description);
        }
    );
    map.addOverlay(marker);
    marker.openInfoWindowHtml(description);
    map.setCenter(new GLatLng(latitude, longitude), zoom);
}

function checkFormSubmit(form) {
    if (typeof (Page_ClientValidate) == 'function') {
        Page_ClientValidate();
    }
    return Page_IsValid;
}

function checkFormSubmit(form, group) {
    if (typeof (Page_ClientValidate) == 'function') {
        Page_ClientValidate(group);
    }
    return Page_IsValid;
}


function showLocation(ele, latitude, longitude, description, locationID, locationIndex, pushPin) {

    if (ele == null || ele.length == 0) {
        ele = $('.location').eq(0)[0];
    }

    document.getElementById('LocationID').value = locationID;
    document.getElementById('LocationIndex').value = locationIndex;
    document.getElementById('divSelected').innerHTML = description;

    if (typeof (pushPin) != "undefined" && pushPin != "") {
        var icon = new GIcon(G_DEFAULT_ICON);
        icon.image = pushPin;
        icon.iconSize = new GSize(36, 28);
        icon.iconAnchor = new GPoint(18, 14);
        icon.infoWindowAnchor = new GPoint(18, 14);
    }
    else {
        var icon = new GIcon(G_DEFAULT_ICON);
    }

    var point = new GLatLng(latitude, longitude);
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, 'click',
        function() {
            marker.openInfoWindowHtml(description);
        }
    );
    map.addOverlay(marker);
    marker.openInfoWindowHtml(description);
    map.setCenter(new GLatLng(latitude, longitude), 13);

    if (ele.id != undefined) {
        $(".selectedLocation").removeClass("selectedLocation");
        $(ele).addClass("selectedLocation");
    }
    else {
    }
}

function DisableControl(controlId) {
    document.getElementById(controlId).disabled = true;
}

function DisableControl_SetTimeout(controlId, interval) {
    setTimeout("DisableControl('" + controlId + "')", interval);
}

function DisableControlInAMillisecond(control) {
    DisableControl_SetTimeout(control.id, 1);
}

function changeProductPhoto(imageID, zoomID, imageName) {
    document.getElementById(imageID).src = '/Common/Images/custom/products/' + imageName.replace('thumb', 'full');
    document.getElementById(zoomID).href = '/Common/Images/custom/products/' + imageName.replace('thumb', 'zoom');
}

function changeProductPhotoDDL(ddlID, imageID, zoomID) {
    var index = document.getElementById(ddlID).selectedIndex - 1;
    if (smallPhotos[ddlID] != null) {
        if (smallPhotos[ddlID][index] != null) {
            if (smallPhotos[ddlID][index] != '') {
              changeProductPhoto(imageID, zoomID, smallPhotos[ddlID][index]);               
            }
        }
    }
}
