
//var start_h = document.body.offsetHeight; 
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}



function scrollimage() {
		
	var start_h = document.body.offsetHeight; 
	
		var n_height = document.body.offsetHeight;
		
	//	document.body.style.height = '100%';
		
	if(document.getElementById('scroll_image_div')) {
		if(navigator.appName=='Microsoft Internet Explorer' && navigator.appVersion.indexOf("MSIE 7")==-1) {
			document.getElementById('scroll_image_div').style.bottom = '10px';
			document.getElementById('scroll_image_div').style.right = '10px';
			//document.getElementById('scroll_image_div').innerHTML = '';
		} else {
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
			
	
			
			var verschil = n_height - start_h;
			
		///	alert(verschil + '-' + y);		
			
			document.getElementById('scroll_image_div').style.bottom =  (verschil - y + 10) + 'px';
			//document.getElementById('foto').innerHTML = (document.documentElement.scrollLeft);
			document.getElementById('scroll_image_div').style.right =  (10) + 'px';
		}	
	}
	
	//		document.body.style.height = '';

}
	

function add_to_nrt_order(cnt,value) {
	var elm_aantal = $('bestel_aantal'+cnt);
	var elm_vbn = $('vbn'+cnt);
	
	if (IsNumeric(elm_aantal.value) == true || elm_aantal.value == '') {
	
		if (elm_aantal.value == '' || value == 0) {
			elm_aantal.value = 0;
		}
		
		var url = 'vbn/add_to_nrt_order.php?cnt=' + cnt+'&aantal='+value;
		if (elm_vbn) {
			url+= '&vbn='+elm_vbn.value;	
		}
		
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) {
			
					
			elm_order_overview = $('orderoverview');
			winkelwagen_ophalen();

			if (elm_order_overview) {
				var even = $$('#orderoverview .even');
				var oneven = $$('#orderoverview .oneven');
				var counter = 0;
				for (i=0;i<even.length;i++) {
					if ($(even[i].id).style.display == '') {
						(counter++);
					}
				}
				for (i=0;i<oneven.length;i++) {
					if ($(oneven[i].id).style.display == '') {
						(counter++);
					}
				}
				
				var stuks = $('stuks'+cnt).innerHTML;
				var totaal_regel = $('totaalprijs_per_stuk'+cnt);
				var totaal_totaal = $('totaalprijs_besteloverzicht');
				var prijs_per_stuk = $('prijs_per_stuk'+cnt).value;
				var oud_regelprijs = totaal_regel.innerHTML;
				var new_regelprijs = (stuks*elm_aantal.value)*prijs_per_stuk;
				totaal_regel.innerHTML = new_regelprijs.toFixed(2);
				totaal_regel.innerHTML = totaal_regel.innerHTML.replace(/\./,",");
				totaal_totaal.innerHTML = $('blok_totaalbestelling_totaal').innerHTML;
				if (counter == 1) {
					if (elm_aantal.value == 0) {
						window.location = window.location;
					}
				} else {
					if (elm_aantal.value == 0) {
						Effect.BlindUp('regel'+cnt,{duration:0.5});	
					}
				}
				 
			}
				elm_aantal.className = 'bestel_aantal_true';
			return true;
		  }
		});	
		
	} else {
		//elm_aantal.value = '';
		elm_aantal.className = 'bestel_aantal_false';
		elm_aantal.focus();
		alert('geen juiste waarde ingevoerd.');
		return false;
	}
	
}


function verstuur_bestelling() {
		
	if (confirm('TM: weet u het zeker') == true) {
		
		window.location = 'verstuur_bestelling.php';
		return true;
		
	} else {
		return false;	
	}
}


function save_bestelopmerking() {
	
	var url = 'vbn/save_bestelopmerking.php';
	var bestelopmerking = $('bestelopmerking').value;
	var params = 'bestelopmerking='+bestelopmerking;
	new Ajax.Request(url, {
	  method: 'post',
	  parameters: params,
	  onSuccess: function(transport) {
		return true;
	 }
	});	
	
}



function send_nrt_order() {
	
	if (confirm('Sind Sie sicher?') == true) {
		winkelwagen_ophalen();
		
		//if ($('blok_totaalbestelling_aantal') && $('blok_totaalbestelling_aantal').innerHTML != '0') {
		
			elm_knopf = $('send_knopf');
			elm_plaatje = $('bestelling_verzenden');
			
			if (elm_knopf) {
				elm_knopf.disabled = true;
			}
			if (elm_plaatje) {
				elm_plaatje.src = 'loader.gif';	
			}
			var url = '../webshop/?action=send_nrt_order&from_site=1';
			new Ajax.Request(url, {
			  method: 'post',
			  onSuccess: function(transport) {
				  if (elm_knopf) {
					elm_knopf.disabled = false;
				  }
				  var response = transport.responseText;
				  if (response[0] == '0') {
					 window.location = 'order_send.php?al_besteld=1';
				  } else {
					 window.location = 'order_send.php';
				  }
				
				//$('test').innerHTML = transport.responseText;
			 }
			});	
		//} else {
		//	 window.location = 'order_send.php?al_besteld=1';
		//}
	
	}	
	
}
window.onscroll = function() {  scrollimage(); }
