// Begin BM Functions

function submitStep2(){
	var r = document.form2.r2.value;
	var gasit = false;
	if (!isNumeric(r)){gasitsubmitStep1() = true;}
	r = document.form2.r3cash.value;
	if (!isNumeric(r)){gasit = true;}
	r = document.form2.r3pin.value;
	if (!isNumeric(r)){gasit = true;}
	r = document.form2.r5a.value;
	if (!isNumeric(r)){gasit = true;}
	r = document.form2.r5b.value;
	if (!isNumeric(r)){gasit = true;}
	if (gasit == true){
		alert('U heeft niet alle velden ingevuld!');
	}else{
		top.location.href='result.asp';
		document.form2.submit();
	}
}

function submitStep1(){
	var gasit = false;
	var r = document.form1.RadioGroup1a.value;
	if (!document.form1.RadioGroup1a[0].checked && !document.form1.RadioGroup1a[1].checked)
	{
		gasit=true;
	}
	r = document.form1.RadioGroup1b.value;
	if (!document.form1.RadioGroup1b[0].checked && !document.form1.RadioGroup1b[1].checked)
	{
		gasit=true;
	}
	r = document.form1.RadioGroup1c.value;
	if (!document.form1.RadioGroup1c[0].checked && !document.form1.RadioGroup1c[1].checked)
	{
		gasit=true;
	}
	r = document.form1.RadioGroup1d.value;
	if (!document.form1.RadioGroup1d[0].checked && !document.form1.RadioGroup1d[1].checked)
	{
		gasit=true;
	}
	r = document.form1.RadioGroup1e.value;
	if (!document.form1.RadioGroup1e[0].checked && !document.form1.RadioGroup1e[1].checked)
	{
		gasit=true;
	}
	r = document.form1.RadioGroup1f.value;
	if (!document.form1.RadioGroup1f[0].checked && !document.form1.RadioGroup1f[1].checked){gasit=true;}
	if (gasit == true){
		alert('U heeft niet alle velden ingevuld!');
	}else{
		top.location.href='step2.asp'
		document.form1.submit();
	}
		
}

function percentage3a()	{

    var perc1 = document.form2.r3pin.value;
	var perc2 = 100 - perc1 ;
		if(perc1 <= 100) {
		document.form2.r3cash.value = perc2;
		document.form2.r3pin.focus();
		}
		else {
		alert("voer een waarde in tussen 0 en 100%");
		document.form2.r3pin.value = 0;
		}
}

function percentage3b()	{
    var perc2 = document.form2.r3cash.value;
	var perc1 = 100 - perc2 ;
		if(perc1 <= 100) {
	    document.form2.r3pin.value = perc1;
		}
		else {
		alert("voer een waarde in tussen 0 en 100%");
		document.form2.r3cash.value = 0;
		}
}

function toggle_show(itemID){
		document.getElementById(itemID).style.display = 'inline';
} 

function toggle_hide(itemID){ 
        document.getElementById(itemID).style.display = 'none'; 
}

function toggle_hide2(itemID){ 
  var1 = itemID.substr(0,3)
  var2 = var1 + '2'
  var3 = itemID.substr(0,2)
		document.getElementById(var2).value = '';
		document.getElementById(var3).selectedIndex = 0;
		document.getElementById(itemID).style.display = 'none';

}


function validate_form() {
alert ('test');
}

function validate_required(field,alerttxt) {
	with (field)
	{
	if (value==null||value=="")
	  {alert(alerttxt);return false}
	else {return true}
	}
	}function validate_form(thisform)
	{
	with (thisform)
	{
	if (validate_required(email,"Email must be filled out!")==false)
	  {email.focus();return false}
	}
}


function hide_explain(itemID){
		document.getElementById(itemID).style.display = 'none';
		var1=itemID + '_button'
		document.getElementById(var1).style.display = 'inline';
}

function show_explain(itemID){
		document.getElementById(itemID).style.display = 'inline';
		var1=itemID + '_button'
		document.getElementById(var1).style.display = 'none';
}

function checkIP(itemID) {

  var1 = document.getElementById(itemID).value;
  var2 = itemID + 'b1'
  var3 = itemID + 'b2'

  var4 = document.getElementById('1Cb1').style.display;
  var5 = document.getElementById('1Db1').style.display;
  var6 = document.getElementById('1Eb1').style.display;
  var7 = document.getElementById('1Fb1').style.display;

// Look if choice is broadband and not chosen before, if true then show extra input field 
  if ((var1 == 3) && (var4 == 'none') && (var5 == 'none') && (var6 == 'none') && (var7 == 'none')  ) {
 	  document.getElementById(var2).style.display = 'inline';
	  document.getElementById(var3).focus();
  }
// in all other cases hide extra input field (or keep hidden)
  else { document.getElementById(var2).style.display = 'none';
  }


}

addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

enterAsTab = function(){
	function next(e){
		var l, i, f, j, o = e.target;
		if(e.key == 13 && !/textarea|select/i.test(o.type)){
			for(i = l = (f = o.form.elements).length; f[--i] != o;);
			for(j = i; (j = (j + 1) % l) != i && (!f[j].type || f[j].disabled || f[j].readOnly || f[j].type.toLowerCase() == "hidden"););				
			e.preventDefault(), j != i && f[j].focus();
		}
	}
	for(var f, i = (f = document.forms).length; i; addEvent(f[--i], "keypress", next));
};


// End BM Functions


function checkIt(string) {
	place = navigator.userAgent.toLowerCase().indexOf(string) + 1
	return place
}

function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length)
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1)
	}
	return s
}

function onEnterReturnFalse(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode
	if (keyCode == 13) {
		return false
	}
	else {
		return true
	}
}

function onEnter(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode
	if (keyCode == 13) {
		alert("Klik op de knop \"Volgende\" om het formulier op te sturen!")
		return false
	}
	else {
		return true
	}
}

function enterKeyPressed(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode
	if (keyCode == 13) {
		return true
	}
	else {
		return false
	}
}

var newWin

function openWindowCentered(url, WinWidth, WinHeight, WinOptions) {
	// set default window width
	if (WinWidth == null) WinWidth = 650;

	// set default window height
	if (WinHeight == null) WinHeight = 540;

	if (WinOptions == null) {
		// set default window options
		WinOptions = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
	}
	
	// half the screen width minus half the new window width (plus 5 pixel borders).
	var iMyWidth = (window.screen.width/2) - ((WinWidth/2) + 10);
	// half the screen height minus half the new window height (plus title and status bars).
	var iMyHeight = (window.screen.height/2) - ((WinHeight/2) + 50);
	// open the window
	var newWin = window.open(url, '_blank', "height=" + WinHeight + ",width=" + WinWidth + ",left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ',' + WinOptions);
	
	// set the focus to it
	if (newWin) newWin.focus();
	
	return newWin;
}

function openPopup(url) {
	newWin = window.open(url, 'HBDPopup', "width=640,height=480,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no", true)
	newWin.focus()
}

function openPrintWindow(url) {
	newWin = window.open(url , 'HBDPrintWindow', "width=640,height=480,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no", true)
	// close newWin
	//setTimeout("closeWindow()", 1500)
}

function closePrintWindow() {
	if (newWin) newWin.close()
}

function isNumeric(vTestValue)
{
	// put the TEST value into a string object variable
	var sField = new String(vTestValue);
	
	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}
	
	// made it through the loop - we have a number
	return true;
}

function IsEmpty(value) {
   if (value==null) return true;
   if ((value.length==0) ||
   (value==null)) {
      return true;
   }
   else { return false; }
}	