﻿

//************************ Link Thumbnail start *********************************
var GC_navigator = navigator.userAgent.toLowerCase();
var GC_isOpera = GC_navigator.indexOf('opera') >= 0 ? true : false;
var GC_isIE = GC_navigator.indexOf('msie') >= 0 && !GC_isOpera ? true : false;
var GC_isSafari = GC_navigator.indexOf('safari') >= 0 || GC_navigator.indexOf('khtml') >= 0 ? true : false;
var GC_linkThumbUseClassName = true;

var GC_linksources = [['http://images.websnapr.com/?size=s&url=', 202, 152],
						  ['http://thumbnails.alexa.com/image_server.cgi?size=small&url=', 160, 120],
						  ['http://msnsearch.srv.girafa.com/srv/i?s=MSNSEARCH&r=', 160, 120]];
var GC_linksource = 0;

function GC_linkpic() {
    var b = document.domain;
    var A = document.getElementsByTagName('A');

    for (var i = 0, l = A.length, c = 0; i < l; i++) {
        var a = A[i];
        var h = a.href;
        if ((b == '' || h.indexOf(b) < 0) && h.indexOf('://') > 0 && ((GC_linkThumbUseClassName && a.className.indexOf('linkthumb') >= 0) || !GC_linkThumbUseClassName)) {
            try {
                a.className += ' GC_linkpicLNK';
                if (a.id == '')
                    a.id = 'GC_link' + i;
                var d = GC_newNode('div', 'GC_linkpic' + i, 'GC_linkpic');
                var m = GC_newNode('img', '', 'GC_linkpicIMG');
                // var n = h.replace(/[^:]*:\/\/([^:\/]*)(:{0,1}\/{1}.*)/, '$1');
                var n = escape(h);
                m.src = GC_linksources[GC_linksource][0] + n;
                m.width = GC_linksources[GC_linksource][1];
                m.height = GC_linksources[GC_linksource][2];
                m.style.width = GC_linksources[GC_linksource][1] + 'px';
                m.style.height = GC_linksources[GC_linksource][2] + 'px';
                m.border = 0;
                m.alt = '[Picture of ' + n + ']';
                m.title = a.title;

                d.style.overflow = 'hidden';
                d.style.zIndex = '9999';
                d.style.position = 'absolute';
                d.height = '140px';
                d.style.height = '140px';
                d.width = m.width;
                d.style.width = m.style.width;
                
                d.appendChild(m);
                document.body.appendChild(d);

                GC_addEvent(a, 'mouseover', function() { GC_showThumb(GC_isIE ? event.srcElement.id : this.id); });
                GC_addEvent(a, 'mouseout', function() { GC_hideThumb(GC_isIE ? event.srcElement.id : this.id); });
            } catch (err) {
                a = null;
            }
        }
    }
}

function GC_showThumb(id) {
    try {
        var k = document.getElementById(id);
        var top = GC_findDimension(k, 'Top');
        var lnh = GC_getStyle(k, 'lineHeight', 'font-size');
        var default_height = 20;
        if (!lnh)
            lnh = default_height;
        else if (lnh.indexOf('pt') > 0)
            lnh = parseInt(lnh) * 1.3;
        else if (lnh.indexOf('em') > 0)
            lnh = parseInt(lnh) * 10;
        else if (lnh.indexOf('px') > 0)
            lnh = parseInt(lnh);
        else if (GC_isNumeric(lnh))
            lnh = parseInt(GC_isIE ? lnh * 10 : GC_isOpera ? lnh / 100 : lnh); // IE brings back em units
        else
            lnh = default_height;
        var lft = GC_findDimension(k, 'Left');
        var nlf = GC_findMatchingDimensionViaNodes(k, 'Left', lft, 0);
        var pid = id.replace(/GC_link/, 'GC_linkpic');
        var p = document.getElementById(pid);
        //var oMousePos = MousePosition(e);
        p.style.display = 'block';
       p.style.top = (top + (GC_isIE && nlf ? lnh + -18 : 4) + lnh) + 'px';
        p.style.left = lft + 'px';
    } catch (err) { return; }
}

function GC_hideThumb(id) {
    try {
        var k = document.getElementById(id);
        var pid = id.replace(/GC_link/, 'GC_linkpic');
        var p = document.getElementById(pid);
        p.style.display = 'none';
    } catch (err) { return; }
}

function GC_getStyle(obj, styleIE, styleMoz) {
    if (GC_isString(obj)) obj = document.getElementById(obj);
    if (obj.currentStyle)
        return obj.currentStyle[styleIE];
    else if (window.getComputedStyle)
        return document.defaultView.getComputedStyle(obj, null).getPropertyValue(styleMoz);
}

function GC_findDimension(obj, pType) {
    if (GC_isString(obj)) obj = document.getElementById(obj);
    var cur = 0;
    if (obj.offsetParent)
        while (obj.offsetParent) {
        switch (pType.toLowerCase()) {
            case "width":
                cur += obj.offsetWidth; break;
            case "height":
                cur += obj.offsetHeight; break;
            case "top":
                cur += obj.offsetTop; break;
            case "left":
                cur += obj.offsetLeft; break;
        }
        obj = obj.offsetParent;
    }
    return cur;
}

function GC_findMatchingDimensionViaNodes(obj, pType, matching, notMatching) {
    var cur = 0, counter = 0;
    notMatching = notMatching == null ? -1 : notMatching;
    if (obj.parentNode)
        while (obj.parentNode) {
        cur = GC_findDimension(obj, pType);
        if (cur == matching && cur != notMatching)
            counter++;
        if (counter >= 2) return true;
        obj = obj.parentNode;
    }
    return false;
}

/* Events */
function GC_isString(o) { return (typeof (o) == "string"); }

function GC_isNumeric(o) { return (typeof (parseFloat(o).toString() == 'NaN' ? 'xxx' : parseFloat(o)) == "number" && parseFloat(o) != ''); }

function GC_addEvent(e, meth, func, cap) {
    if (GC_isString(e)) e = document.getElementById(e);

    if (e.addEventListener) {
        e.addEventListener(meth, func, cap);
        return true;
    } else if (e.attachEvent)
        return e.attachEvent("on" + meth, func);
    return false;
}

/* Nodes */
function GC_newNode(t, i, s, x, c) {
    var node = document.createElement(t);
    if (x != null && x != '') {
        var n = document.createTextNode(x);
        node.appendChild(n);
    }
    if (i != null && i != '')
        node.id = i;
    if (s != null && s != '')
        node.className = s;
    if (c != null && c != '')
        node.appendChild(c);
    return node;
}

/* Onload */
GC_addEvent(window, 'load', GC_linkpic);

//************************************** Link Thumbnail end *******************************

function ShowHide(idvalu, IdLabel, IdRadio) {
    var lebel = document.getElementById(IdLabel);
    var radio = document.getElementById(IdRadio);
    if (idvalu.checked) {
        lebel.style.display = 'none';
        radio.style.display = 'none';

    }
    else {
        lebel.style.display = 'block';
        radio.style.display = 'block';

    }
}
function enableAllValidators(parentName,enable)
{
    var childs = parentName.getElementsByTagName('*');                 
    //alert('childs: ' + childs);
    for (var i=0; i<childs.length; i++)
    {                    
        if(childs[i].id.lastIndexOf('rfv') !=-1)
        { 
            ValidatorEnable(childs[i], enable);
        }
    }    
}

function ShowHideTable(chkbox, strTr) 
{               
    var trList = document.getElementsByTagName('tr');                    
    if(trList !=null)
    {
        if (chkbox.checked) 
        {                  
            //Show vlgrupper billing custom field checkboxes  
            for (var i=0; i < trList.length; i++)     
            {           
                if (trList[i].id.lastIndexOf(strTr)!=-1) 
                {                               
                    var currTR = document.getElementById(trList[i].id);
                    var comboElements = currTR.getElementsByTagName('select');                             
                    if(comboElements != null)
                    {                    
                        for(var j=0; j<comboElements.length; j++)
                        {                                    
                            comboElements[j].selectedIndex = 63; //63=Denmark                                    
                        }
                    }
                    //Enable required field validators
                    enableAllValidators(currTR,true);                         
                    //Show text boxes                          
                    trList[i].style.display = '';                                                                                                                                                       
                }
            }
        }
        else //checkbox is unchecked
        {          
            for (var i=0; i < trList.length; i++)     
            {           
                if (trList[i].id.lastIndexOf(strTr)!=-1) 
                { 
                    //Empty texts in text fields
                    var currTR = document.getElementById(trList[i].id);
                    var elements = currTR.getElementsByTagName('input');                          
                    if(elements !=null)
                    {          
                        //alert('elements count: ' + elements.length);      
                        for (var j=0; j < elements.length; j++) 
                        { 
                            if (elements[j].type == 'text') 
                            { 
                                elements[j].value = '';                                                                                   
                            }                 
                        }                
                    }                    

                    //Hide vlgrupper billing custom field checkboxes                                                      
                    trList[i].style.display = 'none';  
                    enableAllValidators(trList[i],false);                                                                                                
                }                
            } 
        }
    }
}
    
function TabStyle(objid, sUrl) {
    if (sUrl) {
        var obj = document.getElementById(objid);
        var sRealUrl = new String(sUrl);
        if (sRealUrl.substr(0, 1) == '/') {
            sRealUrl = sRealUrl.substr(1, sRealUrl.length);
        }
        if (navigator.appName != 'Netscape') {
            obj.style.cursor = 'wait';
            document.body.style.cursor = 'wait';
        }

        window.location = sRealUrl;
    }
}
function MoveMenuToRight(objImage, elemObj, iValue) {

    var iImageX = 0;
    var oimage = objImage;
    try {
        if (document.all) {
            while (objImage.offsetParent != null) {
                iImageX += objImage.offsetLeft;
                objImage = objImage.offsetParent;
            }
            //elemObj.style.right = document.body.clientWidth-20-iImageX-iValue; 
            //alert(iImageX+": menu "+elemObj.clientWidth+": image"+oimage.clientWidth);
            var LeftOffset = iImageX - (elemObj.clientWidth - oimage.clientWidth) + 2 - iValue;
            if (LeftOffset < 0) {
                LeftOffset = 0;
            }
            elemObj.style.left = LeftOffset + 'px';
        }
        else {

            iImageX = getAbsX(objImage);
            var RightOffset = document.body.clientWidth - 18 - iImageX - iValue;

            if (document.body.clientWidth - RightOffset > 100) {
                elemObj.style.right = RightOffset + 'px';
            }
            else {
                elemObj.style.left = '0px';
            }
        }
    }
    catch (ex) {
        alert(ex);
    }

}
function showToolTip(obj, oEvent, toolTipDivId, sText) {
    var el = document.getElementById(toolTipDivId);
    var oPosition = getElementPositionFortoolTip(obj);

    el.innerHTML = "<table cellspacing='0' border='0' cellpadding='0'><tr><td class='TooltipTd2'>&nbsp;</td><td  rowspan='3' valign='top' class='TooltipTd1'>" + sText + "</td></tr><tr><td style='height:30px;width:52px;'><img src='Images/Icons/Event/toolTip.gif' border='0'></td></tr><tr><td class='TooltipTd2' style='height:10px;'>&nbsp;</td></tr></table>";

    el.style.top = oPosition.y - 20 + "px";
    el.style.left = oPosition.x + oPosition.width + 3 + "px";
    //el.style.width="150px";
    el.style.display = "block";

    var elPosition = getElementPositionFortoolTip(el);

    el.style.top = oPosition.y - elPosition.height + 20 + "px";

    document.onmouseout = function() {
        el.style.display = "none";
    }

}

function getElementPositionFortoolTip(element) {

    var result = new Object();

    result.x = 0;
    result.y = 0;
    result.width = 0;
    result.height = 0;

    if (element.offsetParent) {
        result.x = element.offsetLeft;
        result.y = element.offsetTop;
        var parent = element.offsetParent;
        while (parent) {
            result.x += parent.offsetLeft;
            result.y += parent.offsetTop;
            var parentTagName = parent.tagName.toLowerCase();
            if (parentTagName != 'table' &&
       parentTagName != 'body' &&
       parentTagName != 'html' &&
       parentTagName != 'div' &&
       parent.clientTop &&
       parent.clientLeft) {
                result.x += parent.clientLeft;
                result.y += parent.clientTop;
            }
            parent = parent.offsetParent;
        }
    }
    else if (element.left && element.top) {
        result.x = element.left;
        result.y = element.top;
    }
    else {
        if (element.x) {
            result.x = element.x;
        }
        if (element.y) {
            result.y = element.y;
        }
    }

    if (element.offsetWidth && element.offsetHeight) {
        result.width = element.offsetWidth;
        result.height = element.offsetHeight;
    }
    else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
        result.width = element.style.pixelWidth;
        result.height = element.style.pixelHeight;
    }

    return result;
}

function ShowDayViewPopup(obj, oEvent, toolTipDivId, sText) {
    var el = document.getElementById(toolTipDivId);
    var oPosition = getElementPositionFortoolTip(obj);

    el.innerHTML = sText; //"<table cellspacing='0' border='0' cellpadding='0'><tr><td class='TooltipTd2'>&nbsp;</td><td  rowspan='3' valign='top' class='TooltipTd1'>" + sText + "</td></tr><tr><td style='height:30px;width:52px;'><img src='Images/Icons/Event/toolTip.gif' border='0'></td></tr><tr><td class='TooltipTd2' style='height:10px;'>&nbsp;</td></tr></table>";

    el.style.top = oPosition.y - 20 + "px";
    //el.style.left=oPosition.x + oPosition.width + 3 + "px";
    el.style.left = oPosition.x + 1 + "px";

    el.style.display = "block";

    var elPosition = getElementPositionFortoolTip(el);

    el.style.top = oPosition.y - elPosition.height + "px";

    document.onmouseout = function() {
        el.style.display = "none";
    }
}

function KeyDownHandlerWithHourGlass(e, buttonid) {
    if (e.keyCode == 13) {
        try{
        var elemObj = document.getElementById(buttonid);
        elemObj.click();

        if (!Page_ClientValidate('newuser')) {
            window.document.body.style.cursor = 'default';
        }
        else {
            document.body.style.cursor = 'wait';
        }
        }
        catch (ex) {
            alert(ex);
        }
        return false;
    }
}
function CancelAsyncPostBack() {
    var objMan = Sys.WebForms.PageRequestManager.getInstance();
    if (objMan.get_isInAsyncPostBack()) {
        objMan.abortPostBack();
    }
}
function StopAsyncPostBack() {
    var objMan = Sys.WebForms.PageRequestManager.getInstance();
    if (objMan) {
        objMan.dispose();
    }
}


function MousePosition(e) {

    var xMousePos = 0; // Horizontal position of the mouse on the screen
    var yMousePos = 0; // Vertical position of the mouse on the screen
    var xMousePosMax = 0; // Width of the page
    var yMousePosMax = 0; // Height of the page

    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth + window.pageXOffset;
        yMousePosMax = window.innerHeight + window.pageYOffset;
    }
    else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x + document.body.scrollLeft;
        yMousePos = window.event.y + document.body.scrollTop;
        xMousePosMax = document.body.clientWidth + document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight + document.body.scrollTop;
    }
    else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth + window.pageXOffset;
        yMousePosMax = window.innerHeight + window.pageYOffset;
    }
    return { XPos: xMousePos, YPos: yMousePos, XPosMax: xMousePosMax, YPosMax: yMousePosMax };
}
function stopDefaultAction(e) {
    if (!e) var e = window.event;

    if (e) {
        try {
            if (e.preventDefault) {
                e.preventDefault();
                //e.cancelBubble is supported by IE - this will kill the bubbling process.
                /*
                e.cancelBubble = true;
                e.returnValue = false;
                */
                //e.stopPropagation works only in Firefox.
                if (e.stopPropagation) {
                    e.stopPropagation();
                }
            }
            else {
                e.returnValue = false;
            }
        }
        catch (ex) {
            alert(ex);
        }
    }
    return false;
}
function MoveStatusMakeDefault() {
    bDragStart = false;
    sDestinationFolder = null;
    sSourceFolder = null;
    $("#moveinfo").attr("class", "HideMoveMessageDiv");
    $("#moveinfo").css({ left: '-10px', top: '-10px' });
}

function TravelTreeNode(otable) {
    
    if (!$(':checkbox', otable)[0].checked) {
        var Nextdiv = $(otable).next('div');
        $(':checkbox', Nextdiv).removeAttr('checked');
        //$(':checkbox', Nextdiv).attr('disabled', 'disabled');
        return;
    }
    var oCurentdiv = $(otable).next('div')

    for (var itempcount = 0; $(oCurentdiv).children('table').length > itempcount; itempcount++) {
        var TempcurrentNode = $(oCurentdiv).children('table')[itempcount];
        if ($(TempcurrentNode).next('div').length > 0) {
            TravelTreeNode(TempcurrentNode); //.siblings()
        }
    }

}
function CheckedAllParent(continerdiv) {
    if (continerdiv.attr('class') == 'homemainselect') {
        return;
    }
    var parenttable = $(continerdiv).prev('table');
    $(':checkbox', parenttable).attr('checked', 'checked');
    CheckedAllParent($(parenttable).parent());
}
function pageLoad() {
    $(document).ready(function() {
        $(".newWindow").click(function() {
            $(this).modal({ width: 833, height: 550 }).open(); return false;
        });
        //Possition person photo in grid in proper place
        var vClientBrowser = (document.all && document.getElementById) ? true : false;
        if (!vClientBrowser) {
            $(".PersonPhotoDefault").css('margin-top', "-7px");
        }
        $(".PersonPhotoDefault").hover(function() {
            $(".PersonPhotoDefault").css('z-index', "1");
            $(this).css('z-index', "10");
            $(this).stop().animate({ width: '100px', height: '80px' }, 1000);
        },
                    function() {
                        $(this).css('z-index', "2");
                        $(this).stop().animate({ width: '20px', height: '15px' }, 1000);
                    });
        $(".PersonPhotoDefault,.PersonPhoto").click(function() {
            var sLocation = $(this).attr("src");
            sLocation = sLocation.substring(sLocation.indexOf('Photo/') + 6);
            displayPhoto(sLocation);
        });

        $(':checkbox', $('.homemainselect')).click(function() {
            //debugger
            //alert($(this).parent().parent().parent()[0].id);
            var parenttable = $(this).parent().parent().parent().parent(); //[0];
            var Nextdiv = parenttable.next('div');
            //                alert($(':checkbox', parenttable).length);
            //alert($(':checkbox', Nextdiv).length);
            if (this.checked) {
                //$(':checkbox', Nextdiv).attr('checked', 'checked');
                $(':checkbox', Nextdiv).removeAttr('disabled');
                var parentdiv = parenttable.parent();
                if (parentdiv.attr('class') != 'homemainselect') {
                    CheckedAllParent(parentdiv);
                }
            }
            else {
                $(':checkbox', Nextdiv).removeAttr('checked');
                //$(':checkbox', Nextdiv).attr('disabled', 'disabled');
            }

            //alert($(':checkbox', Nextdiv).length);
            //.next()
        });

        //***************** Start Disabling treenode****************
        
        var icount = 0;
        var oActiveNode = $('.homemainselect');
        if (oActiveNode.length > 0) {
            for (icount = 0; oActiveNode.children('table').length > icount; icount++) {
                var currentNode = oActiveNode.children('table')[icount];
                if ($(currentNode).next('div').length > 0) {

                    TravelTreeNode(currentNode); //.siblings()

                }
            }
        }
        //***************** End ************************************

    });
}
