﻿//New

function HdrClearKeywordText() {
    if (document.getElementById("hdrkeyword").value == "Find Freelancers") {
        document.getElementById("hdrkeyword").value = "";
        document.getElementById("hdrkeyword").style.color = "#000000";
    }
}

function HdrRevertKeywordText() {
    if (document.getElementById("hdrkeyword").value == "") {
        document.getElementById("hdrkeyword").value = "Find Freelancers";
        document.getElementById("hdrkeyword").style.color = "#8C8C8C";
    }
}

function HdrCheckAndSubmit(baseUrl) {
    HdrCheckSearch(baseUrl)
       
}

function HdrCheckSearch(baseUrl) {    
    if (document.getElementById("hdrkeyword").value != "Find Freelancers")
        document.getElementById("keyword").value = document.getElementById("hdrkeyword").value;
    window.location.replace(baseUrl + "/emp/search.aspx?#&&Keyword=" + encodeURIComponent(document.getElementById("keyword").value));
}

function HdrActivate() {
    document.getElementById('hdrkeyword').className = 'hdrSearchBoxHome2'
}
function HdrDisable() {
    document.getElementById('hdrkeyword').className = 'hdrSearchBoxHome1'
}

function Hdr_ChkEnterAndSearchByKeyWord(event, baseUrl) {
    if (Hdr_ChkEnterEvent(event)) {
        if (document.getElementById("hdrkeyword").value != "Find Freelancers") {
            window.location.replace(baseUrl + "/emp/search.aspx?#&&Keyword=" + encodeURIComponent(document.getElementById("keyword").value));
        }      
    }
}

function Hdr_ChkEnterEvent(event) {
    if (event.which || event.keyCode) {
        if ((event.which == 13) || (event.keyCode == 13)) {

            return true;
        }
        return false;
    }
}


//Header Menu pop javasript
var HeaderItem = function(element, hoverOverClass, hoverOutClass, active) {
    this.Item = element;
    this.hoverOverClass = hoverOverClass;
    this.hoverOutClass = hoverOutClass;
    this.active = active;
    var that = this;
    if (!this.active) {
        this.Item.onmouseover = function() { this.className = that.hoverOverClass; }
        this.Item.onmouseout = function() { this.className = that.hoverOutClass; }
    }
    this.popupPanelId = null;
    this.linkId = null;
    this.useHoverClassOnClick = false; 
    this.open = false;
}

HeaderItem.prototype = {

    InitPopUp: function(popPanel, linkId, useHoverClassOnClick) {
        this.popupPanelId = popPanel;
        this.linkId = linkId;
        this.useHoverClassOnClick = useHoverClassOnClick;
        Guru.Util.RegisterPopUps(popPanel, linkId);

        var that = this;
        document.getElementById(this.linkId).onclick = function() {
            if (document.getElementById(that.popupPanelId).style.display == '') { // it is there hide it if clicked.
                hide(that.popupPanelId);
                if(that.active){
                    that.Item.className = "active";
                }
                else {
                       that.Item.className = '';
                }
                that.Item.onmouseover = function() { this.className = that.hoverOverClass; };
                that.Item.onmouseout = function() { this.className = that.hoverOutClass; };
                that.open = false;
            }
            else {
                show(that.popupPanelId);
                that.Item.onmouseover = null;
                that.Item.onmouseout = null;
                if (that.useHoverClassOnClick == true) {
                    that.Item.className = that.hoverOverClass;
                }
                else {
                    if (that.active) {
                        that.Item.className = 'active openPanelHead';
                    }
                    else {
                        that.Item.className = 'openPanelHead';
                    }
                }
                that.open = true;
                HeaderItemClicked(that);
            }
        }
    }
}


function InitHeaders(elementId, hoverOnClass, hoverOutClass, callBack) {
    var headerItems = new Array();
    var header = document.getElementById(elementId);
    var headerItem;
    var divs = header.getElementsByTagName('div');
    for (i = 0; i < divs.length; i++) {
        if (divs[i].className.indexOf("active") == -1) {
            headerItem = new HeaderItem(divs[i], hoverOnClass, hoverOutClass, false);
        }
        else {
             headerItem = new HeaderItem(divs[i], hoverOnClass, hoverOutClass, true);
        }
        headerItems[i] = headerItem;
    }

    if (callBack != null)
        callBack(headerItems);
}

function HeaderItemClicked(headerItem) {
    for (j = 0; j < allHeaderItem.length; j++) {
        if (allHeaderItem[j].open == true && allHeaderItem[j] != headerItem) {
            hide(allHeaderItem[j].popupPanelId);
            if (allHeaderItem[j].active) {
                document.getElementById(allHeaderItem[j].Item.id).className = "active";
            }
            else {
                document.getElementById(allHeaderItem[j].Item.id).className = allHeaderItem[j].hoverOutClass;
            }
        }
    }
}





