/**********************************************
* The following two methods we use to submit the form when user clicks on go button next to the search box in header
* This functionality is requried for remote sites also
************************************************/
function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function checkForEmpty(searchString) {
	if(trim(searchString) != "") {
		document.getElementById("globalSearchForm").submit();
	}
	else {
		window.location="/utilities/search.esp"
	}
}

/**********************************************
* This method is called when user clicks on any of the search item under the SEARCHES section in MOST POPULAR ON EMC.COM
* After that the above functions are called, similar to the search functionality
************************************************/
function showSearchResults(searchString){
	document.globalSearchForm.searchString.value = searchString;
	checkForEmpty(searchString);
}

function getURI(url){
	var temp = url.indexOf(".com") + 4
	var checkUrl = url.substring(temp,url.length);
	setPdfpath(checkUrl);
}
var multipleLangCountries =[["http://dev-engb.emc.com", "/langInterceptor-Canada.htm","Canadalanguage1!http://dev1-engb.emc.com/index.htm#Canadalanguage2!http://dev-engb.emc.com/index.htm"], ["http://dev-de.emc.com", "/langInterceptor-Germany.htm","Germanylanguage1!http://dev1-de.emc.com/index.htm#Germanylanguage2!http://dev-de.emc.com/index.htm"]];


function ReadCookie(name) {
	var cookieString = document.cookie;
	var cookiesArray = document.cookie.split(";");
	if(cookiesArray.length >1) {
		for(var i=0;i<cookiesArray.length;i++) {
			cookieArray = cookiesArray[i].split("=");
			cookieName = cookieArray[0];
			cookieValue = cookieArray[1];
			if(cookieName.indexOf(name) >= 0) {
				return cookieValue;
			}
		}
	}
	else {
		cookieArray = cookieString.split("=");
		cookieName = cookieArray[0];
		cookieValue = cookieArray[1];
		if(cookieName.indexOf(name) >= 0) {
			return cookieValue;
		}
	}
	return "";
}


function deleteCookie(name) {
	document.cookie = name+"=;domain=emc.com;expires=Fri, 17 Feb 1995 10:00:00 GMT;path=/";
} 

function redirectSite(siteUrl) {
	if(document.getElementById("rememberchoice")) {
		if(document.getElementById("rememberchoice").checked) {
			window.status = ip;
			if((ip.indexOf("128.221.24") < 0) && (ip.indexOf("10.24.3") < 0))
				document.cookie = "EMCSiteUrl="+unescape(siteUrl)+";expires=Fri, 17 Dec 2020 10:00:00 GMT;domain=emc.com;path=/";
		}
	}
	if(siteUrl != "") {
		redirectUrl(siteUrl);
	}
}

function redirectUrl(url) {
	for(var i=0;i<multipleLangCountries.length;i++) {
		
		if(url.indexOf(multipleLangCountries[i][0]) != -1)  {
			window.location = multipleLangCountries[i][0]+multipleLangCountries[i][1];
			return;
		}
	}
	window.location = url+"?fromGlobalSiteSelect";
}

function redirectToSite (url) {
	if(ReadCookie("EMCSiteUrl").indexOf(url) > 0) {
			document.cookie = "EMCSiteUrl="+unescape(url)+";expires=Fri, 17 Dec 2020 10:00:00 GMT;domain=emc.com;path=/";
		}
	window.location = url;
}

function selectLanguage(selectLanguage,siteUrl) {
	if((ip.indexOf("128.221.24") < 0) && (ip.indexOf("10.24.3") < 0))
		document.cookie = "EMCSiteUrl="+unescape(siteUrl)+";expires=Fri, 17 Dec 2020 10:00:00 GMT;domain=emc.com";
	window.location=siteUrl;
}

function getUrlVars() 
{ 
    var vars = [], hash; 
	if((window.location.href.indexOf("?") > 0) && (window.location.href.indexOf("=") > 0)) {
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 
		for(var i = 0; i < hashes.length; i++) 
		{ 
			hash = hashes[i].split('='); 
			vars.push(hash[0]); 
			vars[hash[0]] = hash[1]; 
		} 
	}
    return vars; 
}

function setDefaultOptionToComboByPassingValue(comboBox,value) {
	var comboObj = document.getElementById(comboBox);
	for (var i=0 ; i < comboObj.options.length; i++) {
		if (comboObj.options[i].value.toLowerCase()==unescape(value.toLowerCase())){
			comboObj.selectedIndex = i;
			return;
		}
	}
}

function setDefaultOptionToComboByPassingLabel(comboBox,label) {
	var comboObj = document.getElementById(comboBox);
	for (var i=0 ; i < comboObj.options.length; i++) {
		if (comboObj.options[i].text.toLowerCase()==unescape(label.toLowerCase())){
			comboObj.selectedIndex = i;
			return;
		}
	}
}


if(self.pageTitle) {
	var cookieValue =  ReadCookie("tabName");
	if(cookieValue != "") {
		  var cookieValues  =  cookieValue.split("<<>>");
		  var pageName = cookieValues[0];
		  var tabName = cookieValues[1];

			  if(pageName == pageTitle) {
				if(tabName != "") {
					if(self.displayTab) {
						displayTab(document.getElementById("tab"+tabName));
					}
					else {
						if(document.getElementById("tab"+tabName+"Link")) {
							document.getElementById("tab"+tabName+"Link").onclick();
						}
					}
				}
			}
	}
}



			
