/*
	Navigate functions for general page navigation
	Kenneth Kufluk 05/2k5
	Modem Media
	Version 1.0
*/

/*
	Redirect user according to page security status.
	KPK Digitas 10/2k7
*/
if (typeof pageSecured=="undefined") pageSecured=false;
var https = (location.protocol=="https:");
var secureURL = "https://www.globalbuypower.com";
var nonSecureURL = "http://www.opel."+navCountry.toLowerCase();
if (location.host.match("itl")) {
	secureURL = "https://"+location.host;
	nonSecureURL = "http://"+location.host;
}
if (pageSecured && !https) {
//	alert("redirecting to secure page");
	location.replace(secureURL+location.pathname+location.search);
}
if (!pageSecured && https) {
//	alert("redirecting to non-secure page");
	location.replace(nonSecureURL+location.pathname+location.search);
}

/////////////////////////////////
function getWinName(URLstr) {
	var acceptStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var returnStr = "";
	for (var i=0;i<URLstr.length;i++) {
		if (acceptStr.indexOf(URLstr.charAt(i))!=-1) returnStr += URLstr.charAt(i);
	}
	return returnStr;
}

var navCountryString = "cntryCd=" + navCountry + "&langCd=" + navLang + "&webSiteId=" + navWebsiteId;
function navigateTo(primary, secondary) {
	if (primary=="home") {goactionTo('gmehome&nav=main');return false;}
	if (primary=="showroom") {
		if (!secondary) {goactionTo('showroom&nav=main');return false;}
		if (secondary) {location = "/action/landing?model=" + secondary + "&" + navCountryString + "&nav=main";return false;}
	}
	if (primary=="commercial") {
		if (!secondary) {goactionTo('commercial_vehicles&nav=main');return false;}
		if (secondary) {location = "/action/landing?model=" + secondary + "&" + navCountryString + "&nav=main";return false;}
	}
	location = "/action/brandsite?branch=" + primary + "&asset=" + secondary + "&" + navCountryString + "&nav=main";
	return false;
}

var breadcrumbCountryString = navCountryString + "&nav=breadcrumb";
function breadcrumbTo(link) {
	if (link.match(/\?/)) location = link + "&" + breadcrumbCountryString;
	else location = link + "?" + breadcrumbCountryString;
}

function goactionTo(goaction) {
	location = "/action/go?"+navCountryString + "&page=" + goaction;
	return false;
}

function catwalkTo(goaction) {
	location = "/action/go?"+navCountryString + "&page=" + goaction + "&nav=catwalk";
	return false;
}

function utilityTo(goaction) {
	location = "/action/go?"+navCountryString + "&page=" + goaction + "&nav=servicebox";
	return false;
}

function getNsform(nsformname) {
	var mylocation = "";
	mylocation = "/jsp/"+navCountry+"/"+navLang+"/"+navWebsiteId+"/nsforms/nsform.jsp?cntryCd="+navCountry+"&langCd="+navLang+"&websiteId="+navWebsiteId+"&form="+nsformname+"&nav=servicebox";
	if (location.href.match("itlcs")) {
		mylocation = mylocation;
	} else {
		if (location.href.match("pprod")) {
			mylocation = mylocation;
		} else {
			mylocation = "https://www.globalbuypower.com" + mylocation;
		}
	}
	return mylocation;
}


function popWindowTo(URL, winprops, sophus) {
	if (sophus) {
		tc_redirect(getWinName(URL), URL, '/' + sophus, winprops);
	} else {
		window.open(URL, getWinName(URL), winprops);
	}
	return false;
}

var tempSophusTimer = 0;
function tc_redirect(a,b,c,d) {
	clearTimeout(tempSophusTimer);
	tempSophusTimer = setTimeout("tc_redirect(\""+a+"\", \""+b+"\", \""+c+"\", \""+d+"\")",1000);
}

