﻿/*--------------------------------------------------------------*
    ShowDiv() - shows div element
*---------------------------------------------------------------*/
function ShowDiv(WhatId) {
    document.getElementById(WhatId).style.display = "block";
}

/*--------------------------------------------------------------*
    HideDiv() - hides div element
*---------------------------------------------------------------*/
function HideDiv(WhatId) {
    document.getElementById(WhatId).style.display = "none";
}

/*--------------------------------------------------------------*
    ShowHideDiv() - shows and hides div element (automatic)
*---------------------------------------------------------------*/
function ShowHideDiv(WhatId) {
    var DivStyle = document.getElementById(WhatId).style;

    if (DivStyle.display == "block") {
        DivStyle.display = "none";
    } else {
        DivStyle.display = "block";
    }
}

/*--------------------------------------------------------------*
    ShowHidePopupDiv() - shows and hides div element (automatic)
                          acting as a popup and position it relatively to PopupParent
*---------------------------------------------------------------*/
function ShowHidePopupDiv(WhatId, PopupParent) {
    var DivStyle = document.getElementById(WhatId).style;

    if (DivStyle.display == "block") {
        DivStyle.zIndex = 0;
        DivStyle.display = "none";
    } else {
        DivStyle.display = "block";
        DivStyle.zIndex = 200;
        DivStyle.left = PopupParent.offsetLeft + "px";
        DivStyle.top = PopupParent.offsetTop + parseInt(PopupParent.style.height) + "px";
    }
}

/*--------------------------------------------------------------*
    ChangeDivBg() - changes div background
*---------------------------------------------------------------*/
function ChangeDivBg(WhatId, Color) {
    document.getElementById(WhatId).style.backgroundColor = Color;
}

/*--------------------------------------------------------------*
    ChangeDivBgBorder() - changes div background and border
*---------------------------------------------------------------*/
function ChangeDivBgBorder(WhatBgId, Color, WhatBorderId, Border) {
    document.getElementById(WhatBgId).style.backgroundColor = Color;
    document.getElementById(WhatBorderId).style.border = Border;
}

/*--------------------------------------------------------------*
    ShowFullscreenMap() - shows map in fullscreen mode
*---------------------------------------------------------------*/
function ShowFullscreenMap() {
    var NewWindow = window.open("/Map.aspx", "newwin", "fullscreen=yes,toolbar=0,location=0,direct ories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + screen.width + ",height=" + screen.height);
    NewWindow.focus();
}

/*--------------------------------------------------------------*
    
*---------------------------------------------------------------*/

function SelectFromImgList(IconImgSrc, IconIDForm, IconGroupForm, IconID, IconGroup) {
    document.getElementById('SelectedImg').src = IconImgSrc;
    IconIDForm.value = IconID;
    IconGroupForm.value = IconGroup;
}

function SelectFromColorList(IconPickerUpdate, IconColorForm, Color, ColorID) {
    document.getElementById('SelectedColor').style.backgroundColor = Color;
    IconColorForm.value = ColorID;
    __doPostBack(IconPickerUpdate, "");
}

function SelectFromDeviceList(DevicePickerUpdate, DeviceIDForm, DeviceID) {
    DeviceIDForm.value = DeviceID;
    __doPostBack(DevicePickerUpdate, "");
}

function SelectFromDriverList(DriverPickerUpdate, DriverIDForm, DriverID) {
    DriverIDForm.value = DriverID;
    __doPostBack(DriverPickerUpdate, "");
}

function CheckDate(d, m, y) {
    return m > 0 && m < 13 && y > 0 && y < 32768 && d > 0 && d <= (new Date(y, m, 0)).getDate();
}

function CheckTime24(h, m, s) {
    return h >= 0 && h < 24 && m >= 0 && m < 60 && s >= 0 && s < 60;
}

function autoIframe(frameId) {
    try{
        IFrameInstance = document.getElementById(frameId);
        IFrameInstance.on
        InnerDoc = (IFrameInstance.contentDocument) ? IFrameInstance.contentDocument : IFrameInstance.contentWindow.document;

        IFrameInstance.height = InnerDoc.body.scrollHeight + 20;
        if (IFrameInstance.height < 450) IFrameInstance.height = 450;
    }
    catch(err){
        window.status = err.message;
    }
}

function CopyObject(obj) {
    if (obj == null || typeof (obj) != 'object')
        return obj;

    var temp = new obj.constructor(); // changed

    for (var key in obj) {
        temp[key] = CopyObject(obj[key]);
    }
    return temp;
}

