﻿var timer=null;
$(document).ready(function(){
    
    /*if(getCookie("visit") == "")
    {   
        //alert("visit == ''");
        setCookie();
        clearTimeout(timer);
	    setTimeout(function(){
	    tb_show("Undersökning","http://www.plan-survey.se/k/9S9cRgnd/?KeepThis=true&TB_iframe=true&height=550&width=700","");
		    }, 15000);
    }*/
    if(getCookie("survey") == "")
    {   
        //alert(getCookie("survey"));
        setCookie();
        clearTimeout(timer);
	    setTimeout(function(){
	    tb_show("Sensus","/test/Survey-test.aspx?height=300&width=350","");
		    }, 1000);
    }
});

function TimedPop() 
{
    
    var result = getCookie("visitt");
    //alert("result: " + result);
    //if(document.cookie.length > 0)
    if(!result)
    {
        //alert("cookie.length > 0");
        //var length = document.cookie.indexOf("visit4=true")
        //alert(length);
        //if( length < 0)
        //{
          //  alert("length < 0");
            setPopup();
        //}
    }
    //else
      //  setPopup();
        
}

function setPopup()
{ 
    setCookie();
    
    width = 320; // width of window in pixels
    height = 390; // height of window in pixels
    delay = 1; // time in seconds before popup opens
    timer = setTimeout("popup()", delay*1000);
}

function popup() 
{
    var page = "http://www.dn.se";
    var windowprops = "width=380,height=500,location=no,menubar=no,toolbar=no,scrollbars=no,resizable=no";
    newWindow = window.open(page,'PopupName',windowprops);
}

function setCookie()
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+ 1);
    document.cookie="survey=true;path=/";//;expires="+exdate.toUTCString();
   // alert("Efter setCookie: " + document.cookie);
}

function getCookie(Name) 
{
  var search = Name + "="
  var returnvalue = "";
  //alert("Cookien: " + document.cookie);
  if (document.cookie.length > 0) 
  {
    //alert("document.cookie.length: " + document.cookie.length);
    offset = document.cookie.indexOf(search)
    //alert("offset: " + offset);
    // if cookie exists
    if (offset != -1) 
    { 
        
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      //alert("end: " + end);
      // set index of end of cookie value
        if (end == -1) 
            end = document.cookie.length;
        returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
   //alert(returnvalue);
  return returnvalue;
}


