var theUrl 	= new String();
theUrl 		= document.URL;
theUrl 		= theUrl.toLowerCase();

var catcountry		= getCatCountryFromUrl();
var countrypath		= getCountryPath(catcountry);

var tab_product 	= "Products";
var tab_features 	= "Features";
var tab_accessories 	= "Upgrades & support";
var tab_innovation	= "Innovation";
var lang_folder		= "en";

var tabCount		= 3;
var tabLink1		= 'http://www.pc.ibm.com';
var tabLink2		= 'http://www.pc.ibm.com';
var tabLink3		= 'http://www.pc.ibm.com';
var tabText1		= tab_product;
var tabText2		= tab_features;
var tabText3		= tab_accessories;

function getCountryPath(CatCountry) {
	
	if (CatCountry == 'chfr') {
		return 'ch/fr';
	}
	else if (CatCountry == 'chde') {
		return 'ch/de';
	}
	else {
		return CatCountry;
	}
}

function getCatCountryFromUrl() {

        var pageHref    = new String(document.location.href);
        var pagePath 	= new String(document.location.pathname);
            pagePath 	= pagePath.substr(1);

        var currcountry     = pagePath.substr(0, pagePath.indexOf('/'));

        if (currcountry.length != 2) {
        	currcountry = 'europe';
        }

        if (pageHref.indexOf('sourcesite') != -1 || pageHref.indexOf('cntry') != -1 ) {
		currcountry = getCatParamFromQuery('sourcesite');
	}
		
	if (pageHref.indexOf('cntry') != -1) {
		currcountry = getCatParamFromQuery('cntry');
	}
	currcountry = currcountry.toLowerCase();
	currcountry = currcountry.replace('-l','');
	currcountry = currcountry.replace('-L','');
	

	return currcountry;
}

function getCatParamFromQuery(paramName,searchQuery) {
	var query 		= unescape(document.location.search.substring(1));
    var passedQuery = searchQuery;

	if (passedQuery != undefined && passedQuery.indexOf('?') != -1) {
                query = unescape(passedQuery.substring((passedQuery.indexOf('?')+1)));
     }

	var params  	= query.split('&');

        for (i=0; i<params.length; i++) {
            var param = params[i].split('=');

            if (param[0].toLowerCase() == paramName.toLowerCase()) {
                return param[1] || "";
            }
        }

        return null;
}

switch (catcountry) {
	case 'at' :
		tab_product 	= "Produkte";
		tab_features 	= "Eigenschaften";
		tab_accessories = "Upgrades & support";
		tab_innovation	= "Innovationen";
		lang_folder		= "de";
	break;
	case 'de' :
		tab_product 	= "Produkte";
		tab_features 	= "Eigenschaften";
		tab_accessories = "Upgrades & support";
		tab_innovation	= "Innovationen";
		lang_folder		= "de";
	break;
	case 'chde' :
		tab_product 	= "Produkte";
		tab_features 	= "Eigenschaften";
		tab_accessories = "Upgrades & support";
		tab_innovation	= "Innovationen";
		lang_folder	= "de";
	break;
	case 'chfr' :
		tab_product 	= "Produits";
		tab_features 	= "Découvrez les produits";
		tab_accessories = "Options";
		tab_innovation	= "Innovations";
		lang_folder	= "fr";
	break;
	case 'ch' :
		tab_product 	= "Produkte";
		tab_features 	= "Eigenschaften";
		tab_accessories = "Upgrades & support";
		tab_innovation	= "Innovationen";
		lang_folder	= "de";
	break;
	case 'fr' :
		tab_product 	= "Produits";
		tab_features 	= "Découvrez les produits";
		tab_accessories = "Options";
		tab_innovation	= "Innovations";
		lang_folder		= "fr";
	break;
	case 'es' :
		tab_product 	= "Productos";
		tab_features 	= "Características";
		tab_accessories = "Actualizaciones y soporte";
		tab_innovation	= "Innovación";
		lang_folder		= "en";
	break;
	case 'it' :
		tab_product 	= "Prodotti";
		tab_features 	= "Caratteristiche";
		tab_accessories = "Accessori e aggiornamenti";
		tab_innovation	= "Innovazione";
		lang_folder		= "it";
	break;
	case 'dk' :
		tab_product 	= "Produkter";
		tab_features 	= "Features";
		tab_accessories = "Opgraderinger oq support";
		tab_innovation	= "Innovation";
		lang_folder		= "en";
	break;
	case 'no' :
		tab_product 	= "Produkter";
		tab_features 	= "Features";
		tab_accessories = "Opgraderinger oq support";
		tab_innovation	= "Innovasjon";
		lang_folder		= "en";
	break;
}

// THINKPAD TABS
if(theUrl.indexOf("thinkpad+r+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/thinkpad/index.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/thinkpad/why/'+lang_folder+'/rseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkpad+t+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/thinkpad/index.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/thinkpad/why/'+lang_folder+'/tseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkpad+x+series+tablet")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/thinkpad/index.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/thinkpad/why/'+lang_folder+'/xtablet.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkpad+x+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/thinkpad/index.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/thinkpad/why/'+lang_folder+'/xseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkpad+z+notebooks")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/thinkpad/index.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/thinkpad/why/'+lang_folder+'/zseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkcentre+a+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/desktops/thinkcentre.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/desktops/why/'+lang_folder+'/tcaseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkcentre+m+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+catcountry+'/desktops/thinkcentre.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/desktops/why/'+lang_folder+'/tcmseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+catcountry+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkcentre+e+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+catcountry+'/desktops/thinkcentre.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/desktops/why/'+lang_folder+'/tceseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+catcountry+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkcentre+s+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/desktops/thinkcentre.html';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/desktops/why/'+lang_folder+'/tcsseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("flat+panel")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/monitors/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/monitors/why/'+lang_folder+'/flat_panel.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("crt+essential") != -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/monitors/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/monitors/why/'+lang_folder+'/crt.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+catcountry+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("lenovo+3000+c+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/notebooks/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/notebook/why/'+lang_folder+'/cseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("lenovo+3000+n+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/notebooks/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/notebook/why/'+lang_folder+'/nseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("lenovo+3000+j+series")!= -1) {
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/desktops/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/desktops/why/'+lang_folder+'/jseries.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_features;
	tabLink3 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText3 = tab_accessories;
}
else if(theUrl.indexOf("thinkpad") != -1) {
	tabCount = 2;
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/thinkpad/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText2 = tab_accessories;
}
else if(theUrl.indexOf("thinkcentre") != -1) {
	tabCount = 2;
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/desktops/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText2 = tab_accessories;
}
else if(theUrl.indexOf("desktops") != -1) {
	tabCount = 2;
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/desktops/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/'+countrypath+'/accessories/';
	tabText2 = tab_accessories;
}
else {
	tabCount = 2;
	tabLink1 = 'http://www.pc.ibm.com/'+countrypath+'/';
	tabText1 = tab_product;
	tabLink2 = 'http://www.pc.ibm.com/europe/think/'+lang_folder+'/index.html?'+catcountry+'&cc='+catcountry;
	tabText2 = tab_innovation;
}

if (tabCount == 3) {
document.write('<table cellpadding="0" cellspacing="0" border="0" summary="thinkpad-tabs"><tr><td class="v14-graphic-tab-selected"><img class="display-img" alt="" height="19" width="9" src="//www.lenovo.com/i/c.gif"/></td><td class="v14-graphic-tab-selected">');
document.write('<a class="v14-tab-link-selected" href="'+tabLink1+'">'+tabText1+'</a>');
document.write('</td><td class="v14-tab-hlrt"><img alt="" height="1" width="30" src="//www.lenovo.com/i/c.gif"/></td><td class="v14-graphic-tab-unselected">');
document.write('<a class="v14-tab-link-unselected" href="'+tabLink2+'">'+tabText2+'</a>');
document.write('</td><td class="v14-tab-dmrt"><img alt="" height="1" width="30" src="//www.lenovo.com/i/c.gif"/></td><td class="v14-graphic-tab-unselected">');
document.write('<a class="v14-tab-link-unselected" href="'+tabLink3+'">'+tabText3+'</a>');
document.write('</td><td class="v14-tab-dmrt-end"><img alt="" height="1" width="30" src="//www.lenovo.com/i/c.gif"/></td></tr></table>');
}
else if (tabCount == 2) {
document.write('<table cellpadding="0" cellspacing="0" border="0" summary="thinkpad-tabs"><tr><td class="v14-graphic-tab-unselected"><img class="display-img" alt="" height="19" width="9" src="//www.lenovo.com/i/c.gif"/></td><td class="v14-graphic-tab-unselected">');
document.write('<a class="v14-tab-link-unselected" href="'+tabLink1+'">'+tabText1+'</a>');
document.write('</td><td class="v14-tab-dmrt"><img alt="" height="1" width="30" src="//www.lenovo.com/i/c.gif"/></td><td class="v14-graphic-tab-unselected">');
document.write('<a class="v14-tab-link-unselected" href="'+tabLink2+'">'+tabText2+'</a>');
document.write('</td><td class="v14-tab-dmrt-end"><img alt="" height="1" width="30" src="//www.lenovo.com/i/c.gif"/></td></tr></table>');
}
else if (tabCount == 0) {}
document.write('<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td class="v14-graphic-tab-lblue-table"><img class="display-img" alt="" height="4" width="1" src="//www.lenovo.com/i/c.gif"/></td></tr><tr><td class="v14-graphic-tab-dblue-table"><img class="display-img" alt="" height="1" width="1" src="//www.lenovo.com/i/c.gif"/></td></tr></table>');