/**
*
*  MD5 (Message-Digest Algorithm)
*  http://www.webtoolkit.info/
*
**/

var MD5 = function (string) {

    function RotateLeft(lValue, iShiftBits) {
        return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
    }

    function AddUnsigned(lX,lY) {
        var lX4,lY4,lX8,lY8,lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
     }

     function F(x,y,z) { return (x & y) | ((~x) & z); }
     function G(x,y,z) { return (x & z) | (y & (~z)); }
     function H(x,y,z) { return (x ^ y ^ z); }
    function I(x,y,z) { return (y ^ (x | (~z))); }

    function FF(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function GG(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function HH(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function II(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function ConvertToWordArray(string) {
        var lWordCount;
        var lMessageLength = string.length;
        var lNumberOfWords_temp1=lMessageLength + 8;
        var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
        var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
        var lWordArray=Array(lNumberOfWords-1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while ( lByteCount < lMessageLength ) {
            lWordCount = (lByteCount-(lByteCount % 4))/4;
            lBytePosition = (lByteCount % 4)*8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount-(lByteCount % 4))/4;
        lBytePosition = (lByteCount % 4)*8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
        lWordArray[lNumberOfWords-2] = lMessageLength<<3;
        lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
        return lWordArray;
    };

    function WordToHex(lValue) {
        var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
        for (lCount = 0;lCount<=3;lCount++) {
            lByte = (lValue>>>(lCount*8)) & 255;
            WordToHexValue_temp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
        }
        return WordToHexValue;
    };

    function Utf8Encode(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;
    };

    var x=Array();
    var k,AA,BB,CC,DD,a,b,c,d;
    var S11=7, S12=12, S13=17, S14=22;
    var S21=5, S22=9 , S23=14, S24=20;
    var S31=4, S32=11, S33=16, S34=23;
    var S41=6, S42=10, S43=15, S44=21;

    string = Utf8Encode(string);

    x = ConvertToWordArray(string);

    a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

    for (k=0;k<x.length;k+=16) {
        AA=a; BB=b; CC=c; DD=d;
        a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
        d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
        c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
        b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
        a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
        d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
        c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
        b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
        a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
        d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
        c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
        b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
        a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
        d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
        c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
        b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
        a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
        d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
        c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
        b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
        a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
        d=GG(d,a,b,c,x[k+10],S22,0x2441453);
        c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
        b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
        a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
        d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
        c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
        b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
        a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
        d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
        c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
        b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
        a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
        d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
        c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
        b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
        a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
        d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
        c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
        b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
        a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
        d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
        c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
        b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
        a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
        d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
        c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
        b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
        a=II(a,b,c,d,x[k+0], S41,0xF4292244);
        d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
        c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
        b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
        a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
        d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
        c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
        b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
        a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
        d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
        c=II(c,d,a,b,x[k+6], S43,0xA3014314);
        b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
        a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
        d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
        c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
        b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
        a=AddUnsigned(a,AA);
        b=AddUnsigned(b,BB);
        c=AddUnsigned(c,CC);
        d=AddUnsigned(d,DD);
    }

    var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);

    return temp.toLowerCase();
}

/** 
 * 
 * 
 * 
 *  MW START
 * 
 * 
 * **/

function showNormal(itemID) {
	$("#"+itemID+"Facts").slideUp("slow");
	$("#"+itemID+"Review").slideUp("slow");
	$("#normalViewHighlight"+itemID).show();
	$("#getter_"+itemID+"_1").hide();
	$("#factsViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_2").show();
	$("#discussViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_3").show();
}

function showFacts(itemID) {
	$("#"+itemID+"Review").slideUp("slow");
	$("#"+itemID+"Facts").slideDown("slow");
	$("#factsViewHighlight"+itemID).show();
	$("#getter_"+itemID+"_2").hide();
	$("#discussViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_3").show();
	$("#normalViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_1").show();
}

function showDiscuss(itemID) {
	$("#"+itemID+"Facts").slideUp("slow");
	$("#"+itemID+"Review").slideDown("slow");
	$("#discussViewHighlight"+itemID).show();
	$("#getter_"+itemID+"_3").hide();
	$("#normalViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_1").show();
	$("#factsViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_2").show();
}

function getterMouseOver(id) {
	document.getElementById(id).style.backgroundColor = "#e9e5db";
}

function getterMouseOut(id) {
	document.getElementById(id).style.backgroundColor = "#f5f3ec";
}

function hideBestellLayer(id) {
	$("#"+id).hide();
}

function showBestellAnzahlLayer(id) {
	$("#"+id).show();
}

function initWeintipHover(itemID) {
	$("#"+itemID+"subline").hover(
		function() {
			$('#'+itemID+'hendrik_thoma_weintipp').css({display: "block"});
		},
		function () {
			$('#'+itemID+'hendrik_thoma_weintipp').css({display: "none"});
		}
	);
}

var imageViewerWin;

function isOpen(win)
{
	return win && !win.closed; 
}

function closeOne(win)
{
	if(isOpen(win))
		win.close();
}

function closeAll()
{
	closeOne(imageViewerWin);
}

function openWindow(url, title, data) {
	window.open(url, title, data);
}

function openRecommendationWindow(url) {
	openWindow(url, "forwardingWin", "width=714,height=783,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no");
}


function openImageViewerWindow(url) 
{
	imageViewerWin = openWindow(url, "imageViewerWin", "width=600,height=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no")
	//imageViewerWin = openWindow(imageViewerWin,     url, "imageViewerWin",     "width=600,height=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no");
}

function openForwardingWindow(url) 
{
	openWindow(url, "forwardingWin", "width=630,height=430,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no");
}

function openOrderPrintWindow(url) 
{
	openWindow(url, "orderPrintWin", "width=850,height=430,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no");
}

function openPrintWindow(url) 
{
	openWindow(url, "orderPrintWin", "width=660,height=430,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no");
}

function ajaxHelpful(url, index) {
	$.get(url, '', function(responseText, textStatus, XMLHttpRequest) {
//    		document.getElementById('eval_quality'+index).innerHTML = responseText;
//    		document.getElementById('eval_question'+index).innerHTML = 'Vielen Dank f&uuml;r Ihre Meinung.';
    		$('#eval_quality'+index).html(responseText);
    		$('#eval_question'+index).html('Vielen Dank f&uuml;r Ihre Meinung.');
  		}
	);	
}

	function listOn(listItem) {
	listItem.style.background = '#F1ECEA';
	}
	function listOff(listItem) {
	listItem.style.background='#ffffff';
	}
	
	document.onkeydown = keyCheck;
	var sgCur = 0;
	var sgMax = 0;
	var isOverSuggest = false;
	var isSuggestOpened = true;
	var isSgOff = false;
	var isMLCTActivated = false;
	function is_ie(v) {
		var agt=navigator.userAgent.toLowerCase();
		var appVer = navigator.appVersion.toLowerCase();
		var is_minor = parseFloat(appVer);
		var is_major = parseInt(is_minor);
		var iePos = appVer.indexOf('msie');
		if (iePos !=-1) {
			is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
			is_major = parseInt(is_minor);
		}
		var is_ie = ((iePos!=-1));
		return (is_ie && is_major == v);
	}
	function clearSearch() {
		if (document.forms.search.searchField.value == 'Suche') 
			document.forms.search.searchField.value = '';
	}
	function search(text) {
		text = text.replace(/\+/g," ");
		if (!is_ie(7)) text = decodeURI(text); //FF IE6
			else text = unescape(text); //IE7
		if (!is_ie(6)) {
			text = unescape(text);//text.replace(/\%25/,"%");
		}
		document.getElementById('searchForm_searchField').style.color='#aaa';
		document.getElementById('searchForm_searchField').value = text;
		sendMLCT();
		document.forms.search.submit();
		var elem = document.getElementById('search_drops');
		elem.style.display = 'none';
		isSuggestOpened = false;
	}
	document.onmousedown = function() {
		if (!isOverSuggest) {
			var elem = document.getElementById('search_drops');
			if (elem != null) {
				elem.style.display = 'none';
				isSuggestOpened = false;
			}
		}
	}
	// keyboard nav
	function keyCheck(e) {
		if (isSuggestOpened == true) {
			var keyID = (window.event) ? event.keyCode : e.keyCode;
			var block = false;
			switch(keyID) {
				case 13:
				sgEnter();
				break;
				case 38:
				sgUp(); block = true;
				break;
				case 40:
				sgDown(); block = true;
				break;
				default:
				sgCur = 0;
				sgMax = getSgMax();
			}
			if (block) {
				if (window.event) window.event.returnValue = false;
				else e.preventDefault();
			}
		}
	}
	function sgDown() {
		if (sgCur == 0) {
			sgMax = getSgMax();
		}
		if (sgMax != 0) {
			if (document.getElementById('s'+(sgCur+1)) != null) {
				if (document.getElementById('s'+sgCur) != null)
					sgOff('s'+sgCur);
				sgOn('s'+(sgCur+1));
				sgCur++;
			}
			else {
				if (document.getElementById('s'+sgCur) != null)
					sgOff('s'+sgCur);
				sgOn('s1');
				sgCur = 1;
			}
		}
	}
	function sgUp() {
		if (sgCur == 0) {
			sgMax = getSgMax();
		}
		if (sgMax != 0) {
			if (document.getElementById('s'+(sgCur-1)) != null) {
				if (document.getElementById('s'+sgCur) != null)
					sgOff('s'+sgCur);
				sgOn('s'+(sgCur-1));
				sgCur--;
			}
			else {
				if (document.getElementById('s'+sgCur) != null)
					sgOff('s'+sgCur);
				sgOn('s'+sgMax);
				sgCur = sgMax;
			}
		}
	}
	
	function sgEnter() {
		if (document.getElementById('s'+sgCur) != null) {
			var functionCall = document.getElementById('s'+sgCur).href;
			var start = functionCall.indexOf('\'')+1;
			var end = functionCall.lastIndexOf('\'');
			var result = functionCall.substring(start,end);
			isSgOff = true;
			search(result);
		}
	}
	function sgOn(id) {
		var el = document.getElementById(id);
		el.style.fontWeight = '700';
		el.style.color='#af2419';
	}
	function sgOff(id) {
		var el = document.getElementById(id);
		el.style.fontWeight = 'normal';
		el.style.color='#333333';
	}
	function getSgMax() {
		var c=0;
		while (document.getElementById('s'+(c+1)) != null)
			c++;
		return c;
	}
	function sendMLCT() {
		if (!isMLCTActivated)
			cmCreateManualLinkClickTag('/searchresult');
		isMLCTActivated = true;
	}
	function searchChange(url) {
		var searchString = document.getElementById('searchForm_searchField').value;
		$.get(url+'&searchString='+searchString, function(transport) { 
				var elem = document.getElementById('search_drops');
				if ((elem.style.display == 'none' || elem.style.display == '') && !isSgOff) {
					elem.style.display = 'block';
					sgCur = 0;
					isSuggestOpened = true;
				}
				elem.style.visibility = 'visible';
				document.getElementById('search_list').innerHTML = transport;
                                if (sgCur != 0)
                                        sgOn('s'+sgCur);
		}); 
	}

function showLabelIfEmpty(input,label) {
	if (input.value == '') {
		getEl(label).style.visibility='visible';
		getEl(label).style.zIndex=50;
	}
}
function hideLabelSetFocus(label,input) {
	getEl(label).style.visibility='hidden';
	getEl(label).style.zIndex=0;
	input.focus();
}

function showMenue2(menuename) {
	var elem = document.getElementById(menuename);
	var dropHeight = elem.offsetHeight;
	if (dropHeight > 180) {
		elem.style.height = '180px';
		elem.style.overflow = 'auto';
	}
	if ($('#'+menuename).is(':hidden')) {
		document.getElementById(menuename+'drop').style.display='block';
		$('#'+menuename).slideDown('fast');
	}
	else elem.style.display='block';
}
function hideMenue2(menuename) {
	$('#'+menuename).slideUp('fast',function() { deMenuHead(menuename) });
}
function toggleMenue2(menuename) {
	if (!($('#'+menuename).is(':visible'))) showMenue2(menuename);
		else hideMenue2(menuename);
}
var overIds = new Array();
function over(id) {
	document.getElementById(id).style.display = 'block';
	if (!overIds[id])
		overIds[id] = 1;
	else 
		overIds[id]++;
}
function out(id) {
	var action = 'performOut(\''+id+'\')';
	window.setTimeout(action, 1000);
}
function performOut(id) {
	if (!overIds[id]) {
	} else {
		overIds[id]--;
		if (overIds[id] < 2)
			hideMenue2(id);
	}
}
function deMenuHead(menuename) {
	document.getElementById(menuename+'drop').style.display='none';
}

/* jquery globals */

$(document).ready(function() {
  $("body").click(function (event) {
    var outsideCart = $(event.originalTarget).parents("#cart_popup").length == 0;
    if (outsideCart) {
        $("#cart_popup").hide();
    }
    alldown();
});
 });

/* top navigation logic */

function hoverCloseShow(closeId, showId, elem) {
	if (getEl(closeId) != null)
		hide(getEl(closeId));
	showById(showId);
	elem.blur();
	return false;
}

function activate(pop,head) {
alldown();
head.style.backgroundPosition = '0px 0px';
if (pop != null)
  if ($(pop).is(':hidden')) show(pop);
  else pop.style.display='block';
}

function getEl(str) {
return document.getElementById(str);
}

function alldown() {
var nav = document.getElementById('topnav');
var a = nav.getElementsByTagName("div");
var delayed = null;
for (var i=1;i<=a.length;i++) {
  if (a[i-1].className == "popup") {
    if ($(a[i-1]).is(':visible')) {
      hide(a[i-1]);
      delayed=a[i-1].parentNode;
    }
  }
}
deHead(nav,delayed);
}

function deHead(elm,except) {
var a = elm.getElementsByTagName("div");    
for (var j=1;j<=a.length;j++) {
  if (a[j-1].className == "tab") {
    if ((except == null) || !(a[j-1].parentNode == except))
      a[j-1].getElementsByTagName('a')[0].style.backgroundPosition = "0px -35px";
  }
}
}

/* equalize content box length */

//this does it for three or two
function sortNum(a,b) {
  return b-a
}
function equalHeight(one,two,three) {
  if (document.getElementById(one)) {
    var  obj=new Array(3);
    var option;
    if (document.getElementById(two)==null) 
      option=[one,three];
    else 
      option=[one,two,three];
    for(var i=0; i<option.length; i++) {
      document.getElementById(option[i]).style.height="auto";
      obj[i]=document.getElementById(option[i]).offsetHeight;
      nh=obj.sort(sortNum);
    }
    nh1=nh.splice(1,2);
    for(var i=0; i<option.length; i++) {
      document.getElementById(option[i]).style.height=nh+"px";
    }
  }
}

window.onload=function(){
  equalHeight('equalleft','equalright','equalcontent');
}


  var tn_overIds = new Array();
  function tn_over(id) {
    document.getElementById(id).style.display = 'block';
    if (!tn_overIds[id])
      tn_overIds[id] = 1;
    else 
      tn_overIds[id]++;
  }
  function tn_out(id) {
    var action = 'tn_performOut(\''+id+'\')';
    window.setTimeout(action, 600);
  }
  function tn_performOut(id) {
    if (!tn_overIds[id]) {
    } else {
      tn_overIds[id]--;
      if (tn_overIds[id] < 2)
        hide(document.getElementById(id));
    }
  }

function showById(id) {
  if (getEl(id) != null)
	$("#" + id).slideDown("fast");
}
function show(elm) {
$(elm).slideDown("fast");
}
function hide(elm) {
$(elm).slideUp("fast",function() { deHead(elm.parentNode) });
}



/* home wine detail navigation logic */

function wineOpen(clink, ostr) {
var list = clink.parentNode.parentNode.parentNode;
var a = list.childNodes;
for (i=1;i<=a.length;i++) {
  if (a[i-1].className != null && a[i-1].className != "getterbox") {
    if (a[i-1].className == ostr) {
      for (j=1;j<=a[i-1].childNodes.length;j++) {
        if (a[i-1].childNodes[j-1].className != null) {
          a[i-1].childNodes[j-1].style.visibility='visible';
        }
      }
    }
    else {
      for (k=1;k<=a[i-1].childNodes.length;k++) {
        if (a[i-1].childNodes[k-1].className != null) {
          a[i-1].childNodes[k-1].style.visibility='hidden';
        }
      }
    }
  }
}
}


function logout(url) {
    $.ajax({
        type: "get",
        url: url,
        success: function(e) {
            $("#loginContainer").html(e);
        }
    });
  }


function isSafari() {
return ((navigator.userAgent.toLowerCase().indexOf('safari') != -1 )||(navigator.userAgent.toLowerCase().indexOf('applewebkit') != -1 ));
}
function isSafariAndIE() {
return ((navigator.userAgent.toLowerCase().indexOf('safari') != -1 )||(navigator.userAgent.toLowerCase().indexOf('applewebkit') != -1 ) ||(navigator.userAgent.toLowerCase().indexOf('msie') != -1 ));
}
function showMenue(menuename) {
var elem = document.getElementById(menuename);
elem.style.visibility = 'visible';
if (!isSafariAndIE()) elem.style.display = 'block';
var dropHeight = elem.offsetHeight;
if (dropHeight > 180) {
elem.style.height = '180px';
elem.style.overflow = 'auto';
}
}
function hideMenue(menuename) {
var elem = document.getElementById(menuename);
if (!isSafariAndIE()) elem.style.display = 'none';
elem.style.visibility = 'hidden';
}
function toggleMenue(menuename) {
var elem = document.getElementById(menuename);
if (elem.style.display == 'none' || elem.style.display == '' ) elem.style.display = 'block';
else if (!isSafariAndIE()) elem.style.display = 'none';
elem.style.visibility = (elem.style.visibility == 'hidden' || elem.style.visibility == '' ) ? 'visible' : 'hidden';
var dropHeight = elem.offsetHeight;
if (dropHeight > 180) {
elem.style.height = '180px';
elem.style.overflow = 'auto';
}
}
function listOn(listItem) {
listItem.style.background = '#F1ECEA';
}
function listOff(listItem) {
listItem.style.background='#ffffff';
}
function selectPulldown(formName, fieldName, value, changeId, changeText, submitOnChange, showPleaseWait) {
document.forms[formName].elements[fieldName].value = value;
document.getElementById(changeId).innerHTML = changeText;
if (showPleaseWait)
showPleaseWaitDialog();
if (submitOnChange)
document.forms[formName].submit();
}

function showNLPopup() {
        grayOut(true);
        document.getElementById('nwl_popup').style.display='block';
}
function hideNLPopup() {
        document.getElementById('nwl_popup').style.display='none';
        grayOut(false);
}
function disableNLPopup() {
    d = new Date();
    d.setMinutes(d.getMinutes() + 60 * 24 * 1005);
    document.cookie='showNLPopup=false;path=/;expires=' + d.toGMTString();
    hideNLPopup();
}

function grayOut(show) {
        var vis = (show == false) ? false : true;
        var zindex = 192;
        var opacity = 50;
        var opaque = (opacity / 100);
        var bgcolor = '#000000';
        var dark=document.getElementById('darkenScreenObject');
        if (!dark) {
          var tbody = document.getElementsByTagName("body")[0];
          var tnode = document.createElement('div');
              tnode.style.position='absolute';
              tnode.style.top='0px';
              tnode.style.left='0px';
              tnode.style.overflow='hidden';
              tnode.style.display='none';
              tnode.id='darkenScreenObject';
          tbody.appendChild(tnode);
          dark=document.getElementById('darkenScreenObject');
        }
        if (vis) {
           // Calculate the page width and height
         if(navigator.appName.indexOf("Explorer") == -1) {
             var pageWidth='100%';
             var pageHeight='100%';
             dark.style.position='fixed';
          } else if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
              var pageWidth = document.body.scrollWidth+'px';
              var pageHeight = document.body.scrollHeight+24+'px'; //24 for IE7
          } else if( document.body.offsetWidth ) {
            var pageWidth = document.body.offsetWidth+'px';
            var pageHeight = document.body.offsetHeight+24+'px';
          } else {
             var pageWidth='100%';
             var pageHeight='100%';
          }
          //set the shader to cover the entire page and make it visible.
          dark.style.opacity=opaque;
          dark.style.MozOpacity=opaque;
          dark.style.filter='alpha(opacity='+opacity+')';
          dark.style.zIndex=zindex;
          dark.style.backgroundColor=bgcolor;
          dark.style.width= pageWidth;
          dark.style.height= pageHeight;
          dark.style.display='block';
        } else {
          dark.style.display='none';
        }      
      }

