//Browsercheck (needed)

function lib_bwcheck(){
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);

	return this;

}


var activeLayer = '';

function updatePrice() {
	var key = '';

	for (i=1; i<6; i++) {
		var o = document.getElementById('p'+i);

		if (o!=null && typeof(o)=='object') {
			if (key!='') {key += '_';}
			key += o.value;
		}
	}

/*
	if (key == '') {
		key=0;
	}
*/

	if (!o || typeof(o) == 'undefined') {
		// use key of first and only item
		if (typeof(items) != 'undefined' && items.length == 1) {
			for (var key in items) {}
		}
	}

	var o = document.getElementById('divPrice');

	if (o!=null && typeof(o)=='object') {
		var s = '';

		//s += '<table width="280" border="0" cellpadding="0" cellspacing="0">';
		//s += '<tr>';
		//s += '<td align="left"><span style="font-size:10pt; font-family: Arial; color: #000000;">'+gui_order+' '+items[key][1]+'</span></td>';
		//s += '<td align="right"><span style="font-size:10pt; font-family: Arial; color: #000000;">';
		s += gui_order+' '+items[key][1]+'<br />';

		multiple_from = '';

		if (items[key][6]=='mehrfach') {
			multiple_from = gui_multiple_from + ' '+'<br />';
		}

		if (separate_vat) {
			s += gui_net+' '+multiple_from+items[key][3]+'<br />';//+' </span></td></tr>';
			//s += '<tr><td>&nbsp;</td><td align="right"><span style="font-size:10pt; font-family:Arial; color: #000000; font-weight: bold;">'+gui_gross+' '+multiple_from+items[key][4]+' </span></td></tr>';
			s += '<strong>'+gui_gross+' '+multiple_from+items[key][4]+'</strong><br />';

		} else {
			s += '<strong>'+gui_price+' '+multiple_from+items[key][2]+'</strong><br />';//+' </span></td></tr>';
		}

		if (items[key][6]=='mehrfach') {
			//s += '<tr>';
			//s += '<td colspan="2" style="padding-top: 8px; padding-bottom: 8px; color: #AA0000;">'+gui_multiple_hint+'</td>';
			s += gui_multiple_hint+'<br />';
			//s += '</tr>';
		}

		if (items[key][5]!='') {
			//s += '<tr>';
			//s += '<td colspan="2" align="right"><a href="'+items[key][5]+'">'+gui_add_normal+'</a></td>';

			if (items[key][8] == true) {
				s += '<p>&nbsp;</p><a class="basket" href="javascript:void(0);" onclick="javascript:loadConfigurator(\''+key+'\');">'+gui_add_configure+'</a>';
			} else {
				s += '<p>&nbsp;</p><a class="basket" href="'+items[key][5]+'">'+gui_add_normal+'</a>';
			}

			//s += '</tr>';
		}

		//s += '</table>';

		o.innerHTML = '<p>'+s+'</p>';
	}
}

function switchLayer(id) {
  if (activeLayer!='' && activeLayer!=id) {
    obj = document.getElementById(activeLayer);
    if (typeof(obj)=='object') {
      obj.style.display = 'none';
      obj.style.visibility = 'hidden';
    }
  }
  obj = document.getElementById(id);
  if (typeof(obj)=='object') {
    if (obj.style.visibility=='visible') {
      obj.style.display = 'none';
      obj.style.visibility = 'hidden';
      activeLayer = '';
    } else {
      obj.style.display = 'block';
      obj.style.visibility = 'visible';
      activeLayer = id;
    }
  }
}

function submitNation() {

	if (document.frmSel.sys_nation.value.substring(0,6)!='extern') {
		document.frmSel.sys_sel_action.value='nation';
		document.frmSel.submit();

	}else {
		var x = window.open(document.frmSel.sys_nation.value.substring(7,document.frmSel.sys_nation.value.length), 'extern');
	}
}

function submitsearch(ev) {
	if (document.frmSel.sys_search.value!='') {
		if (navigator.appName=='Netscape') {
			if (ev.which==13) {document.frmSel.submit();}
		} else if (navigator.appName=='Microsoft Internet Explorer') {
			if (window.event.keyCode==13) {document.frmSel.submit();}
		}
	}
}

function checkagb() {
  if (document.agbfrm.agb.checked) {
    document.agbfrm.submit();
  } else {
    alert(gui_agbmsg);
  }
}

function urlencode (str) {
    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };

    var ret = '';
    var unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();

    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            // Reserved assumed to be in UTF-8, as in PHP
            if (code === 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) { // 3 bytes
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}