// JScript File
//Copyright 2003-2010 by Ars Datum, Inc. All rights reserved. 

//NOTE: GOOGLE KEY assigned in arsMap.js

//global variables for each Page
var IsIE = $.browser.msie;          //check if browser is IE, IE's width/height differs from Mozilla by a little bit
var BrowserVer = $.browser.version;
var wdWindow = parseInt(document.documentElement.clientWidth);
var htWindow = parseInt(document.documentElement.clientHeight);
var htTop = 130;        //nav and header section
var htBottom = 40;      //footer section
var popUpStatus = 0;    //boolean to show/hide popup window (0==>hide, 1==>show)

//map variables
var websiteURL = "http://api.cctraffic.net/";
//var websiteMapIcon = "http://api.mrtlab.com/feeds/map/";
var sponsorWebsiteServer = 'http://sponsor.cctraffic.net/';
var mapLayerServer = 'http://fox.cctraffic.net/map/';

//global functions

//highlight a list item: onmouseover and onmouseout
function Hover(className) {
    $("."+className).hover(
        function () {
            //action when hover over
            $(this).css({backgroundColor: '#ECECEC', cursor: 'arrow'});
            $(this).find(".admin").css({visibility: 'visible'});
        },
        function () {
            //action when hover out
            $(this).css({backgroundColor: '#FFFFFF'});
            $(this).find(".admin").css({visibility: 'hidden'});
        }
    );
}

//highlight a list item: onmouseover and onmouseout and show mouse as pointer
function HoverClick(className) {
    $("."+className).hover(
        function () {
            //action when hover over
            $(this).css({backgroundColor: '#ECECEC', cursor: 'pointer'});
            $(this).find(".admin").css({visibility: 'visible'});
        },
        function () {
            //action when hover out
            $(this).css({backgroundColor: '#FFFFFF', cursor: 'default'});
            $(this).find(".admin").css({visibility: 'hidden'});
        }
    );
}

//highlight a list item: onmouseover and onmouseout and show mouse as pointer
function CursorOver(className, cursorName) {
    $("."+className).hover(
        function () {
            //action when hover over
            $(this).css({cursor: cursorName});
        },
        function () {
            //action when hover out
            $(this).css({cursor: 'default'});
        }
    );
}

//highlight a sub-list item: onmouseover and onmouseout
function HoverSub(className) {
    $("."+className).hover(
        function () {
            //action when hover over
            $(this).find(".admin-sub").css({visibility: 'visible'});
        },
        function () {
            //action when hover out
            $(this).find(".admin-sub").css({visibility: 'hidden'});
        }
    );
}

//highlight a traffic list item: onmouseover and onmouseout
function HoverTraffic(className) {
    $("."+className).hover(
        function () {
            //action when hover over
            var color = $(this).attr("color");
            $(this).removeClass(color);
            $(this).addClass(color + 'Highlight');
        },
        function () {
            //action when hover out
            var color = $(this).attr("color");
            $(this).removeClass(color + 'Highlight');
            $(this).addClass(color);
        }
    );
}

//onmouseover and onmouseout for button class
function HoverButton(className) {
    $("."+className).hover(
        function () {
            //action when hover over
            $(this).removeClass("button")
            $(this).addClass("buttonHover")
            $(this).find("a").css({color: '#444444'});
        },
        function () {
            //action when hover out
            $(this).removeClass("buttonHover")
            $(this).addClass("button")
            $(this).find("a").css({color: '#444444'});
        }
    );
}

//center the popup window
function CenterPopUpWindow() {
    var popUpWidth = $("#popUpWindow").width();
    var popUpHeight = $("#popUpWindow").height();
    var posTop = (htWindow/2 - popUpHeight/2);
    var posLeft = (wdWindow/2 - popUpWidth/2);
    
    //center it
    $("#popUpWindow").css({"position": "absolute", "top": posTop, "left": posLeft});
    $("#popUpBackground").css({"height": htWindow});
}

//show the popup window
function ShowPopUpWindow() {
    if (popUpStatus == 0) {
        $("#popUpBackground").css({"opacity": "0.7"});

        $("#popUpBackground").fadeIn("slow");
        $("#popUpWindow").fadeIn("slow");
        
        //center the popup
        CenterPopUpWindow();
        
        //flag a popup window is being displayed
        popUpStatus = 1;
    }
}

//hide the popup window
function HidePopUpWindow() {
    if (popUpStatus == 1) {
        $("#popUpHeader").html("");
        $("#popUpContent").html("");
        $("#popUpBackground").fadeOut("slow");
        $("#popUpWindow").fadeOut("slow");
        popUpStatus = 0;
    }
}


//check / un-check all checkboxes
function CheckAll(oCheckbox, value) {
    if (oCheckbox) {
        var lenCheckbox = oCheckbox.length;
        if (lenCheckbox > '') {
            for (i=0; i < lenCheckbox; i++) {
                if (value == 1)
                    oCheckbox[i].checked = true;
                else
                    oCheckbox[i].checked = false;
            }                
        } else {
            //only one item
            if (value == 1)
                oCheckbox.checked = true;
            else
                oCheckbox.checked = false;
        }            
    }
}

//get the first id checked
function GetID(oCheckbox) {
    var returnID = '';
    if (oCheckbox) {
        var lenCheckbox = oCheckbox.length;
        if (lenCheckbox > '') {
            for (i=0; i < lenCheckbox; i++) {
                if (oCheckbox[i].checked == true) {
                    returnID = oCheckbox[i].value;
                    break;
                }
            }                
        } else {
            //only one item
            if (oCheckbox.checked == true)
                returnID = oCheckbox.value;
        }            
    }

    return returnID;
}

//get the first attribute checked
function GetAttr(oCheckbox, attrName) {
    var returnAttr = '';
    if (oCheckbox) {
        var lenCheckbox = oCheckbox.length;
        if (lenCheckbox > '') {
            for (i=0; i < lenCheckbox; i++) {
                if (oCheckbox[i].checked == true) {
                    returnAttr = oCheckbox[i].attributes[attrName].value;
                    break;
                }
            }                
        } else {
            //only one item
            if (oCheckbox.checked == true)
                returnAttr = oCheckbox.attributes[attrName].value;
        }            
    }

    return returnAttr;
}

//get the all id checked
function GetAllID(oCheckbox) {
    var returnID = '';
    var delimiter = ',';
    if (arguments.length > 1)
        delimiter = arguments[1];
    
    if (oCheckbox) {
        var lenCheckbox = oCheckbox.length;
        if (lenCheckbox > '') {
            for (i=0; i < lenCheckbox; i++) {
                if (oCheckbox[i].checked == true) {
                    if (returnID > '')
                        returnID += delimiter;
                    returnID += oCheckbox[i].value;
                }
            }                
        } else {
            //only one item
            if (oCheckbox.checked == true)
                returnID = oCheckbox.value;
        }            
    }

    return returnID;
}



