﻿// JavaScript File
/****************
Cookie Control
****************/
var Cookie = {
    /*
    * create cookie
    */
    'create' : function(key, value, days) {
        
        var expiresOn;
        
        if(days != null) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expiresOn = '; expires=' + date.toUTCString();
        } else {
            expiresOn = '';
        }
        
        document.cookie = key + '=' + value + expiresOn + '; path=/';
    },
    /*
    * read cookie
    */
    'read' : function(key) {
        var keyEq = key + '=';
        var cookies = document.cookie.split(';');
        for(var index = 0; index < cookies.length; index++) {
            var cookieElement = cookies[index];
            
            while(cookieElement.charAt(0) == ' ')
                cookieElement = cookieElement.substring(1, cookieElement.length);
                
            if(cookieElement.indexOf(keyEq) == 0)
                return cookieElement.substring(keyEq.length, cookieElement.length);
        }
        
        return null;
    },
    /*
    * erase cookie
    */
    'erase' : function(key){
        this.create(key, null, -1);
    }
};

/****************
Tooltip Control
****************/

var Tooltips = {
    'timerId' : null,
    'IE' : document.all ? true : false,
    //'mouse_posx' : 0,
    //'mouse_posy' : 0,
    // hide the tooltip
    'hideTooltip' : function () {
        var ele = document.getElementById("tooltip_ctl");
        
        if(ele != null)
            document.body.removeChild(ele);
     },
      // show tooltip
    'showTooltip' : function (e, tooltipText, srcElement) {
        var mouse_coords;
        if (this.timerId) {
            clearTimeout(this.timerId);
        }

        if (!this.IE) { 
            //if(srcElement != null)
            //    srcElement.addEventListener("mousemove", this.getMouseCoords, false );
            //else
            //    document.addEventListener("mousemove", this.getMouseCoords, false );
        } else {
            mouse_coords = this.getMouseCoords(window.event);
        }

        var ele;
        ele = document.getElementById("tooltip_ctl");
        if(ele == null) {
            ele = document.createElement('div');
            
            ele.id = "tooltip_ctl";
            ele.style.backgroundColor = "#ffffd0";
            ele.style.position = "absolute";
            ele.style.border = "solid 1px #010101";
            ele.style.padding = "5px 5px 5px 5px";
            
            ele.innerHTML = tooltipText;
            
            document.body.appendChild(ele);
        }

        if(!this.IE) {
            ele.style.left = e.clientX + "px";
            ele.style.top = (e.clientY + 20) + "px";
        } else {
            ele.style.left = mouse_coords[0];
            ele.style.top = mouse_coords[1] + 20;
        }

        this.timerId = setTimeout('var ele = document.getElementById(\'tooltip_ctl\'); if(ele != null) document.body.removeChild(ele);' , 5000);
    },
    // get mouse coordinates 
    'getMouseCoords' : function (e) {
        if(!this.IE) {
            //if (e.pageX || e.pageY) {
            //    this.mouse_posx = e.pageX;
            //    this.mouse_posy = e.pageY;
           // }
        } else {
            var ee = window.event;
            if (ee.clientX || ee.clientY) {
                var posx, posy;
                posx = ee.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                posy = ee.clientY + document.body.scrollTop + document.documentElement.scrollTop;

                return [posx, posy];
            }
        }
        return null;
    }
};

showPopup = function(url, height, width)
{
    var w_height = height || 250;
    var w_width = width || 400;
    var left = (screen.width - w_width) / 2;
    var top = (screen.height - w_height) / 2;
    var params = 'width=' + w_width + ', height=' + w_height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    newwin=window.open(url,'winname', params);
    if (window.focus) {newwin.focus()}
    return false;
}
