﻿var fcolor = "WHITE";
var backcolor = "BLACK";
var textcolor = "BLACK";
var fwidth = "200";
var border = "1";
var offsetx = -10;
var offsety = 10;
var bunnerX = 2;

var x = 0;
var y = 0;
var dir = 1;
var isDisplayed = false;
document.onmousemove = mouseMove

function getColorCookieTop() {
    name = "ColorCookie";
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length)))
        return null;
    if (start == -1)
        return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1)
        end = document.cookie.length;
    Change_Header_color_top(unescape(document.cookie.substring(len, end)))
}

function getColorCookie() {
    name = "ColorCookie";
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length)))
        return null;
    if (start == -1)
        return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1)
        end = document.cookie.length;
    Change_Header_color_new(unescape(document.cookie.substring(len, end)))
}

function getTheColorCookie() {
    name = "ColorCookie";
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length)))
        return null;
    if (start == -1)
        return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1)
        end = document.cookie.length;
}

function addColorCookie(color) {
    value = color;
    var date = new Date();
    date.setTime(date.getTime() + (5 * 365 * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
    document.cookie = "ColorCookie=" + value + expires + "; path=/";
}

function Change_Header_color_top(color) {
    document.getElementById("Div_1").className = "SectionTitle " + color + "Title";
    document.getElementById("Div_6").className = "SectionTitle " + color + "Title";
    document.getElementById("Div_11").className = "SectionTitle " + color + "Title";
    document.getElementById("Div_21").className = "SectionTitle " + color + "Title";
    for (i = 1; i < 11; i++) {
        try {
            document.getElementById("tabhead_" + i).className = "MenuTitle " + color + "Title";
        } catch (ex) { }
    }
}

function Change_Header_color_new(color) {
    if (color == "")
        color = "Blue"
    /*for (i=1; i<20; i++)
    {
    try
    {
    document.getElementById("Div_"+i).className = "SectionTitle " +color+"Title";
    }catch(ex){}
    }*/
    for (i = 1; i < 37; i++) {
        try {
            document.getElementById("Div_" + i).className = "SectionTitle " + color + "Title";
        } catch (ex) { }
    }

    for (i = 1; i < 4; i++) {
        try {
            document.getElementById("td_bottom" + i).className = color + "Title";
        } catch (ex) { }
    }
    for (i = 1; i < 12; i++) {
        try {
            document.getElementById("tabhead_" + i).className = "MenuTitle " + color + "Title";
            if (color == "LiteBlue")
                document.getElementById("linkhead_" + i).className = "activePageBlack13";
            else
                document.getElementById("linkhead_" + i).className = "activePageWhite13";
        } catch (ex) { }
    }

    for (i = 11; i < 34; i++) {
        try {
            document.getElementById("tabhead_" + i).className = "MenuTitle " + color + "Title";
            if (color == "LiteBlue")
                document.getElementById("linkhead_" + i).className = "activePageBlack13";
            else
                document.getElementById("linkhead_" + i).className = "activePageWhite13";
        } catch (ex) { }
    }

    for (i = 101; i < 108; i++) {
        try {
            document.getElementById("div_" + i).className = "PageTitle " + color + "Title15";
        } catch (ex) { }
    }

    if (color == "LiteBlue") {
        try { document.getElementById("link_k1").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_k2").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_k3").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_k5").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_k12").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_21").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_26").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_33").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_bottom1").className = "activePageBlack12" } catch (ex) { }
        try { document.getElementById("link_bottom2").className = "activePageBlack12" } catch (ex) { }
        try { document.getElementById("link_bottom3").className = "activePageBlack12" } catch (ex) { }
        try { document.getElementById("link_15").className = "activePageBlack13" } catch (ex) { }
        try { document.getElementById("link_106").className = "activePageBlack15" } catch (ex) { }
    }
    else {
        try { document.getElementById("link_k1").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_k2").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_k3").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_k5").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_k12").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_21").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_26").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_33").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_15").className = "activePageWhite13" } catch (ex) { }
        try { document.getElementById("link_bottom1").className = "activePageWhite12" } catch (ex) { }
        try { document.getElementById("link_bottom2").className = "activePageWhite12" } catch (ex) { }
        try { document.getElementById("link_bottom3").className = "activePageWhite12" } catch (ex) { }
        try { document.getElementById("link_106").className = "activePageWhite15" } catch (ex) { }
    }
    addColorCookie(color);
}

function Change_Header_color(color) {
    try {
        for (i = 1; i < 10; i++) {
            document.getElementById("Right" + i).className = "tabRight" + color
            document.getElementById("Center" + i).className = "tabCenter2" + color + " " + color + "TextB";
            document.getElementById("Left" + i).className = "tableft" + color
        }

        for (i = 31; i < 32; i++) {
            document.getElementById("Right" + i).className = "tabRight" + color
            document.getElementById("Center" + i).className = "tabCenter2" + color + " " + color + "TextB";
            document.getElementById("Left" + i).className = "tableft" + color
        }


        for (i = 11; i < 16; i++) {
            try {
                document.getElementById("Right" + i).className = "tabRight" + color
                document.getElementById("Center" + i).className = "tabCenter" + color + " " + color + "TextB";
                document.getElementById("Left" + i).className = "tableft" + color
            } catch (ex) { }
        }
        for (i = 21; i < 23; i++) {
            document.getElementById("Right" + i).className = "tabRight" + color
            document.getElementById("Center" + i).className = "tabCenter3" + color + " " + color + "TextB";
            document.getElementById("Left" + i).className = "tableft" + color
        }
        addColorCookie(color);
    }
    catch (ex) { }
}

function Change_Search_Tab(iIndex) {
    document.getElementById("tab_1").className = "not_selected"
    document.getElementById("tab_2").className = "not_selected"
    document.getElementById("tab_3").className = "not_selected"
    document.getElementById("tab_4").className = "not_selected"
    document.getElementById("tab_5").className = "not_selected"

    document.getElementById("link_1").className = "ncTxt"
    document.getElementById("link_2").className = "ncTxt"
    document.getElementById("link_3").className = "ncTxt"
    document.getElementById("link_4").className = "ncTxt"
    document.getElementById("link_5").className = "ncTxt"

    document.getElementById("tab_" + iIndex).className = "selected"
    document.getElementById("link_" + iIndex).className = "arialblack12"

    switch (iIndex) {
        case 1:
            document.getElementById("searchLink").value = "http://www.google.com/search?q=";// "http://www.google.co.il/cse"; //"http://www.google.com/custom"
            break
        case 2:
            document.getElementById("searchLink").value = "http://www.bing.com/search?q=";
            break
        case 3:
            document.getElementById("searchLink").value = "http://search.walla.co.il/?e=utf&t=0&q=";
            break
        case 4:
            document.getElementById("searchLink").value = "http://he.wikipedia.org/w/index.php?search=";
            break
        case 5:
            document.getElementById("searchLink").value = "http://www.netex.co.il/?searchPhrase=";
            break
    }
}

function handleKP() { if (event.keyCode == 13) goSearch(); }

function goSearch() {
    searchLink = document.getElementById("searchLink").value;
//    if (searchLink == "http://www.google.co.il/cse")
//        document.form1.submit();
//    else {
        searchValue = document.getElementById("sbi").value;
        window.open(searchLink + searchValue);
//    }
}

function Initialize() {
    try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
        try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (oc) { req = null; }
    }
    if (!req && typeof XMLHttpRequest != "undefined") {
        req = new XMLHttpRequest();
    }
}

function InitializeChart() {
    try { reqChart = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
        try { reqChart = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (oc) { reqChart = null; }
    }
    if (!reqChart && typeof XMLHttpRequest != "undefined") {
        reqChart = new XMLHttpRequest();
    }
}

function SendQuery() {
    Initialize();
    var url = "BuildFinanceXml.aspx";
    //alert(url)
    if (req != null) {
        //req.onreadystatechange = Process;
        req.open("GET", url, true);
        req.send(null);
    }
}

function Process() {
    if (req.readyState == 4) {
        if (req.status == 200)

            alert("ok");
        else
            alert("no");
    }
}

function GetCharts() {
    InitializeChart();
    var url = "SaveChart.aspx";

    if (reqChart != null) {
        reqChart.open("GET", url, true);
        reqChart.send(null);
    }
}

function getBanner() {
    //document.getElementById("td_banner").height = "95";
    //document.getElementById("td_banner").innerHTML = '<iframe id="1" marginWidth="0" hspace="0" vspace="0" marginHeight="0" src="http://www.nrg.co.il/cache/banners/ban_m.php?vnum=111&vpage=658&loc=2"	frameBorder="0" width="770" scrolling="no" height="90"></iframe>'
    var date = new Date();
    if (date.getSeconds() % 3 == 0)
        document.getElementById("td_banner").innerHTML = '<iframe id="1" marginWidth="0" hspace="0" vspace="0" marginHeight="0" src="http://service.bizportal.co.il/web/webnew/bizbannerreklamanotsecure.shtml?pos=3007&bpos=1&refresh=150&url=/homepage.shtml"	frameBorder="0" width="730" scrolling="no" height="90" style="background-color:#eae9e4;"></iframe>'
    else
        document.getElementById("td_banner").innerHTML = "<a href='scripts/adv.aspx?sid=16207' target='_blank'><img src='images/ad_800x90_anim.gif' alt='boogito.com' border='0'></a>";
    //document.getElementById("td_banner").innerHTML = '<a href="scripts/adv.aspx?sid=16206" target="_blank" title="כנס סמכות הורית"><img src="images/kenes1.png" alt="כנס סמכות הורית" border="0" /></a>';
    //setTimeout("changeBanner()", 5000);
}

function changeBanner() {
    document.getElementById("td_banner").innerHTML = '<a href="images/kenes.pdf" target="_blank" title="כנס סמכות הורית"><img src="images/kenes' + bunnerX + '.png" alt="כנס סמכות הורית" border="0" /></a>';
    var delay = 5000;
    if (bunnerX == 1) {
        bunnerX = 2;
    }
    else {
        bunnerX = 1;
        delay = 300
    }
    setTimeout("changeBanner()", delay);
}

function get_radio_station() {
    var url = window.location.href;
    var x = url.indexOf('radio')
    var radio = url.substr(x + 6)
    mPlay.fileName = stations[parseInt(radio) - 1][0];
    document.getElementById("td_station").innerHTML = "עכשיו מנגן : " + stations[parseInt(radio) - 1][1] + "&nbsp;&nbsp;&nbsp;"
}

function right(e) {
    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
        return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
        alert("You are listening to SEEIT Radio");
        return false;
    }
    return true;
}

function launch(url) {
    remote = open(url, "Station", "width=250,height=120");
}

function mPlay_play() {
    mPlay.Play();
    document.getElementById("img_play").src = "images/radio-play-on.gif"
    document.getElementById("img_stop").src = "images/radio-stop-off.gif"
}

function mPlay_stop() {
    mPlay.Stop();
    document.getElementById("img_play").src = "images/radio-play-off.gif"
    document.getElementById("img_stop").src = "images/radio-stop-on.gif"
}

function AddVolume() {
    if (mPlay.volume <= -500) {
        mPlay.volume += 500;
    }
}

function SubVolume() {
    if (mPlay.volume >= -4500) {
        mPlay.volume -= 500;
    }
}

function MuteVolume() {
    last_volume = mPlay.volume
    mPlay.volume = -5000;
    document.getElementById("td_mute").innerHTML = "<img src='images/mute-on.gif' alt='השמע' border='0' onclick='MuteVolumeOff()'>"
}

function MuteVolumeOff() {
    mPlay.volume = last_volume;
    document.getElementById("td_mute").innerHTML = "<img src='images/mute-off.gif' alt='השתק' border='0' onclick='MuteVolume()'>"
}

function launch2(page) {
    alert(page)
    var sPage = page
    if (sPage == "" || sPage == undefined) {
        try {
            sPage = document.getElementById("station").value
        }
        catch (ex) {
            sPage = "1"
        }
    }
    OpenWin = this.open('Radio.aspx?radio=' + sPage, "Station", "width=250,height=120,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,status=no");
}

function openPictureWin(id) {
    var width = 900
    var height = 900
    window.open("PictureOfTheDay.aspx?aid="+id, "pic", "toolbar=no,width=" + width + ",height=" + height + ",status=no,scrollbars=yes,resizable=no left=" + (screen.width - width) / 2 + ",top=5");
}

function openTermWin() {
    window.open("terms.aspx", "terms", "toolbar=no,width=500,height=600,status=no,resizable=no left=" + (screen.width - 500) / 2 + ",top=5");
}

function playRadio(station) {
    if (station == 0) {
        // Get RadioStationCookie
        var name = "RadioStationCookie";
        var start = document.cookie.indexOf(name + "=");
        var len = start + name.length + 1;
        var end = document.cookie.indexOf(";", len);
        if (end == -1)
            end = document.cookie.length;
        station = (document.cookie.substring(len, end));
        if (station == 0)
            station = 1
    }

    // add RadioStationCookie
    var value = station
    var date = new Date();
    date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
    document.cookie = "RadioStationCookie=" + value + expires + "; path=/";

    // play the radio
    OpenWin = this.open('Radio.aspx?radio=' + station, "Station", "width=250,height=120,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,status=no");

    //launch2(station) 
}

function getRadioCookie(autoPlay) {
    var name = "RadioCookie";
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;

    if (((!start) && (name != document.cookie.substring(0, name.length))) || start == -1) {
        // add RadioCookie
        var value = 1
        var date = new Date();
        date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
        document.cookie = "RadioCookie=" + value + expires + "; path=/";
        playRadio(1);
    }

    //if (start == -1)
    //	playRadio(1);

    var end = document.cookie.indexOf(";", len);
    if (end == -1)
        end = document.cookie.length;
    if (!autoPlay)
        playRadio(document.cookie.substring(len, end));
}

function slc(text) {
    var windowWidth = window.innerWidth ? window.innerWidth : document.body.clientWidth
    if (windowWidth - x < 100)
        dir = 0;
    else if (windowWidth - x < 200)
        dir = 2;
    else
        dir = 1;
    display(text);
}
// Clears popups if appropriate
function nd() {
    over.visibility = "hidden";
    isDisplayed = false;
}
function display(text) {
    if (text == "")
        return;
    txt = "<table class='SmallFont' width='" + fwidth + " border='0' cellpadding='" + border + "' cellspacing='0' BGCOLOR=\"" + backcolor + "\">" +"<tr><td>" +"<table class=arialblack12 WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\"" + fcolor + "\" dir=rtl>" +"<tr><td align=right>" +"<FONT COLOR=\"" + textcolor + "\">" + text + "</FONT>" +"</td></tr>" +"</table>" +"</td></tr>" +"</table>"
    document.all["overDiv"].innerHTML = txt;
    if (dir == 2) { // Center
        moveTo(over, x + offsetx - (fwidth / 2), y + offsety);
    }
    if (dir == 1) { // Right
        moveTo(over, x + offsetx, y + offsety);
    }
    if (dir == 0) { // Left
        moveTo(over, x - offsetx - fwidth, y + offsety);
    }
    over.visibility = "visible";
    isDisplayed = true;
}
// Move a layer
function moveTo(obj, xL, yL) {
    obj.left = xL;
    obj.top = yL;
}
// Moves the layer
function mouseMove() {
    try {
        x = window.event.clientX + document.body.scrollLeft;
        y = window.event.clientY + document.body.scrollTop;
    }
    catch(e) {}
}
function setHeight() {
    try 
    {
        if (document.getElementById && !(document.all)) {
            h = document.getElementById("addResponseIF").contentdocument.body.scrollHeight;
            document.getElementById("addResponseIF").height = h - 6;
        }
        else if (document.all) {
            h = document.frames("addResponseIF").document.body.scrollHeight;
            document.all.addResponseIF.height = h + 9;
        }
    }
    catch (e) {}
}
function setHeightAdv() {
    try 
    {          
        if (document.getElementById && !(document.all)) {
            h = document.getElementById("AdvertisementIF").contentdocument.body.scrollHeight;
            document.getElementById("AdvertisementIF").height = h - 6;
        }
        else if (document.all) {
            h = document.frames("AdvertisementIF").document.body.scrollHeight;
            document.all.AdvertisementIF.height = h;
        }
    }
    catch (e) {}
}

function IndicesData() {
    var sData = "";
    for (var i = 0; i <= indices.length - 1; i++) {
        var sName = indices[i][3] + ""
        if (sName == "ta25" || sName == "ta100" || sName == "ta75" || sName == "tltk15" || sName == "ytr30") {

            var sColorStyle = "GreenText11B";
            var sPChange = indices[i][1] + ""
            var sLast = indices[i][2] + ""

            switch (sName) {
                case "ta25":
                    sName = "ת\"א 25"
                    break;
                case "ta75":
                    sName = "ת\"א 75"
                    break;
                case "ta100":
                    sName = "ת\"א 100"
                    break;
                case "tltk15":
                    sName = "תלטק 15"
                    break;
                case "ytr30":
                    sName = "יתר 50"
                    break;
            }

            if (sPChange != "null") {
                if (indices[i][0] == "-")
                    sColorStyle = "OrangeText11B";
                sPChange += "%"
            }
            else
                sPChange = "";

            if (sLast == "null") sLast = "";

            sData += '<tr><td colspan="3""><img height="3" src="images/pxl.gif" alt="" /></td></tr>' +
                '<tr>' +
                '	<td style="padding-right:4px;" class="arialblack11B">' + sName + '</td>' +
                '	<td width="60" class="arialblack11">' + sLast + '</td>' +
                '	<td width="50" align="right" dir="ltr" class="' + sColorStyle + '">' + sPChange + '</td>' +
                '</tr>';
        }
    }
    document.write(sData)
}

function BoltotData() {
    var sData = "";
    for (var i = 0; i <= 2; i++) 
    {
        sData += '<table width="100%" bgcolor="#ffffff" cellpadding="0" cellspacing="0" border="0" style="BORDER-RIGHT:#dadada 1px solid; BORDER-TOP:#dadada 0px solid; BORDER-LEFT:#dadada 1px solid; BORDER-BOTTOM:#dadada 1px solid" id="table_boltot_' + i + '">'
        for (var j = 0; j <= boltot_ta[i].length-1; j++)
        {
            var sName = boltot_ta[i][j][5] + ""
            var sColorStyle = "GreenText11B";
            var sPChange = boltot_ta[i][j][2] + ""
            sPChange = formatFloat(sPChange, 2)
            var sLast = boltot_ta[i][j][3] + ""
            sLast = formatFloat(sLast, 2)
            if (sPChange != "null") {
                if (boltot_ta[i][j][1] == "-")
                    sColorStyle = "OrangeText11B";
                sPChange += "%"
            }
            else
                sPChange = "";

            if (sLast == "null") sLast = "";
            sData +=    '<tr>' +
                '	<td style="padding-right:4px;padding-top:3px;" class="arialblack11B">' + sName + '</td>' +
                '	<td width="65" class="arialblack11">' + sLast + '</td>' +
                '	<td width="45" align="right" dir="ltr" class="' + sColorStyle + '">' + sPChange + '</td>' +
                '</tr>';
        }
        sData += '</table>'
    }
    document.write(sData)
    document.getElementById("table_boltot_1").style.display = "none";
    document.getElementById("table_boltot_2").style.display = "none";
}
function changeBoltotTab(tab) {
    for (var i = 0; i < 3; i++) {
        if (i != tab) {
            document.getElementById("table_boltot_" + i).style.display = "none";
            document.getElementById("boltotLink_" + i).className = "activePage11U";
        }
    }
    document.getElementById("table_boltot_" + tab).style.display = "block";
    document.getElementById("boltotLink_" + tab).className = "activePage11U_on";
}

function formatFloat(aFloat, aPrecision) {
    var thousand_sep = ",";
    var decimal_point = ".";

    try {
        number = parseFloat(aFloat + '');
        if (isNaN(number))
            return "NaN";
    }
    catch (e) {
        return "NaN";
    }
    number = Math.round(number * Math.pow(10, aPrecision)) / Math.pow(10, aPrecision);
    integerpart = '' + ((number < 0) ? Math.ceil(number) :
    Math.floor(number));
    decimalpart = Math.abs(Math.round((number - integerpart) * (Math.pow(10, aPrecision))));
    if (decimalpart < 10)
        decimalpart = "0" + decimalpart;
    if (decimalpart == 0)
        decimalpart = "00";
    var buff = "";
    for (j = -1, i = integerpart.length; i >= 0; i--, j++) {
        if ((j % 3) == 0 && j > 1)
            buff = thousand_sep + buff;
        buff = integerpart.charAt(i) + buff;
    }
    if (aPrecision > 0)
        return buff + decimal_point + decimalpart;
    return buff;
}

