function novaprivate_takesurvey(surveyurl) {
    if(surveyurl)
      window.open(surveyurl, "surveyPopUp",
                       'toolbar=0,location=0,scrollbars=1,menubar=0,' +
                       'resizable=1,width=800,height=600');
    
    // alert(document.referrer);

    /* if(document.referrer.indexOf("http://10.100.199.20/") == 0) {
      // For some reason, this History is too short, so use
      // the referrer instead.
      window.location = document.referrer;

    } else if(window.history.length > 1) {
      // If the history is correct, this should return the user
      // to the page they meant to visit in the first place.
      // alert(window.history.length);
      history.back();

    } else {
      // Can't figure out where the user came from, so just follow
      // the hard-coded URL on the invite page.
      return true;
    } */

    return false;
}

// Pass -1 as the frequency to force opening survey.
function novaprivate_open_survey(inviteurl, cookiename, frequency) {
    var take = (frequency == -1);
    //alert("inviteurl " + inviteurl + "\n" +
    //	  "cookiename " + cookiename + "\n" +
    //	  "frequency " + frequency + "\n");
    //alert("take " + take);

    if(!take) {
      // Check to see if they've already taken the survey.
      var surveyflag = pbs_get_cookieval(cookiename);
      //alert("surveyflag " + surveyflag);
      if(surveyflag != "1") {
      
      	if ((surveyflag > 2) && (surveyflag <= (frequency + 1))) {
      		// count down to 2
      		pbs_set_cookieval(cookiename, (surveyflag - 1));
      	} else if (surveyflag == 2) {
      		// propose the survey
      		take = true;
      		pbs_set_cookieval(cookiename, 1);
      	} else {
      		// no cookie yet; start at frequency + 1
      		pbs_set_cookieval(cookiename, (frequency + 1));
      	}
      }
    }

    if(take)
      // window.location = inviteurl;
      novaprivate_takesurvey(inviteurl);
    return false;
}

function novaprivate_reset_survey(cookiename, frequency) {
	pbs_set_cookieval(cookiename, (frequency + 1));
	return false;
}

function novaprivate_popup_survey(cookiename, frequency) {
	// decrements cookie count but doesn't pop window
    var take = (frequency == -1);

    if(!take) {
      // Check to see if they've already taken the survey.
      var surveyflag = pbs_get_cookieval(cookiename);
      if(surveyflag != "1") {
      
      	if ((surveyflag > 2) && (surveyflag <= (frequency + 1))) {
      		// count down to 2
      		pbs_set_cookieval(cookiename, (surveyflag - 1));
      	} else if (surveyflag == 2) {
      		// do nothing; leave cookie count at 2
      	} else {
      		// no cookie yet; start at frequency + 1
      		pbs_set_cookieval(cookiename, (frequency + 1));
      	}
      }
    }

    return false;
}
