// GLOBAL VARIABLES ----------------------------------------------------------
var productImagesHref = "inc/090_getImage_";
var removeLineItem=null;

// HANDLE WINDOW.ONLOAD:s ----------------------------------------------------
if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
	window.onload = init;
}

var onLoads = new Array;

function init() {
	for (var i = 0; i < onLoads.length; i++) {
		if(onLoads[i]){
			eval(onLoads[i]);
		}
	}
}

function addOnLoad(func) {
	onLoads[onLoads.length] = func;
}

// REPLACE SUBMIT BUTTONS ----------------------------------------------------

addOnLoad('init_formSubmits()');

function init_formSubmits() {

	var allInputs = document.getElementsByTagName('INPUT');
	var allSubmits = new Array();
	var k = 0;
	for (var i = 0; i < allInputs.length; i++) {
		if (allInputs[i].type == 'submit') {
			allSubmits[k] = allInputs[i];
			k++;
		}
	}
	
	for (var i = 0; i < allSubmits.length; i++) {
		var submit = allSubmits[i];
		
		if (submit.className.indexOf('hidden') == -1){ // Do this only once.....
		
			var form = submit.form;
			
			var theLink       = document.createElement('A');
			theLink.href      = "#";
			theLink.className = "button " + submit.className;
			theLink.formId    = form.id;
			theLink.onclick   = submitForm;
			var theSpan       = document.createElement('SPAN');
			
			theSpan.appendChild(document.createTextNode(submit.value));
			theLink.appendChild(theSpan);
			
			submit.className += " hidden";
			submit.parentNode.appendChild(theLink);
			
			// Add invisble input-field
			if( submit.name ) {
				var invisTxt   = document.createElement('input');
				invisTxt.type  = 'hidden';
				invisTxt.name  = 'invisible_field';
				invisTxt.value = submit.name;
				submit.parentNode.appendChild(invisTxt);
			}
		}
	}
}

function submitForm() {
	var formId = "";
	if( this.formId != null && this.formId != "" )
		formId = this.formId;
	else if( this.getAttribute("formId") != null && this.getAttribute("formId") != "" )
		formId = this.getAttribute("formId");

	if( formId != "" )
		document.getElementById(formId).submit();
}

function sumbmitMembership (Scenario3No,checkout) {
	var passwordOK=validatePassword();
	var usernameOK=true;
	if(document.getElementById('RegForm_Username')){
		validateUsername();
	}
	var ifError=false;
	if(passwordOK&&usernameOK){
		if (document.getElementById('submitingAppliFormMessage')) {
			sendingMsgObj = document.getElementById('submitingAppliFormMessage');
			sendingMsgObj.style.display = "block";
		}
		if(Scenario3No){
			document.getElementById('Scenario3No').value="true";
		}
		if(checkout){
			document.getElementById('checkout').value="true";
		}
		document.getElementById('become_member').submit();
	}
	return false;
}

function removeSocialSecurityErrorMessages(){
	document.getElementById('errorDiv').style.display="none";
	document.getElementById('wrongSocialSecurityNumber').style.display="none";
}

function updateMembership (checkout) {
	var passwordOK=validatePassword();
	var usernameOK=validateUsername();
	if(passwordOK&&usernameOK){
		if (document.getElementById('submitingAppliFormMessage')) {
			sendingMsgObj = document.getElementById('submitingAppliFormMessage');
			sendingMsgObj.style.display = "block";
		}
		if(checkout){
			document.getElementById('checkout').value="true";
		}
		document.getElementById('Scenario3Yes').value="true";
		document.getElementById('become_member').submit();
	}
	return false;
}

// ------------------------------------------------------------
// Function used to add "on enter key" submition functionality
// when needed since all submit buttons are set to hidden
// ------------------------------------------------------------
function submitionHandler(formObj) {
	browserCheck = detectBrowser();
	
	if (browserCheck.isIE && window.event.keyCode == 13) {
		formObj.submit();
	}
}

// BROWSER DETECT ------------------------------------------------------------

	var userBrowser = detectBrowser();

	function detectBrowser() {
		var agent 	= navigator.userAgent.toLowerCase();
	
		this.isSafari	= (agent.indexOf('safari') != -1);
		this.isSafari2 = (this.isSafari && (parseFloat(agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).substring(0,agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).indexOf(' '))) >=  300));
		this.isOpera	= (agent.indexOf('opera') != -1);
		this.isNN		= (agent.indexOf('netscape') != -1);
		this.isFF		= (agent.indexOf('firefox') != -1);		
		this.isIE		= (agent.indexOf('msie') != -1);
		
		return this;
	}
	
//-----------------------------------------------------------------------
// FAQ  (Common FAQ-function in right column)
//-----------------------------------------------------------------------
addOnLoad('init_HELP_getAnswer()');
function init_HELP_getAnswer() {
	if( document.getElementById("help_menu") ) {
		document.getElementById("help_menu").onchange = HELP_getAnswer;
	}
}

function HELP_getAnswer() {
		if( document.getElementById("help_menu").options[document.getElementById("help_menu").options.selectedIndex].value != "#" ) {
			var HELP_dd = document.getElementById("help_menu");
			var href = HELP_dd.options[HELP_dd.options.selectedIndex].value;
			var myAjax = new Ajax.Updater("help_answer", href, {method: 'get', parameters: ""});
		}
}	




//---------------------------------------
// ACTIVATE PRINT BUTTON 
//---------------------------------------
addOnLoad('init_prinBtn()');
function init_prinBtn() {
	if( document.getElementById("printBtn") ) {
		document.getElementById("printBtn").onclick = printPage;
	}
}
function printPage() {
	
	if(document.getElementById('printBtn')
	   && document.getElementById('largeProductImage')
	   && document.getElementById('product_lnk'))
	{
	
		printButtonObj = document.getElementById('printBtn');
		prodImageObj   = document.getElementById('largeProductImage');
		//prodVariant    = prodImageObj.getAttribute('productUUID');
		prodLnkObj     = document.getElementById('product_lnk');

		// Set new print button href
		//printButtonObj.href = prodLnkObj.value + "&variantImage=" + prodImageObj.src + "&variantUUID=" + prodVariant;
		printButtonObj.href = prodLnkObj.value + "&variantImage=" + prodImageObj.src;
	}

	var winX = (screen.width-560) / 2;
	var winY = (screen.height-500) / 2;
	window.open(this.href,'printable','toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,copyhistory=0,width=560,height=500,left='+winX+',top='+winY);	
	return false;
}


//------------------------------------------------------
// FUNCTIONS FOR LIGHTBOX AND LITBOX 
// ---------------------------------------------------
function showSelectBoxes() {

	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
	
	objectElements = document.getElementsByTagName("object");
	for (i = 0; i != objectElements.length; i++) {
		objectElements[i].style.visibility = "visible";
	}
	
	embedElements = document.getElementsByTagName("embed");
	for (i = 0; i != embedElements.length; i++) {
		embedElements[i].style.visibility = "visible";
	}

}
//----------------------------------------------
//Sitemap RSS & ATOM link Litbox
//------------------------------------------------------
function feedsInformation(triggerObj, header ) {

	if(!document.getElementById("LitBox")) {
		litbox = new LITBox(triggerObj.href, {type:'window', overlay:true, height:270, width:450, resizable:true, opacity:1, header: header});
		litbox.focusFirstField();
		
	}
	return false;
}
//------------------------------------------------------
// Opens litbox for cookie information
// ---------------------------------------------------
function cookieInformationDialog(triggerObj, header) {

	if(!document.getElementById("LitBox")) {
		litbox = new LITBox(triggerObj.href, {type:'window', overlay:true, height:240, width:420, resizable:true, opacity:1, header: header});
		litbox.focusFirstField();
		
	}
	return false;
}
function init_cookieInfoTrigger() {
	if (document.getElementById('cookieInfoOpener')) {
		trigerObj = document.getElementById('cookieInfoOpener');
		trigerObj.onclick = function () {
			return cookieInformationDialog(this);
		}
	}
}
addOnLoad('init_cookieInfoTrigger()');
//------------------------------------------------------
// Opens litbox for requesting a new password
// ---------------------------------------------------
function requestNewPasswordDialog(triggerObj, header) {

	if(!document.getElementById("LitBox")) {
		litbox = new LITBox(triggerObj.href, {type:'window', overlay:true, height:320, width:420, resizable:true, opacity:1, header: header});
		litbox.focusFirstField();
	}
	return false;
}


//------------------------------------------------------
//Opens litbox for requesting a new password
//---------------------------------------------------
function viewPageContentDialog(triggerObj) {

	if(!document.getElementById("LitBox")) {
		litbox = new LITBox(triggerObj.href, {type:'window', overlay:true, height:320, width:420, resizable:true, opacity:1, header:''});
		litbox.focusFirstField();
	}
	return false;
}

//------------------------------------------------------
// Opens litbox to update user login details
// -----------------------------------------------------
function changeLoginDialog ( piplineUrl, header ) {

	//piplineUrl sould be the URL to pipline 'cc_ViewUser-UpdateLoginDialog'

	LITBox.prototype.closeLock = function(){
		this.close.style.display = "none";
		this.close.onclick = "";
		this.d.onclick = "";
	}

	litbox = new LITBox(piplineUrl, {type:'window', overlay:true, height:370, width:520, resizable:true, opacity:1, header: header});
	litbox.closeLock();
	litbox.focusFirstField();
	return false;
}

// ---------------------------------------------------
function sendUpdateNewLogin (buttonObj) {
	
	if (!buttonObj.getAttribute('pipeline')) {
		return;
	}
	
	emailVal        = document.getElementById('UpdateLoginForm_email').value;
	emailConfirmVal = document.getElementById('UpdateLoginForm_confirmEMail').value;
	passVal         = document.getElementById('UpdateLoginForm_newPassword').value;
	passConfirmVal  = document.getElementById('UpdateLoginForm_confirmNewPassword').value;

	qString = "UpdateLoginForm_email=" + emailVal + "&UpdateLoginForm_confirmEMail=" + emailConfirmVal + "&UpdateLoginForm_newPassword=" + passVal + "&UpdateLoginForm_confirmNewPassword=" + passConfirmVal

	var myAjax = new Ajax.Updater("update_new_login", buttonObj.getAttribute('pipeline') , {method: 'post', parameters: qString});
	
	showSubmitionLoader(buttonObj);
	return false;
}
//------------------------------------------------------
// Opens litbox width membership rules
// -----------------------------------------------------
function memdershipRulesDialog(triggerObj,title) {

	if(!document.getElementById("LitBox")) {		
		litbox = new LITBox(triggerObj.href, {type:'window', overlay:true, height:340, width:420, resizable:true, opacity:1, header: title});		
	}
	return false;
}

function memdershipAlreadyExisting(href,title) {

	if(!document.getElementById("LitBox")) {
		litbox = new LITBox(href, {type:'window', overlay:true, height:340, validation:true, width:420, resizable:true, opacity:1, header: title});
	}
	return false;
}

function renewCaptcha(objId, targetUrl) {

	targetObj = document.getElementById(objId);
	targetObj.src = targetUrl;
    return false;
}

// ---------------------------------------------------
function sendRequestNewPassword (buttonObj) {
	
	if (!buttonObj.getAttribute('pipeline')) {
		return;
	}
	
	queryString = "ForgotForm_Login=" + document.getElementById('forgot_username').value;

	var myAjax = new Ajax.Updater("request_new_password", buttonObj.getAttribute('pipeline') , {method: 'post', parameters: queryString});	
	showSubmitionLoader(buttonObj);
	return false;
}


function sendRequestNewPasswordFoundMember (pipeline) {
		
	if (!pipeline) {
		return;
	}
		
	queryString = "ForgotForm_Login=" + document.getElementById('forgot_username').value;
	queryString = queryString +"&forgot_username2="+document.getElementById('forgot_username2').value;
	queryString = queryString +"&j_captcha_response="+document.getElementById('j_captcha_response_new').value;
	
	var myAjax = new Ajax.Updater("request_new_password", pipeline , {method: 'post', parameters: queryString});	
	showSubmitionLoader(buttonObj);
	return false;
}

function elementShiftDisplay(elemIds) {

	// Check if argument is array
	if (elemIds.constructor == Array) {
	
		// Loop through element ids
		for (i = 0; i <= elemIds.length; i++) {
			if ( document.getElementById( elemIds[i] ) ) {
				elementObj = document.getElementById( elemIds[i] );
				
				// Shift element object display style
				if (elementObj.style.display == "block" || elementObj.style.display == "") {
					elementObj.style.display = "none";
				}
				else {
					elementObj.style.display = "block";
				}
			}
		}
	
	} // If argument is not a array
	else {
		if ( document.getElementById( elemIds ) ) {
			elementObj = document.getElementById( elemIds );
			
			// Shift element object display style
			if (elementObj.style.display == "block" || elementObj.style.display == "") {
				elementObj.style.display = "none";
			}
			else {
				elementObj.style.display = "block";
			}
		}
	}
	
	return false;
}
// ---------------------------------------------------
function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
	
	objectElements = document.getElementsByTagName("object");
	for (i = 0; i != objectElements.length; i++) {
		objectElements[i].style.visibility = "hidden";
	}
	
	embedElements = document.getElementsByTagName("embed");
	for (i = 0; i != embedElements.length; i++) {
		embedElements[i].style.visibility = "hidden";
	}	
	popupArticleID=document.getElementById('PopupArticleUUID');	
	if(popupArticleID){		
		flashobj=document.getElementById('flashobj_'+popupArticleID.value+'_popup')		
		flashemb=document.getElementById('flashemb_'+popupArticleID.value+'_popup')
		if(flashobj){
			flashobj.style.display="";
			flashobj.style.visibility="visible";
		}
		if(flashemb){
			flashemb.style.display="";
			flashemb.style.visibility="visible";
		}
	}
	

}

//----------------------------------------------------
// Function to update minicart
// ---------------------------------------------------
function updateMiniCart(){
	eventAddToChart = true;
	var divLeftBasket = document.getElementById("left_basket");

	var myAjax = new Ajax.Updater("left_basket", divLeftBasket.getAttribute('url') , {method: 'get', parameters: "", evalScripts: true});
}

eventAddToChart = false;
function productAddedNotice() {
	if ( eventAddToChart == true && document.getElementById('product_added_notice') ) {
		document.getElementById('product_added_notice').style.display = "block";
		window.setTimeout ( "hideProductAddedNotice()", 5000 );
	}
}
function hideProductAddedNotice () {
	if ( document.getElementById('product_added_notice') ) {
		document.getElementById('product_added_notice').style.display = "none";
		eventAddToChart = false;
		enableLink('buyButton','selectVariationsMessage(\'Du m�ste v�lja F&auml;rg och Storlek.\');','#');
	}
}
function updateTopCartLink(notExpand,ifGiftcard) {
	var topCartLinkObj = document.getElementById("basket_top");
	var giftcardParam=null;
	if(ifGiftcard){
		giftcardParam="true";
	}
	var myAjax = new Ajax.Updater("basket_top", topCartLinkObj.getAttribute('pipline') , {method: 'get', parameters: "addedToBasket=true&ifGiftcard="+giftcardParam+"", asynchronous: false});
	if(!notExpand){
		window.scrollTo(0,0);
		showElement('expandedMiniBasket');
		forceToBeAbove();
		switchClass('basket_top','expanded');
		Effect.SlideDown('basket_top', { duration: 0.1 });	
	}
}
//----------------------------------------------------
// Function to update minicart
// ---------------------------------------------------
function showSubmitionLoader(obj) {
	
	triggerObj = obj;
	if(obj.getAttribute('targetId')) {
		obj = document.getElementById( obj.getAttribute('targetId') );
		targetObj = obj;
		targetObj.innerHTML = "";
	}
	else {
		while ( obj.tagName != "FORM") {
			obj = obj.parentNode;
		}
		targetObj = obj.parentNode;
		obj.style.display = "none";
	}
	
	loaderObj = document.createElement('div');
	loaderObj.className = "lb_loading";
	targetObj.appendChild(loaderObj);
}

//----------------------------------------------------
// FLASH BUILD AND FLASH LOADER FACTORY CLASS
// ---------------------------------------------------
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;


function flashLoader() {
	
	// Properties
	this.flashloaderFile  = null;
	this.objectIdentifyer = null;
	this.loadFile         = null;
	this.loadUrl          = null;
	this.urlTarget        = null;
	this.locationHref     = "http://";
	
	// Methods
	this.render = render;
	
	// Outputs flash to js comunicating scripts for flashloader objects
	function render() {
		if (this.objectIdentifyer) {
		
		var hasReqestedVersion = DetectFlashVer(0, 0, 0);	
									
			if(hasReqestedVersion){	
				var opStr="";
				
				var flashDiv=document.getElementById(this.objectIdentifyer);
				//Startsidans översta kampanj
				if(document.getElementById(this.objectIdentifyer).parentNode.parentNode.id=='start_campaign'){
					flashDiv.style.height="339px";
					flashDiv.style.width="810px";
					flashDiv.style.marginLeft = "0";
				}
				//Startsidans högerkolumnen
				else if(document.getElementById(this.objectIdentifyer).parentNode.parentNode.id=='start_right_ad_container'){
					flashDiv.style.height="220px";
					flashDiv.style.width="315px";
					flashDiv.style.marginLeft = "0";
				}
				//Startsidans middle content area
				else if(document.getElementById(this.objectIdentifyer).parentNode.parentNode.className=="ContentArea"){
					flashDiv.style.height="220px";
					flashDiv.style.width="150px";
				}
								
				// Handle all the FSCommand messages in a Flash movie.
				opStr =  '<script language=\"JavaScript\"\>\n';
				opStr += 'function flPuff'+ this.objectIdentifyer +'_DoFSCommand(command, args) {\n';
				opStr += '  var containerObj = document.getElementById(\''+ this.objectIdentifyer +'\');\n';
				opStr += '  if (command == "setHeight" && args != "undefined") {\n';
				opStr += '    containerObj.style.height = parseInt(args).toString() + \'px\';\n';
				opStr += '  }\n';
				opStr += '  if (command == "setWidth" && args != "undefined") {\n';
				opStr += '    containerObj.style.width = parseInt(args).toString() + \'px\';\n';
				opStr += '  }\n';
				opStr += '  if (command == "locationHref") {\n';
				opStr += '     document.location.href = \''+ this.locationHref +'\';\n';
				opStr += '  }\n';			
				opStr += '}\n';
				opStr += '</script\>\n';
	
				// Hook for Internet Explorer.
				if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
					opStr += '<script language=\"VBScript\"\>\n';
					opStr += 'On Error Resume Next\n';
					opStr += 'Sub flPuff'+ this.objectIdentifyer +'_FSCommand(ByVal command, ByVal args)\n';
					opStr += '  Call flPuff'+ this.objectIdentifyer +'_DoFSCommand(command, args)\n';
					opStr += '}\n'
					opStr += 'End Sub\n';
					opStr += '</script\>\n';
				}

				document.write(opStr);
								
				var flashLoaderFile=decideFlashLoaderFile(this.loadFile,this.flashloaderFile);	
								
				var so = new SWFObject(flashLoaderFile, "flPuff"+this.objectIdentifyer, "100%", "100%", "0", "#FFFFFF");
				so.addParam("allowScriptAccess", "sameDomain");
				so.addParam("flashVars", "urlToGoTo="+ this.loadUrl +"&urlTarget="+ this.urlTarget +"&movieToPlay="+ this.loadFile);
				so.addParam("quality", "high");
				so.addParam("align", "middle");
				so.addParam("valign", "top");
				so.addParam("play", "true");
				so.addParam("loop", "true");
				so.addParam("wmode", "opaque");
				so.write(this.objectIdentifyer);
								
				if(document.getElementById("category_campaign")){
					enlargeFlashLoaderContainer('category_campaign',this.objectIdentifyer);
				}
				
				document.getElementById(this.objectIdentifyer).style.display = "block";
								
			}else{
				if(document.getElementById("country_locale")) {
					var c_locale = document.getElementById("country_locale").innerHTML;
					var str_flash = "";
					switch(c_locale) {
					case "SE":
						str_flash = '<div class="error" id="flash_error"><strong>DIN DATOR SAKNAR SENASTE FLASH PLAYER</strong><span>En del sidor best&aring;r av Flash, men din dator verkar inte ha Flash Player installerat.<br>F&ouml;r att ta del av stadium.se p&aring; b&auml;sta s&auml;tt rekommenderar vi att du installerar programmet genom att gratis ladda ner och installera det fr&aring;n <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">www.adobe.com</a></span></div>'
						break;
					case "FI":
						str_flash = '<div class="error" id="flash_error"><strong>Koneellasi ei ole uusinta Flash soitinta<br>Osa sivuista vaatii Flash soittimen, mutta koneellasi ei näytä olevan sitä asennettu. Jotta voit saada mahdollisimman paljon irti sivustosta stadium.fi, suosittelemme ilmaisen Flash soittimen latauksen ja asennuksen sivustolta www.adobe.com<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">www.adobe.com</a></span></div>';
						break;
					case "DK":
						str_flash = '<div class="error" id="flash_error"><strong>DIN COMPUTER HAR IKKE DEN SENESTE FLASH PLAYER<br> En del sider består af Flash, men det virker til at Flash Player ikke er installeret på din computer. For at tage del af stadium.dk på den bedste måde anbefaler vi, at du installerer programmet ved at downloade og installere det gratis fra www.adobe.com<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">www.adobe.com</a></span></div>';
						break;
					default:
						break;
							
					}
					document.write(str_flash);
				}
				
			}
		}
	} // end of render
}

function enlargeFlashLoaderContainer(flashContainerDiv,flashDivId){
	var flashContainerDiv=document.getElementById(flashContainerDiv);
	flashContainerDiv.style.height="100%";
	flashContainerDiv.style.width="810px";
					
	var flashDiv=document.getElementById(flashDivId);
	flashDiv.style.height="100%";
}

function decideFlashLoaderFile(flashFile,flashloaderFile){
	var filePath=getFilePath(flashloaderFile);
	var flashloaderFile;
	if(flashFile.indexOf("_as3")!=-1){
		flashloaderFile=filePath+"flashloader_as3.swf";
	}
	else{
		flashloaderFile=filePath+"flashloader.swf";
	}
	return flashloaderFile;
}

function getFilePath(file){
	var lastCatalogIndex=file.lastIndexOf("/");
	var filePath=file;
	if(lastCatalogIndex!=-1){
		filePath=file.substring(0,(lastCatalogIndex+1));
	}
	return filePath;
}

// ---------------------------------------------------
// Supportive function to trim whitespaces from string
// ---------------------------------------------------
String.prototype.fulltrim = function() {
	return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"").replace(/\s+/g," ");
}

// Flash Player Version Detection - Rev 1.5
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var str = '';
    if (isIE && isWin && !isOpera)
    {
  		str += '<object ';
  		for (var i in objAttrs)
  			str += i + '="' + objAttrs[i] + '" ';
  		for (var i in params)
  			str += '><param name="' + i + '" value="' + params[i] + '" /> ';
  		str += '></object>';
    } else {
  		str += '<embed ';
  		for (var i in embedAttrs)
  			str += i + '="' + embedAttrs[i] + '" ';
  		str += ' wmode=\'transparent\'> </embed>';
    }

    document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function switchClass(divId,newClass){
	if(document.getElementById(divId)){
		document.getElementById(divId).className=newClass;
	}
}

function changeTopCartLink(){
	if(document.getElementById('top_cart_link')){
		if(document.getElementById('top_cart_link').innerHTML>0){
			switchClass('basket_top','');
		}
		else{
			switchClass('basket_top','empty');
			
			setIE6StyleEmpty();
		}
	}
}

function disableLink(id){
	if(document.getElementById(id)){
		document.getElementById(id).onclick=null;
		document.getElementById(id).href="#";
		document.getElementById(id).style.cursor="default";
	}
}

function enableLink(id,onclick,href){
	if(document.getElementById(id)){
		document.getElementById(id).onclick=onclick;
		document.getElementById(id).href=href;
		document.getElementById(id).style.cursor="pointer";
	}
}

function showElement(elementId){
	if(document.getElementById(elementId)){
		document.getElementById(elementId).style.display="block";
	}
}

//Because display:block cause different behavior than nothing.
function elementVisible(elementId){	
	if(document.getElementById(elementId)){
		document.getElementById(elementId).style.display="";
	}
}

function hideElement(elementId){
	if(document.getElementById(elementId)){
		document.getElementById(elementId).style.display="none";
	}
}

/* hideElement was also in popcalendar.js used in "Köp presentkort", so also added this*/
function brsHideElement(elementId){
	if(document.getElementById(elementId)){
		document.getElementById(elementId).style.display="none";
	}
}

function emailCheck(inputId){
	var testresults;
	var str="";
	if(document.getElementById(inputId)){
		str=document.getElementById(inputId).value;
	}
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
		testresults=true;
	}
	else{
		testresults=false;
	}
	if(testresults){
		if(str.indexOf("@")==-1||str.indexOf(".")==-1){
			testresults=false;
		}
	}
	return (testresults);
}

function quickCheckOutEmail(){
	var ifCorrect = emailCheck("QuickCheckoutForm_Email");
	if(!ifCorrect){
		document.getElementById("wrongEmail").style.display="block";
	}
	return ifCorrect;
}

function validateFieldsFilledIn(fieldsArrayIDs){
	var allValuesFilledIn=true;
	var fieldId=null;
	for(var i=0;i<fieldsArrayIDs.length;i++){
		fieldId=fieldsArrayIDs[i];
		if(document.getElementById(fieldId)&&!document.getElementById(fieldId).value){
			allValuesFilledIn=false;
			if(fieldId=='QuickCheckoutForm_FirstName'){
				document.getElementById('missingFirstname').style.display="block";
			}
			if(fieldId=='QuickCheckoutForm_LastName'){
				document.getElementById('missingLastname').style.display="block";
			}
			if(fieldId=='QuickCheckoutForm_Email'){
				document.getElementById('missingEmail').style.display="block";
				document.getElementById("wrongEmail").style.display="none";
			}
			break;
		}
	}
	return allValuesFilledIn;
}

function ifIE(){
	var ifIE=false;
	if (navigator.appVersion.match(/\bMSIE\b/)){
		ifIE=true;
	}
	return ifIE;
}

function ifIE8(){
	var ifIE8=false;
	if (navigator.appVersion.match(/\bMSIE 8.0\b/)){
		ifIE8=true;
	}
	return ifIE8;
}

function ifSafari(){
	var ifSafari=false;
	if (navigator.appVersion.match(/\Safari\b/)){
		ifSafari=true;
	}
	return ifSafari;
}

function whichElementClickedOn(e){
	var targ;
	if(e.type=='click'){
	if (!e)
  	{
  		var e=window.event;
  	}
	if (e.target)
  	{
  		targ=e.target;
  	}
	else if (e.srcElement)
  	{
  		targ=e.srcElement;
  	}
	if (targ.nodeType==3) // defeat Safari bug
  	{
  		targ = targ.parentNode;
  	}
  	}
	return targ;
}

function loadStandardLitBox(href,title,height,width) {
	litbox = new LITBox(href, {type:'window', overlay:true, height:height, validation:false, width:width, resizable:true, opacity:1, header: title});
	return false;
}

function loadFlashCompatibleLitBox(href,title,height,width) {
	litbox = new LITBox(href, {type:'window', overlay:true, height:height, validation:false, width:width, resizable:true, opacity:1, header: title});
	var flashUrl=document.getElementById('flashUrl');
	if(flashUrl){
		flashUrl=document.getElementById('flashUrl').value;
	}
	if(flashUrl){
		document.getElementById('LB_content_id').innerHTML="<object width=\"480\" height=\"300\"><param name=\"movie\" value=\""+flashUrl+"\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"/is-bin/intershop.static/WFS/Stadium-SwedenB2C-Site/-/sv_SE/swf/flashloader.swf\" flashvars=\"urlToGoTo=false&urlTarget=false&movieToPlay="+flashUrl+"\" allowscriptaccess=\"sameDomain\" allowfullscreen=\"true\" width=\"480\" height=\"300\"></embed></object>";
	}
	return false;
}



function loadGimletCompatibleLitBox(href,title,height,width,baseDir,applicationdir,locale,flashContent_ID,bFullScreenButton) {
	
	if(DetectFlashVer(0,"10.0.0",0)) {
		litbox = new LITBox(href, {type:'window', overlay:true, height:height, validation:false, width:width, resizable:true, opacity:1, header: title, top:"121"});	
		loadGimletFlash(height,width,baseDir,applicationdir,locale,flashContent_ID,bFullScreenButton);
		//Göm start_campaign diven när litboxendiven
		if(document.getElementById('start_campaign'))
			document.getElementById('start_campaign').style.visibility = "hidden";
	}
	
	return false;
}

function showLitBox() {
	var href = document.getElementById("gimlet_href").value;
	var title = document.getElementById("gimlet_title").value;
	var height = document.getElementById("gimlet_height").value;
	var width = document.getElementById("gimlet_width").value;
	var baseDir = document.getElementById("gimlet_basedir").value;
	var applicationdir = document.getElementById("gimlet_appdir").value;
	var locale = document.getElementById("gimlet_locale").value;
	var flashContent_ID = document.getElementById("flashContent_ID").value;
	var fullscreenButton = document.getElementById("gimlet_fullscreen").value;
	
	
	if(DetectFlashVer(0,"10.0.0",0)) {
		litbox = new LITBox(href, {type:'window', overlay:true, height:height, validation:false, width:width, resizable:true, opacity:1, header: title, top:"121"});	
		loadGimletFlash(height,width,baseDir,applicationdir,locale,flashContent_ID, fullscreenButton);
		//Göm start_campaign diven när litboxendiven
		if(document.getElementById('start_campaign'))
			document.getElementById('start_campaign').style.visibility = "hidden";
	}	
}



function loadGimletFlash(height,width,baseDir,applicationdir,locale,flashContent_ID, bFullScreenButton) {
	var BASE_DIRECTORY = baseDir;
	var APPLICATION_PATH = applicationdir;
	var LOCALE = locale;
	
	bFullScreenButton == 1 ? bFullScreenButton = true : bFullScreenButton = false;
	

    <!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. -->
    var swfVersionStr = "10.0.0";
    <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
    var xiSwfUrlStr = baseDir+"/rcaplayer/playerProductInstall.swf";
    var flashvars = {base_dir:BASE_DIRECTORY, application_path:APPLICATION_PATH,  locale: LOCALE, primary_index: 0, secondary_index: -1, fullscreen_button: bFullScreenButton, close_button: false};
    var params = {};
    params.quality = "high";
    params.bgcolor = "#ffffff";
    params.allowscriptaccess = "sameDomain";
    params.allowfullscreen = "true";
    var attributes = {};
    attributes.id = "RCAPlayer";
    attributes.name = "RCAPlayer";
    attributes.align = "middle";
    swfobject.embedSWF(
    		baseDir+"/rcaplayer/rcaplayer.swf", flashContent_ID,
        width, height,
        swfVersionStr, xiSwfUrlStr,
        flashvars, params, attributes);
	<!-- JavaScript enabled so display the #flashContent_ID# div in case it is not replaced with a swf object. -->
	swfobject.createCSS(flashContent_ID, "text-align:left;");
	
	return false;
}



function getScrollY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

//The browser seem to not load the image from the beginning since it's included in a 
//display:none element from the beginning
function loadImage(imageUrl){
	if (document.images)
	{
  		var img = new Image();
  		img.src=imageUrl; 	
	}
}

//Make sure loading background image is loaded. It is set in a css attribute so can not check if its 
//loaded like with the animated gif that's is in a img-tag.	
function loadLoadingBackgroundImage(){
	var img=new Image();
	img.src=loadingImage;
}

function showLoading(yPosition){
	document.getElementById('laddningsSnurra').style.display='block';
	if(yPosition){
		document.getElementById('laddningsSnurra').style.top=yPosition+'px';
	}
	else{
		var yPosition=getScrollY()+199;
		//yPosition=yPosition+120;
		/*
		+199
		if(getScrollY()>0){
			if(getScrollY()<122){
				yPosition=yPosition-getScrollY();
			}
			else{
				yPosition=getScrollY();
			}
		}
		*/	
		document.getElementById('laddningsSnurra').style.top=yPosition+'px';
	}
	document.getElementById('snurraYttreDiv').style.zIndex='11000';
	if(!document.getElementById('laddningsSnurraBild').complete){
		loadImage(document.getElementById('laddningsSnurraBild').src);
	}
	//To make sure the gif animation runs
	if(ifIE()){
		refreshElement(document.getElementById('laddningsSnurra'));	
		refreshElement(document.getElementById('snurraYttreDiv'));
	}
}

//Needed for element including animateds gifs for IE
function refreshElement(element){
	element.innerHTML=element.innerHTML;
}

function showLoadingPayway(yPosition){
	var pElt	= document.getElementById('laddningsSnurra_p_payWay');
	var p2Elt	= document.getElementById('laddningsSnurra_p2_payWay');
	if( p2Elt ) {
		p2Elt.style.display='none';
	}
	if( pElt ) {
		pElt.style.display='block';
	}
	document.getElementById('laddningsSnurra_2').style.display='block';
	if(yPosition){
		document.getElementById('laddningsSnurra_2').style.top=yPosition+'px';
	}
	else{
		var yPosition=getScrollY();
		yPosition=yPosition+199;
		document.getElementById('laddningsSnurra_2').style.top=yPosition+'px';
	}
	document.getElementById('snurraYttreDiv_2').style.zIndex='11000';

	if(!document.getElementById('laddningsSnurraBild_2').complete){
		loadImage(document.getElementById('laddningsSnurraBild_2').src);
	}
	//To make sure the gif animation runs
	if(ifIE()){
		refreshElement(document.getElementById('laddningsSnurra_2'));
		refreshElement(document.getElementById('snurraYttreDiv_2'));
	}
}

function changeTextLoadingPayway( text ) {
	var pElt	= document.getElementById('laddningsSnurra_p_payWay');
	var p2Elt	= document.getElementById('laddningsSnurra_p2_payWay');
	if( pElt && p2Elt ) {
		pElt.style.display="none";
		p2Elt.style.display="inline";
		p2Elt.innerHTML = text;
	}
}


function showLoadingRemoveFromBasket(yPosition){
	document.getElementById('laddningsSnurra_3').style.display='block';
	if(yPosition){
		document.getElementById('laddningsSnurra_3').style.top=yPosition+'px';
	}
	else{
		var yPosition=getScrollY();
		yPosition=yPosition+199;
		document.getElementById('laddningsSnurra_3').style.top=yPosition+'px';
	}
	document.getElementById('snurraYttreDiv_3').style.zIndex='11000';
	document.getElementById('snurraYttreDiv_3').style.zIndex='11000';
	if(!document.getElementById('laddningsSnurraBild_3').complete){
		loadImage(document.getElementById('laddningsSnurraBild_3').src);
	}
	//To make sure the gif animation runs
	if(ifIE()){
		refreshElement(document.getElementById('laddningsSnurra_3'));
		refreshElement(document.getElementById('snurraYttreDiv_3'));
	}
}


function hideLoading(){
	hideElement('laddningsSnurra');
	document.getElementById('snurraYttreDiv').style.zIndex='-1';
	if(document.getElementById('snurraYttreDiv_2')){
		document.getElementById('snurraYttreDiv_2').style.zIndex='-1';
	}
}

function hideLoadingPayWay(){
	brsHideElement('laddningsSnurra_2');
	if(document.getElementById('snurraYttreDiv_2')){
		document.getElementById('snurraYttreDiv_2').style.zIndex='-1';
	}
	else if(document.getElementById('snurraYttreDiv')){
		document.getElementById('snurraYttreDiv').style.zIndex='-1';
	}
	if(document.getElementById('top_cart_link').innerHTML!='0'){
		updateTopCartLink(true);
	}
}


function hideLoadingRemoveFromBasket(){
	if(document.getElementById('snurraYttreDiv_3')){
		hideElement('laddningsSnurra_3');
		document.getElementById('snurraYttreDiv_3').style.zIndex='-1';
		document.getElementById('snurraYttreDiv_3').style.zIndex='-1';
		var nrOfProducts=document.getElementById("top_cart_link").innerHTML-1;
		if(nrOfProducts>0){
			updateTopCartLink(false);
		}
		else{
			updateTopCartLink(true);
			switchClass('basket_top','empty');
						
			setIE6StyleEmpty();
			
			minimizeMiniBasket();
		}
	}
}

function removeFromMinibasket(url,urlTotal,LineItemID,removedProductSKU,TotalQuantity){
	if(LineItemID==removeLineItem){
		return;
	}
	var ifCheckout="false";
	removeLineItem=LineItemID;
	if(document.getElementById("deliveryMethodWholeDiv")){
		if(ifStep3()){
			saveAddress();
		}
	}	
	var myAjax = new Ajax.Updater("removedFromMiniBasket", url , {method: 'post', parameters: "LineItemID="+LineItemID+"&removedProductSKU="+removedProductSKU+"&TotalQuantity="+TotalQuantity+"&ifCheckout="+ifCheckout+"", evalScripts: true, asynchronous: false});			
	
	if(location.href.indexOf("ViewRequisition-View")!=-1){
		setToEmpty();
		return;
	}	
	
	if(location.href.indexOf("Requisition")!=-1){
		ifCheckout="true";
	}
	
	if(ifCheckout=="true"&&(TotalQuantity-1)==1){
		document.getElementById("removeLink").href=document.getElementById('step1Path').innerHTML;
		window.location=document.getElementById('step1Path').innerHTML;
	}
	else{
		document.getElementById("removeLink").href=location.href;
	}
	
	if(document.getElementById("basket_confirm_total")){
		reloadRequisitionTotal( urlTotal );
	}
}

function checkIfCheckedWhenMultipleRadiobutton(radiobuttons){
	for(var i = 0; i < radiobuttons.length; i++) {
		if(radiobuttons[i].checked) {
			return true;
		}
	}
	return false;
}

function cutToLongText(text,maximumSize){
	if(text.length>maximumSize){
		var newText=text.substring(0,maximumSize);
		return newText;
	}
	else{
		return text;
	}
}

/* Used by new product detail page. */
function trim(text){
	var index=text.indexOf(" ");
	while(index>0){
		text=text.substring(0,index)+text.substring((index+1));
		index=text.indexOf(" ");
	}
	return text;
}

function replaceAll(replace,replaceWith){
	var index=text.indexOf(replace);
	while(index>0){
		text=text.substring(0,index)+replaceWith+text.substring((index+replace.length));
		index=text.indexOf(replace);
	}
	return text;
}
