function enhanceCheckboxes() {

// finds every checkbox on the page
// and converts it to a graphical version
  
  // find all input controls:
  var els=document.getElementsByTagName("input");
  
  // for each input element...
  for(var i=0; i < els.length; i++) {
      

    if (els[i].type=='checkbox') { // its a checkbox
  
      // hide the original checkbox control:  
      els[i].style.display='none';
      
      // create the graphical alternative:
      var img = document.createElement("img");
      
      // initial state of graphical checkbox 
      // is the same as the original checkbox:
       
      if (els[i].checked) {
       
        //img.src="/CheckboxChecked.gif.gif";
        img.src="/images/site/checkbox_checked.gif";
        img.title="Checked";
      }
      else {
      
        //img.src="/CheckboxUnchecked.gif";
        img.src="/images/site/checkbox.gif";
        img.title="Unchecked";
      } 
      
      // assign our onclick event 
      img.onclick= toggleCheckbox;
      
      // insert the new, clickable image into the DOM
      // infront of the original checkbox:
      
      els[i].parentNode.insertBefore(img, els[i]);
      
    }  
  
  }
 

}


function toggleCheckbox() {

// graphical checkbox onclick event handler
  var value = 50;
  // toggle the checkbox state:
  
  if (this.title == "Checked") {

    // toggle the image and title:  
   
    //this.src="/CheckboxUnchecked.gif";
    this.src="/images/site/checkbox.gif";
    this.title="Unchecked";
    
    // update the hidden real checkbox to match the state of the graphical 
    // version:
    this.nextSibling.checked=false;
   	value= parseFloat(this.nextSibling.value);
  }
  else {
  
    // toggle the image and title:  
    
    //this.src="/CheckboxChecked.gif";
    this.src="/images/site/checkbox_checked.gif";
    this.title="Checked";

    // update the hidden real checkbox to match the state of the graphical 
    // version:
    this.nextSibling.checked=true;
    value= parseFloat(this.nextSibling.value);
  }
  var total = document.getElementById('total').innerHTML.split(" ");
  var optie = document.getElementById('optie').innerHTML.split(" ");
  document.getElementById('total').innerHTML = (this.title == "Checked")? Math.round( parseFloat(total[0]) + value)+' &euro;' :  Math.round(parseFloat(total[0]) - value )+' &euro;' ;
	document.getElementById('optie').innerHTML = (this.title == "Checked")?  Math.round(parseFloat(optie[0]) + value )+' &euro;' :  Math.round(parseFloat(optie[0]) - value)+' &euro;'  ;
}

function EnhanceRadio() {

  // add popup links to all lookup fields

  var els=document.getElementsByTagName("input");

  for(var i=0; (el=els[i]); i++) {
  
    if (el.type == "radio") {
    
      el.style.display='none';

      var img=document.createElement("img");
      if (el.checked) {
       
        img= new Image(16,16);
        img.src="/images/site/checked.gif";
        img.title="Checked";
       // img.width="18";
        //img.height="18":
      }
      else {
      
       img= new Image(16,16);
        img.src="/images/site/unchecked.gif";
        img.title="Unchecked";
        //img.width="17";
        //img.height="17":
      } 
      //img.setAttribute("src", "/RadioboxUnchecked.gif");
     // img.setAttribute("src", "/images/radiobutton.gif");
     // img.setAttribute("alt", "Unchecked");
      img.onclick= toggleRadio;
      el.onchange=toggleRadio;
      
      el.parentNode.insertBefore(img, el);
          
    }

  }
    
}

function toggleRadio() {

// graphical checkbox onclick event handler
  
  // toggle the checkbox state:

  this.nextSibling.checked=true;
  
  els=this.parentNode.parentNode.getElementsByTagName("input");
  
  for(var i=0; (el=els[i]); i++) {
  
    if (el.type == "radio") {
    
      if(el.checked) {
      
        //el.previousSibling.setAttribute("src", "/RadioboxChecked.gif");
        el.previousSibling.setAttribute("src", "/images/site/checked.gif");
        
      }
      else {
        //el.previousSibling.setAttribute("src", "/RadioboxUnchecked.gif");
        el.previousSibling.setAttribute("src", "/images/site/unchecked.gif");
      }

    }

  }
  
}

window.onload = function() {

	
  enhanceCheckboxes();
  EnhanceRadio();
 
}

//---------------------------------------------------------------//
//   AANBOD PAGINA  =>  TOON WAGEN ON MOUSEOVER	 					  		 //
//---------------------------------------------------------------//
function showPic (whichpic) {
			if (document.getElementById) {
			var rev_array = whichpic.rev.split('----');
			document.getElementById('aanbod_car').src ='/images/uploaded/cars/'+rev_array[1];
			  if (whichpic.title) {
			   document.getElementById('car_name').innerHTML = whichpic.title;
			  }
			   if (whichpic.rel) {
			   	var stock = whichpic.rel.split('-');
			   	
			   document.getElementById('car_stock').innerHTML = 'in stock : '+stock[1];
			  }
			  if (whichpic.rev) {
			   document.getElementById('car_percent').innerHTML = rev_array[0]+'%';
			  }
			  return false;
			 } else {
			  return true;
			 }
}

//---------------------------------------------------------------//
//  CONTACT PAGINA  =>  CHECK FIELDS            					  		 //
//---------------------------------------------------------------//


/**************************************
| OVERRIDE NORMAL ALERT FUNCTION      |
***************************************/


		// constants to define the title of the alert and button text.
		var ALERT_TITLE = "Gelieve onderstaande velden aan te passen";
		var ALERT_BUTTON_TEXT = "Ok";
		
		// over-ride the alert method only if this a newer browser.
		// Older browser will see standard alerts
		if(document.getElementById) {
			window.alert = function(txt) {
				createCustomAlert(txt);
			}
		}
		
		function createCustomAlert(txt) {
			// shortcut reference to the document object
			d = document;
		
			// if the modalContainer object already exists in the DOM, bail out.
			if(d.getElementById("modalContainer")) return;
			
			
			/*bo = d.getElementsByTagName("body");
			bo.style.backgroundcolor= "#000000";*/
			// create the modalContainer div as a child of the BODY element
			mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
			mObj.id = "modalContainer";
			 // make sure its as tall as it needs to be to overlay all the content on the page
			mObj.style.height = document.documentElement.scrollHeight + "px";
			
			
			// create the DIV that will be the alert 
			alertObj = mObj.appendChild(d.createElement("div"));
			alertObj.id = "alertBox";
			// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
			if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
			// center the alert box
			
			alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
		
			// create an H1 element as the title bar
			h1 = alertObj.appendChild(d.createElement("h1"));
			h1.appendChild(d.createTextNode(ALERT_TITLE));
		
			//tekst in pre tag gewrapped
			msgInner = alertObj.appendChild(d.createElement("pre"));
			msgInner.appendChild(d.createTextNode(txt));
			
		
		
			// create an anchor element to use as the confirmation button.
			btn = alertObj.appendChild(d.createElement("a"));
			btn.id = "closeBtn";
			btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
			btn.href = "#";
			// set up the onclick event to remove the alert when the anchor is clicked
			btn.onclick = function() { removeCustomAlert();return false; }
		
			
		}
		
		// removes the custom alert from the DOM
		function removeCustomAlert() {
			document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
		}


/**************************************
| VALDIATION OF FORM FIELDS            |
***************************************/

			
//formulier controle	
			function validateFormOnSubmit(theForm) {
			var reason = "";
		
		  reason += validateEmptyMore(theForm.first_name , "Voornaam *",  "- Uw Voornaam" , "#ffffff");
		  reason += validateEmptyMore(theForm.last_name , "Achternaam *",  "- Uw Achternaam" , "#ffffff");
		  reason += emailCheck(theForm.email, "#ffffff");
		  reason += validateEmptyMore(theForm.company,"Bedrijf*",  "- Naam van het bedrijf", "#ffffff");
		  reason += validateEmptyMore(theForm.phone, "Tel. *","- Telefoon", "#ffffff");
		 
		      
		  if (reason != "") {
		    alert("Sommige velden werden niet ingevuld:\n\n" + reason);
		    return false;
		  }
		
		  return true;
		}
		
		function validateEmpty(fld, fieldname, color) {
		    var error = "";
		 
		    if (fld.value.length == 0) {
		        fld.style.background = '#8eb63e'; 
		        error = fieldname+ " is niet ingevuld.\n"
		    } else {
		        fld.style.background = color;
		    }
		    return error;  
		} 
		
		function validateEmptyMore(fld, defaultname, fieldname, color) {
		    var error = "";
		 		if (fld.value.length == 0 || fld.value == defaultname) {
		        fld.style.background = '#8eb63e'; 
		        error = fieldname+ " is niet ingevuld.\n"
		    }
		    else if (fld.value.length < 3) {
		        fld.style.background = '#8eb63e'; 
		        error = fieldname+ " is niet correct ingevuld.\n"
		    } else {
		        fld.style.background = color;
		    }
		    return error;  
		}
		
		function validatePhone(fld, defaultname, fieldname, color) { 
			var error = "";
			 prompt(defaultname);
			var reg = /([^a-zA-Z])$/;
		   var phone = fld.value;
		   if(reg.test(phone) == false) {
		     error="- Uw telefoon nummer is ongeldig.\n";
		     fld.style.background = '#8eb63e'; 
		   }
		   else	if (fld.value.length == 0 || fld.value == defaultname) {
		        fld.style.background = '#8eb63e'; 
		        error = fieldname+ " is niet ingevuld.\n"
		    }
		    else if (fld.value.length < 9) {
		        fld.style.background = '#8eb63e'; 
		        error = fieldname+ " is niet correct ingevuld.\n"
		    } 
		     else if (fld.value.length < 3) {
		        fld.style.background = '#8eb63e'; 
		        error = fieldname+ " is niet correct ingevuld.\n"
		    } 
		    else {
		        fld.style.background = color;
		    }
		    return error;  
		}
		
		function closeWarning(i){
			document.getElementById('warning'+i).style.display ='none';
		}
		
		function emailCheck(email, color) {
			
			var error = "";
		   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		   var address = email.value;
		   if(reg.test(address) == false) {
		     error="- Uw e-mail is ongeldig.\n";
		     email.style.background = '#8eb63e'; 
		   }
		   else{
		   	 email.style.background = color;
		   }
		   return error
		}
		

/*----------------------------------
| PNG TRANSPARENCY IE 6.0          |
+---------------------------------*/


function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

/**********************************************
/* VIEW CLIP
/*********************************************/

function showCorrectClip(x, full){
	var str='<ul class="movie_list">';
	for(var i=1; i<=3; i++){
		if(i == x){
			
			str+='<li onclick="javascript:showCorrectClip(' + i + ', \''+full+'\')"  ><span class="act">'+i+'</span></li>';
		}
		else{
			str+='<li onclick="javascript:showCorrectClip('+i+',\''+full+'\')"  ><span>'+i+'</span></li>';
		}
	}
	str+='</ul>';
	var movie = x+'_'+full;
	document.getElementById('container_media1').innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8" width="274" height="176" id="theMediaPlayer">'+
	'<param name=movie value="flvplayer.swf">'+
	'<param name=allowFullScreen value="true">'+
	'<param name=allowScriptAccess value="never">'+
	'<param name="FlashVars" value="file=movie'+movie+'.flv&width=274&image=/images/site/screen'+x+'.jpg&height=176&fullscreen=true&screencolor=0x444444&loadingcolor=0x999999&javascriptid=theMediaPlayer2">'+
							
	'<embed type="application/x-shockwave-flash" src="/flv/player.swf" id="player" name="player" quality="high" allowfullscreen="true" allowscriptaccess="never" flashvars="file=movie'+movie+'.flv&amp;image=/images/site/screen'+x+'.jpg&amp;fullscreen=true" height="176" width="274"></embed></object>'+str;
	

}
