﻿function CallAssignFiles(HjsAutoComplete, HjsDrag, HjsSearchWindow) {
    HjsAutoComplete.src = 'newjs/jquery.autocomplete.js';
    HjsDrag.src = 'js/jquery.easydrag.js';
    HjsSearchWindow.src = 'js/SearchOnWindow.js'
    
}

function CallvisiblityNone(HdivSearchLinks) {
    var lnkdiv = HdivSearchLinks;
    if (lnkdiv.style.display != 'none' && flag == false && CheckFlag == false) {
        lnkdiv.style.display = 'none';
        objSiteName = "";
    }
    flag = false;
}

function GetNew(idval, obj) {
    $('#divSearchLinks').fadeOut('fast');
    AssignFiles();
    focusontext(obj);
    $().ready(function() {
        $('[Id$=' + idval + ']').autocomplete("WebForm5.aspx",
             {
                 delay: 1,
                 minChars: 1,
                 matchSubset: 1,
                 matchContains: 1,
                 cacheLength: 10,
                 onItemSelect: selectItem,
                 onFindValue: findValue,
                 formatItem: formatItem,
                 selectFirst: false

             });
    });
}
function findValue(li) {
    if (li == null) return alert("No match!");
    // if coming from an AJAX call, let's use the CityId as the value
    if (!!li.extra) var sValue = li.extra[0];
    // otherwise, let's just display the value in the text box
    else var sValue = li.selectValue;
}
function selectItem(li) {
    findValue(li);
}
function formatItem(row) {
    return row[0];
}
function formatResult(row) {
    return row[0].replace(/(<.+?>)/gi, '');
}

function Close_Popup() {
    $('#popup').fadeOut('fast');
    $('#window').fadeOut('fast');
}

function focusontext(obj) {
    if (obj.value == 'americasfavorite.org') {
        obj.value = ''
    }
    else if (obj.value == '') {
        obj.value = 'americasfavorite.org'
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    else {
        var Location = findPosFF(obj);
        curleft = Location[0];
        curtop = Location[1];
    }
    return [curleft, curtop];
}

function ShowHideHeaderItem(flag) {

    if (flag != '') {
        ShowHeader();
        var temp = flag.split(',')
        var num = 0;
        while (num < temp.length) {
            if (temp[num] == '0') {
                $("#liweb").fadeOut("fast");
            }
            else if (temp[num] == '1') {
                document.getElementById('liimage').style.display = 'none';
            }
            else if (temp[num] == '2') {
                document.getElementById('livideo').style.display = 'none';
            }
            else if (temp[num] == '3') {
                document.getElementById('limap').style.display = 'none';
            }
            else if (temp[num] == '4') {
                document.getElementById('liNews').style.display = 'none';
            }
            else if (temp[num] == '5') {
                document.getElementById('liShoppings').style.display = 'none';
            }
            num += 1;
        }
    }
    else {
        ShowHeader();
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    else {
        var Location = findPosFF(obj);
        curleft = Location[0];
        curtop = Location[1];
    }
    return [curleft, curtop];
}

function ShowHeader() {

    $("#liweb").fadeIn("fast");
    $("#liimage").fadeIn("fast");
    $("#livideo").fadeIn("fast");
    $("#limap").fadeIn("fast");
    $("#liNews").fadeIn("fast");
    $("#liShoppings").fadeIn("fast");
}

function mainmenu() {
    $(" #nav ul ").css({ display: "none" }); // Opera Fix
    $(" #nav li").hover(function() {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show(400);
    }, function() {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });
}
$(document).ready(function() {
    mainmenu();
});




//if (navigator.appName != "Mozilla") { document.onkeydown = selection }
//else { document.addEventListener("keypress", selection, true); }
function callselection(e, ScmbServices3, SIDShowwin, UserID) {
    if (document.getElementById("divSearchLinks").style.display != 'none') {
        document.getElementById('Idonwindow').onkeydown = function(e) { return false; }
        document.getElementById('IDNewwindow').onkeydown = function(e) { return false; }
        if (window.event) { e = window.event; }
        if ((e.keyCode == 13) || (e.keyCode == 9) || (e.keyCode >= 37 && e.keyCode <= 40)) {
            if (e.keyCode == 13) {
                var setval;
                if (IDCount == 0) {
                    setval = "li" + IDCount;
                }
                else {
                    setval = "li" + (IDCount - 1);
                }
                var gethtml = document.getElementById(setval).innerHTML;
                var setstring = gethtml.substring(gethtml.indexOf("SetSiteName2"), (gethtml.indexOf(")") + 1))
                eval(setstring);
                IDCount = 0;
                ScmbServices3.focus();
                return;
            }
            var arrayhtml = new Array();
            var gethtm = document.getElementById("li0").innerHTML;
            arrayhtml = gethtm.substring((gethtm.indexOf("(") + 1), gethtm.indexOf(")")).split(",");
            var maxval = 0;
            maxval = arrayhtml[4].substring(1, (arrayhtml[4].length - 1)); //arrayhtml[4];
            if (IDCount != 0) {
                var oldval = IDCount - 1
                var old = "li" + oldval;
                document.getElementById(old).className = "link";
                if (IDCount == maxval) {
                    IDCount = 0;
                }
            }
            if (e.keyCode == 37) { // Left Arrow Key
                IDCount -= 2;
            }
            if (e.keyCode == 40) { // Down Arrow Key
                if (IDCount != 0) {
                    IDCount += 14;
                    if (IDCount > maxval) {
                        IDCount = 0;
                    }
                }
            }
            if (e.keyCode == 38) { // Up Arrow Key
                if (IDCount == 0) {
                    IDCount += (maxval - 16);
                    if (IDCount < 0) {
                        IDCount = 0;
                    }
                }
                else {
                    IDCount -= 16;
                }
            }
            if (IDCount < 0) {
                IDCount = 0;
            }

            var setID = "li" + IDCount;
            var t = document.getElementById(setID);
            t.className = "link1";
            IDCount += 1;
            if (e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40 && e.keyCode != 9) {
                if (UserID == '') {
                    document.getElementById('TXT_Search_Box').focus();
                }
            }
            if (SIDShowwin.style.visibility == 'hidden') {
                if (e.keyCode == 9) {
                    document.getElementById('TXT_Search_Box').focus();
                }
            }
        }
        else {
            IDCount = 0;
        }

    }
    else {
        document.getElementById('Idonwindow').onkeydown = function(e) { return true; }
        document.getElementById('IDNewwindow').onkeydown = function(e) { return true; }
    }
}

function Show_Popup(height, width, src, fwidth, fheight, header) {
    //debugger;
    AssignFiles();
    $('#popup').fadeIn('fast');
    $('#window').fadeIn('fast');
    document.getElementById('window').style.width = width;
    document.getElementById('window').style.height = height;
    document.getElementById('frm').style.width = fwidth;
    document.getElementById('frm').style.height = fheight;
    if (src == 'UserSiteLogoSelection.aspx') {
        var SiteID = document.getElementById("<%=HDDSiteID.ClientID %>").value
        document.getElementById('frm').src = src + '?SiteID=' + SiteID;
    }
    else
        document.getElementById('frm').src = src;
    document.getElementById("divHeader").innerHTML = "<b>" + header + "</b>";
    if (header == "Forgot Password") {
        document.getElementById('window').style.top = '200px';
    }
    else if (header == "Edit Profile" || header == "Create An Account") {
        document.getElementById('window').style.top = '75px';
    }
    else if (header == "Auto Login") {
        document.getElementById('window').style.top = '150px';
    }
    else if (header == "Login") {
        document.getElementById('window').style.top = '150px';
    }
    $('#window').easydrag();
}

function setfocusonLoad() {
    AssignFiles();

    var imgServ3 = document.getElementById('<%= cmbServices3.ClientID %>');
    if (imgServ3 != null)
        imgServ3.focus()

}
function imgOndemand() {
    $('img.img-ondemand').each(function() {
        var $img = $(this);
        $img.attr('src', $img.attr('longdesc')).removeClass('img-ondemand');
    });
}

function OpendivSearchLinksT1(objImg) {
    IDCount = 0;
    document.getElementById('TXT_Search_Box').value = '';
    GetImages(objImg);
    var lnkdiv = document.getElementById('divSearchLinks');
    var location = findPos(document.getElementById(objImg));
    lnkdiv.style.position = 'absolute';
    lnkdiv.style.top = (location[1] + 25) + 'px';
    lnkdiv.style.left = (location[0]) + 'px';
    flag = true;
    $("#divSearchLinks").fadeIn("fast");

    if (objImg == 'divImage1')
        return false;
    else {
        imgOndemand();
    }
}

