/****************************************************************************************************
** JS Cobrand (cobrand.js)
** Tim Michaels (tmichaels) 11/16/00
** Description: Allows a single page to display cobranded elements based on current and previous
** URL and, in some cases, parameters passed by the ISAPI code.  Cobranded elements include headers
** and footers, promos, links, forms actions, and certain form attributes.  SSI vars are defined    
** in localdefs.  Available functions: ReadCookie(name); DeleteCookie (name,domain,path);
** WriteCookie(name,value,domain,path,expires,secure); cobrandLinks(); cobrandFormRedirect(chosen);
** cobrandForms(); searchAttribs(); writeRegCookie(); writeHeader(); writeHeaderNoATC(); writeFooter()
*****************************************************************************************************/
var machine = "http://include.ebay.com/"; // machine these files are hosted on
var path = "aw/pics/js/cobrand/"; //  and path to the files -- leave thse two blank for relative paths 
var siteID = "0"; // set site default to core
var thisPage = location.href.toLowerCase();
var lastPage = document.referrer.toLowerCase();
// the following code finds out what site we're on, and sets siteID for the current page
if ((thisPage.indexOf(".aol.") > 0) || (lastPage.indexOf(".aol.") > 0) || (thisPage.indexOf("ht=5&") > 0) || (thisPage.indexOf("s_partnerid=5&") > 0) || (thisPage.indexOf("ht=2&") > 0) || (thisPage.indexOf("co_partnerid=5&") > 0) || (thisPage.indexOf("co_partnerid=500&") > 0)){
	if ((thisPage.indexOf(".com/aol/") > 0) || (lastPage.indexOf(".com/aol/") > 0) || (thisPage.indexOf("ht=5&") > 0) || (thisPage.indexOf("s_partnerid=5&") > 0) || ((thisPage.indexOf("co_partnerid=5&") > 0) && (thisPage.indexOf("co_partnerid=500&") == -1))){
		siteID = "1";// aolcom
	}
	else if (lastPage.indexOf("web.aol.com") < 1){
		siteID = "2";// aol
	}
}   
else if ((thisPage.indexOf(".compuserve.") > 0) || (lastPage.indexOf(".compuserve.") > 0) || (thisPage.indexOf("ht=6&") > 0) || (thisPage.indexOf("s_partnerid=6&") > 0) || (thisPage.indexOf("co_partnerid=6&") > 0)){
	siteID = "3";// compuserve
}
else if ((thisPage.indexOf(".digitalcity.") > 0) || (lastPage.indexOf(".digitalcity.") > 0) || (thisPage.indexOf("ht=7&") > 0) || (thisPage.indexOf("s_partnerid=7&") > 0) || (thisPage.indexOf("co_partnerid=7&") > 0)){
	siteID = "4";// digitalcity
}
else if ((thisPage.indexOf(".ebay.go.") > 0) || (lastPage.indexOf(".ebay.go.") > 0) || (thisPage.indexOf("ht=10&") > 0) || (thisPage.indexOf("s_partnerid=10&") > 0) || (thisPage.indexOf("co_partnerid=10&") > 0)){
	siteID = "5";// go
}
else if ((thisPage.indexOf(".icq.") > 0) || (lastPage.indexOf(".icq.") > 0) || (thisPage.indexOf("ht=8&") > 0) || (thisPage.indexOf("s_partnerid=8&") > 0) || (thisPage.indexOf("co_partnerid=8&") > 0)){
	siteID = "6";// icq
}

else if ((thisPage.indexOf(".netscape.") > 0) || (lastPage.indexOf(".netscape.") > 0) || (thisPage.indexOf("ht=9&") > 0) || (thisPage.indexOf("s_partnerid=9&") > 0) || (thisPage.indexOf("co_partnerid=9&") > 0)){
	siteID = "7";// netscape
}

else if ((thisPage.indexOf(".lycos.") > 0) || (lastPage.indexOf(".lycos.") > 0) || (thisPage.indexOf("ht=37&") > 0) || (thisPage.indexOf("s_partnerid=37&") > 0) || (thisPage.indexOf("co_partnerid=37&") > 0)){
	siteID = "8";// lycos
}
else if ((thisPage.indexOf(".carpoint.") > 0) || (thisPage.indexOf("carpoint.") > 0) || (lastPage.indexOf(".carpoint.") > 0) || (thisPage.indexOf("ht=28&") > 0) || (thisPage.indexOf("s_partnerid=28&") > 0) || (thisPage.indexOf("ht=28&") > 0) || (thisPage.indexOf("co_partnerid=28&") > 0) || (thisPage.indexOf("co_partnerid=28&") > 0)){
	if ((thisPage.indexOf(".com/ebaymotors") > 0) || (((lastPage.indexOf(".com/ebaymotors") > 0)||(lastPage.indexOf(".ebaymotors.") > 0)) && (thisPage.indexOf("pages.") ==-1) && (thisPage.indexOf("www.ebay.com") ==-1) && (thisPage.indexOf("cgi") ==-1)  && (thisPage.indexOf("listings") ==-1) && (thisPage.indexOf(".com/ebaymotors") ==-1)) || (thisPage.indexOf(".ebaymotors.") > 0) || (thisPage.indexOf("ht=28&") > 0) || (thisPage.indexOf("s_partnerid=28&") > 0) || (thisPage.indexOf("co_partnerid=28&") > 0)){
		siteID = "9";// carpoint on ebaymotors
	}
}
if ((thisPage.indexOf(".ebaystores.") > 0) || (lastPage.indexOf(".ebaystores.") > 0)){
	siteID = "0";// do not cobrand Storefronts pages
}
if ((thisPage.indexOf("crs.ebay.com") > 0) || (lastPage.indexOf("crs.ebay.com") > 0)){
	siteID = "0";// do not cobrand
}
if (thisPage.indexOf("arribada.") > 0){
	siteID = "0";// do not cobrand
}

// cookie functions
function ReadCookie(name){
	var allCookie, cookieVal, length, start, end;
	cookieVal="";
	name=name+"=";
	allCookie=document.cookie;
	length=allCookie.length;
	if (length>0){
		start=allCookie.indexOf(name, 0);
		if (start!=-1){
			start+=name.length;
			end=allCookie.indexOf(";",start);
			if (end==-1) {
				end=length;
			}
			cookieVal=unescape(allCookie.substring(start,end));
		}
	}
	return(cookieVal);
}
function WriteCookie(name,value,domain,path,expires,secure){ 
	var CookieVal, CookError;
	CookieVal=CookError="";
	if (name){
		CookieVal=CookieVal+escape(name)+"=";
	}
	if (value){
		CookieVal=CookieVal+escape(value);
	}
	if (domain){
		CookieVal=CookieVal+"; domain="+domain;
	}
	if (path){
		CookieVal=CookieVal+"; path="+path;
	}
	if (expires){
		CookieVal=CookieVal+"; expires="+expires.toGMTString();
	}
	if (secure){
		CookieVal=CookieVal+"; secure="+secure;
	}
	else{
		CookError=CookError+"Write failure";
	}
	document.cookie=CookieVal;  // sets the cookie
}
function DeleteCookie (name,domain,path){
   var expireDate=new Date(1);
   if (ReadCookie(name)){
      WriteCookie(name, " ", domain, path, expireDate);
   }
}
// begin micro-branding code
var mbID = "0";
var pageName;
if (!pageName)pageName = "";
if ((pageName.toLowerCase() == "pageviewitem")||(pageName.toLowerCase() == "pageacceptbid")||(pageName.toLowerCase() == "pageautosviewitemforvehicle")||(pageName.toLowerCase() == "pagebinconfirm")||(pageName.toLowerCase() == "pagebincongrats")||(pageName.toLowerCase() == "pagemakebid")){
	if ((lastPage.indexOf('techrepublic.com') > -1)||(ReadCookie('mb') == '100')){
		mbID = "100";
		siteID = "0";
		document.write("<SCRIPT SRC=\"" + machine + path + "mb/techrepublic.js\"></SCRIPT>");
	}
	else if ((lastPage.indexOf('tmichaels') > -1)||(lastPage.indexOf('smccarth') > -1)||(lastPage.indexOf('hhuling') > -1)||(lastPage.indexOf('tmichae') > -1)||(ReadCookie('mb') == 'test')){
		mbID = "test";
		siteID = "0";
		document.write("<SCRIPT SRC=\"" + machine + path + "mb/mb_test.js\"></SCRIPT>");
	}
}
// end microbranding code
if (siteID != "0"){
	document.write("<SCRIPT SRC=\"" + machine + path + "cobrand_functions.js\"></SCRIPT>");
}
function writeHeader(){ // writes the, um, header
	document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.afa.js\"></SCRIPT>");
	if (((thisPage.indexOf("motors/") > 0) || (thisPage.indexOf("motors.") > 0)) && (thisPage.indexOf("ebayisapi.dll?signin&usingssl=1") == -1)){
		if (siteID == "1"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/autos.header.aolcom.js\"></SCRIPT>");
		}
		else if (siteID == "2"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/autos.header.aol.js\"></SCRIPT>");
		}   
		else if (siteID == "3"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/autos.header.compuserve.js\"></SCRIPT>");
		}
		else if (siteID == "4"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/autos.header.digitalcity.js\"></SCRIPT>");
		}
		else if (siteID == "6"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/autos.header.icq.js\"></SCRIPT>");
		}
		else if (siteID == "7"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/autos.header.netscape.js\"></SCRIPT>");
		}
		else if (siteID == "8"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/autos.header.lycos.js\"></SCRIPT>");
		}
		else if (siteID == "9"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/autos.header.carpoint.js\"></SCRIPT>");
		}
	}
	else{
		if (siteID == "1"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.aolcom.js\"></SCRIPT>");
		}
		else if (siteID == "2"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.aol.js\"></SCRIPT>");
		}   
		else if (siteID == "3"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.compuserve.js\"></SCRIPT>");
		}
		else if (siteID == "4"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.digitalcity.js\"></SCRIPT>");
		}
		else if (siteID == "5"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.go.js\"></SCRIPT>");
		}
		else if (siteID == "6"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.icq.js\"></SCRIPT>");
		}
		else if (siteID == "7"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.netscape.js\"></SCRIPT>");
		}
		else if (siteID == "8"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.lycos.js\"></SCRIPT>");
		}
		else if (siteID == "9"){
			document.write("<SCRIPT SRC=\"" + machine + path + "headers/top/header.carpoint.js\"></SCRIPT>");
		}
	}
}
function writeBrow(){
	if (siteID != "0"){
		document.write("<SCRIPT SRC=\"" + machine + path + "headers/brow.js\"></SCRIPT>");
	}
}
function writeATC(){ // writes the ATC logo
	if (siteID != "4"){
	document.write("<SCRIPT SRC=\"" + machine + path + "headers/ATC.js\"></SCRIPT>");
	}
}
function writeFooter(){ // writes the cobrand footer
	if ((siteID == "0") && (thisPage.indexOf('cgi.ebay.com/aw-cgi')>-1))document.links[3].href = "http://pages.ebay.com/sitemap.html";	
	if (siteID == "1"){
		document.write("<SCRIPT SRC=\"" + machine + path + "footers/footers.aolcom.js\"></SCRIPT>");
	}
	else if (siteID == "2"){
		document.write("<SCRIPT SRC=\"" + machine + path + "footers/footers.aol.js\"></SCRIPT>");
	}   
	else if (siteID == "4"){
		document.write("<SCRIPT SRC=\"" + machine + path + "footers/footers.digitalcity.js\"></SCRIPT>");
	}
	else if (siteID == "5"){
		document.write("<SCRIPT SRC=\"" + machine + path + "footers/footers.go.js\"></SCRIPT>");
	}
	else if (siteID == "6"){
		document.write("<SCRIPT SRC=\"" + machine + path + "footers/footers.icq.js\"></SCRIPT>");
	}
	else if (siteID == "7"){
		document.write("<SCRIPT SRC=\"" + machine + path + "footers/footers.netscape.js\"></SCRIPT>");
	}
	else if (siteID == "8"){
		document.write("<SCRIPT SRC=\"" + machine + path + "footers/footers.lycos.js\"></SCRIPT>");
	}
	else if (siteID == "9"){
		document.write("<SCRIPT SRC=\"" + machine + path + "footers/footers.carpoint.js\"></SCRIPT>");
	}
}



var cbc = 1; // is this file loaded?

