var browser = '';
jQuery.each(jQuery.browser, function(i, val) {
    if (val) browser = i;
});

function encode_utf(strSource) {
    var ss = '';
    for (i = 0; i < strSource.length; i++) {
        var ii = strSource.charCodeAt(i);
        if ((ii >= 1488)) {
            if (ii != 8211) {
                decCode = 144 + (ii - 1488);
                ss += '%D7' + '%' + (decCode.toString(16).toUpperCase());
            }
        }
        else {
            ss += escape(strSource.charAt(i));
        }
    }
    return ss.toString();
}

function openWindow(url) {
    window.open(url, '_blank');
}

function changeLocation(url) {
	if (url != '')
        window.location.href = url;
}

function init_EngineTabs() {
    $(".t_c .tab_phonebook").click(function() { openWindow('http://www.phonebook.co.il'); });
    $(".t_c .tab_zap").click(function() { openWindow('http://www.zap.co.il'); });
    $(".t_c .tab_madas").click(function() { openWindow('http://www.madas.co.il'); });
    $(".t_c .tab_more").click(function() { $('.tab_more_open').slideToggle(); });
}

function init_footer() {
    $(".footer .inkod").click(function() { openWindow('http://www.inkod-hypera.com') });
    $(".footer .hexoo").click(function() { openWindow('http://www.hexoo.com') });
    $(".footer .Approximatch").click(function() { openWindow('http://www.Approximatch.com') });
    $(".footer .Agent").click(function() { openWindow('http://www.agent.co.il') });
    $(".footer .twitter").click(function() { openWindow('http://twitter.com/DapeyZahav') });
    $(".footer .fLFacebook").click(function() { openWindow('http://www.facebook.com/d.co.il') });
    $(".footer span[title='אודות']").click(function() { openWindow('/aboutus.html') });
    $(".footer span[title='צור קשר']").click(function() { openWindow('/contact_us.html') });
    $(".footer span[title='בלוג חברת דפי זהב']").click(function() { openWindow('http://www.d-blog.co.il/') });
    $(".footer span[title='דרושים']").click(function() { openWindow('/about_wanted.html') });
    $(".footer span[title='תנאי שימוש']").click(function() { openWindow('/about_rules.html') });
    $(".footer span[title='מתחדשים בחלוקה']").click(function() { openWindow('http://www.d-blog.co.il/?p=351') });
    $(".footer span[title='המדריך החדש']").click(function() { openWindow('http://www.activepoint.com/dapei_zahav_2010/enter.html') });
    $(".footer .l2").each(function() { $(this).mouseenter(function() { $(this).addClass("hover"); }).mouseleave(function() { $(this).removeClass("hover"); }) });
    $(".fLinks span").each(function() { $(this).mouseenter(function() { $(this).addClass("hover"); }).mouseleave(function() { $(this).removeClass("hover"); }) });
}

function init_groupLinks() {
    $(".zap_link").click(function() { openWindow('http://www.zap.co.il') });
    $(".rest_link").click(function() { openWindow('http://www.rest.co.il') });
    $(".DnB_link").click(function() { openWindow('http://www.dbisrael.co.il') });
    $(".madas_link").click(function() { openWindow('http://www.madas.co.il') });
    $(".websplanet_link").click(function() { openWindow('http://www.websplanet.com') });
    $(".weekend_link").click(function() { openWindow('http://www.weekend.co.il') });
    $(".mitchatnim_link").click(function() { openWindow('http://www.mitchatnim.co.il') });
    $(".doctors_link").click(function() { openWindow('http://www.doctors.co.il') });
    $(".begilenu_link").click(function() { openWindow('http://www.begilenu.co.il') });
    $(".ilimudim_link").click(function() { openWindow('http://www.ilimudim.co.il') });
    $(".dhome_link").click(function() { openWindow('http://www.d-home.co.il') });
    $(".phonebook_link").click(function() { openWindow('http://www.phonebook.co.il') });
    $(".dmedia_link").click(function() { openWindow('http://www.d-m.co.il') });
    $(".s1213_link").click(function() { openWindow('http://www.1213.co.il') });
    $(".mishpati_link").click(function() { openWindow('http://www.mishpati.co.il') });
    $(".ozeret_link").click(function() { openWindow('http://www.ozeret4u.co.il') });
    $(".kamash_link").click(function() { openWindow('http://www.kamash.co.il') });
    $(".adira_link").click(function() { openWindow('http://www.adira.co.il') });
    $(".wisebuy_link").click(function() { openWindow('http://www.wisebuy.co.il') });
    $(".meetingroom_link").click(function() { openWindow('http://www.meetingroom.co.il') });
    //more sites
    $(".tab_more_open .l").each(function() { $(this).mouseenter(function() { $(this).addClass("hover"); }).mouseleave(function() { $(this).removeClass("hover"); }) });
    //engine buttom links
    $(".engine_links_container .Facebook").click(function() { openWindow('http://www.facebook.com/d.co.il'); });
    $(".engine_links_container .Twitter").click(function() { openWindow('http://twitter.com/DapeyZahav'); });
}

function fbs_click() {
    var u = "http://www.d.co.il/" + vCustId + "/" + vHeadingCode;
    var t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;
}

function fbs_article_click() {
    var u = location.href;
    var t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;
}

function writeToLog(refValue, params) {
    var img = new Image();
    if (img) {
        img.src = (refValue != '') ? "/?ref=" + refValue + params : params;
    }
}

// Mega - START
function fSetMega() {
    if (!vMegaArray[randImage]) return;
    var vMegaHTML = '';
    if (vMegaArray[randImage].match(/\.swf$/i) != null) {
        vMegaHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="FlashTopPanel" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="683" height="60"><PARAM NAME=movie VALUE="' + vMegaArray[randImage] + '"><PARAM NAME=quality VALUE=high><PARAM NAME=menu VALUE=false><PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="' + vMegaArray[randImage] + '" quality=high bgcolor=#FFFFFF  WIDTH="683" height="60" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
    } else {
        vMegaHTML = '<img src="' + vMegaArray[randImage] + '" alt="' + vMegaArray[randImage + 2] + '"  border="0" />';
        if (vMegaArray[randImage + 1]) vMegaHTML = '<a href="' + vMegaArray[randImage + 1] + '" target="_blank">' + vMegaHTML + '</a>';
    }
    document.write(vMegaHTML);
}
// Mega - END



function setCookie(c_name,value,expiredays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = c_name+ "=" + escape(value) + ((expiredays == null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/";
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1; 
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(unescape(document.cookie.substring(c_start,c_end)));
        } 
    }
    return "";
}

function delCookie(c_name){
	document.cookie = c_name + "=; expires=-1; path=/" ;
}