// CAIVIS(LDS) 3/19/09

// NOTE: Any changes tp the 'Cookie Settings' section (right below) will need to be repeated
// in the process.php file in the saveFormData() function ( around line 52 ).
// Process.php is used to store the affiliateID. If the cookie exists - then it 
// uses it's value. If the cookie does not exist then it stores the default value.
// Because php can't use javascript variables - the default value is set in the 
// php file when the function is called - you'll need to change it there.

// Cookie Settings
var cookieName = "affiliateID";
var cookieExpiration = 2592000; // 30 Days
// var cookieDefaultValue = "WMI-905"; // this value is used in process.php (around line 52)

// Get current page by stripping the http:// and the domain.com as well as the preceding '/'
var currentPage = document.URL;
var currentPage = currentPage.replace( /http:\/\//, "" );
var currentPage = currentPage.replace( document.domain, "" );
var currentPage = currentPage.replace( /\//, "" );


var affiliateID = false;
	
switch( currentPage )
{
	
	// ############################################### Affiliates List
	
	// This is where you add your affiliates to the list
	// the case statement value is the landing page of the affiliate
	// the affiliateID variable contains .. you guessed it - the affiliate's ID
	// make sure to leave the affiliate's name in comments above the case statement
	
	// Yahoo ====================>
	case "advance-your-career-1":
	  var affiliateID = "WMI-976";
	  break;
	
	// Demo
	case "demo-landing-page": // page url after the domain.com has been stripped off (example: http://www.demo.com/demo-landing-page )
	  var affiliateID = "DEMO-ID"; // the affiliateID of the affiliate
	  break;
	
	// ###############################################

	default:
	  var affiliateID = false;
}

if ( affiliateID ) {
	setCookie(cookieName, affiliateID, cookieExpiration);
}



// FUNCTIONS
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1; 
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    } 
	  }
	return "";
}
