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, ie7
if (ie4) {
  if (navigator.userAgent.indexOf('MSIE 5')>0) ie5=true
  if (navigator.userAgent.indexOf('MSIE 6')>0) ie6=true
  if (navigator.userAgent.indexOf('MSIE 7')>0) ie7=true
} else ie5 = ie6 = ie7 = false

var ie=ie4||ie5||ie6||ie7
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 || ie7) {
		ox=event.x+document.body.scrollLeft
		oy=event.y+document.body.scrollTop
	}
	
	//alert(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) {	
var inputtext;
if (text !=''){
	inputtext = text;
}else{
	inputtext = 'Sorry, no description available';
}
 //return '<table border="0" cellpadding="0" cellspacing="0" bgcolor="#CAE167" width="240"><tr><td valign="top"  bgcolor="#CAE167"><img src="images/popupgoto.gif" /></td><td valign="top"><table cellpadding="0" cellspacing="0" border="0" width="73%"><tr><td><img src="images/popupballoontop.gif"/></td></tr><tr><td height="205"><table width="100%"height="207" border="0" cellpadding="0" cellspacing="0"><tr><td width="211" height="207" bgcolor="#FFFFFF" style="padding-left:5px;" valign="top" class="welcomediv">'+inputtext+'</td><td width="1%" background="images/popupbg_hor.gif" style="background-repeat:repeat-x"></td></tr></table></td></tr><tr><td><img src="images/popupballoonbottom.gif" /></td></tr></table></td><td width="1" background="images/popupbg_hor.gif" style="background-repeat:repeat-x"></td></tr></table>';	
return '<table width="271" height="166" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="2"><img src="images/popup1.gif" width="271" height="32" alt=""></td></tr><tr><td width="79" height="134"><img src="images/popup2.gif" width="79" height="134" alt=""></td><td width="192" height="134" class="product_popup">'+inputtext+'</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("Your shoppping basket contains at least one item from another race.\nIt's not possible to buy tickets from different races in one order.");
	}

function updateBasket(goPage,prodid,quantity) {
	if (prodid != "" && IsNumeric(quantity) && quantity != "0") {
		document.location.href="submit.asp?pageid="+goPage+"&raceid="+gstrRaceID+"&submitaction=updatebasket&prodid=" + prodid + "&quantity=" + quantity + "&currentpage="+gstrPageID;
		
	} else {
		alert("Please enter a numeric value.");
	}
}

function directBestellen(goPage) {
	var frm = document.bestel01.textfield_prod;
	var prd = document.bestel01.prd;
	var l = frm.length;
	var strPrd="";
	var strAantal="";
	for (var i = 0; i < l; i++){
		if (prd[i].value != "" && IsNumeric(frm[i].value)){
			if (i == l-1){
				strPrd+=prd[i].value;
				strAantal+=frm[i].value;		
			}else{
				strPrd+=prd[i].value+",";
				strAantal+=frm[i].value+",";
			}
		}	
	}
	
	if (strPrd != "" && strAantal != "") {
		document.location.href="submit.asp?pageid="+goPage+"&raceid="+gstrRaceID+"&submitaction=updatebasket&prodid=" + strPrd + "&quantity=" + strAantal;
	} else {
		alert("Please enter a numeric value.");
	}
}


function deleteBasket(prodid) {

if ((gstrPageID == "WWW_GPMONACO_EN_ORDER_CONFIRM")||(gstrPageID == "WWW_GPMONACO_EN_CONTACTUS") || (gstrPageID =="WWW_GPMONACO_EN_BASKET") )
	{gstrPageID = "WWW_GPMONACO_EN";
	}
	
	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 = "The following fields are mandatory:\n\n";
	switch(input) {
		case "bestel1":
			//if (objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == "Select your country" || objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == '---------------') { msg = msg + "- Select your country\n"; }
		break;
		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.value != objForm.inputfield2_1.value) {msg = msg + "- Bevestinging E-mail\n";}
			if (objForm.inputfield3.value == "") { msg = msg + "- Address\n"; }
			if (objForm.inputfield5.value == "") { msg = msg + "- City\n"; }
			if (objForm.inputfield8.value == "") { msg = msg + "- Postal code\n"; }
			
			if (objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == "Select your country" || objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == '---------------') { msg = msg + "- Country\n"; }
			if (objForm.inputfield9.value == "") { msg = msg + "- Telephone\n"; }
			
			if (objForm.inputfield12.selectedIndex == 0) { msg = msg + "- Payment method\n"; }
			if (!objForm.inputfield30.checked) {
				if (objForm.inputfield18.value == "") { msg = msg + "- Billing Name\n"; }
				if (objForm.inputfield20.value == "") { msg = msg + "- Billing Adress\n"; }
				if (objForm.inputfield25.value == "") { msg = msg + "- Billing Postal code\n"; }
				if (objForm.inputfield22.value == "") { msg = msg + "- Billing City\n"; }
				if (objForm.inputfield24.selectedIndex == 0)  { msg = msg + "- Billing Country\n"; }
			}
		
		break;
		case "bestel4":
			if (objForm.inputfield29.checked == false) { msg = msg + "- General terms\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;
		case "callback":
		if (objForm.naam2.value == "") { msg = msg + "- Name\n"; }
		if (objForm.number2.value == "") { msg = msg + "- Phone number\n"; }
		if (objForm.times2.value == "") { msg = msg + "- How many times\n"; }
			
		break;
		
		
		
	}

	if (msg == "") {
		if (input == "contactus" || input == "racelistform" || input == "callback") {
			return true;
		} else {
			objForm.submit();
		}
	} else {
		msg = premsg + msg;
		alert(msg);
		if (input == "contactus" || input == "racelistform" || input == "callback") {
			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.bestel1 != "undefined") {
		var tot = 1*document.forms.bestel1.hiddentotalabsolutes.value + 1*(document.forms.bestel1.hiddentotaladdonsabsolutesonce.value) + 1*(document.forms.bestel1.hiddentotaladdonsrelatives.value)
		if (input) {
			var oHidden = eval("document.forms.bestel1.hiddenoptional_"+input);
			var oInput = eval("document.forms.bestel1.optional_"+input);
			oInput.value = eval("document.forms.bestel1.check_"+input).checked ? oHidden.value : 0;
		}
		for (var i=0; i<document.forms.bestel1.length; i++) {
			if (document.forms.bestel1[i].name.substr(0,9)=="optional_") {
				tot += 1*document.forms.bestel1[i].value;
			}
		}
		document.forms.bestel1.displaygrandtotal.value = Math.round(tot);
		document.forms.bestel1.hiddengrandtotal.value = Math.round(tot);
	}
}

function countryShipping(input) {
	var ShippingfeeCountry;
		switch(input.options[input.selectedIndex].text) {
			case "Select your country": ShippingfeeCountry = 0;
			break;
			
			case "Belgium": ShippingfeeCountry = 25;
break;
case "belgium": ShippingfeeCountry = 25;
break;
case "Belgien": ShippingfeeCountry = 25;
break;
case "België": ShippingfeeCountry = 25;
break;
	
case "Albania":ShippingfeeCountry = 25;break;
case "Andorra":ShippingfeeCountry = 25;break;
case "Austria":ShippingfeeCountry = 25;break;
case "Belarus":ShippingfeeCountry = 25;break;
case "Bosnia and Herzegovina":ShippingfeeCountry = 25;break;
case "Bulgaria":ShippingfeeCountry = 25;break;
case "Croatia":ShippingfeeCountry = 25;break;
case "Cyprus":ShippingfeeCountry = 25;break;
case "Czech Republic":ShippingfeeCountry = 25;break;
case "Denmark":ShippingfeeCountry = 25;break;
case "Estonia":ShippingfeeCountry = 25;break;
case "Finland":ShippingfeeCountry = 25;break;
case "France":ShippingfeeCountry = 25;break;
case "Germany":ShippingfeeCountry = 25;break;
case "Greece":ShippingfeeCountry = 25;break;
case "Hungary":ShippingfeeCountry = 25;break;
case "Iceland":ShippingfeeCountry = 25;break;
case "Ireland":ShippingfeeCountry = 25;break;
case "Italy":ShippingfeeCountry = 25;break;
case "Latvia":ShippingfeeCountry = 25;break;
case "Liechtenstein":ShippingfeeCountry = 25;break;
case "Lithuania":ShippingfeeCountry = 25;break;
case "Luxembourg":ShippingfeeCountry = 25;break;
case "Macedonia":ShippingfeeCountry = 25;break;
case "Malta":ShippingfeeCountry = 25;break;
case "Moldova":ShippingfeeCountry = 25;break;
case "Monaco":ShippingfeeCountry = 25;break;
case "Nederland":ShippingfeeCountry = 25;break;
case "Norway":ShippingfeeCountry = 25;break;
case "Poland":ShippingfeeCountry = 25;break;
case "Portugal":ShippingfeeCountry = 25;break;
case "Romania":ShippingfeeCountry = 25;break;
case "Russia":ShippingfeeCountry = 25;break;
case "San Marino":ShippingfeeCountry = 25;break;
case "Serbia and Montenegro":ShippingfeeCountry = 25;break;
case "Slovakia":ShippingfeeCountry = 25;break;
case "Slovenia":ShippingfeeCountry = 25;break;
case "Spain":ShippingfeeCountry = 25;break;
case "Sweden":ShippingfeeCountry = 25;break;
case "Switzerland":ShippingfeeCountry = 25;break;
case "Turkey":ShippingfeeCountry = 25;break;
case "Ukraine":ShippingfeeCountry = 25;break;
case "United Kingdom":ShippingfeeCountry = 25;break;
case "Vatican City":ShippingfeeCountry = 25;break;

			
			default: ShippingfeeCountry = 25;
		}
	document.forms.bestel1.ship.value = ShippingfeeCountry + "";
	document.forms.bestel1.hiddentotaladdonsabsolutesonce.value = ShippingfeeCountry;
	var tot = 1*document.forms.bestel1.hiddentotalabsolutes.value + 1*(document.forms.bestel1.hiddentotaladdonsabsolutesonce.value) + 1*(document.forms.bestel1.hiddentotaladdonsrelatives.value)
		for (var i=0; i<document.forms.bestel1.length; i++) {
			if (document.forms.bestel1[i].name.substr(0,9)=="optional_") {
				tot += 1*document.forms.bestel1[i].value;
			}
		}
		document.forms.bestel1.displaygrandtotal.value = Math.round(tot);
		document.forms.bestel1.hiddengrandtotal.value = Math.round(tot);
}