// צריך להיות זהה לצד שרת בקובץ הפונקציות
//*******************************************
getE = function (name) { return document.getElementById(name) }
_ = getE;

Array.prototype.write = function () { document.write(this.join("")) }

Array.prototype.string = function () { return this.join("") }

Array.prototype.remove = function (from, to) {
    var rest = this.slice((to || from) + 1 || this.length);

    this.length = from < 0 ? this.length + from : from;

    return this.push.apply(this, rest);

};

String.prototype.write = function () { document.write(this) }

String.prototype.toNick = function () { return this.replaceStr("&", "&amp;").replaceStr("<", "&lt;").replaceStr(">", "&gt;"); }; String.prototype.toHTML = function (str) { var str = this; if (!str) return ""; str += ""; return this.toNick().replaceStr('"', "&quot;").replaceStr("'", "&#39;") }; String.prototype.toJS = function (str) { var str = this; if (!str) return ""; str += ""; return str.replaceStr('"', '\\"').replaceStr("'", '\\\'').replaceStr("\n", "\\n"); }

String.prototype.replaceStr = function (oldValue, newValue) { return this.split(oldValue).join(newValue); }; String.prototype.removeStr = function (oldValue) { return this.replaceStr(oldValue, "") }

String.prototype.Short = function (num) { var str = this; if (!str) return ""; return str.replace(new RegExp("(.{" + num + "}\S{0,})(?:.*)", "gi"), "$1"); }
String.prototype.toHTML = function (str) { var str = this; if (!str) return ""; str += ""; return this.toNick().replaceStr('"', "&quot;").replaceStr("'", "&#39;") }
String.prototype.toJS = function (str) { var str = this; if (!str) return ""; str += ""; return str.replaceStr('"', '\\"').replaceStr("'", '\\\'').replaceStr("\n", "\\n"); }
String.prototype.removeStr = function (oldValue) { return this.replaceStr(oldValue, "") }
String.prototype.Short = function (num) { var str = this; if (!str) return ""; return str.replace(new RegExp("(.{" + num + "}\S{0,})(?:.*)", "gi"), "$1"); }

String.prototype.toHTMLS = function () {
    sString = this; if (!sString) return "";



    function rxescape(str) { return str.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&"); }

    sString = sString.replace(/target=_top/g, "").replace(/(<A |<a)/g, "<A target=_blank ").replace(/<\/?\w+:[^>]*>/gi, "");

    var a = [[":-)", "smile"], [":-D", "vhappy"], [";-(", "boche"], [":-(", "sad"], [":-P", "tongue"], [";-)", "wink"], ["(ישן)", "k"], ["(מחשב)", "computer"], ["(כוכב)", "star"], ["(בלון)", "balon"], ["(דוס)", "dos"], ["(חופר)", "digg"], ["(נשיקה)", "remybussi"], ["(נפנוף)", "nifnuf"], ["(מרחף)", "h"], ["(טלפון)", "telphone"]];

    for (var i = 0; i < a.length; i++) {

        var sSmile = rxescape(a[i][0]); sString = sString.replace(new RegExp("(" + sSmile + (sSmile.indexOf(";") == -1 ? "|" + sSmile.replace("\\-", "") : "") + ")", "gi"), "<img src=\"" + sStaticURL + "images/forum/smilies/" + a[i][1] + ".gif\">")
    }



    sString = sString.replace(/<IMG.{0,50}src=\"http:\/\/forumpics\.a7\.org\/\?file=([0-9.jpg]*)\"[^>]*>/gi, " <a href=http://a7.org/?file=$1 target=_blank><IMG src=\"http://n2.a7.org/Resizer.ashx?image=$1&forum=1&a=500&save=1\"></a> ")

    return sString;

}



//*******************************************
function DoNothing() { }
var sOXURL = "http://info4.a7.org/info/";

var Info = { aIDs: [], aNoAds: [], aOne: [], Vars: {}, View: { a: [] }, BeforeLog: DoNothing, Add: function (zone, id, opts) { Info.aIDs.push({ id: id, zone: zone, opts: opts ? opts : [] }); return Info }, Remove: function (id) { for (var i = 0; i < Info.aIDs.length; i++) if (Info.aIDs[i].id == id) { Info.aIDs.remove(i); } },
    HTML: function (b, opts) {
        if (!opts) opts = {};
        var fileurl = sOXURL + "images/" + encodeURIComponent(b.file);
        var clickurl = sOXURL + "delivery/ck.php?oaparams=2__b=" + b.b + "__z=" + b.z;
        var code = "";
        switch (b.type) {
            case "jpeg": case "png": case "gif":
                code = "<a rel=nofollow href=" + clickurl + " target=_blank>" + (b.width > 1 && !opts.text ? "<img width=" + b.width + " height=" + b.height + " src=" + fileurl + ">" : "") + (opts.text ? b.append + b.alt : "") + "</a>";
                break;
            case "swf":
                var v = "";
                var escu = escape(clickurl) + "&atar1=_blank"; //.replaceStr("{zoneid}",b.zone).replaceStr("{ban"+"nerid}",b.bid)
                if (b.zone % 100 == 80 || window.mit) v = "<PARAM NAME=WMode VALUE=Transparent>";
                code = "<OBJECT codeBase=http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0 height=" + b.height + " width=" + b.width + " classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000>" + v + "<param name=\"flashvars\" value=\"alink1=" + escu + "\" /><PARAM NAME=Movie VALUE='" + fileurl + "'><PARAM NAME=Src VALUE='" + fileurl + "'><PARAM NAME=Menu VALUE=-1><PARAM NAME=AllowScriptAccess VALUE=never><PARAM NAME=AllowFullScreen VALUE=false><embed src='" + fileurl + "' quality=high wmode='opaque' width='" + b.width + "' height='" + b.height + "' type='application/x-shockwave-flash' pluginspace='http://www.adobe.com/go/getflashplayer' allowScriptAccess='never' FlashVars=\"alink1=" + escape(clickurl) + "\"></embed></OBJECT>"; break;
            case "html":
                code = b.file.replaceStr("{target}", "_blank").replaceStr("{source}", "").replaceStr("{zoneid}", b.zone).replaceStr("{ban" + "nerid}", b.bid).replaceStr("{url_prefix}", clickurl.split("/c.php")[0]);
        }
        return code;
    },
    Object: function (bid, cid, zone, type, url, file, ver, height, width, append, alt, block_ad, cap_ad, session_cap_ad, block_campaign, cap_campaign, session_cap_campaign, block_zone, cap_zone, session_cap_zone, last_view, last_click) { return { b: bid, c: cid, z: zone, type: type, url: url, file: file, width: width, height: height, append: append, alt: alt }; },
    Insert: function (i, b) {
        Info.View.a.push({ b: b.b, c: b.c, z: b.z, OABLOCK: b.block_ad, OACAP: b.cap_ad, OASCAP: b.session_cap_ad, OACBLOCK: b.block_campaign, OACCAP: b.cap_campaign, OASCCAP: b.session_cap_campaign, OAZBLOCK: b.block_zone, OAZCAP: b.cap_zone, OASZCAP: b.session_cap_zone, OXLIA: b.last_view, OXLCA: b.last_click });
        if (!Info.aIDs[i].opts.func) Info.aIDs[i].opts.func = Info.InsertDo;
        Info.aIDs[i].opts.func(b, i);

    },
    InsertDo: function (b, i) {
        var v = Info.View, id = Info.aIDs[i].id;
        var d = $((id.indexOf(".") > -1 || id.indexOf('#') > -1 ? "" : "#") + id);
        var code = Info.HTML(b, Info.aIDs[i].opts);
        if (Info.aIDs[i].clear) { d.html(code); Info.aIDs[i].opts.clear = ""; } else d.append(code);
    },
    Reload: function () {
        for (var i = 0; i < Info.aIDs.length; i++) Info.aIDs[i].clear = true;
        Info.Final(); Info.View = { a: [] };
    },
    Log: function () {
        this.BeforeLog(); var s = [], a = this.View.a, arr = "b,z,c,OABLOCK,OACAP,OASCAP,OACBLOCK,OACCAP,OASCCAP,OAZBLOCK,OAZCAP,OASZCAP,OXLIA,OXLCA".split(",");
        for (var i = 0; i < arr.length; i++) {
            s.push("&" + arr[i] + "=");
            for (var i2 = 0; i2 < a.length; i2++) s.push((i2 > 0 ? ',' : '') + (a[i2][arr[i]] ? a[i2][arr[i]] : 0))
        }
        ExecuteUrl(sOXURL + "delivery/lg2.php?" + s.string().substring(1) + "&" + new Date().getTime());
        Info.Warn()
    },
    Warn: function () { if (Info.aNoAds.length > 0 && window.console) console.warn("" + Info.aNoAds.join("\n")); Info.aNoAds = []; },
    LoadOne: function (zone, id, opts) { Info.aOne[id] = { id: id, zone: zone, opts: opts ? opts : {} }; ExecuteJS(sOXURL + "a7delivery.php?z=" + zone + "&div=" + id + "&" + new Date().getTime()) },
    One: function (id, b) {
        if (Info.aOne[id].opts.func) { Info.aOne[i].opts.func(b, id); }
        else {
            var d = $((id.indexOf(".") > -1 || id.indexOf('#') > -1 ? "" : "#") + id);
            d.html(Info.HTML(b, Info.aOne[id].opts));
        }
    },
    ReloadTO: function (timeout) { window.setTimeout(this.Reload, timeout) },
    Final: function () {
        var z = "", y = ""; for (i = 0; i < Info.aIDs.length; i++) z += "," + Info.aIDs[i].zone;
        for (x in Info.Vars) { y += "&" + x + "=" + Info.Vars[x] }
        if (z) ExecuteJS(sOXURL + "a7delivery.php?z=" + z.substring(1) + y + "&d=" + new Date().getSeconds());
    },
    LogC: function (type, cat, item, place) { if (type.length == 4) { cat = type[1]; item = type[2]; place = type[3]; type = type[0]; } ExecuteUrl("/Controls/HPJS.ashx?act=log&type=" + type + "&cat=" + cat + "&place=" + place + "&item=" + item + "&_" + new Date().getTime()); }
}


function ExecuteJS(url, func) {
    var scriptElem = document.createElement('script'); scriptElem.setAttribute('src', url + (func ? "&func=" + func : "")); window.document.getElementsByTagName('head')[0].appendChild(scriptElem);
}
function ExecuteUrl(url) { var i = document.createElement("img"); i.src = url + "&_" + new Date().getTime(); i.style.display = "none"; _("divMain").appendChild(i); }
window.ExecuteJS = ExecuteJS; window.ExectueUrl = ExecuteUrl;

var count = 0; //מספר החלפות
var reload = false;
var adLoaded = false;
//var sZones = "";
//var HebsZones = "";
//var sIDs = "";
//var aIDs = []
//function Final() {
//    aIDs = sIDs.split(",");
//    iCountry = sCountry == "IL" ? 1 : 2;
//    url = "http://click.inn.co.il/infojs2.php?c=" + iCountry + "&zones_list=" + sZones
//    var scriptElem = document.createElement('script');
//    scriptElem.setAttribute('src', url);
//    document.getElementsByTagName('head')[0].appendChild(scriptElem);


//    if (HebsZones == "77") {
//        url = "http://click.inn.co.il/infojs.php?&zones_list=" + HebsZones + "&" + new Date().getTime();
//        var scriptElem2 = document.createElement('script');
//        scriptElem2.setAttribute('src', url);
//        document.getElementsByTagName('head')[0].appendChild(scriptElem2);
//    }

//    if (count < 5) { window.setTimeout(Final, 70000); count++; }
//}

//function InsertBad(i, bid, cid, zone, type, url, file, ver, height, width) {
//    newurl = "http://click.inn.co.il/phpA" + "dsNew-en-new/a" + "d";
//    newurle = ".php?bannerid=" + bid + "&zoneid=" + zone + "&clientid=" + cid + "&dest=" + url;
//    fileurl = 'http://click.inn.co.il/info_en/' + file;
//    clickurl = newurl + "click" + newurle;
//    logurl = newurl + "log" + newurle;
//    if (zone == 77) {
//        i = 3; newurl = "http://click.inn.co.il/phpA" + "dsNew/a" + "d";
//        fileurl = 'http://click.inn.co.il/info_he/' + file;
//    }
//    code = "";
//    switch (type) {
//        case "jpeg": case "png": case "gif":
//            code = "<a href=" + clickurl + "><img width=" + width + " height=" + height + " src=" + fileurl + "></a>";
//            break;
//        case "swf":
//            fileurl += "?alink1=" + escape(clickurl) + "&atar1=_blank"
//            code = "<OBJECT codeBase=http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0 height=" + height + " width=" + width + " classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME=Movie VALUE='" + fileurl + "'><PARAM NAME=Src VALUE='" + fileurl + "'><PARAM NAME=WMode VALUE=Transparent><PARAM NAME=Menu VALUE=-1><PARAM NAME=AllowScriptAccess VALUE=never><PARAM NAME=AllowFullScreen VALUE=false><embed src='" + fileurl + "' quality=high wmode='transparent' width='" + width + "' height='" + height + "' type='application/x-shockwave-flash' pluginspace='http://www.adobe.com/go/getflashplayer' allowScriptAccess='never'></embed></OBJECT>"; break;
//        case "html":
//            code = file;
//    }
//    code += "<img src=" + logurl + "&" + new Date().getTime() + " style=display:none>";
//    try {
//        document.getElementById(aIDs[i]).innerHTML = code;
//    } catch (e) { /*alert(i +" "+ sIDs)*/ }
//}
function CheckHiRes() {
    div = document.getElementById("divHiRes");
    if (div) {
        if (document.body.clientWidth < 970) { div.style.visibility = "hidden"; reload = true; }
        else {
            if (document.body.clientHeight < 800) div.style.marginTop = Math.floor(document.body.clientHeight / 2) - 300 + "px";
            if (!adLoaded) {
                adLoaded = true;
//                if (reload) { try { sZones = '67'; sIDs = 'divHiRes'; Final(); reload = false; } catch (e) { } } //טוען מחדש
                //                else { sZones += ',67'; sIDs += ',divHiRes'; }
              Info.Add(100067, 'divHiRes'); //  Info.Final()
            }
            ;

            div.style.visibility = "visible";

        }
    }
}
function CheckHiRes_2() {
    div = document.getElementById("divHiRes_2");
    if (div) {
       // HebsZones = '77'; sIDs += ',divHiRes_2';
        Info.Add(100118,'divHiRes_2');
    }
}

function CheckHiRes_ForAsor() {
    div = document.getElementById("adForAsor");
    if (div) {
       // HebsZones = '77'; sIDs += ',divHiRes_2';
        Info.Add(100118, 'adForAsor');
    }
}
