var owidth=200, iwidth, ooffsetx=13, ooffsety=(ns4)?-20:10, ox=0, oy=0, our=null, html='', delay=250, g_timeout, g_on=false
var DOM2=document.getElementById
var ie4 = (document.all)?true:false
var ns4 = window.Event?true:false
var ie5, ie6
if (ie4) {
  if (navigator.userAgent.indexOf('MSIE 5')>0) ie5=true
  if (navigator.userAgent.indexOf('MSIE 6')>0) ie6=true
} else ie5 = ie6 = false

var ie=ie4||ie5||ie6
var ns6 = (DOM2&&!ie)?true:false
var ns=ns4||ns6

if((ns)||(ie)){
	document.onmousemove=mouseMove
	if(ns4) document.captureEvents(Event.MOUSEMOVE)
} else {
	ourlib=no_lib
	nd=no_lib
}

function no_lib () {
	return true
}

function lwr (what, where) {
	what+="\n";
	if (DOM2) document.getElementById(where).innerHTML = what
	else if (ns) {var l=document.layers[where].document; l.open(); l.write(what); l.close();} 
	else document.all[where].innerHTML = what
}

function lwr_text (what, where) {
	what+="\n";
	if (ns6) {
	  var HTMLElement = document.getElementById(where);
	  if(typeof HTMLElement!="undefined") {
		  var parsedText = document.createTextNode(what);
		  HTMLElement.innerHTML = "";
		  HTMLElement.appendChild( parsedText );
	  }
	} else if (DOM2) document.getElementById(where).innerText = what
	else if (ns) {var l=document.layers[where].document; l.open(); l.write(what); l.close();} 
	else document.all[where].innerText = what
}


function ourlib_delayed () {
	if (typeof(g_timeout) != 'undefined' && g_timeout) clearTimeout(g_timeout) 
	lwr(html, 'ourDiv')
	if (our) showObject(our)
}

function ourlib (p_html, ofs_x, ofs_y) {
  if(ns4) our=document.ourDiv;
  if(ie) our=ourDiv.style;
  if(ns6) our=document.getElementById("ourDiv");
  if (ofs_x) ooffsetx = ofs_x; else ooffsetx=13;
  if (ofs_y) ooffsety = ofs_y; else ooffsety=10;
	repositionTo(our, ox, oy)
	html=p_html
	if (typeof(g_timeout) != 'undefined' && g_timeout) clearTimeout(g_timeout)
	g_timeout=setTimeout('ourlib_delayed()', delay)
	g_on=true
}

function nd () {
	if (typeof(g_timeout) != 'undefined' && g_timeout) clearTimeout(g_timeout)
	if (our) {
		hideObject(our)
		delete our
	}
	g_on=false
	return true
}

function getObject(obj_id) {
  var obj;
  // alert('searching for ' + obj_id);
  if(ns4) obj=eval('document.'+obj_id);
  if(ie) { 
	try {
	  obj = eval(obj_id+'.style');
	} catch (e) { return; };
  }
  if(ns6) obj=document.getElementById(obj_id);
  //  alert('found a ' + typeof(obj_id));
  return obj;
}

function getObj(obj_id) {
  var obj;
  if(ns4) obj=eval('document.'+obj_id);
  if(ie) { 
	try {
	  obj = eval('document.all.'+obj_id);
	} catch (e) { return; };
  }
  if(ns6) obj=document.getElementById(obj_id);
  return obj;
}

function hideObject(obj, no_display){
  if (typeof(obj) == 'undefined') return false;
  if (ie) { obj.visibility="hidden"; if (!no_display) obj.display = 'none'; }
  else if (ns6||DOM2) { obj.style.visibility="hidden"; if (!no_display) obj.style.display = 'none'; }
  else if (ns4) obj.visibility="hide"
}

function showObject(obj, no_display, d_style){
  if (typeof(obj) == 'undefined') return false;
  if (!d_style) d_style = 'block';
   if (ie) { obj.visibility="visible"; if (!no_display) obj.display = d_style; }
  else if (ns6||DOM2) { obj.style.visibility="visible"; if (!no_display) obj.style.display = d_style; }
  else if (ns4) obj.visibility="show"
}

function repositionTo(obj,xL,yL){
	if(ns6){
		obj.style.left=xL + "px"
		obj.style.top=yL+ "px"
	} else if ((ns4)||(ie)) {
		obj.left=xL
		obj.top=yL
	}
}

function placeLayer(){
	var placeX, placeY

	var winoffset=(ie4)? document.body.scrollLeft : pageXOffset
	if (ie4) iwidth=document.body.clientWidth
	if (ns4) iwidth=innerWidth
	if (ns6) iwidth=outerWidth
	
	placeX=ox+ooffsetx
	if((eval(placeX)+ eval(owidth))>(winoffset + iwidth)){
		placeX=iwidth + winoffset - owidth
		if(placeX<0) placeX=0
	}
	
	var scrolloffset=(ie4)? document.body.scrollTop : pageYOffset
	placeY=oy + ooffsety
	if (g_on) repositionTo(our, placeX, placeY)
}

function mouseMove(e){
	if (ns){
		ox=e.pageX
		oy=e.pageY
	}

	if (ie4) {
		ox=event.x
		oy=event.y
	}

	if (ie5 || ie6 ) {
		ox=event.x+document.body.scrollLeft
		oy=event.y+document.body.scrollTop
	}

	placeLayer()
}

function hide_row(id) {
	var obj;
	var i = 0;
  
	while ( typeof(obj = getObject(id+i)) != 'undefined' && obj ) {
		hideObject(getObject(id+i));
		i++;
	}
}

function show_row(id) {
	var obj;
	var i = 0;
  
	while ( typeof(obj = getObject(id+i)) != 'undefined' && obj ) {
		showObject(getObject(id+i), false, ie?'block':'table-row');
		i++;
	}
}

function popup2(text) {		
 return '<table bgcolor="#8d8ba5" cellpadding="1" cellspacing="0" width="250"><tr><td><table width="100%" bgcolor="#ffffff" cellpadding="5" cellspacing="0"><tr><td class="basketcontent"><div align="justify">'+text+'<div></td></tr></table></td></tr></table>';	
 }


function popup() {
	var newWindow=window.open("generalterms.asp","","left=50,top=80,location=0,menubar=0,status=0,resizable=1,scrollbars=1,titlebar=0,toolbar=0,height=750,width=675");
}

function showmessage() 
	{
	alert("Ihren Warenkorb beinhaltet mindestens 1 Teil von einem anderen Rennen. Es ist leider nicht moeglich Tickets fuer verschiedene Rennen mit derselben Bestellung zu erwerben.");
	}

function updateBasket(prodid,quantity) {
	if (prodid != "" && IsNumeric(quantity)) {
		document.location.href="submit.asp?pageid="+gstrPageID+"&raceid="+gstrRaceID+"&submitaction=updatebasket&prodid=" + prodid + "&quantity=" + quantity;
	} else {
		alert("Bitte tragen Sie einen numerischen Wert ein.");
	}
}
function deleteBasket(prodid) {
	if (prodid != "" && prodid != "0") { document.location.href="submit.asp?pageid="+gstrPageID+"&raceid="+gstrRaceID+"&submitaction=deletebasket&prodid=" + prodid; }
}

function pagesubmit(input) {
	var objForm = document.forms[input];
	var msg = "";
	var premsg = "[DE:The following required fields are not correctly filled in]:\n\n";
	switch(input) {
		case "bestel2":
		
			if (objForm.inputfield1.value == "") { msg = msg + "- Name\n"; }
			
			if (objForm.inputfield2.value == "") {
				msg = msg + "- E-mail\n";
			} else {
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objForm.inputfield2.value)) {
				} else {
					msg = msg + "- E-mail\n";
				}
			}
			if (objForm.inputfield2_1.value != objForm.inputfield2.value) {msg = msg + "- E-mail konfirmation\n";}
			if (objForm.inputfield3.value == "") { msg = msg + "- Adresse - 1\n"; }
			if (objForm.inputfield8.value == "") { msg = msg + "- Postleitzahl\n"; }
			if (objForm.inputfield5.value == "") { msg = msg + "- Ort\n"; }
			if (objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == "Selecteer Land" || objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == '---------------') { msg = msg + "- Land\n"; }
			
			if (objForm.inputfield9.value == "") { msg = msg + "- Telefon\n"; }
			
		break;
		case "bestel3":
			if (objForm.inputfield12.options[objForm.inputfield12.selectedIndex].text == "Bitte wählen Sie aus") { msg = msg + "- Zahlungsweise\n"; }
			if (!objForm.inputfield30.checked) {
				if (objForm.inputfield18.value == "") { msg = msg + "- Naam\n"; }
				if (objForm.inputfield20.value == "") { msg = msg + "- Adresse - 1\n"; }
				if (objForm.inputfield25.value == "") { msg = msg + "- Postleitzahl\n"; }
				if (objForm.inputfield22.value == "") { msg = msg + "- Ort\n"; }
				if (objForm.inputfield27.value == "") { msg = msg + "- Telefon\n"; }
				if (objForm.inputfield24.options[objForm.inputfield24.selectedIndex].text == "Selecteer Land" || objForm.inputfield24.options[objForm.inputfield24.selectedIndex].text == '---------------') { msg = msg + "- Land\n"; }
			}
		break;
		case "bestel4":
			if (objForm.inputfield32.checked == false) { msg = msg + "- Allgemeine Bedingungen\n"; }
		break;
		case "contactus":
			if (objForm.naam.value == "") { msg = msg + "- Name\n"; }
			if (objForm.email.value == "") {
				msg = msg + "- E-mail\n";
			} else {
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objForm.email.value)) {
				} else {
					msg = msg + "- E-mail\n";
				}
			}
		break;

		case "racelistform":
			if (objForm.email.value == "") {
				msg = msg + "- E-mail\n";
			} else {
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objForm.email.value)) {
				} else {
					msg = msg + "- E-mail\n";
				}
			}
		break;
	}

	if (msg == "") {
		if (input == "contactus" || input == "racelistform") {
			return true;
		} else {
			objForm.submit();
		}
	} else {
		msg = premsg + msg;
		alert(msg);
		if (input == "contactus" || input == "racelistform") {
			return false;
		}
	}
}
function IsNumeric(strString) {
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

function checkValue(inputfield) {
	if (eval("document.bestel01." + inputfield).value > 99) {
		showErrorMsg(315);
		eval("document.bestel01." + inputfield).value = "";
	}
}

function adjustGrandTotal(input) {
	if (typeof document.forms.bestel4 != "undefined") {
		var tot = 1*document.forms.bestel4.hiddentotalabsolutes.value + 1*(document.forms.bestel4.hiddentotaladdonsabsolutesonce.value) + 1*(document.forms.bestel4.hiddentotaladdonsrelatives.value)
		if (input) {
			var oHidden = eval("document.forms.bestel4.hiddenoptional_"+input);
			var oInput = eval("document.forms.bestel4.optional_"+input);
			oInput.value = eval("document.forms.bestel4.check_"+input).checked ? oHidden.value : 0;
		}
		for (var i=0; i<document.forms.bestel4.length; i++) {
			if (document.forms.bestel4[i].name.substr(0,9)=="optional_") {
				tot += 1*document.forms.bestel4[i].value;
			}
		}
		document.forms.bestel4.displaygrandtotal.value = Math.round(tot);
		document.forms.bestel4.hiddengrandtotal.value = Math.round(tot);
	}
}

function countryShipping(input, promo) {
	var ShippingfeeCountry;
	if(promo == "mcn"){
		ShippingfeeCountry = 0;
	}
	else{
		switch(input.options[input.selectedIndex].text) {
			case "Deutschland": ShippingfeeCountry = 20;break;
			case "Germany":ShippingfeeCountry = 20;break;
			break;
			
			case "Spain": ShippingfeeCountry = 20;break;
			case "Ireland":ShippingfeeCountry = 20;break;
			case "Belgium":ShippingfeeCountry = 20;break;
			case "United Kingdom":ShippingfeeCountry = 20;break;
			case "Portugal":ShippingfeeCountry = 20;break;
			case "Austria":ShippingfeeCountry = 20;break;
			case "Italy":ShippingfeeCountry = 20;break;
			case "Netherlands":ShippingfeeCountry = 20;break;
			case "Luxembourg":ShippingfeeCountry = 20;break;
			case "Denmark":ShippingfeeCountry = 20;break;
			case "Greece":ShippingfeeCountry = 20;break;
			case "Finland":ShippingfeeCountry = 20;break;
			case "France":ShippingfeeCountry = 20;break;
			case "Sweden":ShippingfeeCountry = 20;break;
			case "Cyprus":ShippingfeeCountry = 20;break;
			case "Estonia":ShippingfeeCountry = 20;break;
			case "Hungary":ShippingfeeCountry = 20;break;
			case "Latvia":ShippingfeeCountry = 20;break;
			case "Malta":ShippingfeeCountry = 20;break;
			case "Poland":ShippingfeeCountry = 20;break;
			case "Slovenia":ShippingfeeCountry = 20;break;
			case "Slovakia":ShippingfeeCountry = 20;break;
			case "Czech Republic":ShippingfeeCountry = 20;break;
			case "Bulgaria":ShippingfeeCountry = 20;break;
			case "Lithuania":ShippingfeeCountry = 20;break;
			case "Romania":ShippingfeeCountry = 20;break;
				
			case "United States":ShippingfeeCountry = 20;break;
			case "Canada":ShippingfeeCountry = 20;break;
			case "Iceland":ShippingfeeCountry = 20;break;
			case "Ukraine":ShippingfeeCountry = 20;break;
			case "Russia":ShippingfeeCountry = 20;break;
			case "Turkey":ShippingfeeCountry = 20;break;
			case "Norway":ShippingfeeCountry = 20;break;
			case "Switzerland":ShippingfeeCountry = 20;break;

			
			default: ShippingfeeCountry = 25;
		}
	}
	document.forms.bestel2.ship.value = ShippingfeeCountry + "";
	document.forms.bestel2.hiddentotaladdonsabsolutesonce.value = ShippingfeeCountry;
	var tot = 1*document.forms.bestel1.hiddentotalabsolutes.value + 1*(document.forms.bestel2.hiddentotaladdonsabsolutesonce.value) + 1*(document.forms.bestel2.hiddentotaladdonsrelatives.value)
		for (var i=0; i<document.forms.bestel2.length; i++) {
			if (document.forms.bestel2[i].name.substr(0,9)=="optional_") {
				tot += 1*document.forms.bestel2[i].value;
			}
		}
		document.forms.bestel2.displaygrandtotal.value = Math.round(tot);
		document.forms.bestel2.hiddengrandtotal.value = Math.round(tot);
}

