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


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=1000");
}

function popup_gift() {
	var newWindow2=window.open("giftcertificate.asp","","left=50,top=80,location=0,menubar=0,status=0,resizable=1,scrollbars=1,titlebar=0,toolbar=0,height=600,width=1020");
}

function showmessage() 
	{
	alert("Your shopping-basket contains at least 1 item of a different race. It is not possible to buy tickets from different races in 1 order.");
	}

function updateBasket1(prodid,quantity) {
	if (prodid != "" && IsNumeric(quantity)) {
		document.location.href="submit.asp?pageid="+gstrPageID+"&raceid="+gstrRaceID+"&submitaction=updatebasket&prodid=" + prodid + "&quantity=" + quantity;
	} else {
		alert("Een numerieke waarde invoeren a.u.b.");
	}
}

function updateBasket(goPage,rName,prodid,quantity) {
	if (prodid != "" && IsNumeric(quantity) && quantity != 0 ) {
		document.location.href="submit.asp?pageid="+goPage+"&raceid="+rName+"&submitaction=updatebasket&prodid=" + prodid + "&quantity=" + quantity +  "&currentpage=" + gstrPageID;
	} else {
		alert("Enter a numeric value.");
	}
}

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 = "The following fields aren't filled correctly\n\n";
	switch(input) {
		case "bestel1":
			//if (objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == "Select country" || objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == '---------------') { msg = msg + "- Select country\n"; }
			//alert(objForm.hiddentotalabsolutes.value);
			if (objForm.hiddentotalabsolutes.value == 0) { msg = msg + "No products\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 + "- Confirmation 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 + "- Zip Code\n"; }
			if (objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == "Select Country" || objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == "---------------") { msg = msg + "- Country\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 + "- Home Phone number\n"; }
			
			if (objForm.inputfield12.options[objForm.inputfield12.selectedIndex].text == "Select method") { msg = msg + "- Payment type\n"; }
			//if (objForm.inputfield30.checked && objForm.inputfield18.value != "" && objForm.inputfield20.value != "" && objForm.inputfield25.value != "" && objForm.inputfield22.value != "") {}
			//else if (!objForm.inputfield30.checked){}
			//	else{msg = msg + " \nBilling address:\n"; }
			if (objForm.inputfield30.checked) {
				//if (objForm.inputfield18.value == "" || objForm.inputfield20.value == "" || objForm.inputfield25.value == "" || objForm.inputfield22.value == "" || objForm.inputfield24.options[objForm.inputfield24.selectedIndex].text == "Select Country"){msg = msg + " \nBilling address:\n";} 
				if (objForm.inputfield18.value == "") { msg = msg + "- Billing Name\n"; }
				if (objForm.inputfield20.value == "") { msg = msg + "- Billing Address\n"; }
				if (objForm.inputfield25.value == "") { msg = msg + "- Billing Zip Code\n"; }
				if (objForm.inputfield22.value == "") { msg = msg + "- Billing City\n"; }
				if (objForm.inputfield24.options[objForm.inputfield24.selectedIndex].text == "Select Country" || objForm.inputfield24.options[objForm.inputfield24.selectedIndex].text == '---------------') { msg = msg + "- Billing Country\n"; }
			}
		break;
		case "bestel3":
			if (objForm.inputfield12.options[objForm.inputfield12.selectedIndex].text == "Select method") { msg = msg + "- Payment type\n"; }
			if (!objForm.inputfield30.checked) {
				if (objForm.inputfield18.value == "") { msg = msg + "- Name\n"; }
				if (objForm.inputfield20.value == "") { msg = msg + "- Address\n"; }
				if (objForm.inputfield22.value == "") { msg = msg + "- City\n"; }
				if (objForm.inputfield25.value == "") { msg = msg + "- Zip Code\n"; }
				
				if (objForm.inputfield24.options[objForm.inputfield24.selectedIndex].text == "Select country" || objForm.inputfield24.options[objForm.inputfield24.selectedIndex].text == '---------------') { msg = msg + "- 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;
	}

	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 > 15) {
		showErrorMsg(315);
		eval("document.bestel01." + inputfield).value = "";
	}
}

function adjustGrandTotal(input) {
	if (typeof document.forms.bestel1 != "undefined") {
		var tot = 1*document.forms.bestel1.hiddentotaldiscounts.value + 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, promo) {
	var ShippingfeeCountry;
	if(promo == "mcn"){
		ShippingfeeCountry = 0;
	}
	else{
		/*switch(input.options[input.selectedIndex].text) {
			case "Select country": ShippingfeeCountry = 0;
			break;
			
			case "Spain": ShippingfeeCountry = 25;break;
			case "Ireland":ShippingfeeCountry = 25;break;
			case "Belgium":ShippingfeeCountry = 25;break;
			case "United Kingdom":ShippingfeeCountry = 25;break;
			case "Portugal":ShippingfeeCountry = 25;break;
			case "Austria":ShippingfeeCountry = 25;break;
			case "Germany":ShippingfeeCountry = 25;break;
			case "Italy":ShippingfeeCountry = 25;break;
			case "Netherlands":ShippingfeeCountry = 25;break;
			case "Luxembourg":ShippingfeeCountry = 25;break;
			case "Denmark":ShippingfeeCountry = 25;break;
			case "Greece":ShippingfeeCountry = 25;break;
			case "Finland":ShippingfeeCountry = 25;break;
			case "France":ShippingfeeCountry = 25;break;
			case "Sweden":ShippingfeeCountry = 25;break;
			case "Cyprus":ShippingfeeCountry = 25;break;
			case "Estonia":ShippingfeeCountry = 25;break;
			case "Hungary":ShippingfeeCountry = 25;break;
			case "Latvia":ShippingfeeCountry = 25;break;
			case "Malta":ShippingfeeCountry = 25;break;
			case "Poland":ShippingfeeCountry = 25;break;
			case "Slovenia":ShippingfeeCountry = 25;break;
			case "Slovakia":ShippingfeeCountry = 25;break;
			case "Czech Republic":ShippingfeeCountry = 25;break;
			case "Bulgaria":ShippingfeeCountry = 25;break;
			case "Lithuania":ShippingfeeCountry = 25;break;
			case "Romania":ShippingfeeCountry = 25;break;
				
			case "United States":ShippingfeeCountry = 25;break;
			case "Canada":ShippingfeeCountry = 25;break;
			case "Iceland":ShippingfeeCountry = 25;break;
			case "Ukraine":ShippingfeeCountry = 25;break;
			case "Russia":ShippingfeeCountry = 25;break;
			case "Turkey":ShippingfeeCountry = 25;break;
			case "Norway":ShippingfeeCountry = 25;break;
			case "Switzerland":ShippingfeeCountry = 25;break;
			default: ShippingfeeCountry = 25;		
			}
			*/
			ShippingfeeCountry = 25;
	
	}	
	document.forms.bestel1.ship.value = ShippingfeeCountry + "";
	document.forms.bestel1.hiddentotaladdonsabsolutesonce.value = ShippingfeeCountry;
	var tot = 1*document.forms.bestel1.hiddentotaldiscounts.value + 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);
}

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"
}
