//- Global variables. -//
var cookie_domain = 'sikhnet.com';

// number of days cookie lives for
function setCookie (name, value, expires, path, domain, secure, noEscape) {
	if (!domain) domain = cookie_domain;
	
    var cString = name + "=" + ((noEscape) ? value : escape(value) ) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "; path=/") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = cString;
}

function ged(noDays){
    var today = new Date();
    var expr = new Date(today.getTime() + noDays*24*60*60*1000);
    return  expr.toGMTString();
}

function CheckRedirect(cookieName, redirectURL){
  var start = document.cookie.indexOf(cookieName + '=');

  // If cookie is not found set cookie and redirect the user
  if (start == -1){
    setCookie(cookieName, "No", ged(num_days));
    window.location.replace( redirectURL );
  } 
}


//- *** Actions that are performed as soon as this script is done loading (and before the page itself loads). *** -//

//- Perform a redirect by checking cookies against the current page section. -//
if ( sectionName && sectionName.length > 0 && fundraiserURL && fundraiserURL.length > 0 ) {
	//- Append the current page to the fundraiser URL. -//
	fundraiserURL += window.location.href;
	
	CheckRedirect( sectionName, fundraiserURL );
}

