//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(theLocation) {
	if(theLocation == undefined) 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("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("iqformarketers.com") > -1 ||
	    theLocation.indexOf("now.eloqua.com") > -1 ||
	    theLocation.indexOf("video.sybase.com") > -1 ||
        theLocation.indexOf("sqla.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;
	var cmpid = getCmpid();
	if (theLocation.indexOf("www.sybase.com.ar") > -1){
	   account_no = "DM550906HOEB94EN3"; 
	} else if (theLocation.indexOf("www.sybase.be") > -1){
	   account_no = "DM550906GNBA94EN3"; 
	} else if (theLocation.indexOf("www.sybase.com.br") > -1){
	   account_no = "DM550906IPSC94EN3"; 
	} else if (theLocation.indexOf("www.sybase.dk") > -1){
	   account_no = "DM55090658DV94EN3"; 
	} else if (theLocation.indexOf("www.sybase.fr") > -1){
	   account_no = "DM550906IBMZ94EN3"; 
	} else if (theLocation.indexOf("www.sybase.de") > -1){
	   account_no = "DM550906G1CF94EN3"; 
	} else if (theLocation.indexOf("www.sybase.it") > -1){
	   account_no = "DM550907PLSS94EN3"; 
	} else if (theLocation.indexOf("www.sybase.jp") > -1){
	   account_no = "DM550907MIDM94EN3"; 
	} else if (theLocation.indexOf("www.sybase.com.mx") > -1){
	   account_no = "DM55090795CV94EN3"; 
	} else if (theLocation.indexOf("www.sybase.nl") > -1){
	   account_no = "DM55090797BC94EN3"; 
	} else if (theLocation.indexOf("www.sybase.no") > -1){
	   account_no = "DM5509074LWD94EN3"; 
	} else if (theLocation.indexOf("www.sybase.es") > -1){
	   account_no = "DM5509078NSE94EN3"; 
	} else if (theLocation.indexOf("www.sybase.se") > -1){
	   account_no = "DM5509073ODA94EN3"; 
	} else if (theLocation.indexOf("www.sybase.ch") > -1){
	   account_no = "DM550907N0NR94EN3"; 
	} else if (theLocation.indexOf("www.sybase.co.uk") > -1){
	   account_no = "DM550907OIWZ94EN3"; 
	} else if (theLocation.indexOf("www.sybase.com.au") > -1) {
	   account_no = "DM5607287ICM94EN3"; 
	} else if (theLocation.indexOf("www.sybase.co.nz") > -1) {
	   account_no = "DM5607287ICM94EN3"; 
	} else if (isProduction()){ //get the corp production environments
	    account_no = "DM55021041AA94EN3"  
   	} else {
	   account_no = "DM550401PMDV94EN3"   	
	} 
	return account_no;

}

function querystring(variable) {
	var querystring = window.location.search.substring(1);
	var vars = querystring.split("&");
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return unescape(pair[1]);
		}
	}
}

function getTrackingLocation() {
	var location = document.location.href;
	var cmpid = querystring("cmpid");
	if (cmpid){
		var cmpidArray = cmpid.split("_");
		var region = cmpidArray[1];
		switch(region) 
		{
			case "ar":
				location = "www.sybase.com.ar"; 
				break;
			case "be":
				location = "www.sybase.be";
				break;
			case "br":
				location = "www.sybase.com.br";
				break;
			case "dk":
				location = "www.sybase.dk";
				break;
			case "fr":
				location ="www.sybase.fr";
				break;
			case "de":
				location = "www.sybase.de";
				break; 
			case "it":
				location = "www.sybase.it";
				break;
			case "jp": 
			   location = "www.sybase.jp";
			   break;
			case "mx":
				location = "www.sybase.com.mx";
				break;
			case "nl":
				location = "www.sybase.nl";
				break;
			case "no":
				location = "www.sybase.no";
				break;
			case "es":
				location = "www.sybase.es";
				break;
			case "se":
				location = "www.sybase.se";
				break;
			case "ch":
				location = "www.sybase.ch";
				break;
			case "uk": 
				location = "www.sybase.co.uk";
				break;
			case "au":
				location = "www.sybase.com.au";
				break;
			case "nz":
				location = "www.sybase.co.nz";
				break;
			case "ca":
				location = "www.sybase.ca";
				break;
			case "cn":
				location = "www.sybase.com.cn";
				break;
			case "hk":
				location = "www.sybase.com.hk";
				break;
			case "hu":
				location = "www.sybase.hu";
				break;
			case "in":
				location = "www.sybase.in";
				break;
			case "kr":
				location = "www.sybase.co.kr";
				break;
			case "ap":
				location = "ap.sybase.com";
				break;
			case "my":
				location = "www.sybase.com.my";
				break;
			case "sg": 
				location = "www.sybase.com.sg";
				break;
			case "us":
				location = "www.sybase.com/";
			default:
				location = document.location.href;
		}
	}
	return location;
}

//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 isEloquaForm() {
	var isForm = false;
	var hiddenFieldName = "elqSiteID";
	var hiddenFieldValue = "184"
	var elements = document.getElementsByName(hiddenFieldName);
	var tempValue, tempName;
	
	for (var i = 0; i < elements.length; i++) {
		tempName = elements[i].getAttribute("name");
		
		if (tempName == hiddenFieldName) {
			if (hiddenFieldValue == elements[i].getAttribute("value")) {
				isForm = true;
				break;
			}
		}
	}

	return isForm;
}

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) {}

	if (isEloquaForm()) {
		varEvent =  "event1";
	}

	return varEvent;
}

//gets the correct Omniture account number for env
function getOmnitureAccount() {
	var theLocation = getTrackingLocation();
	if (isProduction(theLocation)){ //get the corp production environments
	    account_no = "sybasesybase.com"  
   	} else if (theLocation.indexOf("www.sybase.com.ar") > -1){
	   account_no = "sybaseargentina"; 
	} else if (theLocation.indexOf("www.sybase.be") > -1){
	   account_no = "sybasebelgium"; 
	} else if (theLocation.indexOf("www.sybase.com.br") > -1 ){
	   account_no = "sybasebrazil"; 
	} else if (theLocation.indexOf("www.sybase.dk") > -1){
	   account_no = "sybasedenmark"; 
	} else if (theLocation.indexOf("www.sybase.fr") > -1){
	   account_no = "sybasefrance"; 
	} else if (theLocation.indexOf("www.sybase.de") > -1){
	   account_no = "sybasegermany"; 
	} else if (theLocation.indexOf("www.sybase.it") > -1){
	   account_no = "sybaseitaly"; 
	} else if (theLocation.indexOf("www.sybase.jp") > -1){
	   account_no = "sybasejapan"; 
	} else if (theLocation.indexOf("www.sybase.com.mx") > -1){
	   account_no = "sybasemexico"; 
	} else if (theLocation.indexOf("www.sybase.nl") > -1){
	   account_no = "sybasenetherlands"; 
	} else if (theLocation.indexOf("www.sybase.no") > -1){
	   account_no = "sybasenorway"; 
	} else if (theLocation.indexOf("www.sybase.es") > -1){
	   account_no = "sybasespain"; 
	} else if (theLocation.indexOf("www.sybase.se") > -1){
	   account_no = "sybasesweden"; 
	} else if (theLocation.indexOf("www.sybase.ch") > -1){
	   account_no = "sybaseswitzerland"; 
	} else if (theLocation.indexOf("www.sybase.co.uk") > -1){
	   account_no = "sybaseuk"; 
	} else if (theLocation.indexOf("www.sybase.com.au") > -1) {
	   account_no = "sybaseaustralia"; 
	} else if (theLocation.indexOf("www.sybase.co.nz") > -1) {
	   account_no = "sybasenewzealand"; 
	} else if (theLocation.indexOf("www.sybase.ca") > -1){
	   account_no = "sybasecanada"; 
	} else if (theLocation.indexOf("www.sybase.com.cn") > -1){
	   account_no = "sybasechina"; 
	} else if (theLocation.indexOf("www.sybase.com.hk") > -1){
	   account_no = "sybasehongkong"; 
	} else if (theLocation.indexOf("www.sybase.hu") > -1){
	   account_no = "sybasehungary"; 
	} else if (theLocation.indexOf("www.sybase.in") > -1) {
	   account_no = "sybaseindia"; 
	} else if (theLocation.indexOf("www.sybase.co.kr") > -1) {
	   account_no = "sybasekorea"; 
	} else if (theLocation.indexOf("ap.sybase.com") > -1) {
	   account_no = "sybaseasiapacific"; 
	} else if (theLocation.indexOf("ianywhere.com") > -1) {
	   account_no = "sybaseianywhere"; 
	} else if (theLocation.indexOf("avantgo.com") > -1) {
	   account_no = "sybaseavantgo"; 
	} else if (theLocation.indexOf("syberspase.sybase.com") > -1) {
	   account_no = "sybasesyberspase"; 
	} else if (theLocation.indexOf("www.sybase.com.my") > -1) {
	   account_no = "sybasemalaysia"; 
	} else if (theLocation.indexOf("www.sybase.com.sg") > -1) {
	   account_no = "sybasesingapore"; 
	} else if (theLocation.indexOf("images.sybase.com") > -1) {
	   account_no = "sybasesybase.com"; 
	} else if (theLocation.indexOf("www.sybase.co.za") > -1) {
	   account_no = "sybasesouthafrica"; 
	} else if (theLocation.indexOf("partner-jp.sybase.com") > -1) { 
		account_no = "sybasejapan"; 
	} else if (theLocation.indexOf("gomobile.sybase.com") > -1) { 
    		account_no = "sybasemobisite"; 
	} else if (theLocation.indexOf("m.sybase.com") > -1) { 
		account_no = "sybasemobisite"; 
	} else {
	   account_no = "sybasedev"   	
	} 
	
	return account_no;

}

