﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="jquery/jquery-1.3.2.min-vsdoc2.js" />


function GetRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function GetRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

function GetWinWidth() {
    var mapFrameWidth = window.innerWidth;
    if (mapFrameWidth == null) {
        if (document.documentElement && document.documentElement.clientWidth)
            mapFrameWidth = document.documentElement.clientWidth
        else
            mapFrameWidth = document.body.clientWidth;
    }
    return mapFrameWidth;
}

function GetWinHeight() {
    var mapFrameHeight = window.innerHeight;
    if (mapFrameHeight == null) {
        if (document.documentElement && document.documentElement.clientHeight)
            mapFrameHeight = document.documentElement.clientHeight;
        else
            mapFrameHeight = document.body.clientHeight;
    }
    return mapFrameHeight;
}

/*MONITOR FUNCTIONS*/
function OpenZonesWindowWithCoords(lng, lat) {
    var url = 'aspx_zones.aspx?opt=n&lng=' + lng + '&lat=' + lat;
    window.open(url, "zonesWindow", "width=1000, height=670, menubar=0, status=0, toolbar=0, location=0, directories=0, scrollbars=1, resizable=0");
}

function CreateBrandsWithCoords(lng, lat) {
    var url = 'aspx_configuration.aspx?brands=1&opt=1&lng=' + lng + '&lat=' + lat;
    window.open(url, "zonesWindow", "width=950, height=590, menubar=0, status=0, toolbar=0, location=0, directories=0, scrollbars=1, resizable=0");
}

function OpenZonesWindow(zid) {
    var url = 'aspx_zones.aspx';
    if (zid != undefined) {
        if (zid > 0) url += "?opt=e&zid=" + zid;
        else url += "?opt=n";
    }
    window.open(url, "zonesWindow", "width=1000, height=670, menubar=0, status=0, toolbar=0, location=0, directories=0, scrollbars=1, resizable=0");
}


////////////////////////////div

var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

// open hidden layer
function mopen(id) {
    // cancel close timer
    mcancelclosetime();

    // close old layer
    if (ddmenuitem) ddmenuitem.style.display = 'none';

    // get new layer and show it
    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.display = 'block';
    ddmenuitem.style["z-index"] = "300000";
}
// close showed layer
function mclose() {
    if (ddmenuitem) ddmenuitem.style.display = 'none';
}

// go close timer
function mclosetime() {
    closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

// close layer when click-out
document.onclick = mclose;


/*MODAL POPUP*/
var modalCloseID = null;
var timerCloseID = null;
var maxTimeOpened = 0;
function RenderModalPopUp(message) {
    if (modalCloseID) window.clearTimeout(modalCloseID);
    if (timerCloseID) window.clearInterval(timerCloseID);
    maxTimeOpened = 30000;

    var d = document;
    var modal = document.getElementById("mainModal");
    modal.style.width = d.documentElement.scrollWidth + "px";
    modal.style.height = d.documentElement.scrollHeight + "px";

    document.getElementById("alertMessage").innerHTML = message;

    var box = document.getElementById("alertBox");
    box.style.left = (GetWinWidth() / 2) - (box.clientWidth / 2) + "px";
    box.style.top = (GetWinHeight() / 2) - (box.clientHeight / 2) + "px";

    box.style.visibility = "visible";
    modal.style.visibility = "visible";

    document.getElementById("clock").innerHTML = maxTimeOpened / 1000;
    modalCloseID = window.setTimeout("RemovePopUp()", maxTimeOpened);
    timerCloseID = window.setInterval("SetTimeClock()", 1000);

    PlayAlert("asjs");
}

function SetTimeClock() {
    maxTimeOpened -= 1000;
    document.getElementById("clock").innerHTML = maxTimeOpened / 1000;
}

function RemovePopUp() {
    document.getElementById("mainModal").style.visibility = "hidden";
    document.getElementById("alertBox").style.visibility = "hidden";
    window.clearTimeout(modalCloseID);
    window.clearInterval(timerCloseID);
    modalCloseID = timerCloseID = null;
    return false;
}

/*FLASH OBJECTS*/

function getFlashMovie(movieName) {
    return document[movieName];
}

function PlayAlert(flashID) {
    getFlashMovie(flashID).playSound();
}

var _furl = "http://feedback.location-world.com";
function MapFeedback() {
    var lat = 0;
    var lon = 0;
    if (monitor.map.map.spatialReference.wkid == 4326) {
        lat = monitor.map.map.extent.getCenter().y;
        lon = monitor.map.map.extent.getCenter().x;
    }
    else {
        var c = esri.geometry.webMercatorToGeographic(monitor.map.map.extent.getCenter());
        lat = c.y;
        lon = c.x;
    }
    
    /*var email = dojo.byId("userEmail").value;
    var name = $("#facebookProfileName").val().trim();
    if (email == "")
        email = $("#facebookProfileEmail").val().trim()*/

    var email = $("input[id*=hddUserEmail]").val();
    var name = $("input[id*=hddUserName]").val();

    window.open(_furl + "?url=" + (_hddSkin == "claro" ? "http://localizador.claro.com.ec" : "http://www.geo.com.ec") + "&lat=" + lat + "&lon=" + lon + "&iscenter=true&level=" + xGetConvertedLevel(monitor.map.map.getLevel()).toString() + (email == "" ? "" : "&email=" + email) + (name == "" ? "" : "&name=" + name), "LWFeedback", "", false);
}

function xGetConvertedLevel(l) {
    return monitor.map.map.spatialReference.wkid != 4326 ? l-1 : l;
}
