function checkDevDomain(){
	//var url="http://www.palm.com/ca/owners/tungsten-t5/";
	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/ca/": tmpRegion="roa"; break;
		case "www.palm.com/la/": tmpRegion="roa"; break;
		case "www.palm.com/ar/": tmpRegion="roa"; break;
		case "www.palm.com/br/": tmpRegion="roa"; break;
		case "www.palm.com/cl/": tmpRegion="roa"; break;
		case "www.palm.com/co/": tmpRegion="roa"; break;
		case "www.palm.com/mx/": tmpRegion="roa"; break;
		case "www.palm.com/pe/": tmpRegion="roa"; break;
		case "www.palm.com/ve/": tmpRegion="roa"; break;
		default: tmpRegion = "roa"; break;
	}
	return (tmpRegion);
}

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

function getCountry(){
	var tmpDomain = getDomain();
	var tmpCountry = "";
	
	switch (tmpDomain){
		case "www.palm.com/ca/": tmpCountry="ca"; break;
		case "www.palm.com/la/": tmpCountry="la"; break;
		case "www.palm.com/ar/": tmpCountry="ar"; break;
		case "www.palm.com/br/": tmpCountry="br"; break;
		case "www.palm.com/cl/": tmpCountry="cl"; break;
		case "www.palm.com/co/": tmpCountry="co"; break;
		case "www.palm.com/mx/": tmpCountry="mx"; break;
		case "www.palm.com/pe/": tmpCountry="pe"; break;
		case "www.palm.com/ve/": tmpCountry="ve"; break;
		default: tmpCountry = "roa";
		break;
	}
	return (tmpCountry);
}

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

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 {
			switch (tmpArray[1]){
				case "ca": tmpCountry="home"; break;
				case "la": tmpCountry="home"; break;
				case "ar": tmpCountry="home"; break;
				case "br": tmpCountry="home"; break;
				case "cl": tmpCountry="home"; break;
				case "co": tmpCountry="home"; break;
				case "mx": tmpCountry="home"; break;
				case "pe": tmpCountry="home"; break;
				case "ve": tmpCountry="home"; break;
				default: tmpCountry = "home";
				break;
			}
			
			tmpChannel="home";
		}
	}
	
	return tmpChannel;
}

/*******************************************************/
function getOS(){
	var tmpArray = getPathBreakdown();
	var tmpValue = tmpArray[4];
	var tmpOS = ""; 

	switch (tmpValue){
		case "treo700wx": tmpOS = "win mo"; break;
		case "treo750": tmpOS = "win mo"; break;
		case "treo750v": tmpOS = "win mo"; break;
		case "foleo": tmpOS = "linux"; break;
		default:
			tmpOS="palm os";
			break;
	}
	
	return tmpOS;
}
/*******************************************************/
function getSubCat(){
	var tmpArray = getPathBreakdown();
	var tmpValue = tmpArray[4];
	
	
	var tmpSubCat = ""; 
	
	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) || (tmpValue.indexOf("treo90") == 0) || (tmpValue.indexOf("z")  == 0)){
		tmpSubCat="handhelds";
	}
	else if (tmpValue.indexOf("lifedrive")  == 0) {
		tmpSubCat="lifedrive";
	}
	else if (tmpValue.indexOf("treo") == 0) {
		tmpSubCat="smartphones";
		
	}
	else if (tmpValue.indexOf("foleo") == 0) {
		tmpSubCat="mobilecompanion";
		
	}	
			
	return tmpSubCat;
}
/*******************************************************/
function getProduct(){
	var tmpArray = getPathBreakdown();
	var tmpValue = tmpArray[4];
	var tmpExt = tmpArray[5];
	
	var tmpProd = ""; 
	
	
	switch (tmpValue){
		case "treo700wx": tmpProd = "treo 700w"; break;
		case "treo700p": tmpProd = "treo 700p"; break;
		case "treo750": tmpProd = "treo 750"; break;
		case "treo680": tmpProd = "treo 680"; break;
		case "treo650": tmpProd = "treo 650"; break;
		case "treo600": tmpProd = "treo 600"; break;
		case "treo300": tmpProd = "treo 300"; break;
		case "treo270": tmpProd = "treo 270"; break;
		case "treo180": tmpProd = "treo 180"; break;
		case "treo180g": tmpProd = "treo 180g"; break;
		default:
			tmpProd=tmpValue;
			break;
	}
	return tmpProd;

}	


/*******************************************************/
function getSubLevel(){
	var tmpArray = getPathBreakdown();
	var tmpSLIndex=3;
	var tmpSubLvl = ""; 
	
	if (tmpArray[tmpSLIndex].indexOf(".html") > 1){
		tmpSubLvl = "";
	}
	else{
		tmpSubLvl=tmpArray[tmpSLIndex];
	}
	return tmpSubLvl;
	
}

/*******************************************************/
function getLanguage(){
	var tmpLang = "";
	var tmpDomain = getDomain();
	var tmpArray = getPathBreakdown();
	
	switch (tmpDomain){
	
		case "www.palm.com/ca/": tmpLang="en"; break;
		case "www.palm.com/la/": tmpLang="es"; break;
		case "www.palm.com/ar/": tmpLang="es"; break;
		case "www.palm.com/br/": tmpLang="bp"; break;
		case "www.palm.com/cl/": tmpLang="es"; break;
		case "www.palm.com/co/": tmpLang="es"; break;
		case "www.palm.com/mx/": tmpLang="es"; break;
		case "www.palm.com/pe/": tmpLang="es"; break;
		case "www.palm.com/ve/": tmpLang="es"; 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 (getSubCat() != "") {
				s.prop4=getOS(); // OS 
				s.prop5=getSubCat(); //sub cat 
				s.prop6=getProduct(); // product 
			}
			else{
				
				s.prop10=getSubLevel(); // content sub level, ie. business_products, solutions, knowledge_center, ways_to_engage, compare, company 
					
			
			}
		s.prop18=getLanguage(); // language
} 
