//variable definitions
spSiteDomainDev = "devwww.amanet.org";
spSiteDomainUat = "devwww.amanet.org";
spSiteDomainProd = ".amaconferencecenters.org";

//Get url parameters
params = getParams();
pcode = unescape(params["pcode"]);
ocode = unescape(params["ocode"]);
spMailingID = unescape(params["spMailingID"]);
spUserID = unescape(params["spUserID"]);
spJobID = unescape(params["spJobID"]);
member_pcode = unescape(params["member_pcode"]);
spSiteDomain = spSiteDomainProd;
spPageName = document.title;
spPageURL = document.URL;
spCookiePath = '/';
var servlet_loc = "https://sdm3.rm04.net/";
//servlet = 'cst';
expireDays = 180;
//var servlet_loc = "http://sdm3.rm04.net/"; changed 06.29.06
//https://marketer1.silverpop.com/cot
// fc 02.18.05 ends



//use for setting the tracking image
function JA_readCookie(JA_name){
	if (document.cookie == '') {
		return false;
		}
	else {
		// if pcode is undefined, set it to ''
		if (JA_name == 'pcode' && (document.cookie.indexOf(JA_name) <= 0 || JA_getCookieValue2(JA_name) == 'undefined')){
			JA_SetCookie('pcode', '', null, spCookiePath, spSiteDomain, false, false);
			}
		return unescape(JA_getCookieValue2(JA_name));
		}
}
// this function makes sure there is an = sign after the name in order to avoid repeated names
function JA_getCookieValue2(JA_name, isLiteral){
	var JA_firstChar, JA_lastChar;
	var JA_theBigCookie = document.cookie;
	if(!isLiteral){
		JA_name = JA_name.toUpperCase();
	}
	JA_firstChar = JA_theBigCookie.indexOf(JA_name + "=");
	if (JA_firstChar != -1){
		JA_firstChar += JA_name.length + 1;
		JA_lastChar = JA_theBigCookie.indexOf(';', JA_firstChar);
		if (JA_lastChar == -1) JA_lastChar = JA_theBigCookie.length;
			return JA_theBigCookie.substring(JA_firstChar, JA_lastChar);
		}
	else
		return "";
}

function JA_SetCookie (name,value,expires,path,domain,secure,isLiteral) {
	if(!isLiteral){
		name = name.toUpperCase();	
	}
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function JA_clearCookie2(JA_cookie_name, isLiteral){
	if(!isLiteral){
		JA_cookie_name = JA_cookie_name.toUpperCase();
	}
	var JA_the_date = new Date("January 01, 1970");
	JA_SetCookie(JA_cookie_name, null, JA_the_date, spCookiePath, spSiteDomain, false, isLiteral);
}


//fc we need to read the orignal url string to make the pcode cookie
function getParams() {
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1) {
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
	   }
	}
	return params;
}

//set all session abd persistent cookies
function setID(){
	var expireDate= new Date();
	expireDate.setDate(expireDate.getDate() + expireDays);
	//if (spMailingID != 'undefined') JA_SetCookie('spMailingID', spMailingID, expireDate, spCookiePath, spSiteDomain, false, false);
	//if (spUserID != 'undefined') JA_SetCookie('spUserID', spUserID, expireDate, spCookiePath, spSiteDomain, false, false);
	//if (spJobID != 'undefined') JA_SetCookie('spJobID', spJobID, expireDate, spCookiePath, spSiteDomain, false, false);
	if (spMailingID != 'undefined') JA_SetCookie('m', spMailingID, expireDate, spCookiePath, spSiteDomain, false, true);
	if (spUserID != 'undefined') JA_SetCookie('r', spUserID, expireDate, spCookiePath, spSiteDomain, false, true);
	if (spJobID != 'undefined') JA_SetCookie('j', spJobID, expireDate, spCookiePath, spSiteDomain, false, true);
	if (member_pcode != 'undefined') JA_SetCookie('member_pcode', member_pcode, null, spCookiePath, spSiteDomain, false, false);
	if (pcode != 'undefined'){ 
		JA_SetCookie("p_pcode", pcode, expireDate, spCookiePath, spSiteDomain, false, false);
		JA_SetCookie('pcode', pcode, null, spCookiePath, spSiteDomain, false, true); 
		JA_SetCookie('PCODE', pcode, null, spCookiePath, spSiteDomain, false, false); 
	}
	if (ocode != 'undefined') JA_SetCookie('ocode', ocode, null, spCookiePath, spSiteDomain, false, false);
	/*if(document.cookie.indexOf("PCODE") != -1){
		var tempPcode= JA_getCookieValue2("pcode");
		alert(tempPcode)
		JA_SetCookie("p_pcode", pcode, expireDate, spCookiePath, spSiteDomain, false);
	}*/
	wmCampaignID = unescape(params["utm_campaign"]);
	var cid = 0;
	if (wmCampaignID != 'undefined'){
		if(wmCampaignID == 'business+writing'){
			//<img src="http://ad.yieldmanager.com/pixel?id=110278&t=2" width="1" height="1" />
			//http://devwww.amanet.org/seminars/category.cfm?cat=219&CMP=KNC-Google_PPC&HBX_PK=Business%20Writing&HBX_OU=50&pcode=XAR7&wm_lpID=843593&wm_ctID=152&wm_kwID=1339350&wm_mtID=3&wm_content=0&wm_g_crID=944446604&wm_g_kw=business%20writing%20training&gclid=CP2jpuKEs5MCFRcaagodQxL2oA&wm_defaultURL=www.amanet.org&wm_kw=business+writing+training&utm_source=google&utm_medium=cpc&utm_term=business+writing+training&utm_campaign=business+writing
			cid = 110278;
		}else if(wmCampaignID == 'communication'){
			//<img src="http://ad.yieldmanager.com/pixel?id=110276&t=2" width="1" height="1" />
			//http://devwww.amanet.org/seminars/category.cfm?cat=204&CMP=KNC-Google_PPC&HBX_PK=Communication&HBX_OU=50&pcode=XAR7&wm_lpID=850163&wm_ctID=152&wm_kwID=1345920&wm_mtID=3&wm_content=0&wm_g_crID=944460104&wm_g_kw=communication%20seminars&gclid=COCNxPOEs5MCFRMYagodjzYZoA&wm_defaultURL=www.amanet.org&wm_kw=communication+seminars&utm_source=google&utm_medium=cpc&utm_term=communication+seminars&utm_campaign=communication
			cid = 110276;
		}else if(wmCampaignID == 'finance%2faccounting' || wmCampaignID == 'finance/accounting'){
			//http://devwww.amanet.org/seminars/category.cfm?cat=197&CMP=KNC-Google_PPC&HBX_PK=Finance%20Accounting&HBX_OU=50&pcode=XAR7&wm_lpID=828949&wm_ctID=152&wm_kwID=1324169&wm_mtID=1&wm_content=0&wm_g_crID=944645684&wm_g_kw=finance%20seminars&gclid=CJ72hI2Fs5MCFSY1agodBnFGog&wm_defaultURL=www.amanet.org&wm_kw=finance+seminars&utm_source=google&utm_medium=cpc&utm_term=finance+seminars&utm_campaign=finance%2faccounting
			//<img src="http://ad.yieldmanager.com/pixel?id=110279&t=2" width="1" height="1" />
			cid = 110279;
		}else if(wmCampaignID == 'human+resources'){
			//http://devwww.amanet.org/seminars/category.cfm?cat=213&CMP=KNC-Google_PPC&HBX_PK=Human%20Resources&HBX_OU=50&pcode=XAR7&wm_lpID=821777&wm_ctID=152&wm_kwID=1316997&wm_mtID=3&wm_content=0&wm_g_crID=944660864&wm_g_kw=human%20resource%20management%20seminars&gclid=CMTi6PmCs5MCFRMYagodjzYZoA&wm_defaultURL=www.amanet.org&wm_kw=human+resource+management+seminars&utm_source=google&utm_medium=cpc&utm_term=human+resource+management+seminars&utm_campaign=human+resources
			//<img src="http://ad.yieldmanager.com/pixel?id=110280&t=2" width="1" height="1" />
			cid = 110280;
		}else if(wmCampaignID == 'leadership'){
			//<img src="http://ad.yieldmanager.com/pixel?id=110277&t=2" width="1" height="1" />
			//http://www.amanet.org/seminars/category.cfm?cat=201&CMP=KNC-Google_PPC&HBX_PK=Leadership&HBX_OU=50&pcode=XAR7&wm_lpID=839030&wm_ctID=152&wm_kwID=1334218&wm_mtID=3&wm_content=0&wm_g_crID=944667884&wm_g_kw=leadership%20training&gclid=CImA7KqCs5MCFRMYagodjzYZoA&wm_defaultURL=www.amanet.org&wm_kw=leadership+training&utm_source=google&utm_medium=cpc&utm_term=leadership+training&utm_campaign=leadership
			cid = 110277;
		}else if(wmCampaignID == 'mgmt%5Fsupervisory+skills' || wmCampaignID == 'mgmt_supervisory+skills'){
			//http://devwww.amanet.org/seminars/category.cfm?cat=203&CMP=KNC-Google_PPC&HBX_PK=Mgmt%20Supervisory%20Skills&HBX_OU=50&pcode=XAR7&wm_lpID=854739&wm_ctID=152&wm_kwID=1350496&wm_mtID=1&wm_content=0&wm_g_crID=992838764&wm_g_kw=management%20seminars&gclid=CKS33oCCs5MCFR8cagodASp9ow&wm_defaultURL=www.amanet.org&wm_kw=management+seminars&utm_source=google&utm_medium=cpc&utm_term=management+seminars&utm_campaign=mgmt%5Fsupervisory+skills
			//<img src="http://ad.yieldmanager.com/pixel?id=110273&t=2" width="1" height="1" />
			cid = 110273;
		}else if(wmCampaignID == 'office+admin+support'){
			//http://devwww.amanet.org/seminars/category.cfm?cat=205&CMP=KNC-Google_PPC&HBX_PK=Office%20Admin%20Support&HBX_OU=50&pcode=XAR7&wm_lpID=834333&wm_ctID=152&wm_kwID=1329553&wm_mtID=1&wm_content=0&wm_g_crID=940997324&wm_g_kw=admin%20seminars&gclid=CPSWqLCFs5MCFSEbagod3VK6oQ&wm_defaultURL=www.amanet.org&wm_kw=admin+seminars&utm_source=google&utm_medium=cpc&utm_term=admin+seminars&utm_campaign=office+admin+support
			//<img src="http://ad.yieldmanager.com/pixel?id=110275&t=2" width="1" height="1" />
			cid = 110275;
		}else if(wmCampaignID == 'project+management'){
			//http://devwww.amanet.org/seminars/category.cfm?cat=209&CMP=KNC-Google_PPC&HBX_PK=Project%20Management&HBX_OU=50&pcode=XAR7&wm_lpID=856183&wm_ctID=152&wm_kwID=1351940&wm_mtID=1&wm_content=0&wm_g_crID=944465384&wm_g_kw=pm%20training&gclid=CLvi28OFs5MCFRMYagodjzYZoA&wm_defaultURL=www.amanet.org&wm_kw=pm+training&utm_source=google&utm_medium=cpc&utm_term=pm+training&utm_campaign=project+management
			//<img src="http://ad.yieldmanager.com/pixel?id=110274&t=2" width="1" height="1" />
			cid = 110274;
		}
	}else{
		var patt1=new RegExp("^http://((dev)|(qa))?www.amanet.org/((index.htm([?].*)?)|(([?].*)?))$", "gi");
		if(patt1.test(document.location.href)){
			cid = 109934;
		}else{
			patt1.compile("^http://((dev)|(qa))?www.amanet.org/onsite(/.*)?$", "gi");
			if(patt1.test(document.location.href)){
				cid = 110272;
			}
		}
	}
	if(cid > 0){
		document.write('<img src="http://ad.yieldmanager.com/pixel?id='+cid+'&t=2" width="1" height="1" />');
	}
}


//used for silverpop tracking
/*function writeTrackingImage(servlet) {
	if (spMailingID != 'undefined');
	if (spUserID != 'undefined');
	if (spJobID != 'undefined');
	if (spPageName != 'undefined');
	if (spPageURL != 'undefined');
	return("<img src='" + servlet_loc + servlet + "?m=" + JA_readCookie("m") + "&r=" + JA_readCookie("r") + "&j=" + JA_readCookie("j") + "&name=" + spPageName + "&s=" + spPageURL + "' border='0', width='1' height='1'>");
}*/
//Testing
function writeTrackingImage(servlet) {
	if (JA_getCookieValue2("m",true).length > 0){
		if (JA_getCookieValue2("r",true).length> 0){
			if (JA_getCookieValue2("j",true).length> 0){
				if (spPageName != 'undefined'){
					if (spPageURL != 'undefined'){
						//alert('setting');
						return("<img src='" + servlet_loc + servlet + "?m=" + JA_getCookieValue2("m",true) + "&r=" + JA_getCookieValue2("r",true) + "&j=" + JA_getCookieValue2("j",true) + "&name=" + spPageName + "&s=" + spPageURL + "' border='0', width='1' height='1'>");
					}
				}
			}
		}
	}
	return "";
}

//set user segmentation for past registrant
function set_p_purchased(){
    currentTime = new Date();
	currentTime.setDate(currentTime.getDate() - 1);
	var tempM = currentTime.getMonth()+1;
	currentTimeString = currentTime.getFullYear()+"/"+tempM+"/"+currentTime.getDate()+" 99:99:99";
	// p_purchaseTime is in cookie check to see if it has been a day
	if(document.cookie.indexOf("p_purchaseTime") != -1){
		var p_time= JA_getCookieValue2("p_purchaseTime", true);
		//The p_puchaseTime is 1 days old
		if(p_time <= currentTimeString){ 
			hbx.seg="--3, 12"; 
			JA_clearCookie2("p_purchaseTime", true);
		}
    }
}

//Used on the corporate.htm page
function galleta(sku, isOCR){
	setID();
	mpcode = JA_getCookieValue2('member_pcode');
	
	// get the values from the cookie so that we can pass them to the amamember page
	m = JA_getCookieValue2("m");
	r = JA_getCookieValue2("r");
	j = JA_getCookieValue2("j"); 
	if(isOCR){
		sku = sku+"&isocr=y";	
	}
	if ( mpcode!='undefined' && mpcode!=null && mpcode!='' )
		document.write("<a href=\"https://www.amamember.org/membersonly/mem_forms.nsf/FmStep1?Open&sku="+sku+"&m=" + m + "&r=" + r + "&j=" + j + "&member_pcode=" + mpcode + "\"><img src=\"images/joinrnow.gif\" alt=\"Join now!\" width=\"84\" height=\"21\" border=\"0\"></a>");
	else
		document.write("<a href=\"https://www.amamember.org/membersonly/mem_forms.nsf/FmStep1?Open&sku="+sku+"&m=" + m + "&r=" + r + "&j=" + j + "\"><img src=\"images/joinrnow.gif\" alt=\"Join now!\" width=\"84\" height=\"21\" border=\"0\"></a>");
}

//Used on the corporate.htm page
function galleta2(sku, isOCR){
	mpcode = JA_getCookieValue2('member_pcode');
	
	// get the values from the cookie so that we can pass them to the amamember page
	m = JA_getCookieValue2("m");
	r = JA_getCookieValue2("r");
	j = JA_getCookieValue2("j"); 
	
	if(isOCR){
		sku = sku+"&isocr=y";	
	}
	
	if ( mpcode!='undefined' && mpcode!=null && mpcode!='' )
		document.write("<area shape=\"rect\" coords=\"85,43,186,70\" href=\"https://www.amamember.org/membersonly/mem_forms.nsf/FmStep1?Open&sku="+sku+"&m=" + m + "&r=" + r + "&j=" + j + "&member_pcode=" + mpcode + "\">");
	else
		document.write("<area shape=\"rect\" coords=\"85,43,190,70\" href=\"https://www.amamember.org/membersonly/mem_forms.nsf/FmStep1?Open&sku="+sku+"&m=" + m + "&r=" + r + "&j=" + j + "\">");
}




////////////////////////////////////////////////////////////////////////////////////////////
/*
These functions are no long in use but are included in this file to maintain backwards compatibility
*/
////////////////////////////////////////////////////////////////////////////////////////////
// no longer used
function JA_getCookieValue(JA_name){
	var JA_firstChar, JA_lastChar;
	var JA_theBigCookie = document.cookie;
	JA_name = JA_name.toUpperCase();
	JA_firstChar = JA_theBigCookie.indexOf(JA_name);
	if (JA_firstChar != -1){
		JA_firstChar += JA_name.length + 1;
		JA_lastChar = JA_theBigCookie.indexOf(';', JA_firstChar);
		if (JA_lastChar == -1) JA_lastChar = JA_theBigCookie.length;
			return JA_theBigCookie.substring(JA_firstChar, JA_lastChar);
		}
	else
		return ;
}

// otto 06.23.05 ends
function setMemberPCode(cookieName, cookieValue){
	JA_SetCookie(cookieName, cookieValue, null, spCookiePath, spSiteDomain, false, false);
}

function JA_clearCookie(JA_cookie_name, isLiteral){
	if(!isLiteral){
		JA_cookie_name = JA_cookie_name.toUpperCase();
	}
	var JA_the_date = new Date("January 01, 1970");
	var JA_the_cookie_date = JA_the_date.toGMTString();
	var JA_the_cookie = JA_cookie_name + "=clear;path=/;expires=" + JA_the_cookie_date;
	document.cookie = JA_the_cookie;
}

