
/*
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, org_pagename, origin_nodeid) {
    //alert(String(document.deletefrombasket.nodeid.value).length );
    //alert(document.getElementsByTagName("body")[0].nodeid);

    //alert(order_number + price_grp + returnurl + article_id + nodeid + org_pagename);

    //org_pagename = escape(org_pagename);
    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 {
            var wichBasket = false;
            if (document.getElementById('Small_Basket')) {
                wichBasket = "Small_Basket";
            } else if (document.getElementById('Large_Basket')) {
                wichBasket = "Large_Basket";
            }
            if (String(document.deletefrombasket.nodeid.value).length != 0 && wichBasket) {
                    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 + "&org_pagename=" + org_pagename + "&origin_nodeid=" + origin_nodeid;
                    //    alert (strurl);
                    updateDynamicContainer(strurl, wichBasket, 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 submitSecondPageSearch(f) {

       
    if (document.getElementById('DynamiskSearchResult')) {

        var strUrl = getFormValues(f);
         
//        alert(strUrl);
//        alert(document.product_search_form.elements);
        upDateDynamicSearch(f);
    } else {
    f.submit();
    }

}


function upDateDynamicSearch(f) {
    var strUrl = getFormValues(f);
    try {
        updateDynamicContainer(strUrl, 'DynamiskSearchResult', '', true);
    } catch (e) {
    //alert(e);
    }
    return false;
}

function getFormValues(fobj,url) {

    if (url) {
        var str = url;
    } else {
        var str = String(fobj.action);
    }

    
    var valueArr = null;
    var val = "";
    var cmd = "";

    if (str.indexOf('?') == -1) {
        str += '?';
    } else {
        str += '&';
    }
    
    for (var i = 0; i < fobj.elements.length; i++) {
        switch (fobj.elements[i].type) {

            case "text":
                str += fobj.elements[i].name +
                     "=" + escape(fobj.elements[i].value) + "&";

                break;
            case "hidden":
                if (fobj.elements[i].name == 'searchParameters') {
                    var oSearchParameters = document.product_search_form;
                    if (oSearchParameters) {
                        for (var y = 0; y < oSearchParameters.elements.length; y++) {
                            if (oSearchParameters.elements[y].name == 'searchParameters') {
                                var oOptions = oSearchParameters.elements[y];
                                for (var z = 0; z < oOptions.options.length; z++) {
                                    if (oOptions.options[z].value == fobj.elements[i].value) {
                                        oSearchParameters.elements[y].selectedIndex = z;
                                        oSearchParameters.elements[y].focus();
                                        oSearchParameters.elements[y].blur();
                                    }
                                }

                            }
                        }
                    }
                }

                str += fobj.elements[i].name +

                     "=" + escape(fobj.elements[i].value) + "&";

                break;

            case "select-one":
                str += fobj.elements[i].name +
                    "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
                break;

            case "checkbox":
                if (fobj.elements[i].checked)
                    str += fobj.elements[i].name +"=" + escape(fobj.elements[i].value) + "&";

                break;

            default:
                break;
        }

    }
    str = str.substr(0, (str.length - 1));
    return String(str);

}

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();
    }
	
}


/*
* 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, key, org_pagename, origin_nodeid ){
    try {

        var siteCatBuyId = escape(key);
        var wichBasket = false;
        var dynContainer;
        if (document.getElementById('Small_Basket') || parent.window.document.getElementById('Small_Basket')) {
            wichBasket = "Small_Basket";
            if (document.getElementById('Small_Basket'))
                dynContainer = document.getElementById('Small_Basket');
            else
                dynContainer = parent.window.document.getElementById('Small_Basket');
        } else if (document.getElementById('Large_Basket') || parent.window.document.getElementById('Large_Basket')) {
            wichBasket = "Large_Basket";
            if (document.getElementById('Large_Basket'))
                dynContainer = document.getElementById('Large_Basket');
            else
                dynContainer = parent.window.document.getElementById('Large_Basket');
        }
        var dynamic_nodeid = dynContainer.getAttribute('dyn_node');
        if (dynamic_nodeid.length != 0 && wichBasket) {
            if (popuptext == "" || popuptext == null) {
                if (document.buy_product_form.product_added_text.value) {
                    popuptext = document.buy_product_form.product_added_text.value;
                }
                
            }
            var strurl = "/cds/showpage.asp";
            if (document.buy_product_form.searchPhraseFullProductID.value != "any")
                if (document.buy_product_form.searchPhraseFullProductID.value != article_id)
                    document.buy_product_form.searchPhrase.value = "";

                strurl += "?nodeid=" + dynamic_nodeid + "&origin_nodeid=" + nodeid + "&form_name=buy_product_form&article_id=" + article_id + "&order_number=" + order_number + "&price_grp=" + price_grp + "&searchPhrase=" + String(document.buy_product_form.searchPhrase.value + "&siteCatBuyId=" + siteCatBuyId + "&org_pagename=" + org_pagename + "&origin_nodeid=" + origin_nodeid);
			//alert (strurl);
                updateDynamicContainer(strurl, wichBasket, 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, siteCatBuyId);
	}
}


function buyProductMultiple(article_id, order_number, price_grp, nodeid, thetarget, popuptext, dynamic_nodeid, key, org_pagename, origin_nodeid) {
    try {

        var siteCatBuyId = escape(key);
        var wichBasket = false;
        var dynContainer;
        if (document.getElementById('Small_Basket') || parent.window.document.getElementById('Small_Basket')) {
            wichBasket = "Small_Basket";
            if (document.getElementById('Small_Basket'))
                dynContainer = document.getElementById('Small_Basket');
            else
                dynContainer = parent.window.document.getElementById('Small_Basket');
        } else if (document.getElementById('Large_Basket') || parent.window.document.getElementById('Large_Basket')) {
            wichBasket = "Large_Basket";
            if (document.getElementById('Large_Basket'))
                dynContainer = document.getElementById('Large_Basket');
            else
                dynContainer = parent.window.document.getElementById('Large_Basket');
        }
        var dynamic_nodeid = dynContainer.getAttribute('dyn_node');
        /*if (document.getElementById('Small_Basket')) {
        wichBasket = "Small_Basket";
        } else if (document.getElementById('Large_Basket')) {
        wichBasket = "Large_Basket";
        }*/
        if (dynamic_nodeid.length != 0 && wichBasket) {
            if (popuptext == "" || popuptext == null) {
                if (document.buy_product_form.product_added_text.value) {
                    popuptext = document.buy_product_form.product_added_text.value;
                }

            }
            var strurl = "/cds/showpage.asp";
            if (document.buy_product_form.searchPhraseFullProductID.value != "any")
                if (document.buy_product_form.searchPhraseFullProductID.value != article_id)
                    document.buy_product_form.searchPhrase.value = "";

            strurl += "?nodeid=" + dynamic_nodeid + "&origin_nodeid=" + nodeid + "&form_name=buy_product_form&article_id=" + article_id + "&order_number=" + order_number + "&price_grp=" + price_grp + "&searchPhrase=" + String(document.buy_product_form.searchPhrase.value + "&siteCatBuyId=" + siteCatBuyId + "&org_pagename=" + org_pagename + "&origin_nodeid=" + origin_nodeid);
            //alert (strurl);
            updateDynamicContainer(strurl, wichBasket, popuptext, true);
        } else {
            //alert('no valid container, not critical error');
            throw 'no valid container';
        }
    } catch (e) {
        // Dynamic update failed, call normal
        //alert(e);

        buyProductMultiple_org(article_id, order_number, price_grp, nodeid, thetarget, siteCatBuyId);
    }
}


function buyProductSegmentationActivity(article_id, order_number, price_grp, nodeid, act_id, act_price, thetarget, popuptext, dynamic_nodeid, key, org_pagename, origin_nodeid) {
	try {
		var siteCatBuyId = escape(key);
        var wichBasket = false;
        var dynContainer;
        if (document.getElementById('Small_Basket') || parent.window.document.getElementById('Small_Basket')) {
            wichBasket = "Small_Basket";
            if (document.getElementById('Small_Basket'))
                dynContainer = document.getElementById('Small_Basket');
            else
                dynContainer = parent.window.document.getElementById('Small_Basket');
        } else if (document.getElementById('Large_Basket') || parent.window.document.getElementById('Large_Basket')) {
            wichBasket = "Large_Basket";
            if (document.getElementById('Large_Basket'))
                dynContainer = document.getElementById('Large_Basket');
            else
                dynContainer = parent.window.document.getElementById('Large_Basket');
        }
		var dynamic_nodeid = dynContainer.getAttribute('dyn_node');
		if (dynamic_nodeid.length != 0 && wichBasket) {
			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 + "&siteCatBuyId=" + siteCatBuyId + "&org_pagename=" + org_pagename + "&origin_nodeid=" + origin_nodeid;
			updateDynamicContainer(strurl, wichBasket, 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, siteCatBuyId)
	}
}


function buyProduct_org(article_id, order_number, price_grp, nodeid, thetarget, siteCatBuyIdKey) {
	//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;
		opener.document.buy_product_form.siteCatBuyId.value = siteCatBuyIdKey;
		
		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;
		document.buy_product_form.siteCatBuyId.value = siteCatBuyIdKey;

		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 buyProductMultiple_org(article_id, order_number, price_grp, nodeid, thetarget, siteCatBuyIdKey) {
    //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;
        opener.document.buy_product_form.siteCatBuyId.value = siteCatBuyIdKey;

        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;
        document.buy_product_form.siteCatBuyId.value = siteCatBuyIdKey;

        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, key){
	var UseOpenWindow = false;
	var siteCatBuyId = escape(key);
	
	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;
		opener.document.buy_product_form.siteCatBuyId.value = siteCatBuyId;
		
		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;
		document.buy_product_form.siteCatBuyId.value = siteCatBuyId;
		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 changeBackground(id, active_css, inavctive_css) {

try {
    if (document.getElementById(id).value != '') 
        document.getElementById(id).className = active_css;
    else 
        document.getElementById(id).className = inavctive_css;

} catch (e) { }

}


function changeBackgroundFocus(id, active_css, inavctive_css) {
try {
    document.getElementById(id).className = inavctive_css;
    } catch(e) {}

}


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 if (document.getElementById('DynamiskSearchResult')) {
	    try {
	        upDateDynamicSearch(document.getElementById(primid));
	    } 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) {
    var 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 (var 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 (var i = 0; i < theForm.elements.length; i++) {
        if (theForm.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 (theForm.elements[i].type != "text" && theForm.elements[i].type != "textarea") {
				//alert("type = " + doc.elements[i].type);
				// This is taking care of all types except select boxes.
                theForm.elements[i].value = unescape(theForm.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, org_pagename, origin_nodeid) {
	//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);
/*
<form name="updatebasket" action="showpage.asp?"
onSubmit="return escapeFormValues(this);">
<input type="hidden" name="form_name" value="updatebasket">
<input type="hidden" name="price_grp">
<input type="hidden" name="basket_row_number">
<input type="hidden" name="nodeid" value="69295"></form>
<input type="hidden" name="dyn_nodeid" value="900888"></form>
*/
    document.updatebasket.basket_row_number.value = basket_row_number;
    document.updatebasket.price_grp.value = price_group;
	try {
	    var wichBasket = false;
	    if (document.getElementById('Small_Basket')) {
	        wichBasket = "Small_Basket";
	    } else if (document.getElementById('Large_Basket')) {
	        wichBasket = "Large_Basket";
	    }
	    if (String(document.updatebasket.nodeid.value).length != 0 && wichBasket) {
	        var strurl = "/cds/showpage.asp";
	        strurl += "?nodeid=" + String(document.updatebasket.dyn_nodeid.value) + "&form_name=updatebasket&basket_row_number=" + basket_row_number + "&price_grp=" + price_group + "&org_pagename=" + org_pagename + "&origin_nodeid=" + origin_nodeid;
	        updateDynamicContainer(strurl, wichBasket, false, true);
	    } else {
	        //alert('no valid container, not critical error');
	        throw 'no valid container';
	    }
	} catch (e) {
	    // Dynamic update failed, call normal
	    //alert(e);
	    document.updatebasket.submit();
	}
}
/*
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="69295">
<input type="hidden" name="article_id" value="">
<input type="hidden" name="order_number" value=""><
input type="hidden" name="monthly" value="39165">
<input type="hidden" name="monthly_nothankstext" value="Detta är din utvalda film ur detta magasin. Vill du avbeställa den?">
<input type="hidden" name="productremove_text" value="En produkt togs bort från din kundvagn"></form>
*/


function accept_gift(basket_row_number, org_pagename, origin_nodeid) {
	document.acceptgift.basket_row_number.value = basket_row_number;
	document.acceptgift.submit();
	try {
	    var wichBasket = false;
	    if (document.getElementById('Small_Basket')) {
	        wichBasket = "Small_Basket";
	    } else if (document.getElementById('Large_Basket')) {
	        wichBasket = "Large_Basket";
	    }
	    if (String(document.acceptgift.nodeid.value).length != 0 && wichBasket) {
	        var strurl = "/cds/showpage.asp";
	        strurl += "?nodeid=" + String(document.acceptgift.dyn_nodeid.value) + "&form_name=acceptgift&basket_row_number=" + basket_row_number + "&org_pagename=" + org_pagename + "&origin_nodeid=" + origin_nodeid;
	        updateDynamicContainer(strurl, wichBasket, false, true);
	    } else {
	        //alert('no valid container, not critical error');
	        throw 'no valid container';
	    }
	} catch (e) {
	    // Dynamic update failed, call normal
	    //alert(e);
	    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);
	if (document.getElementById(formfield).type == 'checkbox') {
	    var theObject = 'false';
	    if (document.getElementById(formfield).checked)
	        var theObject = 'true';
	} else {
	    //var theObject = eval('document.getElementById(' + formfield + ').value');
	var theObject = eval('document.getElementById(\'' + formfield + '\').value');
//	var theObject = document.getElementById(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));
	}
		
	setCookie(strCookieName, strCookie);
	
}

function setFormCookie_select(nodeid, formname, formfield) {
	var strCookieName = 'forms_'+formname;
	var strCookie = getCookie(strCookieName);
	var theObject = eval('document.getElementById(' + formfield + ').selectedIndex');
	//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_obsolete(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]);
				break	
			}
			
		}

	 	var ViewField = eval('document.'+formname+'.'+formfield+'_view');
	 	var HiddenField = eval('document.'+formname+'.'+formfield);

  		ViewField.value = strFieldValue;
  		HiddenField.value = strFieldValue;

	}

}

function getformcookie(nodeid, formname, formfield) {
    try {

            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]);
                        break;
                    }

                }

                if (document.getElementById(formfield).type == 'checkbox') {
                    if (strFieldValue == 'true') 
                        document.getElementById(formfield).checked = true;
                    
                } else {
                    var HiddenField = eval('document.getElementById(\'' + formfield + '\')');
                    var ViewField = eval('document.forms[\'' + formname + '\'].elements [\'' + HiddenField.name + '_view' + '\']');
                    ViewField.value = strFieldValue;
                    HiddenField.value = strFieldValue;
                }
            }

        } catch (e) {
        
    }
}

/*
function getformcookie(nodeid, formname, formfield) {
    try {
        apa++;
		var strCookieName = 'forms_' + formname;
		var strCookie = getCookie(strCookieName);
		//alert(strCookie + " " + runFunc)
		if (apa > 20)
		    clearTimeout(t);
		if (strCookie != null && runFunc) {
			if (document.getElementById(formfield)) {
				
				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]);
						break;
					}
				}
				if (i < arrCookies.length) {
					if (document.getElementById(formfield).type == 'checkbox') {
						if (strFieldValue == 'true')
							document.getElementById(formfield).checked = true;
						if (strFieldValue != document.getElementById(formfield).checked.toString())
							t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
						else
						    clearTimeout(t);
						clearTimeout(t);
					} else {
						var HiddenField = eval('document.getElementById(\'' + formfield + '\')');
						var ViewField = eval('document.forms[\'' + formname + '\'].elements [\'' + HiddenField.name + '_view' + '\']');
						ViewField.value = strFieldValue;
						HiddenField.value = strFieldValue;
						if (ViewField.value != strFieldValue || HiddenField.value != strFieldValue)
							t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
						else
						    clearTimeout(t);
						clearTimeout(t);
					}
				} else {
					t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
				}
			} else {
				t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
			}
		} else {
			t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
		}
	} catch (e) {
    }
}*/

/*
function getformcookie(nodeid, formname, formfield) {
    try {
            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]);
                        break;
                    }

                }

                if (document.getElementById(formfield)) {
                    clearTimeout(t);
					if (document.getElementById(formfield).type == 'checkbox') {
						if (strFieldValue == 'true')
							document.getElementById(formfield).checked = true;
						if (strFieldValue.value != document.getElementById(formfield).checked)
							 t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
					} else {
						var HiddenField = eval('document.getElementById(\'' + formfield + '\')');
						var ViewField = eval('document.forms[\'' + formname + '\'].elements [\'' + HiddenField.name + '_view' + '\']');
if (formfield = '64150' && ViewField.name == 'intro_ssn_view')
	alert(ViewField.name + ' ' + ViewField.value + ' ' + strFieldValue)
	//alert(document.getElementById(HiddenField).name + ' ' + document.getElementById(formfield).value + ' ' + strFieldValue)
	//alert(HiddenField.name + ' ' + HiddenField.value + ' ' + strFieldValue)
						ViewField.value = strFieldValue;
						HiddenField.value = strFieldValue;
						if (ViewField.value != strFieldValue || HiddenField.value != strFieldValue)
							 t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
					}
               } else {
                    t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
                }
			}

        } catch (e) {
		t = setTimeout("getformcookie('" + nodeid + "', '" + formname + "', '" + formfield + "')", 100);
        //alert(e.description + " " + e.number);
    }
}*/

function getformcookie_select(nodeid, formname, formfield) {
    try {
	    var strCookieName = 'forms_'+formname;
	    var strCookie = getCookie(strCookieName);
	    //alert(formfield + ": " + document.getElementById(formfield).value);

    	

	    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]);
				    var HiddenField = eval('document.getElementById(\'' + formfield + '\')');
				    HiddenField.selectedIndex = strFieldValue;
				    return "";
			    }
    			
		    }
	    }
    } catch (e) {

    }


}

function getformcookie_select_obsolete(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]);
                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)+"'";
		var trailerWin=window.open('about:blank','',optWind);

		with (trailerWin.document){
            writeln('<html><head><title>Trailer</title><style>body{margin:0px;}</style>');
            writeln('<sc'+'ript  type="text/javascript" src="/cms/res/Flashplayer/flowplayer.min.js"></sc'+'ript>');
            writeln('<sc'+'ript>');
		    writeln('document.title="' + trailer_name + '";');
		    writeln('if (document.images) window.opener.parent.name=\'homeenter_mainwindow\';');
		    writeln('</sc' + 'ript></head>');

            writeln('<body>');
			writeln('<div id="mainContent" style="display:block;width:'+ trailer_width +';height:'+ trailer_height +'px">');
    		writeln('<a id="flowplayerplayer_popup" href="' + trailer_url +'" style="display:block;width:'+ trailer_width +'px;height:'+ trailer_height +'px">');
    		writeln('<img src="/img/play.png" style="border: none; opacity: 0.6;margin-top:' + ((parseInt(trailer_height, 10) / 2)- 42) + 'px; margin-left:' + ((parseInt(trailer_width, 10) / 2)- 42)  + 'px;"></a></div>');
    		writeln('<sc' + 'ript language="javascript">setTimeout(\'flowplayer("flowplayerplayer_popup", "/cms/res/Flashplayer/flowplayer.swf")\',400);</sc' + 'ript>');
		    writeln('</div>');

		    writeln('</body>');

		    writeln('</html>');
		    //close();
		}
        		
	}

    function popTrailerFlashFanbay(ean, trailer_name, trailer_width, trailer_height, packshot, releasedate, isgame) {
    	    if (isgame == true || isgame == 'true')
    	        isgame = true;
    	    else
    	        isgame = false;

	    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[');

	        if (isgame) {
	            writeln('var qs = "games=1&ean=" + escape(ean);');
	        } else {
	            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('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;
      if (URLtouse == '') throw "empty url";
        try {
        var addMasterNodeID = "";

        if (parent.window.document.getElementsByTagName("body").item(0).attributes.getNamedItem("nodeid")) addMasterNodeID = "&masternodeid=" + String(document.getElementsByTagName("body").item(0).attributes.getNamedItem("nodeid").nodeValue);
    
            URLtouse += "&redirectbasketadd=no" + addMasterNodeID + "&Now=" + new Date() ;


            var xmlhttp=false; //Clear our fetching variable

            if (window.ActiveXObject) {
                if ((navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) || (navigator.userAgent.toLowerCase().indexOf('msie 7') != -1))
                    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
                else
                    xmlhttp = new XMLHttpRequest();
                    
            } else {
                    xmlhttp = new XMLHttpRequest() ;
                  //alert('Firefox ok!!');
            }

            //alert(URLtouse);
    
            if (!xmlhttp && typeof xmlhttprequest!='undefined') { 

                xmlhttp = new xmlhttprequest(); //If we were able to get a working active x object, start an xmlhttprequest 
            }
          
            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 ***

                    if (content) { //Make sure there is something in the content variable 
                        //content = URLtouse;
                        content = String(content);

                        // Generel error info visar vi i huvudarean
                        var reError = /<div class=\"textbox\">(\W*?)<div class=\"errortext\">(.*?)<\/div>(\W*?)<\/div>(\W*?)<img src=\"\/img\/gx_blank\.gif\" width=\"1\" height=\"5\">/g;
                        var reAlert = /<div id=\"alert_box\" class=\"textbox\">(.*?)<\/div>(\W*?)<img src=\"\/img\/gx_blank\.gif\" width=\"1\" height=\"5\">/gi;
                        var reInfo = /<div id=\"info_box\" class=\"textbox\">(.*?)<\/div>(\W*?)<img src=\"\/img\/gx_blank\.gif\" width=\"1\" height=\"5\">/gi;

                        var arr_error = content.match(reError);
                        var arr_Alert = content.match(reAlert);
                        var arr_Info = content.match(reInfo);

                        var ErrorText = "";
                        var AlertText = "";
                        var InfoText = "";

                        if (arr_error) ErrorText = arr_error.join(" ");
                        if (arr_Alert) AlertText = arr_Alert.join(" ");
                        if (arr_Info) InfoText = arr_Info.join(" ");

                        // Kill alert and error
                        content = content.replace(reError, '');
                        content = content.replace(reAlert, '');
                        content = content.replace(reInfo, '');

                        parent.window.document.getElementById(IDtoupdate).innerHTML = content; //Change the inner content of your div to the newly retrieved content **** 

                        try {
                            if (ErrorText != '') {
                                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, CLOSECLICK, EXCLUSIVE, FULLHTML, CENTEROFFSET, -50, -50, NOCLOSE);
                                new overlib(ErrorText, CENTERPOPUP, STICKY, CLOSECLICK, EXCLUSIVE, FULLHTML, CENTEROFFSET, -50, -50, NOCLOSE);
                                //return nd();
                            } else if (AlertText != '') {
                                // Städa lite mer .. kan säkert göras snyggare .. men jag hatar regex		                
                                var re_start = /<div id=\"alert_box\" class=\"textbox\">/gi;
                                var re_stop = /<\/div>(\W*?)<img src=\"\/img\/gx_blank\.gif\" width=\"1\" height=\"5\">/gi;
                                AlertText = AlertText.replace(re_start, '');
                                AlertText = AlertText.replace(re_stop, '');
                                AlertText = popuptext(AlertText, 'OverLib');
                                //return new overlib(AlertText, CENTERPOPUP, STICKY, CLOSECLICK, EXCLUSIVE, FULLHTML, CENTEROFFSET, -50, -50, NOCLOSE);
                                new overlib(AlertText, CENTERPOPUP, STICKY, CLOSECLICK, EXCLUSIVE, FULLHTML, CENTEROFFSET, -50, -50, NOCLOSE);
                                //return nd();
                            } else if (InfoText != '') {
                                // Städa lite mer .. kan säkert göras snyggare .. men jag hatar regex		                
                                var re_start = /<div id=\"info_box\" class=\"textbox\">/gi;
                                var re_stop = /<\/div>(\W*?)<img src=\"\/img\/gx_blank\.gif\" width=\"1\" height=\"5\">/gi;
                                InfoText = InfoText.replace(re_start, '');
                                InfoText = InfoText.replace(re_stop, '');
                                InfoText = popuptext(InfoText, 'OverLib');
                                //return new overlib(InfoText, CENTERPOPUP, TIMEOUT, 3000, FULLHTML, CENTEROFFSET, -50, -50);
                                new overlib(InfoText, CENTERPOPUP, TIMEOUT, 3000, FULLHTML, CENTEROFFSET, -50, -50);
                                //return nd();                                
                            } else if (poputext) {
                                poputext = popuptext(poputext, 'OverLib');
                                overlib(poputext, CENTERPOPUP, TIMEOUT, 3000, FULLHTML, CENTEROFFSET, -50, -50);
                                nd();
                            }
                        } catch (e) { }
                    }
                    var search = content;
                    var script;

                    while (script = search.match(/(<script[^>]+javascript[^>]+>\s*(<!--)?)/i)) {
                        search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length);
                        if (!(endscript = search.match(/((-->)?\s*<\/script>)/))) break;
                        block = search.substr(0, search.indexOf(RegExp.$1));
                        search = search.substring(block.length + RegExp.$1.length);
                        //alert(block)
                        var oScript = document.createElement('script');
                        oScript.text = block;
                        parent.window.document.getElementsByTagName("head").item(0).appendChild(oScript);
                    }
                    /*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
            //alert('hej');
            //return;
        } catch (e) {
        //alert('ERROR:' + e);
        //alert('ERROR:' + e.description);
            throw e;      
        }

    }

    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 = '';


				}
		}


		function ol(data) {
		    try {
		        var header = String(data.split('|')[0]);
		        var pricecollection = data.split('|')[1];

		        var htmlstring = '';
		        htmlstring += '<table style="width:100%;" cellpadding="3" cellspacing="0" border="0">';

		        if (header != '') {
		            htmlstring += '<tr>';
		            htmlstring += '<td align="left" colspan="2" class="overlibheader"><b>';
		            htmlstring += header;
		            htmlstring += '</b></td>';
		            htmlstring += '</tr>';
		        }

		        var prices = pricecollection.split('#');

		        if (prices.length > 0) {
		            for (var i = 0; i < prices.length - 1; i++) {
		                htmlstring += '<tr>';
		                htmlstring += '<td align="left"><b>' + prices[i].split('¤')[0] + '</b></td>';
		                htmlstring += '<td align="right"><b>' + prices[i].split('¤')[1] + '</b></td>';
		                htmlstring += '</tr>';
		            }
		        }

		        htmlstring += '</table>';
		        overlib(htmlstring, WIDTH, 170, CELLPAD, 0, 0, 0, 0, FGCOLOR, '#F4F4F4', BGCOLOR, '#000000', VAUTO, HAUTO);
		    } catch (e) {
		    }
        }

        function IncludeJavaScript(jsFile) {
            // alert(jsFile);
            document.write('<script type="text/javascript" src="' + jsFile + '"></scr' + 'ipt>');

        }

