//gets the psid value from the cookie
function getpsidcookie() {
	var nameEQ = "PSID" + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return true;
	}
	return false;
}

// returns prod env true/false...add prod apps as needed
function isProduction() {
	var theLocation = document.location.href;
	if (theLocation.indexOf("www.sybase.com/") > -1 ||
	    theLocation.indexOf("search.sybase.com") > -1 ||
	    theLocation.indexOf("investor.sybase.com") > -1 ||
	    theLocation.indexOf("http://sybase.com") > -1 ||
	    theLocation.indexOf("downloads.sybase.com") > -1 ||
	    theLocation.indexOf("profile.sybase.com") > -1 ||
	    theLocation.indexOf("login.sybase.com") > -1 ||
	    theLocation.indexOf("my.sybase.com") > -1 ||
	    theLocation.indexOf("eshop.sybase.com") > -1 ||
	    theLocation.indexOf("certification.sybase.com") > -1 ||
	    theLocation.indexOf("info.sybase.com") > -1 ||
	    theLocation.indexOf("forums.sybase.com") > -1 ||
	    theLocation.indexOf("case-express.sybase.com") > -1 ||
	    theLocation.indexOf("casexpress.sybase.com") > -1 ||
	    theLocation.indexOf("sybooks.sybase.com") > -1 ||
	    theLocation.indexOf("infocenter.sybase.com") > -1 ||
	    theLocation.indexOf("ptnrweb.sybase.com") > -1 ||
	    theLocation.indexOf("crm.sybase.com") > -1 ||
	    theLocation.indexOf("jobs.sybase.com") > -1 ||
	    theLocation.indexOf("surveys.sybase.com") > -1 ||
	    theLocation.indexOf("sed.sybase.com") > -1 ||
	    theLocation.indexOf("www.sybase-iad-services.com") > -1 ||
	    theLocation.indexOf("techwave.sybase.com") > -1 ||
	    theLocation.indexOf("try.sybase.com") > -1 ||
	    theLocation.indexOf("blogs.sybase.com") > -1 ||
	    theLocation.indexOf("blog.sybase.com") > -1 ||
	    theLocation.indexOf("slc.sybase.com") > -1 ||
	    theLocation.indexOf("iablog.sybase.com") > -1 ||
	    theLocation.indexOf("m.sybase.com") > -1 ||
	    theLocation.indexOf("response.sybase.com") > -1 ||
   	    theLocation.indexOf("partner.sybase.com") > -1 ||
	    theLocation.indexOf("marketing.ianywhere.com") > -1 ||
	    theLocation.indexOf("marketing.sybase365.com") > -1 ||
	    theLocation.indexOf("datagov.sybase.com") > -1 ||
	    theLocation.indexOf("mobilegov.sybase.com") > -1 ||
	    theLocation.indexOf("video.sybase.com") > -1 ){
		
		return true;
	} else {
		return false;
	}
}

// returns domain env true/false...add prod apps as needed
function whichApp() {
	var theLocation = document.location.href;
	var theQueryString = document.location.search;
	var app = "";
	
	if (theLocation.indexOf("/eshop") > -1 ){		
		return "eshop";
	} 
	
	if (theLocation.indexOf("/search/simple.do") > -1 ||
	    theLocation.indexOf("/search/advanced.do") > -1 ){		
		return  "search";
	}
	
	return "none"
 
}

//gets the correct websidestory account number for env
function getWSSAccount() {
var theLocation = document.location.href;
	if (isProduction()){ //get the corp production environments
	    account_no = "DM55021041AA94EN3"  
   	} else if (theLocation.indexOf("www.sybase.com.ar") > -1){
	   account_no = "DM550906HOEB94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.be") > -1){
	   account_no = "DM550906GNBA94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.br") > -1){
	   account_no = "DM550906IPSC94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.dk") > -1){
	   account_no = "DM55090658DV94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.fr") > -1){
	   account_no = "DM550906IBMZ94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.de") > -1){
	   account_no = "DM550906G1CF94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.it") > -1){
	   account_no = "DM550907PLSS94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.jp") > -1){
	   account_no = "DM550907MIDM94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.mx") > -1){
	   account_no = "DM55090795CV94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.nl") > -1){
	   account_no = "DM55090797BC94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.no") > -1){
	   account_no = "DM5509074LWD94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.es") > -1){
	   account_no = "DM5509078NSE94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.se") > -1){
	   account_no = "DM5509073ODA94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.ch") > -1){
	   account_no = "DM550907N0NR94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.co.uk") > -1){
	   account_no = "DM550907OIWZ94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.au") > -1) {
	   account_no = "DM5607287ICM94EN3"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.co.nz") > -1) {
	   account_no = "DM5607287ICM94EN3"; //ACCOUNT NUMBER
	} else {
	   account_no = "DM550401PMDV94EN3"   	
	} 
	return account_no;

}

//removes illegal characters from the title
//and plus pluses for spaces
function removeIllegalCharacters(title) {
    return title.replace(/[',"&|#$%^*:!<>~;]/g,"").replace(/\//g,"").replace(/\s/g,"+")
}

function getTitle() {
	var varTitle = "";
	
	try {
		var varShortTitle = document.getElementById("shortTitle");
		if(varShortTitle != null) {
			varTitle = varShortTitle.value;
		} else {
			varTitle = document.title;
		}
	} catch (e) {
		varTitle = document.title;
	}
	
	return varTitle;

}

function getMlc() {
	varMlc = document.location.pathname;

	if (varMlc.indexOf("/detail") > -1 ){
		try {
			varInfo = document.getElementById("info");
			varMlc = varMlc + "/" + varInfo.value;;
		} catch (e) {}
	}
	return varMlc.replace(/\s/g,"+");

}

function getLevel(num) {
	var varPath = document.location.pathname;

	//if (varPath.indexOf("/detail") > -1 ){
	//	try {
	//		varInfo = document.getElementById("info");
	//		varPath = varPath + "/" + varInfo.value;;
	//	} catch (e) {}
	//}

	//if (varPath.indexOf("/detail_list") > -1 ){
	//	try {
	//		varInfo = document.getElementById("id");
	//		varPath = varPath + "/" + varInfo.value;

	//	} catch (e) {}
	//}
	var varLevel = "";
	var arryPath = varPath.split("/");
	try {
		varLevel = arryPath[num];
	} catch(e) {}

	return varLevel;
}

function getId() {
	var varElem ="";
	var varId = "";

	try {
		varElem = document.getElementById("id");
		if(varElem != null) {
			varId = varElem.value;
		}
	} catch (e) {}

	return varId;
}

function getEventType() {
	var varEvent = "";
	var thankyouinfo = "";
	try {
		var varInfo = document.getElementById("info");
		if(varInfo != null) {
			thankyouinfo = varInfo.value;
			if (thankyouinfo == "Thank You Page") {
				varEvent =  "event2";
			}
		}
	} catch (e) {}

	return varEvent;
}

//gets the correct websidestory account number for env
function getOmnitureAccount() {
var theLocation = document.location.href;
	if (isProduction()){ //get the corp production environments
	    account_no = "sybasesybase.com"  
   	} else if (theLocation.indexOf("www.sybase.com.ar") > -1){
	   account_no = "sybaseargentina"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.be") > -1){
	   account_no = "sybasebelgium"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.br") > -1){
	   account_no = "sybasebrazil"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.dk") > -1){
	   account_no = "sybasedenmark"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.fr") > -1){
	   account_no = "sybasefrance"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.de") > -1){
	   account_no = "sybasegermany"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.it") > -1){
	   account_no = "sybaseitaly"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.jp") > -1){
	   account_no = "sybasejapan"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.mx") > -1){
	   account_no = "sybasemexico"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.nl") > -1){
	   account_no = "sybasenetherlands"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.no") > -1){
	   account_no = "sybasenorway"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.es") > -1){
	   account_no = "sybasespain"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.se") > -1){
	   account_no = "sybasesweden"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.ch") > -1){
	   account_no = "sybaseswitzerland"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.co.uk") > -1){
	   account_no = "sybaseuk"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.au") > -1) {
	   account_no = "sybaseaustralia"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.co.nz") > -1) {
	   account_no = "sybasenewzealand"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.ca") > -1){
	   account_no = "sybasecanada"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.cn") > -1){
	   account_no = "sybasechina"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.hk") > -1){
	   account_no = "sybasehongkong"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.hu") > -1){
	   account_no = "sybasehungary"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.in") > -1) {
	   account_no = "sybaseindia"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.co.kr") > -1) {
	   account_no = "sybasekorea"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("ap.sybase.com") > -1) {
	   account_no = "sybaseasiapacific"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("ianywhere.com") > -1) {
	   account_no = "sybaseianywhere"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("avantgo.com") > -1) {
	   account_no = "sybaseavantgo"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("syberspace.sybase.com") > -1) {
	   account_no = "sybasesyberspase"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.my") > -1) {
	   account_no = "sybasemalaysia"; //ACCOUNT NUMBER
	} else if (theLocation.indexOf("www.sybase.com.sg") > -1) {
	   account_no = "sybasesingapore"; //ACCOUNT NUMBER
	} else {
	   account_no = "sybasedev"   	
	} 

	return account_no;

}
