
/*
Inserts the correct stylesheet according to browser.
*/
platform = ((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)>=4))? "ns" : "ie";

function CSS_reload(init) {
    if (init) {
        with (navigator) {
            if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
                document.pgW=innerWidth;
                document.pgH=innerHeight;
                onresize=CSS_reload;
            }
        }
    }
}
CSS_reload(true);


/*
call like this:
foo = open_window({yourparam:yourvalue});
*/
function open_window(obj){
	if(obj.url){
		var arr_param = new Array();
		var obj_default = {url:"", name:"win", left:0, top:0, width:400, height:300, titlebar:"no", menubar:"no", scrollbars:"auto", location:"no", directories:"no", resizable:"no", statusbar:"no", toolbar:"no"};
		// Centering functionality
		w = (obj.width)? obj.width : obj_default.width;
		h = (obj.height)? obj.height : obj_default.height;
		if(obj.left=="center") obj.left = parseInt((screen.availWidth - w)/2);
		if(obj.top=="center") obj.top = parseInt((screen.availHeight - h)/2);

		// Gathering window features
		for(var i in obj_default){
			if(i != "url" && i != "name")arr_param[arr_param.length] = (new String(obj[i])!="undefined")? i+"="+obj[i] : i+"="+obj_default[i];
		}

		winname = (new String(obj.name)!="undefined")? obj.name : obj_default.name;
		eval(winname+"=window.open('"+obj.url+"','"+winname+"','"+new String(arr_param)+"');");
		return winname;
	} else {
		return new String("you must specify an URL");
	}
}

function chop_product_name(str){
	document.write((str.length>20)?str.substr(0,20)+"..." : str);
}

function mix_chop_relation_name(str){
	document.write((str.length>20)?str.substr(0,20): str);
}

/*
<form name="deletefrombasket" action="showpage.asp?" onSubmit="return escapeFormValues(this);">
<input type="hidden" name="form_name" value="deletefrombasket">
<input type="hidden" name="cat_num">
<input type="hidden" name="price_grp">
<input type="hidden" name="nodeid" value="837635">
<input type="hidden" name="article_id" value="">
<input type="hidden" name="order_number" value="">
<input type="hidden" name="monthly" value="">
<input type="hidden" name="monthly_nothankstext" value="Detta är din utvalda film ur detta magasin. Vill du avbeställa den?">
</form>

*/


function deletefrombasket(order_number, price_grp, returnurl, article_id, nodeid) {
    //alert(String(document.deletefrombasket.nodeid.value).length );
    //alert(document.getElementsByTagName("body")[0].nodeid); 
    try {
        if (order_number == document.deletefrombasket.monthly.value) {
            var str = String(document.deletefrombasket.monthly_nothankstext.value);
            if (!confirm('' + str)) {
                order_number = '';
            }
        }
    } catch (E) {
        //alert('krash');
    }
    var popuptext = '';
    try {
        popuptext = String(document.deletefrombasket.productremove_text.value);
    } catch (e) {

    }
    if (order_number != '') {
        try {
            if (String(document.deletefrombasket.nodeid.value).length != 0 && document.getElementById('Small_Basket')) {
                var strurl = "/cds/showpage.asp";
                strurl += "?nodeid=" + String(document.deletefrombasket.nodeid.value) + "&form_name=deletefrombasket&cat_num=" + order_number + "&article_id=" + article_id + "&price_grp=" + price_grp;
            //    alert (strurl);
                updateDynamicContainer(strurl, 'Small_Basket', popuptext, true);
            } else {
                //alert('no valid container, not critical error');
                throw 'no valid container';
            }
        } catch (e) {
            // Dynamic update failed, call normal
            //alert(e);
            deletefrombasket_org(order_number, price_grp ,nodeid, article_id);
        }
    }
}

function deletefrombasket_org(cat_num, price_grp, returnurl, article_id) {
    // alert(document.getElementsByTagName("body")[0].getAttribute("nodeid"));
        if (cat_num != '') {
            document.deletefrombasket.nodeid.value = document.getElementsByTagName("body")[0].getAttribute("nodeid");
            document.deletefrombasket.cat_num.value = cat_num;
            document.deletefrombasket.price_grp.value = price_grp;
        if (document.deletefrombasket.order_number && document.deletefrombasket.article_id) {
            document.deletefrombasket.order_number.value = cat_num;
            document.deletefrombasket.article_id.value = article_id;
        }
        try {
            document.deletefrombasket.monthly.value = '';
            document.deletefrombasket.monthly_nothankstext.value = '';
        } catch (E) {
        		
        }		
            document.deletefrombasket.submit();
    //alert('Buggfixing ..  Will work soon');
    }
	
}


/*
* This function is called when user is buying a product, thereby placing a product
* in the shopping basket.
*/
function buyProduct(article_id, order_number, price_grp, nodeid,thetarget,popuptext,dynamic_nodeid){
    try {
		if (dynamic_nodeid.length != 0 && document.getElementById('Small_Basket')) {
			var strurl = "/cds/showpage.asp";
			strurl +="?nodeid="+dynamic_nodeid+"&origin_nodeid="+nodeid+"&form_name=buy_product_form&article_id="+article_id+"&order_number="+order_number+"&price_grp="+price_grp;
			//alert (strurl);
			updateDynamicContainer(strurl,'Small_Basket',popuptext,true );
		} else {
			//alert('no valid container, not critical error');
			throw 'no valid container';
		}                
	} catch(e){
		// Dynamic update failed, call normal
		//alert(e);
		buyProduct_org(article_id, order_number, price_grp, nodeid,thetarget);
	}
}

function buyProductSegmentationActivity(article_id, order_number, price_grp, nodeid, act_id, act_price,thetarget,popuptext,dynamic_nodeid){
    try {
		if (dynamic_nodeid.length != 0 && document.getElementById('Small_Basket')) {
			var strurl = "/cds/showpage.asp";
			strurl +="?nodeid="+dynamic_nodeid+"&origin_nodeid="+nodeid+"&form_name=buy_product_form&article_id="+article_id+"&order_number="+order_number+"&price_grp="+price_grp;
			//alert (strurl);
			updateDynamicContainer(strurl,'Small_Basket',popuptext,true );
		} else {
			//alert('no valid container, not critical error');
			throw 'no valid container';
		}                
	} catch(e){
		// Dynamic update failed, call normal
		//alert(e);
		buyProductSegmentationActivity_org(article_id, order_number, price_grp, nodeid, act_id, act_price,thetarget)
	}
}


function buyProduct_org(article_id, order_number, price_grp, nodeid,thetarget){
	//alert('DEBUG, buyProduct is activated');

//nodeid = '121503';
//thetarget = 'smallcart';

	var UseOpenWindow = false;

	try {
		if (opener.document.buy_product_form.article_id) {
			UseOpenWindow = true;
//			alert ('Ok to use ');
		} 
	} catch (E) {
//		alert ('crashed');
		UseOpenWindow = false;
		}
		
		
		
	if(UseOpenWindow){
//		alert ('Valid opener found');
		opener.document.buy_product_form.article_id.value = article_id;
		opener.document.buy_product_form.order_number.value = order_number;
		opener.document.buy_product_form.price_grp.value = price_grp;
		opener.document.buy_product_form.nodeid.value = nodeid;
		
		if (opener.document.buy_product_form.searchPhraseFullProductID.value != "any")
			if (opener.document.buy_product_form.searchPhraseFullProductID.value != article_id)
				opener.document.buy_product_form.searchPhrase.value = "";
		
		if (thetarget) {
			opener.document.buy_product_form.target = thetarget;
		}
		
		opener.document.buy_product_form.submit();

		window.close();
	} else {
//		alert ('NO Valid opener found');
		document.buy_product_form.article_id.value = article_id;
		document.buy_product_form.order_number.value = order_number;
		document.buy_product_form.price_grp.value = price_grp;
		document.buy_product_form.nodeid.value = nodeid;

		if (document.buy_product_form.searchPhraseFullProductID.value != "any")
			if (document.buy_product_form.searchPhraseFullProductID.value != article_id)
				document.buy_product_form.searchPhrase.value = "";

		if (thetarget) {
			document.buy_product_form.target = thetarget;
		}
		
	//	alert("article_id: " + document.buy_product_form.article_id.value);
	//	alert("order_id: " + document.buy_product_form.order_number.value);
	//	alert("price_grp: " + document.buy_product_form.price_grp.value);
	//	alert("nodeid: " + document.buy_product_form.nodeid.value);
		document.buy_product_form.submit();
	}
}




function buyProductSegmentationActivity_org(article_id, order_number, price_grp, nodeid, act_id, act_price,thetarget){
	var UseOpenWindow = false;

	try {
		if (opener.document.buy_product_form.article_id) {
			UseOpenWindow = true;
//			alert ('Ok to use ');
		} 
	} catch (E) {
//		alert ('crashed');
		UseOpenWindow = false;
		}
		
	if(UseOpenWindow){
		opener.document.buy_product_form.article_id.value = article_id;
		opener.document.buy_product_form.order_number.value = order_number;
		opener.document.buy_product_form.price_grp.value = price_grp;
		opener.document.buy_product_form.nodeid.value = nodeid;
		opener.document.buy_product_form.act_id.value = act_id;
		opener.document.buy_product_form.act_price.value = act_price;
		if (opener.document.buy_product_form.searchPhraseFullProductID.value != "any")
			if (opener.document.buy_product_form.searchPhraseFullProductID.value != article_id)
				opener.document.buy_product_form.searchPhrase.value = "";
		if (thetarget) {
			opener.document.buy_product_form.target = thetarget;
		}
		opener.document.buy_product_form.submit();
		window.close();
	
	} else {
		document.buy_product_form.article_id.value = article_id;
		document.buy_product_form.order_number.value = order_number;
		document.buy_product_form.price_grp.value = price_grp;
		document.buy_product_form.nodeid.value = nodeid;
		document.buy_product_form.act_id.value = act_id;
		document.buy_product_form.act_price.value = act_price;
		if (document.buy_product_form.searchPhraseFullProductID.value != "any")
			if (document.buy_product_form.searchPhraseFullProductID.value != article_id)
				document.buy_product_form.searchPhrase.value = "";
		if (thetarget) {
			document.buy_product_form.target = thetarget;
		}
		document.buy_product_form.submit();
	
	}
}

function linkto(adress){
//	alert('DEBUG, linkto is activated');
	if(opener){
		opener.location = adress;
		window.close();
	} else {
		window.location = adress;
	}
}

function becomeMember(msg,nodeid,articleid,maintype){
	
	if (nodeid =='') {
	alert(msg);
	} else {
		window.open('/cds/showpage.asp?form_name=product_readmore&nodeid='+nodeid+'&article_id='+articleid+'&maintype='+maintype,'becomeMember', 'resizable=yes,scrollbars=1,width=445,height=500');
	}
}




function product_readmore(article_id, magazine_id) {
	document.product_readmore.article_id.value = article_id;
	document.product_readmore.magazine_id.value = magazine_id;
	document.product_readmore.submit();
}

function search_this_type(thistype) {
	document.product_search_form_multi.search_criterias.value = thistype;
	document.product_search_form_multi.submit();
}



function mix_product_readmore(article_id, maintype, nodeid, relationtype) {
	document.product_readmore.article_id.value = article_id;
	document.product_readmore.maintype.value = maintype;
	document.product_readmore.nodeid.value = nodeid;
	document.product_readmore.relationtype.value = relationtype;
	document.product_readmore.submit();
}

function product_reject_monthly() {
	//alert('DEBUG, function product_reject_monthly is activated');
	document.product_reject_monthly.submit();
}

/*
* This function is called when user is deleting a single row in the "show previous order" view.
* It removes the line from the order and returns to the same page.
*/
function removeOrderrowFromUnhandledOrder(ord_num, cat_num, price_grp){
	//alert('DEBUG, removeRowFromPreviousOrder is activated');
	document.remove_orderline_form.ord_num.value = ord_num;
	document.remove_orderline_form.cat_num.value = cat_num;
	document.remove_orderline_form.price_grp.value = price_grp;
	//alert("ord_num: " + document.buy_product_form.ord_num.value);
	//alert("cat_num: " + document.buy_product_form.cat_num.value);
	//alert("price_grp " + document.buy_product_form.price_grp.value);
	document.remove_orderline_form.submit();
}

/*
* This function is called when user is deleting an entire order in the "show previous order" view.
* It removes the line from the order and returns to the same page.
*/
function removeWholeOrderFromUnhandledOrders(ord_num){
	//alert('DEBUG, removeRowFromPreviousOrder is activated');
	document.remove_order_form.ord_num.value = ord_num;
	//alert("ord_num: " + document.remove_orderline_form.ord_num.value);
	document.remove_order_form.submit();
}

/*
* This function is logging a user out of the system, afterwards returning to a specified page.
*/
function userLogout(){
	
	if (document.logout.yousure.value == '') {
		document.logout.yousure.value = 'Are you sure you want to logout?\nAll products you have in your basket will be removed.';
	}
	if (confirm(''+document.logout.yousure.value)) {	
		document.logout.yousure.value = '';
		document.logout.submit();
	}

}

/*
* This function replaces the character | in a string with <br>
*/
function fixAttributeList(attributeList) {
	var returnStr = new String(attributeList);
	document.write(returnStr.replace(/\|/g, "<br>"));
}

/*
* This function sets a formfield named page_chosen in a form named adv_product_search_form
* to the parameter value and then submits the form...
* it is used in search_result to tell which page to show next
*/

function getSearchPage(pageNumber,primid) {
    // Sätt page till rätt    
    document.getElementById(primid).page_chosen.value = pageNumber;
    //alert(document.getElementsByTagName('body')[0].id);
    // submita till dynamiskt....
    if (document.getElementById('DynamiskProductlista')) {
        try {    
                // plocka ut de imput element som finns
                var strurl = String(document.getElementById(primid).getAttribute('action'));
                //alert (document.getElementById('DynamiskProductlista').childNodes  );
                
                var children = document.getElementById(primid).childNodes ;
                for (var i=0;i < children.length ;i++) {
                    strurl += '&' +String(children[i].name) + '='+ encodeURI(children[i].value);        
                }
			    updateDynamicContainer(strurl,'DynamiskProductlista','',true);
	    } catch(e){
	        // Fel krashar allt
	    }
    } else {
	    document.getElementById(primid).submit();
    }                
}

/*
* This function sets a formfield named sort_by in a form named adv_product_search_form
* to the parameter value and then submits the form...
* it is used in search_result to tell which to sort by
*/
function sortSearchPage(sortBy,primid) {

        document.getElementById(primid).page_chosen.value = 1;
		document.getElementById(primid).sort_by.value = sortBy;
		//document.getElementById(primid).submit();

    //alert(document.getElementsByTagName('body')[0].id);
    // submita till dynamiskt....
    if (document.getElementById('DynamiskProductlista')) {
        try {    
                // plocka ut de imput element som finns
                var strurl = String(document.getElementById(primid).getAttribute('action'));
                //alert (document.getElementById('DynamiskProductlista').childNodes  );
                
                var children = document.getElementById(primid).childNodes ;
                for (var i=0;i < children.length ;i++) {
                    strurl += '&' +String(children[i].name) + '='+ encodeURI(children[i].value);        
                }
			    updateDynamicContainer(strurl,'DynamiskProductlista','',true );
	    } catch(e){
	        // Fel krashar allt
	    }
    } else {
	    document.getElementById(primid).submit();
    }                





}

/*
* This function turn on and off pictures
*/
function setPictureOnOffANDHowManyToShow(picturewidth,howmany,primid) {
//    alert (document.getElementById(primid).sort_by.value);
//alert(picturewidth);
		if (picturewidth != null) document.getElementById(primid).picturewidth.value = picturewidth;
		
//		alert(document.getElementById(primid).picturewidth.value);
		if (howmany != null) {
		    document.getElementById(primid).howmany.value = howmany;
		    document.getElementById(primid).page_chosen.value = 1;
        }
//		document.getElementById(primid).submit();


    //alert(document.getElementsByTagName('body')[0].id);
    // submita till dynamiskt....
    if (document.getElementById('DynamiskProductlista')) {
        try {    
                // plocka ut de imput element som finns
                var strurl = String(document.getElementById(primid).getAttribute('action'));
                //alert (document.getElementById('DynamiskProductlista').childNodes  );
                
                var children = document.getElementById(primid).childNodes ;
                for (var i=0;i < children.length ;i++) {
                    strurl += '&' +String(children[i].name) + '='+ encodeURI(children[i].value);        
                }
			    updateDynamicContainer(strurl,'DynamiskProductlista','',true);
	    } catch(e){
	        // Fel krashar allt
	    }
    } else {
	    document.getElementById(primid).submit();
    }                

		
		
		
		
}



/*

* This function sets a formfield named first_letter in a form named first_letter_product_search_form

* to the parameter value and then submits the form...

* it is used in search_result to tell which letter to search for

*/
function getFirstLetterSearchPage(firstLetter) {
	if(platform=="ie" && document.forms["first_letter_product_search_form"].tagName !="FORM") {
	// This is an Array of forms
		document.forms["first_letter_product_search_form"][0].first_letter.value = escape(firstLetter);
		document.forms["first_letter_product_search_form"][0].submit();
	}
	else if(platform=="ie") {
		document.first_letter_product_search_form.first_letter.value = escape(firstLetter);
		document.first_letter_product_search_form.submit();
	} else {
		document.forms["first_letter_product_search_form"].first_letter.value = escape(firstLetter);
		document.forms["first_letter_product_search_form"].submit();
		
	}
}

/*
* This function converts the prices from a float value to a string with two decimals. The function
* assumes that the format is either; 29, 29.0 or 29.00. It does not shorten the decimals (e.g.
* 29.000 to 29.00).
*/
function fixDecimals(floatPrice) {
	var strResult = floatPrice.toString();
	var re = /\./;
	if (strResult.match(re)) {
		strResult = strResult.replace(/\./, ",");
		if (strResult.substr(strResult.length-2, 1) == ",") {
			strResult += "0";
		}
	} else {
		strResult += ",00";
	}
	return strResult;
}

/******************************************************************************
This function runs through all the fields in a form, and run escape() on the
values to support special characters. Showpage.asp then runs unescape() on the
values in getRequestData() function.
******************************************************************************/
function escapeFormValues(theForm) {
		doc = theForm;
		// There is an exception with login form fields that is handled here
		if(doc.username_view && doc.username && doc.password_view && doc.password) {
			if(doc.username_view.value != doc.username.value) {
				doc.username.value = doc.username_view.value;
			}
			if(doc.password_view.value != doc.password.value) {
				doc.password.value = doc.password_view.value;
			}
		}
		// We need to unescape all these first in case the user presses back in
		// the browser after we have escaped them... unescaped values will not be
		// affected.
		unEscapeFormValues(doc);
		for(i=0; i<doc.elements.length; i++) {
			// alert(doc.elements[i].type);
			if (doc.elements[i].type != "select-one") {
				// Checking to see if fields are input or textarea tags. If yes, do not escape
				// values, since these are copied to hidden values in mastertemplate.xsl.
				//if ((doc.elements[i].type != "text") || (doc.elements[i].type != "textarea")) {
				if (doc.elements[i].type != "text" && doc.elements[i].type != "textarea") {
					//alert("type = " + doc.elements[i].type);
					// This is taking care of all types except select boxes.
					doc.elements[i].value = escape(doc.elements[i].value);
				} else {
					//alert("This is a text or textarea field");
				}
			} else {
				// This is taking care only of select boxes.
				// eval("document." + theForm.name + "." + theForm.elements[i].name + "[" + theForm.elements[i].selectedIndex + "].value = escape(document." + theForm.name + "." + theForm.elements[i].name + "[" + theForm.elements[i].selectedIndex + "].value)");
			}
		}
		return true;
}
function unEscapeFormValues(theForm) {
	for(i=0; i<doc.elements.length; i++) {
		if (doc.elements[i].type != "select-one") {
			// Checking to see if fields are input or textarea tags. If yes, do not escape
			// values, since these are copied to hidden values in mastertemplate.xsl.
			//if ((doc.elements[i].type != "text") || (doc.elements[i].type != "textarea")) {
			if (doc.elements[i].type != "text" && doc.elements[i].type != "textarea") {
				//alert("type = " + doc.elements[i].type);
				// This is taking care of all types except select boxes.
				doc.elements[i].value = unescape(doc.elements[i].value);
			} else {
				//alert("This is a text or textarea field");
			}
		} else {
			// This is taking care only of select boxes.
			// eval("document." + theForm.name + "." + theForm.elements[i].name + "[" + theForm.elements[i].selectedIndex + "].value = unescape(document." + theForm.name + "." + theForm.elements[i].name + "[" + theForm.elements[i].selectedIndex + "].value)");
		}
	}
}

/******************************************************************************
This function changes a single basket_row's pricegroup to a new pricegroup (usually a new price).
The function is called from basket_large.
Setting parameters in the form and submits the form.

parameters:

	basket_row_number: 	the row that should be updated.
	price_grp: 			the new price_grp the current should be changed into.

******************************************************************************/
function update_basket(basket_row_number, price_group) {
	//alert('DEBUG, update_basket is activated');
	//alert('DEBUG, incomming parameters in update_basket are basket_row_number ' + basket_row_number);
	//alert('DEBUG, incomming parameters in update_basket are price_group ' + price_group);
	document.updatebasket.basket_row_number.value = basket_row_number;
	document.updatebasket.price_grp.value = price_group;
	document.updatebasket.submit();
}


function accept_gift(basket_row_number) {
	document.acceptgift.basket_row_number.value = basket_row_number;
	document.acceptgift.submit();
}
/*****************************************************************************
These are a capture for the ENTER key in the event model, to ensure that
escapeFormValues are run when the user presses ENTER on a field.
******************************************************************************/
function netscapeKeyPress(e) {
    if (e.which == 13)
        return true;
}

function microsoftKeyPress() {
    if (window.event.keyCode == 13)
        return true;
}
if (navigator.appName == 'Netscape' && (parseInt(navigator.appVersion) < 5)) {
    window.captureEvents(Event.KEYPRESS);
    window.onKeyPress = netscapeKeyPress;
}

// This function launches the help window displayed to the user.
function openHelpWindow(urlNodeId) {
	doit = window.open(urlNodeId,'Help','directories=0,left=' + ((screen.width-320)/2) + ',top=' + ((screen.height-360)/2) + ',location=0,toolbar=0,scrollbars=yes,menubar=no,width=320,height=360,resizable=no');
}

// This function launches the chat window.
function openchat() {
	psUser= "" + document.chat_login.user_name.value;
	doit = window.open('/chat/chatloader.asp?nick='+psUser,'MixChat','toolbar=no,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0 width=682,height=441');
}


/******************************************************************************
This function is used for launching the popup of extra article images
******************************************************************************/

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 350;
defaultHeight = 490;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	function popImage(picture_url,imageTitle){
		var imageURL = fixScreenShotName(picture_url);
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(500,100);');
		writeln('width=500-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');
		writeln('window.innerWidth=document.images["img"].width;');writeln('window.innerHeight=document.images["img"].height;}}');
		writeln('function doTitle(){document.title="' + imageTitle + '";}');writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()" onclick="self.close()">');
		writeln('<img name="" src='+imageURL+' style="display:block"></body></html>');
		close();
	}
}

/******************************************************************************
This function is used for launching the popup of extra article images
******************************************************************************/
function fixScreenShotName(input) {
	var strResult = input.toString();
	var re = /\./;
	if (strResult.match(re)) {
		strResult = strResult.replace(/\./, ".");
	}
	return strResult;
	
	//alert('hej');
}



function openTreeViewSitemap(forcedTopNodeid, forcedSelectedNodeid, nodeid){

			//no warning popup, remove this line and the user get a stupid popup
			window.event.cancelBubble = true;
			window.open('/cds/showpage.asp?nodeid='+nodeid+'&forectopnodeid='+forcedTopNodeid+'&forcedSelectedNodeid='+forcedSelectedNodeid+'&sitemapmode=popup#'+forcedSelectedNodeid, 'overview', 'resizable=no,scrollbars=1,width=400,height=600');
		}
		





function setFormCookie(nodeid,formname,formfield) {
	var strCookieName = 'forms_'+formname;
	var strCookie = getCookie(strCookieName);		
	var theObject = eval('document.'+formname+'.'+formfield+'_view.value');
	//alert(nodeid);
	//alert(formname);
	//alert(formfield);
	//alert(theObject);
	//alert(strCookie);
	

	
	
	if (strCookie != null) {
		
		var arrCookies = strCookie.split('|');

		if (arrCookies.length < 3) {
			//alert ('arrCookies.length < 3 = true :' +arrCookies.length);
			strCookie = String(formname + '|' + formfield + '|'+ String(theObject));
		} else {
			//alert ('arrCookies.length < 3 = false :' +arrCookies.length);
			var testflagga = '';
			for(var i = 0;i<arrCookies.length;i=i+3) {
				if (arrCookies[i] == formname && arrCookies[i+1] == formfield) {
					arrCookies[i+2] = String(theObject);
					testflagga = '1';	
					break	
				}
				
			}
			var x = i;
			//alert ('testflagga : ' + testflagga);
			if (testflagga == '') {
				arrCookies[x] = formname;
				arrCookies[x+1] = formfield;
				arrCookies[x+2] = String(theObject);
				x = x + 3;
			}		
			
			strCookie = arrCookies.join('|');
			
			
		}			
	
	} else {
		strCookie = String(formname + '|' + formfield + '|'+ String(theObject));
	}
	//strCookie = '';
	setCookie(strCookieName, strCookie);
	
}

function setFormCookie_select(nodeid,formname,formfield) {
	var strCookieName = 'forms_'+formname;
	var strCookie = getCookie(strCookieName);		
	var theObject = eval('document.'+formname+'.'+formfield+'.value');
	//alert(nodeid);
	//alert(formname);
	//alert(formfield);
	//alert(theObject);
	//alert(strCookie);
	

	
	
	if (strCookie != null) {
		
		var arrCookies = strCookie.split('|');

		if (arrCookies.length < 3) {
			//alert ('arrCookies.length < 3 = true :' +arrCookies.length);
			strCookie = String(formname + '|' + formfield + '|'+ String(theObject));
		} else {
			//alert ('arrCookies.length < 3 = false :' +arrCookies.length);
			var testflagga = '';
			for(var i = 0;i<arrCookies.length;i=i+3) {
				if (arrCookies[i] == formname && arrCookies[i+1] == formfield) {
					arrCookies[i+2] = String(theObject);
					testflagga = '1';	
					break	
				}
				
			}
			var x = i;
			//alert ('testflagga : ' + testflagga);
			if (testflagga == '') {
				arrCookies[x] = formname;
				arrCookies[x+1] = formfield;
				arrCookies[x+2] = String(theObject);
				x = x + 3;
			}		
			
			strCookie = arrCookies.join('|');
			
			
		}			
	
	} else {
		strCookie = String(formname + '|' + formfield + '|'+ String(theObject));
	}
	//strCookie = '';
	setCookie(strCookieName, strCookie);
	
}


function getformcookie(nodeid,formname,formfield) {
	var strCookieName = 'forms_'+formname;
	var strCookie = getCookie(strCookieName);

	if (strCookie != null) {
		var arrCookies = strCookie.split('|');
		var strFieldValue = '';
		for(var i = 0;i<arrCookies.length;i=i+3) {
			if (arrCookies[i] == formname && arrCookies[i+1] == formfield) {
				strFieldValue = String(arrCookies[i+2]);
				testflagga = '1';	
				break	
			}
			
		}

	 	var ViewField = eval('document.'+formname+'.'+formfield+'_view');
	 	var HiddenField = eval('document.'+formname+'.'+formfield);

  		ViewField.value = strFieldValue;
  		HiddenField.value = strFieldValue;

	}

}

function getformcookie_select(nodeid,formname,formfield) {
	var strCookieName = 'forms_'+formname;
	var strCookie = getCookie(strCookieName);

	//alert(strCookie);

	if (strCookie != null) {
		var arrCookies = strCookie.split('|');
		var strFieldValue = '';
		for(var i = 0;i<arrCookies.length;i=i+3) {
			if (arrCookies[i] == formname && arrCookies[i+1] == formfield) {
				strFieldValue = String(arrCookies[i+2]);
				testflagga = '1';	
				break	
			}
			
		}

	 	var HiddenField = eval('document.'+formname+'.'+formfield);
		//alert(HiddenField);
  		HiddenField.value = strFieldValue;

	}

}

	function popTrailerFlash(trailer_url,trailer_name,trailer_width,trailer_height){
        
	    var optWind="'scrollbars=no,width="+trailer_width+",height="+parseInt(trailer_height,10)+"'";
		trailerWin=window.open('about:blank','',optWind);

		with (trailerWin.document){
		    writeln('<html><head><title>Trailer</title><style>body{margin:0px;}</style>');
		    writeln('<sc'+'ript>');
		    writeln('document.title="' + trailer_name + '";');
//		    writeln('alert(window.opener.parent.name);');
		    writeln('if (document.images) window.opener.parent.name=\'homeenter_mainwindow\';');
		    writeln('</sc'+'ript></head>');
            writeln('<body>');

			writeln('<div id="container">');
			writeln('<div id="mainContent">');
				writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" name="fc" width="'+trailer_width+'" height="'+trailer_height+'" id="fc" title="homeplayer">');
					writeln('<param name="movie" value="/online/videoplayer/homeplayer.swf"/>');
					writeln('<param name="quality" value="high"/>');
					writeln('<param name="allowScriptAccess" value="always">');
					writeln('<param name="flashvars" value="catnr='+trailer_url+'"/>');
			        writeln('<embed src="/online/videoplayer/homeplayer.swf" width="'+trailer_width+'" height="'+trailer_height+'" quality="high" type="application/x-shockwave-flash" flashvars="catnr='+trailer_url+'" allowScriptAccess="always"/>');
				writeln('</object>');
			writeln('</div>');
		    writeln('</div>');

		    writeln('</body>');
		    writeln('</html>');
            close();
    	}
    }

    	function popTrailerFlashFanbay(ean,trailer_name,trailer_width,trailer_height,packshot,releasedate){

	    var optWind="'scrollbars=no,width="+trailer_width+",height="+parseInt(trailer_height,10)+"'";
		trailerWin=window.open('about:blank','',optWind);


		with (trailerWin.document){
		    writeln('<html><head><title>Trailer</title><style>body{margin:0px;}</style>');
		    writeln('<sc'+'ript>');
		    writeln('document.title="' + trailer_name + '";');
//		    writeln('alert(window.opener.parent.name);');
		    writeln('if (document.images) window.opener.parent.name=\'homeenter_mainwindow\';');
		    writeln('</sc'+'ript></head>');
            writeln('<body>');

            writeln('<sc'+'ript type="text/javascript" id="fb_embed_script">');
          


	        writeln('var ean = "'+ean+'"; ');

            writeln('var packshot = "'+packshot+'";');
	        writeln('var release_date = "'+releasedate+'";');

	        writeln('// <![CDATA[');
	        writeln('var qs = "ean="+escape(ean);');

	        writeln('if (window.release_date) qs = qs + "&release_date="+escape(release_date);');
	        writeln('if (window.packshot) qs = qs + "&packshot="+escape(packshot);');

	        writeln('var url = "http://ws.fanbay.se/embed/6/";');

//		    writeln('alert(url);');
//		    writeln('alert(qs);');
	        writeln('var fb_script_tag = document.createElement("script");fb_script_tag.setAttribute("type", "text/javascript");fb_script_tag.setAttribute("src", url + "?" + qs);var fb_embed_script = document.getElementById("fb_embed_script");fb_embed_script.parentNode.insertBefore(fb_script_tag, fb_embed_script);');

	        writeln('//]]>');


            writeln('</sc'+'ript>');

		    writeln('</body>');
		    writeln('</html>');

            close();
        }

    }
    


	function popTrailer(trailer_url,trailer_name,trailer_width,trailer_height,catnr,article_id,nodeid,banner_height){

        if (article_id == '' && catnr == '') banner_height = 0;
	    var optWind="'scrollbars=no,width="+trailer_width+",height="+(parseInt(trailer_height,10)+parseInt(banner_height,10))+"'";
	    
		trailerWin=window.open('about:blank','',optWind);

		with (trailerWin.document){
		    writeln('<html><head><title>Trailer</title><style>body{margin:0px;}</style>');
		    writeln('<sc'+'ript>');
		    writeln('document.title="' + trailer_name + '";');
//		    writeln('alert(window.opener.parent.name);');
		    writeln('if (document.images) window.opener.parent.name=\'homeenter_mainwindow\';');
		    writeln('</sc'+'ript></head>');
            writeln('<frameset rows="'+trailer_height+',' + banner_height + '" border="1" frameborder="1" framespacing="0" framecolor="#000000">');
            writeln('<frame src="'+trailer_url+'" name="Movie" scrolling="no" noresize>');
            //writeln('<frame src="/cds/showpage.asp?form_name=product_readmore&nodeid='+nodeid+'&catnr='+catnr+'&maintype=1" name="BuyField" scrolling="no" noresize>');
            //writeln('<frame src="/cds/showpage.asp?form_name=product_search_form&nodeid='+nodeid+'&search_field='+catnr+'" name="BuyField" scrolling="no" noresize>');
            if (article_id != '') {
            writeln('<frame src="/cds/showpage.asp?form_name=product_search_form&nodeid='+nodeid+'&search_field='+article_id+'" name="BuyField" scrolling="no" noresize>');
            } else if (catnr != '') {
            writeln('<frame src="/cds/showpage.asp?form_name=product_search_form&nodeid='+nodeid+'&search_field='+catnr+'" name="BuyField" scrolling="no" noresize>');
            }
		    writeln('</frameset>');
		    writeln('</html>');
            close();
    	}


    }

    
    function popWmpTrailer(trailer_url,trailer_name,trailer_width,trailer_height,catnr,article_id,nodeid,banner_height){
        
        if (article_id == '' && catnr == '') banner_height = 0;
        
	    var optWind="'scrollbars=no,width="+trailer_width+",height="+(parseInt(trailer_height,10)+parseInt(banner_height,10))+"'";
	    
		trailerWin=window.open('about:blank','',optWind);
		
		with (trailerWin.document){
		    writeln('<html><head><title>Trailer</title><style>body{margin:0px;}</style>');
		    writeln('<sc'+'ript>');
		    writeln('document.title="' + trailer_name + '";');
		    writeln('if (document.images) window.opener.parent.name=\'homeenter_mainwindow\';');
		    writeln('</sc'+'ript></head>');
		    writeln("<br /><br />");
		    writeln("<center>");
            writeln("<OBJECT ID='MediaPlayer' WIDTH='" + (trailer_width - banner_height) + "' HEIGHT='" + (trailer_height - banner_height) + "' classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95'");
            writeln("codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'");
            writeln("standby='Loading Microsoft Windows Media Player components...'");
            writeln("type='application/x-oleobject'>");
            writeln("<PARAM NAME='FileName' VALUE='" + trailer_url + "'>");
            writeln("<PARAM NAME='ShowControls' VALUE='1'>");
            writeln("<PARAM NAME='ShowDisplay' VALUE='0'>");
            writeln("<PARAM NAME='ShowStatusBar' VALUE='1'>");
            writeln("<PARAM NAME='AutoSize' VALUE='1'>");
            writeln("<Embed type='application/x-mplayer2'");
            writeln("pluginspage='http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx/'");
            writeln("filename='" + trailer_url + "'");
            writeln("AllowChangeDisplaySize='1'");
            writeln("AllowSize='1'");
            writeln("AutoSize='1'");
            writeln("DisplaySize='4'");
            writeln("src='" + trailer_url + "'");
            writeln("Name='MediaPlayer'");
            writeln("ShowControls='1'");
            writeln("ShowDisplay='0'");
            writeln("ShowStatusBar='1'");
            writeln("width='" + (trailer_width - banner_height) + "'");
            writeln("height='" + (trailer_height - banner_height) + "'>");
            writeln("</embed><br />");            
            writeln("</OBJECT><br />");
		    writeln("</center>");
		    writeln("<br /><sc"+"ript language='javascript'>");		    
		    writeln("if (navigator.appName.indexOf('Microsoft') != '0'){");
		    writeln("var cookieEnabled=(navigator.cookieEnabled)? true : false;");		    
		    writeln("if (typeof navigator.cookieEnabled=='undefined' && !cookieEnabled){ ");		    
		    writeln("document.cookie='testcookie';");
		    writeln("cookieEnabled=(document.cookie.indexOf('testcookie')!=-1)? true : false }");
		    writeln("if (cookieEnabled) {");
		    writeln("   if ( getCookie('trailercookie') != 'true' ) {");
            writeln("           alert('Warning: You are using ' + navigator.appName + ' ' + parseFloat(navigator.appVersion) + '. \\n\\rIf you have Windows Media PLayer 11. \\n\\rThen your moviescale could be out of focus.');");		                    
		    writeln("           setCookie('trailercookie','true','1');");
		    writeln("   }");
		    writeln("}");
		    writeln("}");		    
            writeln("function getCookie(name) {");
              writeln("var dc = document.cookie;");
              writeln("var prefix = name + '=';");
              writeln("var begin = dc.indexOf('; ' + prefix);");
              writeln("if (begin == -1) {");
                writeln("begin = dc.indexOf(prefix);");
                writeln("if (begin != 0) return null;");
              writeln("} else");
                writeln("begin += 2;");
              writeln("var end = document.cookie.indexOf(';', begin);");
              writeln("if (end == -1)");
                writeln("end = dc.length;");
              writeln("return unescape(dc.substring(begin + prefix.length, end));");
            writeln("}");            
            writeln("function setCookie(c_name,value,expiredays)");
            writeln("{");
                writeln("var exdate=new Date()");
                writeln("exdate.setDate(exdate.getDate()+expiredays)");
                writeln("document.cookie=c_name+ '=' +escape(value)+");
                writeln("((expiredays==null) ? '' : ';expires='+exdate.toGMTString())");
            writeln("}   ");            
		    writeln("</sc"+"ript><br />");
            if (article_id != '') {
            writeln('<iframe frameborder="0" width="100%" align="bottom" src="/cds/showpage.asp?form_name=product_search_form&nodeid='+nodeid+'&search_field='+article_id+'" name="BuyField" scrolling="no" noresize>');
            } else if (catnr != '') {
            writeln('<iframe frameborder="0" width="100%" align="bottom" src="/cds/showpage.asp?form_name=product_search_form&nodeid='+nodeid+'&search_field='+catnr+'" name="BuyField" scrolling="no" noresize>');
            }
		    writeln('</html>');
            close();
    	}//End With   
    }//End Function
   

    function updateDynamicContainer(URLtouse,IDtoupdate,poputext,bExecuteScripts){
        if (bExecuteScripts != false) bExecuteScripts = true;

        try { 
            URLtouse += "&redirectbasketadd=no&Now=" + new Date() ;
           
            var xmlhttp=false; //Clear our fetching variable 

            
            if(window.ActiveXObject) { 
                    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object… 
    //              alert('IE ok!!');
                } else {
                    xmlhttp = new XMLHttpRequest() ;
    //              alert('Firefox ok!!');
            }

         
    
            if (!xmlhttp && typeof xmlhttprequest!='undefined') { 

                xmlhttp = new xmlhttprequest(); //If we were able to get a working active x object, start an xmlhttprequest 
            } 

    //    alert(URLtouse);    
        //alert(IDtoupdate);
        
            xmlhttp.open("GET", URLtouse, true); //Open the file through GET 
            
            xmlhttp.setRequestHeader("Cache-Control", "no-cache");
            xmlhttp.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');
      
            xmlhttp.onreadystatechange=function() { 
            var content = "";
            if (xmlhttp.readyState==4) { //Check if it is ready to recieve data 
            
                var content = xmlhttp.responseText; //The content data which has been retrieved *** 
  
                //alert(IDtoupdate);
                //alert(document.getElementById(IDtoupdate).innerHTML);
                if(content){ //Make sure there is something in the content variable 
                    //content = URLtouse;
                        content =  String(content);
                       
                        //alert(content);
                        
                        var re = /<div class=\"textbox\">(\W*?)<div class=\"errortext\">(.*?)<\/div>(\W*?)<\/div>(\W*?)<img src=\"\/img\/gx_blank\.gif\" width=\"1\" height=\"5\">/;

		                var ErrorRegexp = new RegExp(re);
		                var arr = ErrorRegexp.exec(content);
		                //var ErrorText = String(content.match(re));
		                 var ErrorText = null;
		                if (arr) ErrorText = arr[0];
		                content = content.replace(re,'');
                        document.getElementById(IDtoupdate).innerHTML = content; //Change the inner content of your div to the newly retrieved content **** 
                        
                    try {
                    if (ErrorText) {
                        // Städa lite mer .. kan säkert göras snyggare .. men jag hatar regex		                
		                var re_start = /<div class=\"textbox\">(\W*?)<div class=\"errortext\">/;
		                var re_stop = /<\/div>(\W*?)<\/div>(\W*?)<img src=\"\/img\/gx_blank\.gif\" width=\"1\" height=\"5\">/;
		                ErrorText = ErrorText.replace(re_start,'');
		                ErrorText = ErrorText.replace(re_stop,'');
                        ErrorText = popuptext(ErrorText,'OverLib_error');
                        //return new overlib(ErrorText,CENTERPOPUP, STICKY,EXCLUSIVE,CAPTION, ' ',CLOSECOLOR ,'white',CLOSETEXT, 'X', BGCOLOR, 'red',VAUTO,HAUTO);   
                        return new overlib(ErrorText,CENTERPOPUP, STICKY,CLOSECLICK,EXCLUSIVE,FULLHTML,CENTEROFFSET ,-50,-50,NOCLOSE);   
                        return nd();                 
                        
                    }  else if (poputext) {
                    
                            poputext = popuptext(poputext,'OverLib');
                            overlib(poputext,CENTERPOPUP,TIMEOUT ,3000,FULLHTML,CENTEROFFSET ,-50,-50);   
                            nd();                 
                        }
                    } catch (e) {}
                } 
        try {
            if (bExecuteScripts) {
                var ob = document.getElementById(IDtoupdate).getElementsByTagName("script");
                for(var i=0; i<ob.length; i++) {
                    if(ob[i].text!=null) {
                        if (window.execScript) {
                          //  alert('IE\n\n'+ ob[i].text);
                            window.execScript(ob[i].text);
                        } else {
                          //  alert('NOT IE\n\n'+ ob[i].text);
                            eval(ob[i].text);
           
                        }
                    }
                } 
              //  alert ('All scriptes executed');
            }
        } catch(e) {
            // Tracking failed
           // alert ('Error execiting scripts: ' + e + ', description: ' +  e.description);
            }
         } 
        } 
            xmlhttp.send(null) //Nullify the xmlhttprequest 
            return; 
        } catch (e) { 
            throw e;      
        } 
   
    } 
// http://test2.homeenter.com/cds/showpage.asp?nodeid=408118&debug=11358
    
    function popuptext(strText,stylesheet) {
        var str = "";

		str +="<div class=\"" + stylesheet + "\">";
			str += strText;
			str +="</div>";
		return str;
		
    }
    
    
		function ReverseDisplay(sElement){
				oElement = document.getElementById(sElement);
				if (oElement.style.display != 'none'){
					oElement.style.display = 'none';
				}else{
					oElement.style.display = '';
				}
		}

