var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function setMeta(parameters) {
	var metrics = new Array( );
	var pairs = parameters.split("&");
	for (var i = 0; i < pairs.length; i++) {
		var pair = pairs[i].split("=");
		metrics[pair[0]] = pair[1];
	}

	var myDocumentElements;
	if(document.all) {
		myDocumentElements = document.all.tags("meta");
	} else if(document.documentElement) {
		myDocumentElements = document.getElementsByTagName("meta");
	}
	if(typeof(myDocumentElements) != "undefined") {
		for(var i = 1; i <= myDocumentElements.length; i++) {
			myMeta = myDocumentElements.item(i - 1);
			if(myMeta.name.indexOf('DCSext') == 0) {
				var name = myMeta.name.substring(myMeta.name.indexOf('.') + 1);
				myMeta.content = metrics[name];
			}
		}
	}
}

function trackThis(code) {
 	//alert("Here is the webtrends code: "+code);
 	//var clearObj = InternetExplorer ? clear : document.openisms;
	var strMeta = "item=" + code;
	//alert("this is strMeta " + code);
    setMeta(strMeta);
    dcsVar();
    dcsMeta();
    dcsTag();
}


function trackAndGo(code, url) {
	//alert(code);
 	//alert("Here is the webtrends code: "+code);
 	//var onecardObj = InternetExplorer ? main : document.main;
	var strMeta = "item=" + code;
	//alert("this is strMeta " + code);
    setMeta(strMeta);
    dcsVar();
    dcsMeta();
    dcsTag();
	document.location.href = url;
}

function getQueryString() {
	var rawQS =  new String(document.location.search);
	return rawQS.substr(1);
}



/*
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub trackThis(ByVal args)\n');
	document.write(' call trackThis( args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}*/
//generic name/value pair function, return a hash (of sorts) of name value pairs from the querystring
// uasge: var qsParams = getQsParams();
// then: qsParams['url'] whould equal whatever url=XXX in the querystring

function passATS() {
   var entryCode = "";
   var qsParams = getQsParams();
   entryCode = qsParams['entryCode'];
   //alert(entryCode);
   if (entryCode == "standard") {
	             ATS = "http://www.americanexpress.com/apply/cgi-bin/page.cgi?85/15485/b/10";
	             return ATS;
	             //alert(ATS);
   } else if (entryCode == "rich") {
	             ATS = "http://www.americanexpress.com/apply/cgi-bin/page.cgi?85/15486/b/10";
	             return ATS;
	             //alert(ATS);
   } else {
	             ATS = "http://www.americanexpress.com/apply/cgi-bin/page.cgi?85/15487/b/10";
	             return ATS;
	             //alert(ATS);
   }
}

function flashURL() {
   var entryCode = "";
   var qsParams = getQsParams();
   entryCode = qsParams['entryCode'];
   //alert(entryCode);
   if (entryCode == "standard") {
	             flashURL = "/standardclear.html";
	             return flashURL;
	             //alert(flashURL);
   } else if (entryCode == "rich") {
	             flashURL = "/richclear.html";
	             return flashURL;
	             //alert(flashURL);
   } else {
	             flashURL = "/clear.html";
	             return flashURL;
	             //alert(flashURL);
   }
}

//generic name/value pair function, return a hash (of sorts) of name value pairs from the querystring
// uasge: var qsParams = getQsParams();
// then: qsParams['url'] whould equal whatever url=XXX in the querystring
function getQsParams(){
	var qs = location.search; 
	qs = qs.substring(1);
	// create an 'array' called newArray with the name value pairs from the querystring
	var qsArray = new Array;
	qsArray = qs.split('&'); //creating an array in which the values are separated by ampersands in the code
	var keyValueArray = new Array; //this one loads the names and values into a hash (of sorts)
	for(i=0; i<qsArray.length; i++){
		var nameValue = qsArray[i].split('='); //splitting what we find between each ampersand into key value pairs
	keyValueArray[nameValue[0]] = unescape(nameValue[1]); //we are then turning all the escaped characters back into the 'real thing' ie. %3F turns into a '?' 
   }
   return keyValueArray;
}
