//Remove lumo in Language-Selector


// JavaScript Document
function MM_swapImgRestore(){ //v3.0
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) 
        x.src = x.oSrc;
}

function MM_preloadImages(){ //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) 
            d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++) 
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function MM_findObj(n, d){ //v4.01
    var p, i, x;
    if (!d) 
        d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) 
        x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) 
        x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) 
        x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) 
        x = d.getElementById(n);
    return x;
}

function MM_swapImage(){ //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3) 
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) 
                x.oSrc = x.src;
            x.src = a[i + 2];
        }
}

function popUp(URL){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=400,left = 540,top = 325');");
}



var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true : false;
var ie5 = ((navigator.userAgent.indexOf("MSIE") > -1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;

var origWidth, origHeight;

// avoid error of passing event object in older browsers
if (nodyn) {
    event = "nope"
}

///////////////////////  CUSTOMIZE HERE   ////////////////////
// settings for tooltip 
// Do you want tip to move when mouse moves over link?
var tipFollowMouse = true;
// Be sure to set tipWidth wide enough for widest image
var tipWidth = 330;
var offX = 20; // how far from mouse to show tip
var offY = 12;
var tipFontFamily = "Verdana, arial, helvetica, sans-serif";
var tipFontSize = "8pt";
// set default text color and background color for tooltip here
// individual tooltips can have their own (set in messages arrays)
// but don't have to
var tipFontColor = "#43165e";
var tipBgColor = "#FFFFFF";
var tipBorderColor = "#43165e";
var tipBorderWidth = 2;
var tipBorderStyle = "ridge";
var tipPadding = 4;





////////////////////  END OF CUSTOMIZATION AREA  ///////////////////



var startStr = '<table width="' + tipWidth + '"><tr><td align="center" width="100%"><img src="';
var midStr = '" border="0"></td></tr><tr><td valign="top">';
var endStr = '</td></tr></table>';

var tooltip, tipcss;
function initTip(){
    if (nodyn) 
        return;
    tooltip = (ie4) ? document.all['tipDiv'] : (ie5 || ns5) ? document.getElementById('tipDiv') : null;
    tipcss = tooltip.style;
    if (ie4 || ie5 || ns5) { // ns4 would lose all this on rewrites
        tipcss.width = tipWidth + "px";
        tipcss.fontFamily = tipFontFamily;
        tipcss.fontSize = tipFontSize;
        tipcss.color = tipFontColor;
        tipcss.backgroundColor = tipBgColor;
        tipcss.borderColor = tipBorderColor;
        tipcss.borderWidth = tipBorderWidth + "px";
        tipcss.padding = tipPadding + "px";
        tipcss.borderStyle = tipBorderStyle;
    }
    if (tooltip && tipFollowMouse) {
        document.onmousemove = trackMouse;
    }
}


/////////////////////////////////////////////////
//  doTooltip function
//			Assembles content for tooltip and writes 
//			it to tipDiv
/////////////////////////////////////////////////
var t1, t2; // for setTimeouts
var tipOn = false; // check if over tooltip link
function doTooltip(evt, num, src){
    if (!tooltip) 
        return;
    var tooltipTitel = "";
    if (num.alt) 
        tooltipTitel = num.alt;
    if (t1) 
        clearTimeout(t1);
    if (t2) 
        clearTimeout(t2);
    tipOn = true;
    // set colors if included in messages array
    curBgColor = tipBgColor;
    curFontColor = tipFontColor;
    if (ie4 || ie5 || ns5) {
        var tip = startStr + src + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + tooltipTitel + '</span>' + endStr;
        tipcss.backgroundColor = curBgColor;
        tooltip.innerHTML = tip;
    }
    if (!tipFollowMouse) 
        positionTip(evt);
    else 
        t1 = setTimeout("tipcss.visibility='visible'", 100);
}

var mouseX, mouseY;
function trackMouse(evt){
    standardbody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body //create reference to common "body" across doctypes
    mouseX = (ns5) ? evt.pageX : window.event.clientX + standardbody.scrollLeft;
    mouseY = (ns5) ? evt.pageY : window.event.clientY + standardbody.scrollTop;
    if (tipOn) 
        positionTip(evt);
}

/////////////////////////////////////////////////////////////
//  positionTip function
//		If tipFollowMouse set false, so trackMouse function
//		not being used, get position of mouseover event.
//		Calculations use mouseover event position, 
//		offset amounts and tooltip width to position
//		tooltip within window.
/////////////////////////////////////////////////////////////
function positionTip(evt){
    if (!tipFollowMouse) {
        mouseX = (ns5) ? evt.pageX : window.event.clientX + standardbody.scrollLeft;
        mouseY = (ns5) ? evt.pageY : window.event.clientY + standardbody.scrollTop;
    }
    // tooltip width and height
    var tpWd = (ie4 || ie5) ? tooltip.clientWidth : tooltip.offsetWidth;
    var tpHt = (ie4 || ie5) ? tooltip.clientHeight : tooltip.offsetHeight;
    // document area in view (subtract scrollbar width for ns)
    var winWd = (ns5) ? window.innerWidth - 20 + window.pageXOffset : standardbody.clientWidth + standardbody.scrollLeft;
    var winHt = (ns5) ? window.innerHeight - 20 + window.pageYOffset : standardbody.clientHeight + standardbody.scrollTop;
    // check mouse position against tip and window dimensions
    // and position the tooltip 
    if ((mouseX + offX + tpWd) > winWd) 
        tipcss.left = mouseX - (tpWd + offX) + "px";
    else 
        tipcss.left = mouseX + offX + "px";
    if ((mouseY + offY + tpHt) > winHt) 
        tipcss.top = winHt - (tpHt + offY) + "px";
    else 
        tipcss.top = mouseY + offY + "px";
    if (!tipFollowMouse) 
        t1 = setTimeout("tipcss.visibility='visible'", 100);
}

function hideTip(){
    if (!tooltip) 
        return;
    t2 = setTimeout("tipcss.visibility='hidden'", 100);
    tipOn = false;
}

document.write('<div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100"></div>');



/**
 *
 *  Base64 encode / decode
 *  http://www.webtoolkit.info/
 *
 **/
var Base64 = {

    // private property
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    
    // public method for encoding
    encode: function(input){
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        
        input = Base64._utf8_encode(input);
        
        while (i < input.length) {
        
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);
            
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            }
            else 
                if (isNaN(chr3)) {
                    enc4 = 64;
                }
            
            output = output +
            this._keyStr.charAt(enc1) +
            this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) +
            this._keyStr.charAt(enc4);
            
        }
        
        return output;
    },
    
    // public method for decoding
    decode: function(input){
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
        
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        
        while (i < input.length) {
        
            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));
            
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            
            output = output + String.fromCharCode(chr1);
            
            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }
            
        }
        
        output = Base64._utf8_decode(output);
        
        return output;
        
    },
    
    // private method for UTF-8 encoding
    _utf8_encode: function(string){
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";
        
        for (var n = 0; n < string.length; n++) {
        
            var c = string.charCodeAt(n);
            
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else 
                if ((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
                else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
            
        }
        
        return utftext;
    },
    
    // private method for UTF-8 decoding
    _utf8_decode: function(utftext){
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
        
        while (i < utftext.length) {
        
            c = utftext.charCodeAt(i);
            
            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else 
                if ((c > 191) && (c < 224)) {
                    c2 = utftext.charCodeAt(i + 1);
                    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                    i += 2;
                }
                else {
                    c2 = utftext.charCodeAt(i + 1);
                    c3 = utftext.charCodeAt(i + 2);
                    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                    i += 3;
                }
            
        }
        
        return string;
    }
    
}

var URL_DE = "shoplocator";
var URL_SE = "shoplocator_se";
var URL_IT = "shoplocator_it";
var URL_FI = "shoplocator_fi";
var URL_DK = "shoplocator_dk";



function getLocalizedUrl(langId){
    var url = new String();
    var shopLocatorProto = "http://www.wnwbeauty.de/$/index.php?";
    var splitString = new Array();
    splitString = shopLocatorProto.split('$');
    var intLangId= langId*1;
    switch (intLangId) {
        case 0:
            url += splitString[0];
            url += URL_DE;
            url += splitString[1];
            break;
        case 1:
            url += splitString[0];
            url += URL_SE;
            url += splitString[1];
            break;
        case 2:
            url += splitString[0];
            url += URL_IT;
            url += splitString[1];
            break;
        case 3:
            url += splitString[0];
            url += URL_FI;
            url += splitString[1];
            break;
        case 4:
            url += splitString[0];
            url += URL_DK;
            url += splitString[1];
            break;
        default:
            url += splitString[0];
            url += URL_DE;
            url += splitString[1];
    }
	return url;
	
}

function getLanguage(url)
{
	var baseUrl = document.getElementById('lumoPath').href;
    var basePos = baseUrl.lastIndexOf('L=');
    if (basePos == -1) 
        return "";
    baseUrl = baseUrl.substr(basePos+2,1);
    return baseUrl;
}

function encodeAndSubmit(){
	var myUrl= getRealUrl();
	var langId= getLanguage(myUrl);
	 var shopLocatorUrl = getLocalizedUrl(langId);
	
   // var shopLocatorUrl = "http://www.wnwbeauty.de/$/index.php?";
    var baseUrl = getRealUrl() + Base64.encode(shopLocatorUrl + getFormData());
    document.location = baseUrl;
}

function pageAndSubmit(pageNum){
	var myUrl= getRealUrl();
	var langId= getLanguage(myUrl);
	 var shopLocatorUrl = getLocalizedUrl(langId);
    //var shopLocatorUrl = "http://www.wnwbeauty.de/shoplocator/index.php?";
    var baseUrl = getRealUrl() + Base64.encode(shopLocatorUrl + getFormData() + "&p=" + pageNum);
    //baseUrl+= "&p="+pageNum;
    //alert(baseUrl);
    document.location = baseUrl;
}

function getRealUrl(){
    var lumoParam = 'tx_lumophpinclude_url=';
    var baseUrl = document.getElementById('lumoPath').href;
    var basePos = baseUrl.lastIndexOf('tx_lumophpinclude_url');
    if (basePos == -1) 
        return "";
    baseUrl = baseUrl.substr(0, basePos) + lumoParam;
    return baseUrl;
}



function getFormData(){
    var shopLocatorUrl = "";
    var formData = document.forms[0];
    for (var i = 0; i < formData.length; i++) {
        if (formData.elements[i].value.length > 0) {
        
            shopLocatorUrl += formData.elements[i].name;
            shopLocatorUrl += '=';
            shopLocatorUrl += formData.elements[i].value;
            shopLocatorUrl += '&'
        }
    }
    var lastPos = shopLocatorUrl.lastIndexOf('&');
    if (lastPos == shopLocatorUrl.length - 1) {
        shopLocatorUrl = shopLocatorUrl.substring(0, shopLocatorUrl.length - 1);
    }
    return shopLocatorUrl;
}

function resetSearchForm(param){
    var myUrl= getRealUrl();
	var langId= getLanguage(myUrl);
	 var shopLocatorUrl = getLocalizedUrl(langId);
	//var shopLocatorUrl = "http://www.wnwbeauty.de/shoplocator/index.php?";
    var baseUrl = getRealUrl() + Base64.encode(shopLocatorUrl + param);
    document.location = baseUrl;
}// JavaScript Document

