//get cookie

function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if(dc.length >0){
   begin = dc.indexOf(cname);
   if(begin != -1 ) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin,end));
      }
   } 
return null;
}   

function setCookie(name, value, expires){
document.cookie = name + "=" + escape(value) + "; path=/" + 
 ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}


function genRandom( maxval, devider){ 

        var generatornum=Math.random();//Number between 0 and 1
        var randomnum=Math.round(generatornum*maxval);//Converts to whole num 
       var ndevider = 9; 
        
        if ( (randomnum % ndevider) == 0){
            showwindow();
        } 
}  

function showwindow(){
if (getCookie(cookieName)== null){ 
launchRemote();
}
}


function launch(newURL, newName, newFeatures, orgName) {
var remote = open(newURL, newName, newFeatures);
if (remote.opener == null)
remote.opener = window;
remote.opener.name = "opener";
return remote;
}

function launchRemote() {
myRemote =launch("/survey/popup.html",
"myRemote",
"height=175,width=250,alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0,z-lock=0",
"myWindow");
}

function popup(){
popup =  window.open("","popup","toolbar=no,width=200,height=150,status=no,menubar=no,scrollbars=no,");
popup.location.href = 'popup.html';
if(popup.opener == null) popup.opener = window;
popup.opener.name = "opener";
}

function delCookie(name){
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}

// cookie expires after 30 days
var exp = new Date();
exp.setTime(exp.getTime() + (24 * 60 * 60 * 1000 * 30));
var cookieName = 'StarSurvey0307';
var theMessage = 'test';
