function changeOpac(opacity, id)
{
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 101);
	object.MozOpacity = (opacity / 101);
	object.KhtmlOpacity = (opacity / 101);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function blendimage(divid, imageid, imagefile, millisec)
{
	var speed = Math.round(millisec / 10);
	var timer = 0;

	//set the current image as background
	//document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

	//make image transparent
	changeOpac(0, imageid);

	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 101; i++)
	{
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function setBorder(current){
	for(i = 0; i < images.length; i++){
		thumb = document.getElementById(images[i]);
		if(thumb.id != current){
			thumb.style.border = '1px solid #000000';
		} else {
			thumb.style.border = '1px solid #e4df95';
		}
	}
}

var slideCache = new Array();

function RunSlideShow(divid,imageid,imageFiles,displaySecs)
{
	var imageSeparator = imageFiles.indexOf(";");
	var nextImage = imageFiles.substring(0,imageSeparator);

	changeOpac(0, imageid);

	blendimage(divid,imageid,nextImage,100);

	var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImage;
	setTimeout("RunSlideShow('"+divid+"','"+imageid+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);

	// Cache the next image to improve performance.
	imageSeparator = futureImages.indexOf(";");
	nextImage = futureImages.substring(0,imageSeparator);

	if (slideCache[nextImage] == null)
	{
		slideCache[nextImage] = new Image;
		slideCache[nextImage].src = nextImage;
	}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function selectedpop() {
	window.open("volvoselectedusedcar.php","suc","width=420, height=400");
}

function selectedpop_bovag() {
	window.open("volvo_bovag.php","suc","width=420, height=200");
}

function selectedpop_nieuw() {
	window.open("volvo_nieuw.php","suc","width=420, height=250");
}

function check(theForm) {

  if (theForm.naam.value=="") {
    theForm.naam.focus();
    alert("Vul uw naam in.");
    return false;
  }
  if (theForm.voorletters.value=="") {
    theForm.voorletters.focus();
    alert("Vul uw voorletters in.");
    return false;
  }
  if (theForm.adres.value=="") {
    theForm.adres.focus();
    alert("Vul uw adres in.");
    return false;
  }
  if (theForm.huisnummer.value=="") {
    theForm.huisnummer.focus();
    alert("Vul uw huisnummer in.");
    return false;
  }
  if (theForm.postcode1.value=="") {
    theForm.postcode1.focus();
    alert("Vul uw postcode in.");
    return false;
  }
  if (theForm.postcode2.value=="") {
    theForm.postcode2.focus();
    alert("Vul uw postcode in.");
    return false;
  }
  if (theForm.woonplaats.value=="") {
    theForm.woonplaats.focus();
    alert("Vul uw woonplaats in.");
    return false;
  }
  if (theForm.telefoon.value=="") {
    theForm.telefoon.focus();
    alert("Vul uw telefoonnumer in.");
    return false;
  }
  if (theForm.email.value=="") {
    theForm.email.focus();
    alert("Vul uw email in.");
    return false;
  }
  if (theForm.bday.value=="0") {
    theForm.bday.focus();
    alert("Vul uw geboortedag in.");
    return false;
  }
  if (theForm.bmonth.value=="0") {
    theForm.bmonth.focus();
    alert("Vul uw geboortemaand in.");
    return false;
  }
  if (theForm.byear.value=="0") {
    theForm.byear.focus();
    alert("Vul uw geboortejaar in.");
    return false;
  }
  if (theForm.auto.value=="0") {
    theForm.auto.focus();
    alert("Vul uw huidige auto in.");
    return false;
  }
  if (theForm.type.value=="0") {
    theForm.type.focus();
    alert("Vul het type van uw huidge auto in.");
    return false;
  }
  if (theForm.kenteken1.value=="0") {
    theForm.kenteken1.focus();
    alert("Vul uw kenteken in.");
    return false;
  }
  if (theForm.kenteken2.value=="0") {
    theForm.kenteken2.focus();
    alert("Vul uw kenteken in.");
    return false;
  }
  if (theForm.kenteken3.value=="0") {
    theForm.kenteken3.focus();
    alert("Vul uw kenteken in.");
    return false;
  }
  return true;
}


function checkleasebox(leaseboxvalue) {
	//var leaseboxvalue = valButton(naw_inschrijftabel.lease);
	//var leaseboxvalue = $().attr('value');
	//alert(leaseboxvalue);
	if (leaseboxvalue == "ja") {
		document.getElementById('lease_tr').style.display="inline";
	} else {
		document.getElementById('lease_tr').style.display="none";
	}
}

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

//
function contactformcheck(theForm) {
//  var vestiging = valButton(naw_contacttabel.vestiging);
//  if (vestiging==null) {
//    alert("Kies een vestiging uit.");
//    return false;
//  }
  if (theForm.naam.value=="") {
    theForm.naam.focus();
    alert("Vul uw naam in.");
    return false;
  }
  if (theForm.voorletters.value=="") {
    theForm.voorletters.focus();
    alert("Vul uw voorletters in.");
    return false;
  }
  if (theForm.telefoon.value=="") {
    theForm.telefoon.focus();
    alert("Vul uw telefoonnumer in.");
    return false;
  }
  if (theForm.email.value=="") {
    theForm.email.focus();
    alert("Vul uw email in.");
    return false;
  }
  if (theForm.opmerking.value=="") {
    theForm.opmerking.focus();
    alert("Vul een opmerking of vraag in.");
    return false;
  }
  return true;

}


// Autotab functionaliteit
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}


function meergegevensformcheck(theForm) {
  if (theForm.naam.value=="") {
    theForm.naam.focus();
    alert("Vul uw naam in.");
    return false;
  }
  if (theForm.voorletters.value=="") {
    theForm.voorletters.focus();
    alert("Vul uw voorletters in.");
    return false;
  }
  if (theForm.email.value=="") {
    theForm.email.focus();
    alert("Vul uw email in.");
    return false;
  }

  return true;
}
