

/*******************************************************/
function checkDevDomain(){
	var url=window.location.href;

	var tmpURL = "";
		 
	if (url.indexOf("cms.palm.com") > 1){
		var fstIndex = url.indexOf("/iw-mount/");
		var lstIndex = url.indexOf("/us/");
		var pre = url.substring(0, fstIndex);
		var post = url.substring(lstIndex);
		tmpURL = pre + post; 
	}
	else {
		tmpURL = url; 
	}
	return tmpURL;
}

/*******************************************************/

function getDomain(){
	var domain = "";
	var repStId	= "";
	var subdir = "";
	var teststr = "";
	var url	= checkDevDomain();
		
	// all we need is the domain name and the first directory
 
	var re		= /^https?:\/\/(.*)/i;
	var str		= url;
	var tstUrl	= str.replace(re, "$1");
	var urlPth	= tstUrl.split("/", 2);
   
	domain	= urlPth[0];
	subdir	= urlPth[1];

	var domain = domain + "/" + subdir + "/";
	return (domain);
}


/*******************************************************/

function getRegion(){
	var tmpDomain = getDomain();
	var tmpRegion = "";
	
	switch (tmpDomain){
		case "www.palm.com/intl/":
			tmpRegion="intl";
			break;
		case "www.palm.com/us/":
			tmpRegion="us";
			break;
		default:
			tmpRegion = "us";
		break;
	}
	return (tmpRegion);
}

/*******************************************************/

function getCountry(){
	var tmpDomain = getDomain();
	var tmpCountry = "";
	
	switch (tmpDomain){
		case "www.palm.com/intl/":
			tmpCountry="";
			break;
		case "www.palm.com/us/":
			tmpCountry="us";
			break;
		default:
			tmpCountry = "us";
		break;
	}
	return (tmpCountry);
}

/*******************************************************/

function getCookie(cookiename) {

	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf("cc");

    if (index1==-1 || cookiename=="") return ""; 
    var index2=cookiestring.indexOf(';',index1);
			
    if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}


/*******************************************************/
function getPathBreakdown(){
	var url	= checkDevDomain();
	var re		= /^https?:\/\/(.*)/i;
	var str		= url;
	if (str.indexOf("?") > 1){
		str=str.substring(0,str.indexOf("?"));
	}
	else if (str.indexOf(";") > 1){
		str=str.substring(0,str.indexOf(";"));
	}
	else if (str.indexOf("#") > 1){
		str=str.substring(0,str.indexOf("#"));
	}
	else if (str.indexOf("&") > 1){
		str=str.substring(0,str.indexOf("&"));
	}

	var tstUrl	= str.replace(re, "$1");
	var arrayUrl= tstUrl.split("/", 10);
	
	return arrayUrl;

}

/* this function picks up the 3rd value a.k.a. Channel/Site Section in the URL array */
function getChannel(){
	var tmpArray = getPathBreakdown();
	var tmpChannel ="";

	if ((tmpArray[2] == "") || (tmpArray[2].indexOf("index") == 0)){
		if (tmpArray[1] == "intl"){
			tmpChannel="intl";
		}
		else if (tmpArray[1] == "us"){
			tmpChannel="us";
		}
	}
	else{
		tmpChannel=tmpArray[2];
	}
	
	return tmpChannel;
}

/*******************************************************/
function getOS(){
	var tmpArray = getPathBreakdown();
	var tmpValue = tmpArray[3];
	var tmpOS = ""; 
	
	try{
		if (tmpArray[3] != ""){
			tmpValue = tmpArray[3];
			
			if ((tmpValue.indexOf("zire") == 0) || (tmpValue.indexOf("tungsten")  == 0) || (tmpValue.indexOf("tx")  == 0) || (tmpValue.indexOf("visor") == 0) || (tmpValue.indexOf("palm")  == 0) || (tmpValue.indexOf("pilot")  == 0) || (tmpValue.indexOf("z22")  == 0) || (tmpValue.indexOf("i705") == 0)){
				tmpOS="palm os";
			}
			else if (tmpValue.indexOf("lifedrive")  == 0) {
				tmpOS="palm os";
			}
			else if (tmpValue.indexOf("treo") == 0) {
				var tmpProd = tmpArray[4];
				if(tmpProd.indexOf("treo755p") ==0){
					tmpOS = "palm os";
				}
				else if (tmpProd.indexOf("treo750") ==0){
					tmpOS = "win mo"; 
				}
				else if (tmpProd.indexOf("treo700p") ==0){
					tmpOS = "palm os"; 
				}
				else if (tmpProd.indexOf("treo700w") ==0){
					tmpOS = "win mo"; 
				}
				else if (tmpProd.indexOf("treo700wx") ==0){
					tmpOS = "win mo"; 
				}
				else if (tmpProd.indexOf("treo680") ==0){
					tmpOS = "palm os"; 
				}
				else if (tmpProd.indexOf("treo650") ==0){
					tmpOS = "palm os"; 
				}
				else if (tmpProd.indexOf("treo600") ==0){
					tmpOS = "palm os"; 
				}
				else if (tmpProd.indexOf("treo300") ==0){
					tmpOS = "palm os"; 
				}
				else if (tmpProd.indexOf("treo270") ==0){
					tmpOS = "palm os"; 
				}
				else if (tmpProd.indexOf("treo180") ==0){
					tmpOS = "palm os"; 
				}
				else if (tmpProd.indexOf("treo180g") ==0){
					tmpOS = "palm os"; 
				}
				else if (tmpProd.indexOf("treo90") ==0){
					tmpOS = "palm os"; 
				}
			}
		}
		return tmpOS;
	}
	catch(e){
		return tmpOS;
	}
}
/*******************************************************/
function getSubCat(){
	var tmpArray = getPathBreakdown();
	var tmpValue = tmpArray[3];
	var tmpSubCat = ""; 
	
	try{
		if (tmpArray[3] != ""){
			tmpValue = tmpArray[3];
		
			if ((tmpValue.indexOf("zire") == 0) || (tmpValue.indexOf("tungsten")  == 0) || (tmpValue.indexOf("tx")  == 0) || (tmpValue.indexOf("visor") == 0) || (tmpValue.indexOf("palm")  == 0) || (tmpValue.indexOf("pilot")  == 0) || (tmpValue.indexOf("z22")  == 0) || (tmpValue.indexOf("i705") == 0)){
				tmpSubCat="handhelds";
			}
			else if (tmpValue.indexOf("lifedrive")  == 0) {
				tmpSubCat="lifedrive";
			}
			else if (tmpValue.indexOf("treo") == 0) {
				if (tmpArray[4].indexOf("treo90") == 0){
					tmpSubCat="handhelds";
				}
				else{
					tmpSubCat="smartphones";
				}
			}
		}		
		return tmpSubCat;
	}
	catch(e){
		return tmpSubCat;
	}	

}
/*******************************************************/
function getProduct(){
	var tmpArray = getPathBreakdown();
	var tmpValue = "";
	var tmpProd = ""; 
	
	try{
	
		if (tmpArray[3] != ""){
			tmpValue = tmpArray[3];
			
			if ((tmpValue.indexOf("zire") == 0) || (tmpValue.indexOf("tungsten")  == 0) || (tmpValue.indexOf("tx")  == 0) || (tmpValue.indexOf("visor") == 0) || (tmpValue.indexOf("palm")  == 0) || (tmpValue.indexOf("pilot")  == 0) || (tmpValue.indexOf("z22")  == 0) || (tmpValue.indexOf("i705") == 0)){
				tmpProd=tmpArray[3];
			}
			else if (tmpValue.indexOf("lifedrive")  == 0) {
				tmpProd=tmpArray[3];
			}
			else if (tmpValue.indexOf("treo") == 0) {
				tmpProd = tmpArray[4];
				if(tmpProd.indexOf("treo755p") ==0){
					tmpProd = "treo 755p";
				}
				else if (tmpProd.indexOf("treo750") ==0){
					tmpProd = "treo 750"; 
				}
				else if (tmpProd.indexOf("treo700p") ==0){
					tmpProd = "treo 700p"; 
				}
				else if (tmpProd.indexOf("treo700w") ==0){
					tmpProd = "treo 700w|wx"; 
				}
				else if (tmpProd.indexOf("treo700wx") ==0){
					tmpProd = "treo 700w|wx"; 
				}
				else if (tmpProd.indexOf("treo680") ==0){
					tmpProd = "treo 680"; 
				}
				else if (tmpProd.indexOf("treo650") ==0){
					tmpProd = "treo 650"; 
				}
				else if (tmpProd.indexOf("treo600") ==0){
					tmpProd = "treo 600"; 
				}
				else if (tmpProd.indexOf("treo300") ==0){
					tmpProd = "treo 300"; 
				}
				else if (tmpProd.indexOf("treo270") ==0){
					tmpProd = "treo 270"; 
				}
				else if (tmpProd.indexOf("treo180") ==0){
					tmpProd = "treo 180"; 
				}
				else if (tmpProd.indexOf("treo180g") ==0){
					tmpProd = "treo 180g"; 
				}
				else if (tmpProd.indexOf("treo90") ==0){
					tmpProd = "treo 90"; 
				}
			}
		}	
		return tmpProd;
	}
	catch(e){
		return tmpProd;
	}	
	

}	

/*******************************************************/
function getCarrier(){
	var tmpArray = getPathBreakdown();
	var tmpValue = tmpArray[3];
	var tmpCarrier = ""; 
	
	try{
		if (tmpArray[3] != ""){
			tmpValue = tmpArray[3];
		
			if (tmpValue.indexOf("treo") == 0) {
				var tmpProd = tmpArray[4];
		
				if (tmpProd.indexOf("alltel") > 1) 
					 tmpCarrier="alltel";
				else if (tmpProd.indexOf("bell") > 1) 
					tmpCarrier="bell mobility";
				else if (tmpProd.indexOf("cellsouth") > 1) 
					tmpCarrier="cell south";
				else if ((tmpProd.indexOf("cingular") > 1) || (tmpProd.indexOf("att") > 1))
					tmpCarrier="att";
				else if (tmpProd.indexOf("earthlink") > 1)
					 tmpCarrier="earthlink";
				else if (tmpProd.indexOf("rogers") > 1)
					tmpCarrier="rogers";
				else if (tmpProd.indexOf("sprint") > 1)
					tmpCarrier="sprint";
				else if (tmpProd.indexOf("telus") > 1)
					tmpCarrier="telus";
				else if (tmpProd.indexOf("gsm") > 1)
					tmpCarrier="unlocked";
				else if (tmpProd.indexOf("verizon") > 1)
					tmpCarrier="verizon";		
			}
		}
		return tmpCarrier;
	}
	catch(e){
		return tmpCarrier;
	}
}	
/*******************************************************/
function getSubLevel(){
	var tmpArray = getPathBreakdown();
	var tmpSubLvl = ""; 
	
	try{
		if (tmpArray[3].indexOf(".html") > 1){
			tmpSubLvl = "";
		}
		else{
			tmpSubLvl=tmpArray[3];
		}
		return tmpSubLvl;
	}
	catch(e){
		return tmpSubLvl;
	}
}
/*******************************************************/
function getLanguage(){
	var tmpLang = "";
	var tmpDomain = getDomain();
	var tmpArray = getPathBreakdown();
	
	switch (tmpDomain){
		case "www.palm.com/intl/":
			tmpLang="en";
			break;
		case "www.palm.com/us/":
			tmpLang="en";
			break;
		default:
			tmpLang = "en";
		break;
	}
	return (tmpLang);
}
 

/* Palm.com specific Omniture custom variables */
if ((getDomain().indexOf("dev-www.palm.com") == 0) || (getDomain().indexOf("stage-www.palm.com") == 0) || (getDomain().indexOf("origin-www.palm.com") == 0) || (getDomain().indexOf("www.palm.com") == 0) ){
		s.channel=getChannel(); // Channel or Site Section   
		s.prop1=getRegion(); // Region 
		s.prop2=getCountry(); // Country 
		if ((getChannel() != "error") || (getChannel() != "cgi-bin")){
			if (getSubCat() != "") {
				s.prop4=getOS(); // OS 
				s.prop5=getSubCat(); //sub cat 
				s.prop6=getProduct(); // product 
				if (getChannel() == "support"){
					s.prop7=getCarrier();
				}
			}
			else{
				if ((getSubCat() == "accessories") || (getSubCat() == "software"))
				{
					s.prop5=getSubCat(); //sub cat 
				}
				else{
					s.prop10=getSubLevel(); // content sub level, ie. business_products, solutions, knowledge_center, ways_to_engage, compare, company 
				}
			
			}
		}
		s.prop18=getLanguage(); // language
} 