// JScript File

var mins,secs,TimerRunning,TimerID;
 TimerRunning=false;
 
 function hasCookie()
 {
    //alert("get cookie");
    var count = GetCookie('count');
    if (count == null) 
    {
        Init();
    }
 }
 
 function Init() //call the Init function when u need to start the timer
 {
    mins=1;
    secs=0;
    StopTimer();
    StartTimer();
 }
 
 function StopTimer()
 {
    if(TimerRunning)
       clearTimeout(TimerID);
    TimerRunning=false;
 }
 
 function StartTimer()
 {
    TimerRunning=true;
    window.status="Time Remaining "+Pad(mins)+":"+Pad(secs);
    TimerID=self.setTimeout("StartTimer()",1000);
 
    Check();
    
    if(mins==0 && secs==0)
       StopTimer();
    
    if(secs==0)
    {
       mins--;
       secs=60;
    }
    secs--;
 
 }
 
 function Check()
 {
    //if(mins==0 && secs==30)
       //alert("You have only 30 sec remaining");
       
    if(mins==0 && secs==0)
    {            
       show("UserModal.aspx");
       //show("Survey.aspx?url=http://survey.landolakes.com/LOLSurvey/Web/Take/TakeSurvey.aspx?id=825&menu=0&sg=136");

    }
 }
 
 function Pad(number) //pads the mins/secs with a 0 if its less than 10
 {
    if(number<10)
       number=0+""+number;
    return number;
 }



// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
var expDays = 1; // number of days the cookie should last
var page = "popup_window.html";
var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";

function GetCookie (name) 
{  
    var arg = name + "=";  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  
    while (i < clen) {    
    var j = i + alen;    
    if (document.cookie.substring(i, j) == arg)      
    return getCookieVal (j);    
    i = document.cookie.indexOf(" ", i) + 1;    
    if (i == 0) break;   
    }  
    return null;
}

function SetCookie (name, value) 
{  
    var argv = SetCookie.arguments;  
    var argc = SetCookie.arguments.length;  
    var expires = (argc > 2) ? argv[2] : null;  
    var path = (argc > 3) ? argv[3] : null;  
    var domain = (argc > 4) ? argv[4] : null;  
    var secure = (argc > 5) ? argv[5] : false;  
    document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) +  
    ((domain == null) ? "" : ("; domain=" + domain)) +    
    ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) 
{  
    var exp = new Date();  
    exp.setTime (exp.getTime() - 1);  
    var cval = GetCookie (name);  
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date(); 
//exp.setTime(exp.getTime() + (15*60*1000)); // 15 min
exp.setTime(exp.getTime() + (1*24*60*60*1000)); //1 day


var expNever = new Date(); 
expNever.setTime(expNever.getTime() + (10*365*24*60*60*1000)); // 10 years


function amt()
{
    var count = GetCookie('count')
    if(count == null) {
        SetCookie('count','1')
        return 1
    }
    else 
    {
        var newcount = parseInt(count) + 1;
        DeleteCookie('count')
        SetCookie('count',newcount,exp)
        return count
    }
}

function getCookieVal(offset) 
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() 
{
    var count = GetCookie('count');
    if (count == null) 
    {
        count=1;
        SetCookie('count', count, exp);
        window.open(page, "", windowprops);
    }
    else 
    {
        count++;
        SetCookie('count', count, exp);
    }
}

function setPermanentCookie() 
{  
    
    var count = 1;    
    SetCookie('count', count, expNever);
    //alert("cookie will expire: " + expNever);
    
    CloseLightBox();
}

function set24HrCookie() 
{  
       
    var count = GetCookie('count');
    if (count == null) 
    {
        count=1;             
        SetCookie('count', count, exp);
        //alert("cookie will expire: " + exp);
    }
    else
    {
        //alert("you arleady set a cookie");
    }

     CloseLightBox();

}

function CloseLightBox()
     {
        Element.remove($('lbContent'));
        $('overlay').style.display = "none";
     }
     
function TakeNow()
{
    CloseLightBox();
    show("Survey.aspx?url=http://survey.landolakes.com/LOLSurvey/Web/Take/TakeSurvey.aspx?id=825&menu=0&sg=136");
    //show("UserModal.aspx");
}
