	function getScrollY() {
	  var scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	  }
	  return  scrOfY ;
	}

function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}


function changePrice(){
	vmin	= $('#vmin').val();
	vmax	= $('#vmax').val();
	voorraad= $('#voorraad').val();
	factor	= $('#factor').val();
	aantal	= $('#aantal').val();
	lengte = $('#staffel_lengte').val();
	if (parseFloat(aantal) < parseFloat(factor) || isNaN(aantal)){
		aantal = factor;
	}
	if (aantal % factor < ( factor / 2 ) ){
			aantal = parseFloat ( Math.floor( aantal / factor ) * factor );
	}	 else {
			aantal = parseFloat ( Math.round( aantal / factor ) * factor );
	}
	$('#aantal').val(aantal);
	var prijs= 0;
		for (i=lengte;i>=1 ;i-- )
		{
			if (aantal>=parseFloat($('#staffel_'+i).html())){
				prijs = parseFloat(aantal) * parseFloat($('#price_'+i).html());
				break;
			}
		}
	//onder staffel?
	if (prijs == 0)
	{
		prijs = parseFloat(aantal) * parseFloat($('#totalPrice').val());
	}
	prijs	= Math.round(prijs*100)/100;
	$('#endprice').html(prijs.toFixed(2));	
}
function checkProduct(){
	checked = true;
	for (group=1; group<=parseInt(document.getElementById('totalOptions').value); group++) {
		if (document.getElementById('opt_'+group).value == '0') {
			document.getElementById('opt_title_'+group).className = 'optError';
			document.getElementById('optMelding').style.display='';
			checked = false;
		}
	}	
	if (!checked){
		return false;
	}  else {
		document.getElementById('orderform').submit();
		return false;
	}
}
function trim(str) {
    return str.replace(/(^\s+)([^\s]*)(\s+$)/, '$2');
}
function toggleDate () {
	if ($('rowStartdate').style.display != ''){
		$('rowStartdate').style.display = '';
		$('rowEnddate').style.display = '';
		if ($('rowArchive')){
			$('rowArchive').style.display = '';
		}
	} else {
		$('rowStartdate').style.display = 'none';
		$('rowEnddate').style.display = 'none';
		if ($('rowArchive')){
			$('rowArchive').style.display = 'none';
		}
	}
}
function displayDiv(thediv,selection){
	div = document.getElementById(thediv);
	if (selection == 1){
		div.style.display ='';
	} else {
		div.style.display ='none';
	}
}

function displayBetaal(thediv,selection){
	div = document.getElementById(thediv);
	if (selection == 1){
		div.style.display ='';
	} else {
		div.style.display ='none';
		document.getElementById('ideal').checked=true;
	}
}
function toggleDiv(thediv){
	div = $(thediv);
	if (div.style.display =='none'){
		div.style.display ='';
	} else {
		div.style.display ='none';
	}
}
function toggleAll(num){
	if (!$('alles').checked){
		var value = false;
	} else {
		var value = true;
	}
	for (i=1;i<=num;i++){
		if (!$('acc'+i).disabled) {
			$('acc'+i).checked=value;
		}	
	}
}
function sluitVenster(){
	$('#ajaxContainer').fadeOut(500,function() {
        $('#ajaxOverlay').hide();
		$('#ajaxOverlay').html('');
      });
	 closeBack();
}
function addBasket(){
	$.psv({
		url: siteurl + 'includes/ajax/wish2basket.php',
		type: 'POST',
		data: $('input[name="basket[]"]:checked'),
		success: function(data) {
			openBack();
			$('#ajaxOverlay').html(data);
			$('#ajaxContainer').css('top',(getScrollY()+80) + 'px');
			$('#ajaxOverlay').show();
			$('input:checkbox[name="basket[]"]:checked').each(function(index) { 
				$(this).parent().parent().fadeOut(500);
				$(this).attr('checked',false);
			});
			$('#ajaxContainer').fadeIn(500);
		}
	});
}

function addProduct(prodid,ptype){
	if(checkProduct()){
		if (typeof(ptype) == "undefined"){
			ptype= 'cart';
		}
		var opts = '0';
		if($('.options input:checked').length>0){
			$('.options input:checked').each(function(index) { 
				opts += ',' + $(this).val() ;
			});
		} 
		leaseduur = 0;
		if (ptype == 'lease')
		{
			leaseduur = $('#leasemonth').val();
		}
		$.psv({
			url: siteurl + 'includes/ajax/products.php',
			type: 'POST',
			data: {'options': opts,'type': ptype, 'prod_id': prodid, 'leaselength': leaseduur},
			success: function(data) {
				openBack();
				$('#ajaxOverlay').html(data);
				$('#ajaxOverlay').show();
				$('#ajaxContainer').fadeIn(500);
				$('#ajaxContainer').css('top',(getScrollY()+10) + 'px');
			}
		});
	}
}

function openMenu(){
	$(this).addClass('ie_does_hover');
}
function closeMenu(){
	$(this).removeClass('ie_does_hover');
}
function submitLease(){
	$('#leaseCart').submit();
}
function submitCart(){
	$('#shopCart').submit();
}
/*------------------------------------------------------------------------------*/
function checkSites(val){
	var x = document.getElementsByName('sites[]');
	for (a = 0; a < x.length; a++) {
		x[a].checked=val;
	}
}
function checkColors(val){
	var x = document.getElementsByName('colors[]');
	for (a = 0; a < x.length; a++) {
		x[a].checked=val;
	}
}
function checkSingle(val,head,type){
	for (a = 0; a < val.length; a++) {
		document.getElementById('products'+val[a]).checked=type;
	}
	//document.getElementById('head'+head).checked=type;
}
function checkProps(val,head,type){
	for (a = 0; a < val.length; a++) {
		document.getElementById('properties'+val[a]).checked=type;
	}
	//document.getElementById('head'+head).checked=type;
}
function toggleSites(val){
	document.getElementById('website').style.display='none';
	document.getElementById('verwijzing').style.display='none';
	document.getElementById('landingpage').style.display='none';
	document.getElementById(val).style.display='';	
}
function showGroup(num){
	groep = document.getElementById('groep'+num);
	if (groep.style.display == 'none'){
		groep.style.display = '';
	} else { 
		groep.style.display = 'none'
	}
}
function showPropGroup(num){
	groep = document.getElementById('propgroep'+num);
	if (groep.style.display == 'none'){
		groep.style.display = '';
	} else { 
		groep.style.display = 'none'
	}
}


function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""

	if (obj.getAttribute && obj.value.length>mlength)
	{
		obj.value=obj.value.substring(0,mlength);
	}
}




/*---------------------------------------------------------------------*/
//						Nieuwe Functionaliteiten
/*---------------------------------------------------------------------*/
function getScrollY() {
	  var scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	  }
	  return  scrOfY ;
}
function getPageHeight() {     
	 var yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}
	var windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	return pageHeight;
}
function closeWindow(theclass){
	var win = $('overlay');
	if (win) {
		win.removeClassName(theclass);
		win.style.display = 'none';
		closeBack();
	} else {
		alert(error_no_window);
	}
}
function openBack() {
	$('backgroundOverlay').style.height= getPageHeight() +'px';
	$('backgroundOverlay').style.display='';
}
function closeBack() {
	$('backgroundOverlay').style.display='none';
}

function toggleAll(num){
	if (!$('alles').checked){
		var value = false;
	} else {
		var value = true;
	}
	for (i=1;i<=num;i++){
		if (!$('acc'+i).disabled) {
			$('acc'+i).checked=value;
		}	
	}
}
function togglePages(type){
	arrElm = document.getElementsByName('pages[]');
	for(i=0;i<=(arrElm.length-1);i++){
		arrElm[i].checked=type;
	}
}
function checkEmail(str){
	var testresults = false;
	//uitleg filter: minimaal 1 letter voor @ ; min 1 max 66 letters na @ ; min 2 max 6 letters na punt.
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
		testresults=true;
	}else{
		testresults=false;
	}
	return (testresults);
}	
function aanmeldSubmit(){ // Voor nieuwsbrief aanmeldform naar MuskitoMail
	tel=0;
	if (document.getElementById("last_name").value =='') {				
		tel++;		
		document.getElementById("last_name").className = 'txtInputWrong';
	} else	{ 
		document.getElementById("last_name").className = 'txtInput';
	}
	if (document.getElementById("first_name").value =='') {				
		tel++;		
		document.getElementById("first_name").className = 'txtInputWrong';
	} else	{ 
		document.getElementById("first_name").className = 'txtInput';
	}
	if (document.getElementById("email").value =='' || !checkEmail(document.getElementById("email").value)) {
		tel++;		
		document.getElementById("email").className = 'txtInputWrong';		
	} else	{ 
		document.getElementById("email").className = 'txtInput';
	}
	if(tel==0){
		return true;
	} else {
		return false;
	}	
}

//-------------SEARCH----------------------------

function startSearch(){
		var link	= $('#group').val() + '/';
		link		+= $('#subgroup').val() + '/';
		if($('input:checkbox[name="sexe[]"]:checked').length>0){
			$('input:checkbox[name="sexe[]"]:checked').each(function(index) { 
				if (index == 0)
				{
				link += $(this).val();
				return true;
				}
				link += ',' + $(this).val() ;
			});
			link += '/';
		} else {
			link += 'm-v/';
		}
		if($('input:checkbox[name="brand[]"]:checked').length>0){
			$('input:checkbox[name="brand[]"]:checked').each(function(index) { 
				if (index == 0)
				{
				link += $(this).val();
				return true;
				}
				link += ',' + $(this).val() ;
			});
			link += '/';
		} else {
			link += 'alle-merken/';
		}
		if($('input:checkbox[name="size[]"]:checked').length>0){
			$('input:checkbox[name="size[]"]:checked').each(function(index) { 
				if (index == 0)
				{
				link += $(this).val();
				return true;
				}
				link += ',' + $(this).val() ;
			});
			link += '/';
		} else {
			link += 'alle-maten/';
		}
		if($('input:checkbox[name="price[]"]:checked').length>0){
			$('input:checkbox[name="price[]"]:checked').each(function(index) { 
				if (index == 0)
				{
				link += $(this).val();
				return true;
				}
				link += ',' + $(this).val() ;
			});
			link += '/';
		} else {
			link += 'alle-prijzen/';
		}	
		document.location.href= siteurl + 'producten/' 
		+ link 
		+ $('#sortorder').val() + '/'
		+ $('#perpage').val() + '/'
		+ $('#curpage').val() + '/';
}

function checkInput(input, was, wordt){
	if(input.value==was){
		input.value=wordt;
	}
}
function checkCallBack(){
	tel=0;
	if (document.getElementById("naam").value =='' || document.getElementById("naam").value == 'Naam') {				
		tel++;		
		document.getElementById("naam").className = 'txtInputWrong';
	} else	{ 
		document.getElementById("naam").className = 'txtInput';
	}
	if (document.getElementById("telefoonnummer").value =='' || document.getElementById("telefoonnummer").value == 'Telefoonnummer') {				
		tel++;		
		document.getElementById("telefoonnummer").className = 'txtInputWrong';
	} else	{ 
		document.getElementById("telefoonnummer").className = 'txtInput';
	}
	if (document.getElementById("opmerkingen").value =='' || document.getElementById("opmerkingen").value =='Vragen of opmerkingen') {				
		tel++;		
		document.getElementById("opmerkingen").className = 'txtAreaWrong';
	} else	{ 
		document.getElementById("opmerkingen").className = 'txtArea';
	}
	if(tel==0){					
		return true;
	} else {
		return false;
	}	
}

function checkContactForm(){
	tel=0;
	if (document.getElementById("naam").value =='') {				
		tel++;		
		document.getElementById("naam").className = 'txtInput wrong';
	} else	{ 
		document.getElementById("naam").className = 'txtInput';
	}
	if (document.getElementById("email").value =='' || !checkEmail(document.getElementById("email").value)) {
		tel++;		
		document.getElementById("email").className = 'txtInput wrong';		
	} else	{ 
		document.getElementById("email").className = 'txtInput';
	}
	if (document.getElementById("onderwerp").value =='') {				
		tel++;		
		document.getElementById("onderwerp").className = 'txtInput wrong';
	} else	{ 
		document.getElementById("onderwerp").className = 'txtInput';
	}
	if (document.getElementById("opmerking").value =='') {				
		tel++;		
		document.getElementById("opmerking").className = 'txtArea wrong';
	} else	{ 
		document.getElementById("opmerking").className = 'txtArea';
	}
	if(tel==0){					
		return true;
	} else {
		document.getElementById("formMelding").innerHTML = '<b>* Vul aub. alle verplichte velden in [' + tel + ']</b>';
		return false;
	}	
}

function submitCart(){
	$('#shopCart').submit();
}
