// rootdir is set in cookies.js
	function WebshopLogin(user,pass){
		var url = "http://twswebshop.trelleborg.com/login?ACTION=LOGIN&EUUID="+ user +"&EUPWD="+ pass;
		openPopup(url,740,575);
	}

	function confirmNewUser(usergroup, username, firstname, lastname, company, email){
		return confirm("Is this information correct?\n"+
						"Usergroup: "+ document.getElementById(usergroup)[document.getElementById(usergroup).selectedIndex].text +"\n"+
						"Username: "+ document.getElementById(username).value +"\n"+
						"Firstname: "+ document.getElementById(firstname).value +"\n"+
						"Lastname: "+ document.getElementById(lastname).value +"\n"+
						"Company: "+ document.getElementById(company).value +"\n"+
						"E-mail: "+ document.getElementById(email).value +"\n");
	}

	var selectedStylesheet;
	var normalText = document.styleSheets[2];
	var largeText = document.styleSheets[1];
	var extraLargeText = document.styleSheets[0];
	var arrCss = new Array(normalText,largeText,extraLargeText);	

	function toggleStylesheet(){
		if(document.styleSheets){
			if(selectedStylesheet > 0){
				if(arrCss[selectedStylesheet] == largeText){ // enable extra large
					set_cookie("stylesheet","2");
					normalText.disabled = true;
					largeText.disabled = true;
					extraLargeText.disabled = false;	
					selectedStylesheet = 2;
				} else if(arrCss[selectedStylesheet] == extraLargeText){ // enable normal
					set_cookie("stylesheet","0");
					normalText.disabled = false;
					largeText.disabled = true;
					extraLargeText.disabled = true;
					selectedStylesheet = 0;
				}			
			} else {	// enable large
				set_cookie("stylesheet","1");			
				normalText.disabled = true;
				largeText.disabled = false;
				extraLargeText.disabled = true;
				selectedStylesheet = 1;
			}
		}
	}

	function setStylesheet(index){
		if(document.styleSheets){
			if(arrCss[index] == normalText){ // enable normal
				set_cookie("stylesheet","0");
				normalText.disabled = false;
				largeText.disabled = true;
				extraLargeText.disabled = true;
				selectedStylesheet = 0;			
			} else  if(arrCss[index] == largeText){ // enable large
				set_cookie("stylesheet","1");			
				normalText.disabled = true;
				largeText.disabled = false;
				extraLargeText.disabled = true;
				selectedStylesheet = 1;
			} else if(arrCss[index] == extraLargeText){ // enable extra large
				set_cookie("stylesheet","2");
				normalText.disabled = true;
				largeText.disabled = true;
				extraLargeText.disabled = false;	
				selectedStylesheet = 2;
			}
		}
	}

	function languageSelector(){
		var languageSelector = document.getElementById("languageSelector");
		var languages = document.getElementById("languages");

		if(languages.style.display == "none" || languages.style.display == "" ){ // time to display
			languageSelector.style.border = "1px solid #d8d4bb";
			languages.style.display = "block";
		} else {
			languageSelector.style.border = "1px solid #ffffff";
			languages.style.display = "none";
		
		}
	}

	function openPopup(url,width,height){
		openPopup(url,width,height,'no')
	}

	function openPopup(url,width,height,resizable)
	{
		var features = "";
		features += 'height=' + height +",";
		features += 'width=' + width +",";
		features += "menubar=no,";
		features += "resizable="+ resizable +",";
		features += "scrollbars=auto,";
		features += "status=no,";
		features += "titlebar=no,";
		features += "toolbar=no";
		var openwin = window.open(url,null,features);
		openwin.focus();
	}

	function replaceAhrefIcon(str,classToLookFor,replacementText){
		var currentIndex = str.indexOf(classToLookFor);
		var i;
		var jumpToIndex = 0;
		while(currentIndex != -1){
			if(str[currentIndex+classToLookFor.length] != "."){ // to avoid it being an image
				str = str.substring(0,currentIndex) + str.substring(currentIndex + classToLookFor.length); // remove the class
				i = currentIndex;
				while(str.charAt(i) != "<"){	// find the beginning of the a-tag
					i--;
				}
				str = str.substring(0,i) + replacementText + str.substring(i); // insert replacementtext
				jumpToIndex = currentIndex+replacementText.length;
			} else {
				jumpToIndex = currentIndex;
			}
			currentIndex = str.indexOf(classToLookFor,jumpToIndex);	// find next
		}	
		
		return str;
	}

	function printPage(lang) 
	{
		var subpage = document.getElementById("subpage");
		if(!subpage){
			subpage = document.getElementById("subpage_full");
		}
		var breadCrumbTrail = document.getElementById("breadcrumbTrail");
		
		if(subpage) 
		{
			var body = subpage.innerHTML;	
			body = replaceAhrefIcon(body,"linkArrow","<img src=\""+ ROOTDIR +"Customer/gfx/dblarrow_blue_right.gif\" alt=\"\"/> ");

			body = body.replace(/<script[^>]*>(.|\n)*?<\/script>/gi,"");	// strip script tags
    
			var sStart = "";
			sStart += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
			sStart += "<html>\n";
			sStart += " <head>\n";
			sStart += "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
			sStart += "  <link rel=\"stylesheet\" type=\"text/css\" href=\""+ ROOTDIR +"Customer/css/text_large.css\"/>\n";
			sStart += "  <link rel=\"stylesheet\" type=\"text/css\" href=\""+ ROOTDIR +"Customer/css/stylesheet.css\"/>\n";
			sStart += "  <title>Trelleborg</title>\n";
			sStart += " </head>\n";
			sStart += " <body id=\"printbody\">\n";
			
			var sStop = "";
			sStop += " </body>\n";
			sStop += "</html>\n";

			var header = ""
			header += "<div style='clear:both; width: 100%;text-align:right'>\n";
			header += "	<img src='"+ ROOTDIR +"Customer/gfx/logo.gif' alt='Trelleborg' class='float_right'/>\n";
			header += " <input type='button' id='printButton' value='"+ (lang=="SV"? "Skriv ut" : "Print") +"' class='float_left' onclick='window.print();'/>\n";
			header += "</div>\n";
			if(breadCrumbTrail){
				header += "<div style='clear:both; width: 100%;text-align:center;padding-bottom:10px'>"+ breadCrumbTrail.innerHTML +"<br/><br/></div>";
			}		
			
			var w = window.open('','printWin','width=500,height=480,scrollbars=yes');
			wdoc = w.document;
			wdoc.open();
			wdoc.write(sStart);
			wdoc.write(header);
			wdoc.write(body);
			wdoc.writeln(sStop);
			wdoc.close();
		}
	} 
	
	function clickLink(element){
		list = element.getElementsByTagName("A");
		if(list.length > 0){
			location.href=list[0].href ;
		}
	}

	// Created by http://www.thebitmill.com/tools/password.html
	function genpwd(pwLength){
		if(pwLength == null)
			pwLength = 8;
		str = "";
		ch = new Array();

		for( i = 0; i < 33; i++ )
			ch[ ch.length ] = 0;
		for( ; i < 48; i++ )
			ch[ ch.length ] = 0;	// Punctuation
		for( ; i < 58; i++ )
			ch[ ch.length ] = 1; 	// Numbers
		for( ; i < 65; i++ )
			ch[ ch.length ] = 0;	// Punctuation
		for( ; i < 91; i++ )
			ch[ ch.length ] = 1;	// Uppercase
		for( ; i < 97; i++ )
			ch[ ch.length ] = 0;	// Punctuation
		for( ; i < 123; i++ )
			ch[ ch.length ] = 1;	// Lowercase
		for( ; i < 127; i++ )
			ch[ ch.length ] = 0;	// Punctuation
		ch[ ch.length ] = 0;

		count = 0;
		do
		{
			x = Math.floor( Math.random() * 128 );
			if( ch[ x ] == 1 )
			str += String.fromCharCode( x );
			count++;
		} while ( str.length < pwLength && count < 1024 );

		return str;
	}
	
	function copyText(str){
		window.clipboardData.setData('Text',str);
		alert("Text copied");
    }
    
    function changeTab(element,content){
		var tabs = document.getElementById("tabContainer").getElementsByTagName("DIV");
		for(var i=0;i<tabs.length;i++){
			if(tabs[i].className == "tab" || tabs[i].className == "activeTab"){
				tabs[i].className = "tab";
			}
		}
		
		element.className = "activeTab";
		document.getElementById(content).className = "activeTab";
    }
    
    function round(value, decimals){
		if(decimals > 0){
			return Math.round( value * decimals * 10 ) / ( decimals * 10 );
		} else {
			return Math.round( value );
		}
    }
    
    function isKeyPressed(e, key){
		// handle i.e. (window.event) and firefox (e)
		var eventInstance = window.event ? event : e;
		 
		// handle i.e. (charCode) and firefox (keyCode)
		var unicode = eventInstance.charCode ? eventInstance.charCode : eventInstance.keyCode;
		return (unicode == key ? true : false);
    }
    
   function sleep(time){
      time = time * 1000;
      var sleeping = true;
      var now = new Date();
      var alarm;
      var startingMSeconds = now.getTime();

      while(sleeping){
         alarm = new Date();
         alarmMSeconds = alarm.getTime();
         if(alarmMSeconds - startingMSeconds > time){ 
			sleeping = false; 
		}
      }      
  }    

	var selectedMarketSiteInput = "Defaultframework1_RightConsoleRegionContent_SelectedMarket";
	var selectMarketToolbar = "Defaultframework1_RightConsoleRegionContent_SelectMarketToolbar";
	var selectMarketButton = "Defaultframework1_RightConsoleRegionContent_GoToMarket";
	
	function SetSelectedMarketSite(site){
		var toolbar = document.getElementById(selectMarketToolbar);
		if(toolbar){
			toolbar.style.display = "block";
		}
		document.getElementById(selectedMarketSiteInput).value = site;
		document.getElementById(selectMarketButton).click();
	}    
	
	function changeSrc(element, newSrc){
		element.src = newSrc;
	}
	
	function toggleAccordionItem(headerItem){
		var contentItem = headerItem.nextSibling;
		if(contentItem.style.display == "none" || contentItem.style.display == ""){
			contentItem.style.display = "block";
			headerItem.className += " selected";
		} else {
			contentItem.style.display = "none";
			headerItem.className = "header";
		}
		return false;
	}
	
	$(document).ready(function(){
		alternateRows();
		
		selectedStylesheet = parseInt(get_cookie("stylesheet"));
		if(isNaN(selectedStylesheet)){
			set_cookie("stylesheet","0");
			selectedStylesheet = 0;
		} else {
			setStylesheet(selectedStylesheet);
		}	
		
		if(typeof(pageTracker) == "object"){
			$(".thickbutton").click(function(){
				pageTracker._trackPageview('/visit-subsite');
			});
			
			$("#printThisPageLink").click(function(){
				pageTracker._trackEvent('Print this page', 'Click', location.href);
			});
			
			$("#EmailThisPage .button").click(function(){
				pageTracker._trackEvent('Email this page', 'Click', location.href);
			});
		}
		
		// Trelleborg Flaggor
	if ($('#scrollBox').length > 0) {
		var country = function(){
			var speed = 400, arr, loong, sb, i = 0, nav, insNav = '', text, takeBack, timer,IETRUE = false,weAreAT = 0;
			sb = $('#scrollBox');
			nav = $('#scrollNav');
			text = $('#showNationText');
			if ($.browser.msie && parseInt($.browser.version) <= 6) {IETRUE = true;}
			arr = jQuery.makeArray(sb.children());
			loong = arr.length;
			if(loong > 1){
				insNav +='<a id="scrollNavPartArrowLeft"  href="#"></a>';
			}
			while (i < loong) {
				insNav += '<a class="scrollNavPart" at="'+i+'" newHref="#scrollPart' + i + '" href="#"></a>';
				$(arr[i]).attr({
					'id': 'scrollPart' + i
				});
				i += 1;
			}
			if(loong > 1){
				insNav += '<a id="scrollNavPartArrowRight"  href="#"></a>';
			}
			nav.html(insNav);
			
			$('#scrollNavPartArrowLeft').click(function(){
				if (weAreAT === 0) {
				
				}
				else {
					weAreAT -= 1;
					$('.scrollNavPart[at="' + weAreAT + '"]').trigger('click');
				}
				return false;
			});
			$('#scrollNavPartArrowRight').click(function(){
				if (weAreAT === (loong - 1)) {
				
				}
				else {
					weAreAT += 1;
					$('.scrollNavPart[at="' + weAreAT + '"]').trigger('click');
				}
				return false;
			});
			
			var takeAwayText = function(){
				text.fadeOut(speed);
			}
			$('.country').hover(function(){
				$(this).animate({
					'opacity': '0.3'
				}, 200);
				text.html($(this).children('img').attr('alt')).fadeIn(200);
				clearTimeout(timer);
			}, function(){
				$(this).animate({
					'opacity': '1'
				}, speed);
				timer = setTimeout(takeAwayText, 1000)
			});
			
			$('.scrollNavPart[newHref="#scrollPart0"]').css({
				'background-position': '0 -12px'
			});
			$('.scrollNavPart').click(function(e){
				if (IETRUE) {
					$('.scrollNavPart').css({
						'background-position': '0 1px'
					});
				}else{
					$('.scrollNavPart').css({
						'background-position': '0 0'
					});					
				}
				$('.scrollPart').fadeOut(200);
				weAreAT = parseInt($(this).attr('at'));
				takeBack = $(this).attr('newHref');
				$(this).css({
					'background-position': '0 -12px'
				}).addClass('selectedDOT');
				$(takeBack).fadeIn(speed);
				return false;
			});
			
		}
		country();
	}
	// Trelleborg Flaggor End
		
	});

