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 ox_absolute = 0, oy_absolute = 0;

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 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 updateBasket(prodid,quantity) {
	if (prodid != "" && IsNumeric(quantity)) {
		document.location.href="submit.asp?pageid="+gstrPageID+"&raceid="+gstrRaceID+"&submitaction=updatebasket&prodid=" + prodid + "&quantity=" + quantity;
	} 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 insertAccountAddress(strName, strAddr1, strAddr2, strArea, strCity, strState, strCountry) {
	var formobj = document.bestel3;		
	if (formobj.inputfield30.checked == true) {
		formobj.inputfield18.value = strName;
		formobj.inputfield20.value = strAddr1;
		formobj.inputfield21.value = strAddr2;
		formobj.inputfield25.value = strArea;
		formobj.inputfield22.value = strCity;
		formobj.inputfield23.value = strState;
		for (i=0;i<formobj.inputfield24.length;i=i+1) {
			if (formobj.inputfield24[i].text == strCountry) {
				formobj.inputfield24.selectedIndex = i;
			}
		}
	} else {
		formobj.inputfield18.value = "";
		formobj.inputfield20.value = "";
		formobj.inputfield21.value = "";
		formobj.inputfield22.value = "";
		formobj.inputfield23.value = "";
		formobj.inputfield25.value = "";
		formobj.inputfield24.selectedIndex = 0;
	}
}

function pagesubmit(input) {
	var objForm = document.forms[input];
	var msg = "";
	var premsg = "The following fields aren't filled correctly \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.inputfield3.value == "") { msg = msg + "- Adress\n"; }
			if (objForm.inputfield8.value == "") { msg = msg + "- Zip code\n"; }
			if (objForm.inputfield5.value == "") { msg = msg + "- City\n"; }
			if (objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == "Select Country" || objForm.inputfield7.options[objForm.inputfield7.selectedIndex].text == "---------------") { msg = msg + "- Country\n"; }
			if (objForm.inputfield9.value == "") { msg = msg + "- Home phone number\n"; }
			break;

		case "bestel3":
			if (objForm.inputfield12.options[objForm.inputfield12.selectedIndex].text == "Select method") { msg = msg + "- Payment method\n"; }
			if (!objForm.inputfield30.checked) {
				if (objForm.inputfield18.value == "") { msg = msg + "- Name\n"; }
				if (objForm.inputfield20.value == "") { msg = msg + "- Adress\n"; }
				if (objForm.inputfield25.value == "") { msg = msg + "- Zip code\n"; }
				if (objForm.inputfield22.value == "") { msg = msg + "- City\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-mailadress\n";
			} else {
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objForm.email.value)) {
				} else {
					msg = msg + "- E-mailadress\n"; 
				}
			}
			break;

		case "inform","racelistform":
			if (objForm.email.value == "") {
				msg = msg + "- E-mailadress\n";
			} else {
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(objForm.email.value)) {
				} else {
					msg = msg + "- E-mailadress\n"; 
				}
			}
			break;
	}

	if (msg == "") {
		if (input == "contactus" || input == "inform" || input == "racelistform") {
		return true;
		} else {
		objForm.submit();
		}
	} else {
		msg = premsg + msg;
		alert(msg);
		if (input == "contactus" || input == "inform" || 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 ourlib (p_html, ofs_x, ofs_y) {
	if(p_html == ""){
		return;
	}
	
	var viewHeight = GetViewport().height;
	var viewCorrection_y = 0;
	
	if(ns4) our=document.ourDiv;
	if(ie) our=ourDiv.style;
	if(ns6) our=document.getElementById("ourDiv");
  
	if(viewHeight - oy_absolute <= 195){
		viewCorrection_y = -240;
	}
	
	if (ofs_x) ooffsetx = ofs_x; else ooffsetx=13;
	if (ofs_y) ooffsety = ofs_y; else ooffsety=10 + viewCorrection_y;
	
	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 popup2(text) {	
var inputtext;
if (text !=''){
	inputtext = text;
}else{
	return "";
}
 return '<table class="description" border="0" cellpadding="0" cellspacing="0" width="270">' +
			'<tr><td valign="top" class="description_text">' + inputtext + 				
			'</td></tr>' +
		'</table>';	
}

function mouseMove(e){
	if (ns){
		ox=e.pageX
		oy=e.pageY
		ox_absolute = e.clientX;
		oy_absolute = e.clientY;
	}

	if (ie4) {
		ox=event.x
		oy=event.y
		ox_absolute = ox;
		oy_absolute = oy;
	}

	if (ie5 || ie6 || ie7) {
		ox=event.x+document.body.scrollLeft
		oy=event.y+document.body.scrollTop
		ox_absolute = event.x;
		oy_absolute = event.y;
	}
		
	placeLayer()
}

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 nd () {
	if (typeof(g_timeout) != 'undefined' && g_timeout) clearTimeout(g_timeout)
	if (our) {
		hideObject(our)
		delete our
	}
	g_on=false
	return true
}

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 ourlib_delayed () {
	if (typeof(g_timeout) != 'undefined' && g_timeout) clearTimeout(g_timeout) 
	lwr(html, 'ourDiv')
	if (our) showObject(our)
}

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 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 GetViewport(){
	var width;
	var height;
	var viewport = {x:0,y:0,width:0,height:0};

	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

	if (typeof window.innerWidth != 'undefined')
	{
	  viewport.width = window.innerWidth;
	  viewport.height = window.innerHeight;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewport.width = document.documentElement.clientWidth,
	   viewport.height = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
	   viewport.width = document.getElementsByTagName('body')[0].clientWidth,
	   viewport.height = document.getElementsByTagName('body')[0].clientHeight
	}
	return viewport;
}