﻿// JScript File
//function EnchancedCombo(selectId) {

//    this.SelectId = selectId;
//    this.isLoaded = false;

//    this.combo = $('#' + this.SelectId).combobox({
//        comboboxContainerClass: "comboboxContainer",
//        comboboxValueContainerClass: "comboboxValueContainer",
//        comboboxValueContentClass: "comboboxValueContent",
//        comboboxDropDownClass: "comboboxDropDownContainer",
//        comboboxDropDownButtonClass: "comboboxDropDownButton",
//        comboboxDropDownItemClass: "comboboxItem",
//        comboboxDropDownItemHoverClass: "comboboxItemHover",
//        comboboxDropDownButtonChar: "&#9660;",
//        width: "200px"
//    });
//    this.LoadFavorites = function(BlogID) {
//        if (!this.isLoaded) {
//            this.isLoaded = true;
//            $("#" + this.SelectId).load("HeaderActions.ashx", { utf8: "true", getfav: "true", blog: BlogID },
//                function() {
//                    $("#" + this.SelectId).combobox.update();
//                }
//            );
//        }
//    }


//    this.combo.combobox.onChange = function() {
//        var box = $("#" + document.FavCombo.SelectId);
//        var selectedBlog = box.val();

//        if (selectedBlog > 0)
//            window.location = "/blogread.asp?blog=" + selectedBlog;
//    };

//    this.MoveSelection = function(obj, dir) {

//        if (!this.isLoaded) {
//            this.LoadFavorites();
//            return;
//        }

//        var nextOption = Math.min(obj.selectedIndex + 1, obj.options.length - 1);
//        var prevOption = Math.max(obj.selectedIndex - 1, 0);

//        if (dir > 0) {
//            obj.selectedIndex = nextOption;
//        } else {
//            obj.selectedIndex = prevOption;
//        }

//        $("#" + this.SelectId).combobox.updateSelection();

//    };

//    this.DownloadFavs = function() {
//        window.open('/favorites.asp', 'myFav', 'resizable,width=300,height=440');
//    }
//}

function EncancedSearch(radioGroupName, imagesPath, thisBlogID) {

    this.BlogID = thisBlogID;
    this.RadioGroupName = radioGroupName;
    this.ImagesPath = imagesPath;
    this.ImageOn = imagesPath + "/radio_on.gif";
    this.ImageOff = imagesPath + "/radio_off.gif";
    this.s = 1;

    this.SearchImageFlip = function(senderId) {
        var elmOn = document.getElementById(senderId);
        if (elmOn == null)
            return;

        var radioGroup = document.getElementsByName(this.RadioGroupName);
        for (i = 0; i < radioGroup.length; i++) {
            radioGroup[i].src = this.ImageOff;
        }

        elmOn.src = this.ImageOn;
        switch (senderId) {
            case "SearchByNana":
                this.s = 1;
                break;
            case "SearchByInternet":
                this.s = 2;
                break;
            case "SearchThisBlog":
                this.s = 3;
                break;
            case "Header1_SearchByInternet":
                this.s = 2;
                break;
            case "SearchThisBlog":
                this.s = 3;
                break;
            case "Header1_SearchThisBlog":
                this.s = 3;
                break;
        }

    };

    this.SearchKeyPress = function(e, q) {

        if (e.keyCode == 13) {
            this.GoSearch(q);
        }

    }

    this.SearchKeyPressUTF8 = function(e, q) {

        if (e.keyCode == 13) {
            this.GoSearchUTF8(q);
        }

    }

    this.GoSearch = function(q) {

        if (q == "") {
            return;
        }
        //Bashir: 03012011
        //  alert(this.s);
        
        var today = "";
        var currentTime = new Date();
        if (currentTime.getDate() < 9)
            today += "0";
        today += currentTime.getDate() + "-";
        if (currentTime.getMonth() < 9)
            today += "0";
        today += currentTime.getMonth() + 1;
        today += "-" + currentTime.getFullYear();

        var queryString = "/" + q + "/1_0_0_0_120_1";
        if (this.s == 1) {
            queryString = "/" + q + "/2_0_0_0_120_1_25-08-2001_" + today;
        }
        else if (this.s == 3) {
            queryString = "/" + q + "/3_0_0_0_120_1_25-08-2001_" + today + "_" + this.BlogID;
        }
        queryString += "/1";
        window.top.location = "/SearchPage" + queryString;
        //        var queryString = "q=" + q;
        //        if (this.s == 3) {
        //            this.s = 1;
        //            queryString += "&hasbid=1&bid=" + this.BlogID;
        //        }

        //        queryString += "&s=" + this.s;
        //        window.top.location = "/search/SearchBlog.asp?" + queryString;
    };

    this.GoSearchUTF8 = function(q) {
        //Bashir: 03012011
    //   alert(this.s);
    var currentTime = new Date();
    if (currentTime.getDate() < 9)
        today += "0";
    var today = currentTime.getDate() + "-";
    if (currentTime.getMonth() < 9)
        today += "0";
    today += currentTime.getMonth() + 1;
    today += "-" + currentTime.getFullYear();
        var queryString = "/" + q + "/1_0_0_0_120_1";
        if (this.s == 1) {
            queryString = "/" + q + "/2_0_0_0_120_1_25-08-2001_" + today;
        }
        else if (this.s == 3) {
            queryString = "/" + q + "/3_0_0_0_120_1_25-08-2001_" + today + "_" + this.BlogID;
        }
        queryString += "/1";
        window.top.location = "/SearchPage" + queryString;
//        var queryString = "q=" + q;
//        if (this.s == 3) {
//            this.s = 1;
//            queryString += "&hasbid=1&bid=" + this.BlogID;
//        }

//        queryString += "&s=" + this.s;
//        window.top.location = "/search/SearchBlogUTF8.asp?" + queryString;
    };
}


function LoginKeyPress(e, UserNameID, PasswordID) {

    if (e.keyCode == 13) {
        GoLogin(UserNameID, PasswordID);
    }
}

function GoLogin(UserNameID, PassowrdID) {

    var loginform = document.createElement("form");
    var user = document.createElement("input");
    var pass = document.createElement("input");
    var go = document.createElement("input");
    var ut = document.createElement("input");
    var rem = document.createElement("input");

    loginform.action = "/edit/login.asp";
    loginform.method = "post";
    //loginform.acceptCharset = "windows-1255";

    user.setAttribute("name", "username");
    user.setAttribute("type", "text");
    user.setAttribute("value", document.getElementById(UserNameID).value);

    pass.setAttribute("name", "password");
    pass.setAttribute("type", "text");
    pass.setAttribute("value", document.getElementById(PassowrdID).value);

    rem.setAttribute("name", "remember");
    rem.setAttribute("type", "text");
    if (null != document.getElementById("remember") && document.getElementById("remember").checked) {
        val = 1;
    } else {
        val = 0
    }
    rem.setAttribute("value", val);


    if (
		user.value == null ||
		pass.value == null ||
		user.value == "" ||
		pass.value == ""
    ) {
        alert("מלאו שם משתמש וסיסמה");
        return false;
    }

    go.setAttribute("name", "goto");
    go.setAttribute("value", "/edit/blogrichedit.asp");

    ut.setAttribute("name", "UserType");
    ut.setAttribute("value", "");

    loginform.appendChild(user);
    loginform.appendChild(pass);
    loginform.appendChild(go);
    loginform.appendChild(ut);
    loginform.appendChild(rem);


    document.body.appendChild(loginform);
    loginform.submit();
}

function GoLogout() {
    window.location = "/HeaderActions.asp?logout=true"; //&return=" + window.location;
}

//function AddFav(BlogID) {
//    window.location = "HeaderActions.asp?blog=" + BlogID + "&addfav=true&return=" + window.location;
//}

//function DelFav(BlogID) {
//    window.location = "HeaderActions.asp?blog=" + BlogID + "&delfav=true&return=" + window.location;
//}

function OpenLoginDiv(pid, id) {
    var obj = $("#" + id);
    var jObj = $("#" + pid);
    var c = jObj.offset();

    obj.css("top", c.top + 15);
    obj.css("left", c.left - obj.width() + jObj.width());
    obj.css("display", "");
}
function OpenLoginDivAspx(id) {
    var obj = document.getElementById(id);
    obj.style.display = "block";
}

function CloseLoginDiv(id) {
    var obj = document.getElementById(id);
    obj.style.display = "none";
}

function HeaderDivOnload(favSelectId, searchGroupName, imagesPath, thisBlogId) {
    //document.FavCombo = new EnchancedCombo(favSelectId);
    document.HeaderSearch = new EncancedSearch(searchGroupName, imagesPath, thisBlogId);
}
 function Cookie(sCookieName) {
        //onerror=function (sError,sURL,iLine){	return ClassException('Cookie',sError,sURL,iLine); }
        // This function save cookie
        this.setCookie = setCookie;
        this.getCookie = getCookie;
        this.sCookieName = sCookieName;

        function setCookie(sValue, iMinutes, sDomain) {
            if (iMinutes) {
                var date = new Date();
                date.setTime(date.getTime() + (iMinutes * 60 * 1000))
                var expires = "; expires=" + date.toGMTString()
            } else expires = ""
            var sCookieCont = sCookieName + "=" + sValue + expires + "; path=/"
            sCookieCont += sDomain != "" && sDomain ? " ; domain=" + sDomain : " ; domain=" + location.host;
            document.cookie = sCookieCont
        }
        // This function read the cookie that was saved by saveCookie function
        function getCookie() {
            var nameEQ = sCookieName + "="
            var ca = unescape(document.cookie).split(';')
            var sCookie
            for (var i = 0; i < ca.length; i++) {
                sCookie = ca[i];
                while (sCookie.charAt(0) == ' ') sCookie = sCookie.substring(1, sCookie.length)
                if (sCookie.indexOf(nameEQ) == 0) return sCookie.substring(nameEQ.length, sCookie.length)
            }
        }
    }

    // get query string paramter and return the value
    function RequestQueryString(sParamName, sHref) {
        var arrHref;
        var nParamStartPos = 0, nParamEndPos = 0;
        var sParamValue = '';

        if (typeof (sHref) == "undefined")
            var sHref = document.location.href;

        arrHref = sHref.split("?");
        // return empty string if the query string not exsits
        if (arrHref.length <= 1)
            return (sParamValue);
        sParamName += '=';
        nParamStartPos = arrHref[1].indexOf(sParamName);
        // return empty string if the requested parameter is not exsits
        if (nParamStartPos == -1)
            return (sParamValue);
        nParamStartPos += sParamName.toString().length;
        nParamEndPos = arrHref[1].indexOf("&", nParamStartPos);
        if (nParamEndPos > -1 && nParamEndPos > nParamStartPos)
            sParamValue = arrHref[1].slice(nParamStartPos, nParamEndPos);
        else
            sParamValue = arrHref[1].slice(nParamStartPos);

        return (sParamValue);
    }
    ///////////////////////2011
    function showSearchOptionsDiv() {
        if (document.getElementById('divSearchOptions').style.display == "block")
            document.getElementById('divSearchOptions').style.display = "none";
        else
            document.getElementById('divSearchOptions').style.display = "block";
    }
    function hideSearchOptionsDiv() {
        document.getElementById('divSearchOptions').style.display = "none";
    }
    function searchInThisBlog() {
        document.getElementById('divSearchInBlogSelect').style.display = "block";
        document.getElementById('divSearchUserSelect').style.display = "none";
        document.getElementById('divSearchTextSelect').style.display = "none";
        if (document.getElementById('SearchText').value == "" || document.getElementById('SearchText').value == "חפש שם בלוג/בלוגר" || document.getElementById('SearchText').value == "חפש בכל הבלוגים") {
            document.getElementById('SearchText').value = "חפש בבלוג זה";
        }
        hideSearchOptionsDiv();
    }
    function searchUser() {
        document.getElementById('divSearchInBlogSelect').style.display = "none";
        document.getElementById('divSearchUserSelect').style.display = "block";
        document.getElementById('divSearchTextSelect').style.display = "none";
        if (document.getElementById('SearchText').value == "" || document.getElementById('SearchText').value == "חפש בבלוג זה" || document.getElementById('SearchText').value == "חפש בכל הבלוגים") {
            document.getElementById('SearchText').value = "חפש שם בלוג/בלוגר";
        }
        hideSearchOptionsDiv();
    }
    function searchText() {
        document.getElementById('divSearchInBlogSelect').style.display = "none";
        document.getElementById('divSearchUserSelect').style.display = "none";
        document.getElementById('divSearchTextSelect').style.display = "block";
        if (document.getElementById('SearchText').value == "" || document.getElementById('SearchText').value == "חפש שם בלוג/בלוגר" || document.getElementById('SearchText').value == "חפש בבלוג זה") {
            document.getElementById('SearchText').value = "חפש בכל הבלוגים";
        }
        hideSearchOptionsDiv();
    }
    //////////////////
    // get query string paramter and return the value
    function RequestQueryString(sParamName, sHref) {
        var arrHref;
        var nParamStartPos = 0, nParamEndPos = 0;
        var sParamValue = '';

        if (typeof (sHref) == "undefined")
            var sHref = document.location.href;

        arrHref = sHref.split("?");
        // return empty string if the query string not exsits
        if (arrHref.length <= 1)
            return (sParamValue);
        sParamName += '=';
        nParamStartPos = arrHref[1].indexOf(sParamName);
        // return empty string if the requested parameter is not exsits
        if (nParamStartPos == -1)
            return (sParamValue);
        nParamStartPos += sParamName.toString().length;
        nParamEndPos = arrHref[1].indexOf("&", nParamStartPos);
        if (nParamEndPos > -1 && nParamEndPos > nParamStartPos)
            sParamValue = arrHref[1].slice(nParamStartPos, nParamEndPos);
        else
            sParamValue = arrHref[1].slice(nParamStartPos);

        return (sParamValue);
    }

