//var win_url1 = "http://www.dstudent.co.il/presents.asp";
var win_url2 = "http://www.dstudent.co.il/hot2_pu.asp";
var urlList = urls.split(",");
function setCookie(c_name,value,exMinutes)
{
    var exdate=new Date();
    exdate.setMinutes(exdate.getMinutes() + exMinutes);
    //exdate.setMinutes(exdate.getMinutes() + 200);
    //alert (urlList);
    //alert (exdate.toUTCString());
    var c_value=escape(value) + ((exMinutes==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
    {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        //alert (x + "," + y);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name)
        {
            return unescape(y);
        }
    }
    return "";
}

function topop() 
{
    if(urlList.length == 0)
        return 0;
        
    var popLast = getCookie("popLast");
    var is_popup_already = getCookie("pop2"); 
    
    if (is_popup_already == "") 
    {
        setCookie("pop2", "yes", 60 * 24);  //once a day
        random = getRandom(popLast);
        win_url = urlList[random];
        setCookie("popLast", random, (60 * 24 * 7));
 
        var d = new Date();
        popWin=window.open(win_url,'win_url'+d.getMilliseconds(),'toolbar=1,location=1,directories=1,menubar=1,scrollbars=1,resizable=1'); 
        if (popWin) 
        { 
            window.blur(); 
            window.focus(); 
        } 
    } 
} 
function getRandom(popLast)
{
    if(urlList.length == 1 || isNaN(popLast))
        return 0;
    
    ran = popLast + 1;
    if(ran > urlList.length - 1)
        ran = 0;
    //alert(popLast + ", " + ran); 
    /*max = 10;
    count = 1;
    while(Math.floor(Math.random()*(urlList.length)) && count < max)
        count ++;

    //while(((ran = parseInt(Math.random() * (urlList.length - 1))) == popLast) && count < max)
    //    count ++;
   
    if(ran > urlList.length - 1)
    {
        ran = 0;
        if(popLast == ran && ran+1 <= urlList.length - 1)
            ran++;
        
    }*/
    return parseInt(ran);
}

function addListener(element, event, listener) 
{ 
    if (element) 
    { 
        if(element.addEventListener) 
        { 
            element.addEventListener(event, listener, false); 
            return 0;
        } 
        else if (this.attachEvent) 
        { 
            element.attachEvent("on" + event, listener); return 0; 
        } 
    } 
    return -1; 
} 
function load() {	addListener(document.body,"click", function() { topop();  } ); } 
addListener(this,"load",function() { load(); });


