function register_info(){
	//var newwin=window.open("/User/register_info.htm","REGINFOWIN","height=500,width=500,resizable=yes,scrollbars=yes,status=yes");
    register();
}
function return_visitor(){
	// if session cookie here then return true
	if (getScreenNameCookie()==null) { return false; }
	else { return true; }
}

function killScreenNameCookie(){
	var cname='MJLSnameCookie';
	if (arguments.length>0) { cname = arguments[0] ; }
	//alert('killScreenNameCookie calling deleteCookie, passing cookie name: ' + cname );
	deleteCookie(cname);

}
function killPitCookie(){
	var cname='pitCookie';
	if (arguments.length>0) { cname = arguments[0] ; }
	//alert('killScreenNameCookie calling deleteCookie, passing cookie name: ' + cname );
	deleteCookie(cname);

}
function zapScreenNameCookie(){
	var cname='MJLSnameCookie';
	if (arguments.length>0) { cname = arguments[0] ; }
	//alert('zapScreenNameCookie zapping the ScreenNameCookie');
	// create an instance of the Date object
	var now = new Date();
	// cookie expires in one second
	// 1000 milliseconds in a second
	now.setTime(now.getTime() + 1000);
	setCookie("MJLSnameCookie", "Guest", now);
}
function setScreenNameCookie(sname) {
	// create an instance of the Date object
	var now = new Date();
	// cookie expires in one month (actually, 30 days)
	// 30 days in a month
	// 24 hours in a day
	// 60 minutes in an hour
	// 60 seconds in a minute
	// 1000 milliseconds in a second
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	// get the current value if any
	var currentValue=getCookie("MJLSnameCookie");
	// set up default value...
	var currentLastAccess = "Unavailable";
	if (currentValue == null){
		// was last access passed by caller? (Changed by AZ on aug 21, 2003)
		if (arguments.length>0 && arguments[0]!=null) { currentLastAccess = arguments[0]; }
		// set the new cookie without a last access date
		setCookie("MJLSnameCookie", quote2bar(sname) + "|" + currentLastAccess, now, '/');
	}
	else {
		currentLastAccess = currentValue.substring(1+currentValue.indexOf("|"));
		var cookieValue = quote2bar(sname) + "|" + currentLastAccess ;
		setCookie("MJLSnameCookie", cookieValue, now, '/');
	}
}
function setPitCookie(pit_url, pit_title) {
	// create an instance of the Date object
	var now = new Date();
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
    var cookieValue = pit_url + "|" + pit_title ;
	setCookie("pitCookie", cookieValue, now);
}

function getPitCookie() {
	// get the last visit value or return null
	var cookieValue=getCookie("pitCookie");
	if (cookieValue == null || cookieValue.indexOf("|")==-1) { return null; }
	else
	{
	    if ( cookieValue.substring(0,cookieValue.indexOf("|")) == null) { return null; }
        if ( cookieValue.substring(0,cookieValue.indexOf("|")) == 'null') { return null; }
        var strPIT = '<a target="_blank" class="resources" href="';
        strPIT += cookieValue.substring(0,cookieValue.indexOf("|")) + '">';
        strPIT += cookieValue.substring(1+cookieValue.indexOf("|")) + '</a>';
        return strPIT;
	}
}

//killPitCookie();
//setPitCookie("http://baltimore.planitjewish.com","PlanitJewish Baltimore");
//alert(getPitCookie());

function setLastVisitCookie(lastvisit) {
	// create an instance of the Date object
	var now = new Date();
	// cookie expires in one month (actually, 30 days)
	// 30 days in a month
	// 24 hours in a day
	// 60 minutes in an hour
	// 60 seconds in a minute
	// 1000 milliseconds in a second
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	// get the current value if any
	var currentValue=getCookie("mjlsname");
	if (currentValue == null){
		// set the new cookie without a last access date
		setCookie("MJLSnameCookie", "Visitor" + "|" + lastvisit, now);
	}
	else {
		var currentSname = currentValue.substring(0,currentValue.indexOf("|"));
		var cookieValue = currentSname + "|" + lastvisit ;
		setCookie("MJLSnameCookie", cookieValue, now);
	}
}

function getScreenNameCookie() {
	// get the screen name from the
	// mjl cookie value or return null
	var cookieValue=getCookie("MJLSnameCookie");

	// 2 new lines of code MAF 06/07 as firefox e.g. inserts + instead of space
    if (cookieValue != null)
    if (cookieValue.indexOf("+") > -1 ) {
	cookieValue=(cookieValue.replace(/\+/g, " "));
    cookieValue=(cookieValue.replace(/%7C/g, "|"));
    setScreenNameCookie(cookieValue.substring(0,cookieValue.indexOf("|")));
    }

	if (cookieValue == null || cookieValue.indexOf("|")==-1) { return null; }
	else { return cookieValue.substring(0,cookieValue.indexOf("|")); }
}
function getLastVisitCookie() {
	// get the last visit value or return null
	var cookieValue=getCookie("MJLSnameCookie");
	if (cookieValue == null || cookieValue.indexOf("|")==-1) { return null; }
	else { return cookieValue.substring(1+cookieValue.indexOf("|")); }
}

function getRefererCookie() {
	// get the last visit value or return null
	var cookieValue=getCookie("SS");
	if (cookieValue == null || cookieValue.indexOf("=")==-1) { return null; }
	else { return cookieValue.substring(1+cookieValue.indexOf("=")); }
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
      //((path) ? "; path=" + path : "") +

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "/") +
	// ((path) ? "; path=" : "; path=") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function submitJumpForm(fObj,url, method){
/* 	used to trigger login or sign up when we need to, without losing original page context
	we assume that the following line is found in any file that will call us
<div><form name="JumpForm"><input type="hidden" name="PDATA"><input type="hidden" name="PURL"><input type="hidden" name="PMETHOD"></form></div>
*/
	// invoke page to handle login/register or whatever and then jump to fObj ACTION
	document.JumpForm.action=url; // usually logincheck.jsp
	document.JumpForm.method=method; // usually POST
	document.JumpForm.PDATA.value=packFields(fObj); //this routine is in stdinclude.js
	//alert('document.JumpForm.PDATA.value=' + document.JumpForm.PDATA.value);
	document.JumpForm.PURL.value=fObj.action;
	document.JumpForm.PMETHOD.value=fObj.method.toUpperCase();
	document.JumpForm.submit();
}
function userlogout(){
	// open new window for userlogout.jsp
	var winprops="height=500,width=650,directories=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,status=no,location=no";
	var newloc = getPathToJSP() + '/User/UserLogout2.jsp';
	//alert('userlogout: newloc=' + newloc);
	win = window.open(newloc, "LOGINOUTWIN", winprops);
}
function survey() {
	var cUrl;
	today=new Date();
	jran=today.getTime();
	var number = 4;
	var random_number="";
	var surveynum = new Array(4);
	surveynum[0] = '339';
	surveynum[1] = '294';
	surveynum[2] = '340';
	surveynum[3] = '330';
	surveynum[4] = '339';
	ia=9301;
	ic=49297;
	im=233280;
	jran = (jran*ia+ic) % im;
	random_number = Math.ceil( (jran/(im*1.0)) *number);

	cUrl = 'http://survey.qstation.com/cgi-shl/public/cgiip.exe/WService=Panel/qform/public/MJL/' +
		surveynum[random_number] +
		'-1/form.p?FM=QS' ;
        var xWin = window.open(cUrl,"Survey","resizable,scrollbars,width=600,height=600,screenX=0,screenY=0");
}
function contactus(){
	// for backwards compatibility support existing function
	if (arguments.length==0) { contact(); }
	else {
		locStr = pathToRoot + '/' + arguments[0] ;
		var winprops="height=600,width=500,directories=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,status=no,location=no";
		//win = window.open(locStr,"CONTACTWIN",winprops);
        window.location = locStr;
	}
}
function contact(){
    //var locStr = pathToRoot + '/User/contact_us.html';
    var locStr = 'http://survey.qstation.com/cgi-shl/public/cgiip.exe/WService=Panel/qform/public/MJL/426-1/form.p?FM=QS';
    var winprops="height=500,width=500,directories=no,resizable=yes,scrollbars=auto,toolbar=no,menubar=no,status=no,location=no";
    //win = window.open(locStr,"CONTACTWIN",winprops);
    window.location = locStr;
}
function shmaoffer(){
	var locStr = 'http://survey.qstation.com/cgi-shl/public/cgiip.exe/WService=Panel/qform/public/MJL/426-1/form.p?FM=QS';
	// var locStr = pathToRoot + '/User/shmaoffer.html';
	var winprops="height=600,width=500,directories=no,resizable=yes,scrollbars=auto,toolbar=no,menubar=no,status=no,location=no";
	win = window.open(locStr,"CONTACTWIN",winprops);
}
function referalt(){
	var locStr = pathToRoot + '/User/referalt.html';
	// var locStr = pathToRoot + '/User/shmaoffer.html';
	locStr = 'http://survey.qstation.com/cgi-shl/public/cgiip.exe/WService=Panel/qform/public/MJL/355-1/form.p?FM=QS';
	var winprops="height=600,width=500,directories=no,resizable=yes,scrollbars=auto,toolbar=no,menubar=no,status=no,location=no";
	win = window.open(locStr,"CONTACTWIN",winprops);
}

function doOffers(){
    var source = getParamVal("SS");
    var offer = getParamVal("OO");
    var prize = getParamVal("PP");
    var r = getParamVal("RR");
    //alert('index.htm setting mjloffer cookie to: ' + "O="+offer+"|S="+source+"|P="+prize+"|R="+r);
    var cookieValue=getCookie("mjloffer");
    var exp = new Date();
    exp.setTime(exp.getTime() + (24*60*60*1000));
    if (source!=null && offer!=null && prize!=null && r!=null){
        if (cookieValue == null || cookieValue == "") {
        	//alert("about to set Cookie" + "OO="+offer+"|SS="+source+"|PP="+prize+"|RR="+r);
		setCookie("mjloffer","OO="+offer+"|SS="+source+"|PP="+prize+"|RR="+r, exp);
        }
    }
}
doOffers();
