﻿// BreslovWorld JavaScript File

//function makepage(src, title) {
//    return "<html>\n" +
//    "<head>\n" +
//    "<title>" + title + "</title>\n" +
//    "<script>\n" +
//    "function step1() {\n" +
//    "  setTimeout('step2()', 10);\n" +
//    "}\n" +
//    "function step2() {\n" +
//    "  window.print();\n" +
//    "  window.close();\n" +
//    "}\n" +
//    "</scr" + "ipt>\n" +
//    "</head>\n" +
//    "<body onLoad='step1()'>\n" +
//    "<img src='" + src + "'/>\n" +
//    "</body>\n" +
//    "</html>\n";
//}

//function printme(evt)
//{
//    title = "title";       
//    
//  if (!evt) {
//    evt = window.event;
//  }
//  
//  var image = evt.target;
//  if (!image) {
//    image = window.event.srcElement;
//  }

//  src = image.src;
//  link = "about:blank";
//  var pw = window.open(link, "_new");
//  pw.document.open();
//  pw.document.write(makepage(src, title));
//  pw.document.close();
//}

function bool(string) {
    var boolean_ = new Boolean(string).valueOf();
    return boolean_;
}

String.prototype.boolean = function() {
    return "true" == this;
};

function openShare(shareurl, url) {
    //window.open(shareurl + encodeURIComponent(url));
    window.open(shareurl + encodeURIComponent(url), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;    
}

function getURI(url) {
    return encodeURIComponent(url);
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var ca = document.cookie.split(';');
    var nameEQ = name + "=";
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length); //delete spaces
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function toggleVisibility(me) {
    btn_ = document.getElementById(me.id);
    if (btn_.style.visibility == "hidden") {
        btn_.style.visibility = "visible";
    }
    else {
        btn_.style.visibility = "hidden";
    }
}

function toggleVisibility__(me) {
    btn_ = document.getElementById(me);
    if (btn_.style.visibility == "hidden") {
        btn_.style.visibility = "visible";
        //btn_.style.display = "";
    }
    else {
        btn_.style.visibility = "hidden";
        //btn_.style.display = "none";
    }
}

function toggleVisibility3(me) {
    if (me.style.visibility == "hidden") {
        me.style.visibility = "visible";
        me.style.display = "";
    }
    else {
        me.style.visibility = "hidden";
        me.style.display = "none";
    }
}

function toggleBlock(sBlkId) {
    var b = document.getElementById(sBlkId);
    if (b.style.display == 'none') b.style.display = '';
    else b.style.display = 'none';
}

function doNothing() {
    try {
        event.returnValue = false;
        event.cancelBubble = true;
    } catch (e) { }
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

function CheckTextLength(maxLen) {
    var txtBox = window.event.srcElement;

    if (txtBox.value.length > maxLen - 1) {
        alert("שדה זה מוגבל ל - " + maxLen + " תווים");
        event.returnValue = false;
        event.cancelBubble = true;
    }
}

function CheckTextLengthNoAlert(maxLen) {
    var txtBox = window.event.srcElement;

    if (txtBox.value.length > maxLen - 1) {
        event.returnValue = false;
        event.cancelBubble = true;
    }
}

function formatINT(input, type) {
    // type = 2 - without '.'
    var num = input.value.replace(/\,/g, '');
    if (!isNaN(num)) {

        if (type == 1) {
            if (num.indexOf('.') > -1) {
                alert("חובה להקליד ספרות בלבד");
                input.value = input.value.substring(0, input.value.length - 1);
            }
        }
    }
    else {
        alert("חובה להקליד ספרות בלבד");
        input.value = input.value.substring(0, input.value.length - 1);
    }
}

function checkFormatINT(input) {

    var num = input.value.replace(/\,/g, '').trim();
    var strRes;

    if (isNaN(num)) {

        var i;
        strRes = "";
        for (i = 0; i <= input.value.length; i++) {
            if (!isNaN(input.value.substring(i, 1))) {
                strRes = strRes.toString() + input.value.substring(i, 1).toString();
            }
        }

        if (input.value == "0") {
            input.value = "1";
        }
        else {
            input.value = strRes;
        }

        return false;
    }
    else {

        if (input.value == "0") {
            input.value = "1";
        }
        else {
            input.value = num.trim();
        }
        return false;
    }
}

function checkFormatINT_ShoppingCart(input) {

    var num = input.value.replace(/\,/g, '').trim();
    var strRes;

    if (isNaN(num) || num.indexOf('.') > -1) {

        var i;
        strRes = "";
        for (i = 0; i <= input.value.length; i++) {
            if (!isNaN(input.value.substring(i, i + 1))) {
                strRes = strRes.toString() + input.value.substring(i, i + 1).toString();
            }
        }

        input.value = strRes;
        return false;
    }
    else {
        input.value = num.trim();
        return false;
    }
}

function checkFormatDOUBLE_ShoppingCart(input, CurrencyDecimalSeparator) {

    var num;
    var strRes;

    if (CurrencyDecimalSeparator == ".") {
        num = input.value.replace(/\,/g, '').trim();
    } else {
        num = input.value.replace(/\./g, '').trim();
    }

    if (isNaN(num)) {

        var i;
        strRes = "";
        for (i = 0; i <= input.value.length; i++) {
            if (!isNaN(input.value.substring(i, i + 1)) || input.value.substring(i, i + 1) == CurrencyDecimalSeparator) {
                strRes = strRes.toString() + input.value.substring(i, i + 1).toString();
            }
        }

        input.value = strRes;
        return false;
    }
    else {
        input.value = num.trim();
        return false;
    }
}

function OpenWindow(link) {
    var oWindow;
    oWindow = window.open(link, '', 'channelmode = no, directories = no, width = ' + (screen.width - 30) + 'px, height = ' + (screen.height - 100) + 'px, center = yes, help = no, resizable = yes, status = no, unadorned = yes, scrollbars = yes, toolbar = no, top = 10, left = 10, menubar = no');
}

function OpenWindowImage(href_) {
    var oWindow;
    oWindow = window.open(href_, '', 'channelmode = no, directories = no, width = ' + (screen.width - 200) + 'px, height = ' + (screen.height - 150) + 'px, center = yes, help = no, resizable = yes, status = no, unadorned = yes, scrollbars = yes, toolbar = no, top = 10, left = 10, menubar = no');
}

function ShowModDialog(SiteAddress) {

    //var oWindow;
    //oWindow = window.open(SiteAddress, '', 'channelmode = no, directories = no, width = 550px, height = 560px, center = yes, help = no, resizable = yes, status = no, unadorned = yes, scrollbars = yes, toolbar = no, top = 10, left = 10, menubar = no');	

    var newWin;

    if (navigator.appName == "Mozilla" || navigator.appName == "Netscape") {
        newWin = window.open(SiteAddress, 'Index BreslovWorld - Site Details', 'toolbar=0,status=0,width=550px,height=620px,menubar=0,resizable=no, left=20, top=20, scrollbars = no, center = yes, help = no');
        newWin.focus();
    }
    else if (navigator.appName == "Microsoft Internet Explorer") {

        newWin = window.open(SiteAddress, 'mywindow', 'toolbar=0, status=0, width=550, height=600, menubar=0, resizable=no, left=20, top=20, scrollbars = yes, center = yes, help = no');
        //newWin = window.showModelessDialog(SiteAddress, "Index BreslovWorld - Site Details", "dialogWidth=550px;dialogHeight=620px; center:Yes; resizable:No; status:No; unadorned:yes; edge:sunken; help:No; scroll:No; left:20; top:20;");
        newWin.focus();
    }
    else {
        newWin = window.open(SiteAddress, 'Index BreslovWorld - Site Details', 'toolbar=0,status=0,width=550px,height=620px,menubar=0,resizable=no, left=20, top=20, scrollbars = no, center = yes, help = no');
        newWin.focus();
    }
    return false;

}

function ShowHideDiv(divName) {
    if (eval(divName + '.style.display') == 'none') {
        eval(divName + '.style.display=""');
    }
    else {
        eval(divName + '.style.display="none"')
    }
}

function ShowModDialogSivugim(formURL) {
    var ret = window.showModalDialog(formURL, "", "dialogHeight:450px; dialogWidth:650px; resizable:no; edge:sunken");
}

function ShowModDialogSivugimTable(formURL) {

    //window.location = formURL;
    var ret = window.showModalDialog(formURL, "", "dialogHeight:600px; dialogWidth:700px; resizable:no; edge:sunken");
}

function ShowModDialogNewSite(pnsID) {

    var ret;

    if (pnsID > 0) {
        ret = window.showModalDialog("AdminSiteIndexAddNewSite.aspx?pnsID=" + pnsID, "", "dialogHeight:600px; dialogWidth:700px; resizable:no; edge:sunken");
    }
    else {
        ret = window.showModalDialog("AdminSiteIndexAddNewSite.aspx", "", "dialogHeight:600px; dialogWidth:700px; resizable:no; edge:sunken");
    }
}

function delete_cookies() {
    a = new Array();
    c = new Date();
    a = document.cookie.split(';');
    document.cookie = a[0] + ";expires = " + c.toGMTString() + ";";
    document.cookie = a[1] + ";expires = " + c.toGMTString() + ";";
    document.cookie = a[2] + ";expires = " + c.toGMTString() + ";";
}

function showFlash(filename) {

    filename = filename.toLowerCase();

    if (filename.indexOf("swf") == -1) {
        var newImg = new Image();
        newImg.src = filename;
        var height = newImg.height;
        var width = newImg.width;

        var znamen;

        if (width > 250 || height > 250) {
            znamen = width / 150;
            width = width / znamen;
            height = height / znamen;
        }

        document.all("dek").innerHTML = "<img src='" + filename + "' width='" + width + "' height='" + height + "'/>";
    }
    else {
        var fo = new FlashObject(filename, "animationName", "150", "150", "6", "#FFFFFF");
        fo.addParam("allowScriptAccess", "sameDomain");
        fo.addParam("quality", "high");
        fo.addParam("scale", "scale");
        fo.addParam("loop", "false");
        fo.write("dek");
    }
}

function showSWF(filename, div_, Link, OpenInNewWindow, backColor) {

    var so;

    filename = filename.toLowerCase();

    try {

        div__ = document.getElementById(div_);

        if (filename.indexOf("swf") == -1) {

            if (Link.length > 0) {

                if (OpenInNewWindow == 0) {
                    div__.innerHTML = "<a href='" + Link + "'><img src='" + filename + "' alt='' style='border:0px;' /></a>";
                }
                else {
                    div__.innerHTML = "<a href='" + Link + "' target='_blank'><img src='" + filename + "' alt='' style='border:0px;' /></a>";
                }

            }
            else {
                div__.innerHTML = "<img src='" + filename + "' alt='' />";
            }

        }
        else {

            if (Link.length > 0) {
                so = new SWFObject(filename + "?LinkBlank=" + OpenInNewWindow, div_ + "q", "100%", "100%", "6", backColor);
                // + "&LinkUrl=" + Link
            }
            else {
                so = new SWFObject(filename, div_ + "q", "100%", "100%", "6", backColor);
            }

            so.addVariable("allowScriptAccess", "sameDomain");
            so.addVariable("quality", "high");
            so.addVariable("scale", "exactfit"); //scale
            so.addVariable("loop", "false");
            so.addVariable("wmode", "transparent");
            so.addVariable("LinkUrl", Link.replace(/&/g, "%26"));
            so.write(div__);

        }
    }
    catch (e) {
        //alert("error");
    }

}

function getFlashObj(movie) {
    if (window.document[movie]) {
        return window.document[movie];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movie]) {
            return document.embeds[movie];
        }
    } else {
        return document.getElementById(movie);
    }
}

function getDimensions(movie) {
    var movieObj = getFlashObj(movie);
    var width = movieObj.TGetProperty("/", 8);
    var height = movieObj.TGetProperty("/", 9);
    alert("The current dimensions for the Flash Object (" + movie + ") are " + width + " in width and " + height + " in height.");
}

function get_mouse_old(e) {
    var x = (ns4 || ns6) ? e.pageX : event.x + document.body.scrollLeft;
    skn.left = x + Xoffset;
    var y = (ns4 || ns6) ? e.pageY : event.y + document.body.scrollTop;
    skn.top = y + yyy;
}

function get_mouse(e) {
    var x = (ns4 || ns6) ? e.pageX : event.x + document.documentElement.scrollLeft;
    skn.left = x + Xoffset;
    var y = (ns4 || ns6) ? e.pageY : event.y + document.documentElement.scrollTop;
    skn.top = y + yyy;
}

function kill() {
    try {
        yyy = -1000;
        if (ns4) { skn.visibility = "hidden"; }
        else if (ns6 || ie4)
            skn.display = "none"
    }
    catch (e) {
    }
}

function getImgSize(imgSrc) {
    var newImg = new Image();
    newImg.src = imgSrc;
    var height = newImg.height;
    var width = newImg.width;

    alert('w: ' + width + ' , h: ' + height);
}

function getImgSize2(imgID) {
    var pic = document.getElementById(imgID);
    var h = pic.offsetHeigt;
    var w = pic.offsetWidth;
    alert('w: ' + w + ' , h: ' + h);
}

// <img id='test' src='test.jpg'>
// <button onclick="getImgSize(document.getElementById('test').src);">Get Size</button>

function printWindow() {
    bV = parseInt(navigator.appVersion)
    if (bV >= 4) window.print()
}

function ArticlePrintVersion(domain, params) {

    var newWin;

    newWin = window.open(domain + "/articlePrintVersion.aspx?" + params, '', 'channelmode=no, directories=no, width=550px, height=500px, center=yes, help=no, resizable=no, status=no, unadorned=no, scrollbars=yes, toolbar=no, top=30, left=40, menubar=no');

    return false;
}

function SubscrEmailSendPreview(pagename) {

    var newWin;

    newWin = window.open(pagename, '', 'channelmode=no, directories=no, width=850px, height=600px, center=yes, help=no, resizable=no, status=no, unadorned=no, scrollbars=yes, toolbar=no, menubar=no');

    newWin.focus();
    return false;
}

function ShowModDialogSendArticle(ArticleURL, language, SiteAddress) {

    hdnArticleUrl_ = document.getElementById("hdnArticleUrl");
    hdnArticleUrl_.value = ArticleURL;

    var newWin;
    newWin = window.open(SiteAddress + "?language=" + language, '', 'width=405px, height=400px, left=80, top=50, menubar=no, unadorned=no, resizable=no, toolbar=no, scrollbars=no, center=yes, status=no, help=no, directories=no, channelmode=no');
    newWin.focus();

    return false;
}

function ShowModDialogNewTalkback(url, language, ArticleID, CommentID) {

    var newWin;

    //	if (CommentID != '0') {
    //	    newWin = window.open(url + "?articleID=" + ArticleID + "&commentID=" + CommentID + "&language=" + language, '', 'width=485px, height=430px, left=80, top=50, menubar=no, unadorned=no, resizable=no, toolbar=no, scrollbars=no, center=yes, status=no, help=no, directories=no, channelmode=no');
    //	}
    //	else {
    //	    newWin = window.open(url + "?articleID=" + ArticleID + "&language=" + language, '', 'width=485px, height=430px, left=80, top=50, menubar=no, unadorned=no, resizable=no, toolbar=no, scrollbars=no, center=yes, status=no, help=no, directories=no, channelmode=no');
    //	}

    newWin = window.open(url + "?articleID=" + ArticleID + "&language=" + language, '', 'width=485px, height=430px, left=80, top=50, menubar=no, unadorned=no, resizable=no, toolbar=no, scrollbars=no, center=yes, status=no, help=no, directories=no, channelmode=no');

    newWin.focus();

    return false;
}

function ShowModDialogNewTalkbackVOD(url, language, ArticleID, CommentID) {

    var newWin;

    //	if (CommentID != '0') {
    //	    newWin = window.open(url + "?articleID=" + ArticleID + "&commentID=" + CommentID + "&language=" + language, '', 'width=485px, height=430px, left=80, top=50, menubar=no, unadorned=no, resizable=no, toolbar=no, scrollbars=no, center=yes, status=no, help=no, directories=no, channelmode=no');
    //	}
    //	else {
    //	    newWin = window.open(url + "?articleID=" + ArticleID + "&language=" + language, '', 'width=485px, height=430px, left=80, top=50, menubar=no, unadorned=no, resizable=no, toolbar=no, scrollbars=no, center=yes, status=no, help=no, directories=no, channelmode=no');
    //	}

    newWin = window.open(url + "?vodID=" + ArticleID + "&language=" + language, '', 'width=485px, height=430px, left=80, top=50, menubar=no, unadorned=no, resizable=no, toolbar=no, scrollbars=no, center=yes, status=no, help=no, directories=no, channelmode=no');

    newWin.focus();

    return false;
}

function AddFavor(PleaseClick, DomainName, FavorTitle) {

    var IEstring = "javascript:window.external.addfavorite('" + DomainName + "', '" + FavorTitle + "');";
    var NSstring = PleaseClick + " [Ctrl + D] ";
    var OPstring = PleaseClick + " [Ctrl + T]";
    var OTHstring = "Bookmark this page!"
    var whichString = OTHstring;
    var agt = navigator.userAgent.toLowerCase();
    var app = navigator.appName.toLowerCase();
    var ieAgent = agt.indexOf('msie');
    var nsAgent = app.indexOf('netscape');
    var opAgent = app.indexOf('opera');
    if (ieAgent != -1) { whichString = IEstring; } else if (nsAgent != -1) { whichString = NSstring; } else if (opAgent != -1) { whichString = OPstring; }

    if (ieAgent != -1) {
        eval(whichString);
        return false;
    }
    else {
        alert(whichString);
        return false;
    }

}

function IsItIE() {

    var agt = navigator.userAgent.toLowerCase();
    var app = navigator.appName.toLowerCase();
    var ieAgent = agt.indexOf('msie');
    var nsAgent = app.indexOf('netscape');
    var opAgent = app.indexOf('opera');

    if (ieAgent != -1) {
        return '1';
    }
    else {
        return '0';
    }
}

function ShowModDialog2(SiteAddress, Title, width, height) {

    //var oWindow;
    //oWindow = window.open(SiteAddress, '', 'channelmode = no, directories = no, width = 550px, height = 560px, center = yes, help = no, resizable = yes, status = no, unadorned = yes, scrollbars = yes, toolbar = no, top = 10, left = 10, menubar = no');	

    var newWin;

    if (navigator.appName == "Mozilla" || navigator.appName == "Netscape") {
        newWin = window.open(SiteAddress, Title, 'toolbar=0,status=0,width=' + width + 'px,height=' + height + 'px,menubar=0,resizable=no, left=20, top=20, scrollbars = no, center = yes, help = no');
        newWin.focus();
    }
    else if (navigator.appName == "Microsoft Internet Explorer") {
        newWin = window.showModelessDialog(SiteAddress, Title, "dialogWidth=" + width + "px;dialogHeight=" + height + "px; center:Yes; resizable:No; status:No; unadorned:yes; edge:sunken; help:No; scroll:No; left:20; top:20; toolbar:No;");
        newWin.focus();
    }
    else {
        newWin = window.open(SiteAddress, Title, 'toolbar=0, status=0, width=' + width + 'px, height=' + height + 'px, menubar=0, resizable=no, left=20, top=20, scrollbars = no, center = yes, help = no');
        newWin.focus();
    }

    return false;
}

function certOpen() {
    window.open("https://www.thawte.com/cgi/server/certdetails.exe?referer=http://www.breslev.co.il", "_blank", "height=550,width=500");
    return false;
}
