﻿function validateGratisThuisBezorgen(){
    MM_validateForm('postcode','','R');
    if(document.MM_returnValue){
        submitForm();
    }
}
/*
$(function(){
    $("#Header ul li a").each(
        function(i){
            $(this).click(){
                document.location = $(this).attr("href");
            }
        });
    );
});
*/
function submitForm(){
    document.aspnetForm.submit();
}
function validateContact(){
    MM_validateForm('naam','','R','emailadres','','RisEmail','boodschap','','R');
    if(document.MM_returnValue){
        submitForm();
    }
}
function backToNormal(obj){
    obj.style.backgroundColor = "white"
}

function putLeft(objNaam){
    var obj = document.getElementById(objNaam);
    obj.style.marginLeft = "-230px";
}

function saveExclBBQ(){
    MM_findObj('doUpdate').value= "exclBBQ";
    submitForm();
}
function saveInclService(){
    MM_findObj('doUpdate').value= "inclService";
    submitForm();
}
var t;
var curObj;

function showStandaardBijgeleverd(objNaam, item, side){
    if(curObj && t)
        curObj.style.visibility = "hidden";
    var obj = document.getElementById(objNaam);
    curObj = obj;
    obj.style.visibility = "visible";
    
    if(side == "left"){
        obj.style.marginLeft = "-180px"; /* 230 */
    }else if(side == "left2"){
        obj.style.marginLeft = "-50px"; /* 230 */
    }
    item.onmouseout = function(){
        /*t = setTimeout("hideStandaardBijgeleverd('" + objNaam + "')",1000)*/
        hideStandaardBijgeleverd(objNaam);
    }
    obj.onmouseover = function(){
       /* clearTimeout(t);*/
    }
    obj.onmouseout = function(){
        /*t = setTimeout("hideStandaardBijgeleverd('" + objNaam + "')",500)*/
        hideStandaardBijgeleverd(objNaam);
    }    
    
}
function hideStandaardBijgeleverd(objNaam){
    var obj = document.getElementById(objNaam);
    obj.style.visibility = "hidden";
    /*clearTimeout(t);*/
}

function showProduct(objNaam){
    var obj = document.getElementById(objNaam);
    obj.style.visibility = "visible";
    /*clearTimeout(t);*/
}

function hideProduct(objNaam){
    var obj = document.getElementById(objNaam);
    obj.style.visibility = "hidden";
    /*clearTimeout(t);*/
}

function aantallenAanpassen(aantalveld){
    if (aantalveld.value!='') {
        document.body.style.cursor='wait';
	    MM_findObj('mode').value='aantallenaangepast';
	    url = document.location;
	    document.aspnetForm.action = url;
	    setTimeout("document.aspnetForm.submit();",500);	     
    }
}
function validateTipEenVriend(){
    if(MM_findObj("vriend2").value != "" && MM_findObj("vriend3").value != ""){
        MM_validateForm('Naam','','R','E-mailadres','','RisEmail','vriend1','','RisEmail','vriend2','','RisEmail','vriend3','','RisEmail');
    }else if(MM_findObj("vriend2").value != ""){
        MM_validateForm('Naam','','R','E-mailadres','','RisEmail','vriend1','','RisEmail','vriend2','','RisEmail');
    }else if(MM_findObj("vriend3").value != ""){
        MM_validateForm('Naam','','R','E-mailadres','','RisEmail','vriend1','','RisEmail','vriend3','','RisEmail');
    }else{
        MM_validateForm('Naam','','R','E-mailadres','','RisEmail','vriend1','','RisEmail');
    }
    if(document.MM_returnValue){
        url = document.location;
	    document.aspnetForm.action = url;
	    document.aspnetForm.submit();
    }
}
function validateGastenboekReactie(){
    MM_validateForm('Naam','','R','Woonplaats','','R','Reactie','','R');
    if(document.MM_returnValue){
        url = document.location;
	    document.aspnetForm.action = url;
	    document.aspnetForm.submit();
    }
}
function validateAndGoToStep3(){
    /*MM_validateForm('Dag','','R','Maand','','R','Jaar','','R','Uur','','R','Minuten','','R');*/
    
    
    
    if(isInteger(MM_findObj('Dag').value) && isInteger(MM_findObj('Maand').value) && isInteger(MM_findObj('Jaar').value) && isInteger(MM_findObj('Uur').value) && isInteger(MM_findObj('Minuten').value)){
        if (MM_findObj('Maand').value >= 13 || MM_findObj('Dag').value >= 32)
        {
            alert('De dag of maand is niet correct ingevuld');
        }
        else{
            var time=new Date();

            var day=time.getDate();
            var month=time.getMonth();
            var year = time.getFullYear();
                
            var iday = MM_findObj('Dag').value;
            var imonth = MM_findObj('Maand').value
            var iYear = MM_findObj('Jaar').value
            
            var one_day=1000*60*60*24
            var difference;
            if (iYear < 2000)iYear = parseInt(iYear) + 2000;
            var inputdate=new Date(iYear,imonth-1,iday)
            difference = Math.ceil((inputdate.getTime()-time.getTime())/(one_day))
            
            if (difference <= 1)
            {
            alert('U dient minimaal 2 dagen van te voren te bestellen');
            }
            else
            {
                document.aspnetForm.action = "winkelmandje.aspx?stap=3&winkelmandje=true";
                document.aspnetForm.submit();
            }
        }
    }else{
        alert("Datum en/of tijd is niet correct ingevuld.");
    }
    
}
function stapTerug(stap){
    document.location = "/winkelmandje.aspx?stap=" + stap + "&winkelmandje=true";
}

function validateAndGoToStep4(){
    MM_validateForm('Voornaam','','R','Achternaam','','R','Huisnummer','','R','Straatnaam','','R','Postcode','','R','Plaats','','R','Telefoonnummer','','R','Emailadres','','RisEmail','algemene voorwaarden','','RisCheckbox');
    if(document.MM_returnValue){
        var error = false;
        
        // Telefoon nummer checken op 10 cijfers
        var telefoonnummer = MM_findObj("Telefoonnummer").value;
        if(telefoonnummer.replace(" ","").replace("-","").length != 10 || !isInteger(telefoonnummer.replace(" ","").replace("-",""))){
            error = true;
            MM_findObj("Telefoonnummer").style.backgroundColor='#FFCB2D';
            alert("Het telefoonnummer dat u invoert is niet geldig.")
        }else{
            var postcode = MM_findObj("Postcode").value;
            if(!validatePostalCode(postcode)){
                error = true;
                MM_findObj("Postcode").style.backgroundColor='#FFCB2D';
                alert("De postcode die u invoert is niet geldig.");
            }else if(MM_findObj("Emailadres").value != MM_findObj("Emailadres2").value){
                    error = true;
                    MM_findObj("Emailadres").style.backgroundColor='#FFCB2D';
                    MM_findObj("Emailadres2").style.backgroundColor='#FFCB2D';
                    alert("De 2 emailadressen komen niet overeen.");
            }else if (MM_findObj("sponsornummer").value != MM_findObj("sponsornummer2").value){
                    error = true;
                    MM_findObj("sponsornummer").style.backgroundColor='#FFCB2D';
                    MM_findObj("sponsornummer2").style.backgroundColor='#FFCB2D';
                    alert("De 2 sponsornummers komen niet overeen.");    
                }else{
                    var sponsornummer = MM_findObj("sponsornummer").value;
                    if(sponsornummer != ""){
                        if(sponsornummer.length != 6 || !isInteger(sponsornummer)){
                            error = true;
                            MM_findObj("sponsornummer").style.backgroundColor='#FFCB2D';
                            alert("Het sponsornummer dat u invoert is niet geldig");
                        }
                    }
                    
                    if(error == false){
                        document.aspnetForm.action = "winkelmandje.aspx?stap=4&winkelmandje=true";
                        document.aspnetForm.submit();
                    }
                }
            }
        }
    }
   

function validatePostalCode(strPC) {
  return typeof strPC=='string'
    ?strPC.match(/[1-9][0-9]{3} ?[a-zA-Z]{2}/)==strPC
    :false;
  //Met optimalisaties van Henk KH
}

function validateAndGoToStep5(){
    document.aspnetForm.action = "winkelmandje.aspx?stap=5&winkelmandje=true";
    document.aspnetForm.submit();
}
function goToAndValidateStap6(){
    document.aspnetForm.action = "winkelmandje.aspx?stap=6&winkelmandje=true";
    document.aspnetForm.submit();
}

function enableExtras(){
   var checkboxObj = document.getElementById("extasCheckbox");
   var extrasObj = document.getElementById("extras");
   
   checkboxObj.checked = true;
   extrasObj.style.display = "block";
}
function enableDisableExtras(){   
    var checkboxObj = document.getElementById("extasCheckbox");
    var extrasObj = document.getElementById("extras");
    
    /* Dan kijken of moet enabled of disabelen */
    if(checkboxObj.checked == true){
        extrasObj.style.display = "block";
    }else{
        extrasObj.style.display = "none";
    }
}
var extrasEnabled = false;
function enableDisableExtrasButton(){
    var extrasObj = document.getElementById("extras");
    
    /* Dan kijken of moet enabled of disabelen */
    if(extrasEnabled == true){
        extrasObj.style.display = "none";
        extrasEnabled = false;
    }else{
        extrasObj.style.display = "block";
        extrasEnabled = true;
    }
    scrollDown(420);
}

function scrollDown(size) {
    window.scrollTo(0,size);
}
function roundNumber(number,decimals) {
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
			numString += ".";// give it one at the end
		}
		var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
		var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
		if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
			if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		newString = numString.substring(0,cutoff) + d1.toString();
	}
	if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i<decimals-decs;i++) newString += "0";
	//var newNumber = Number(newString);// make it a number if you like
	return newString;
}



function berekenNieuwePrijsExtras(thisObj, prijs){
    var prijsObj = document.getElementById(thisObj.name + "_prijs");
    var prijs = roundNumber((thisObj.value * parseFloat(prijs.replace(",","."))), 2)
       
    prijsObj.innerHTML = "&euro; " + prijs.replace(".",",") ;
}
function validateUploadUwFoto(){
    MM_validateForm('naam','','R','plaats','','R','emailadres','','RisEmail','bestand','','R');
    if(document.MM_returnValue){
        document.aspnetForm.submit();
    }
}

function postTo(url){
    document.aspnetForm.action = url;
    document.aspnetForm.submit();
}
/* Valideert of het een integer is */

function validateInt()
   {
      var o = document.frmInput.txtInput;
      switch (isInteger(o.value))
      {
         case true:
            alert(o.value + " is an integer")
            break;
         case false:
            alert(o.value + " is not an integer")
      }
   }

   function validateRange()
   {
      var s = document.frmInput.txtInput.value;
      var A = document.frmInput.txtA.value;
      var B = document.frmInput.txtB.value;

      switch (isIntegerInRange(s, A, B))
      {
         case true:
            alert(s + " is in range from " + A + " to " + B)
            break;
         case false:
            alert(s + " is not in range from " + A + " to " + B)
      }
   }

// isIntegerInRange (STRING s, INTEGER a, INTEGER b)
   function isIntegerInRange (s, a, b)
   {   if (isEmpty(s))
         if (isIntegerInRange.arguments.length == 1) return false;
         else return (isIntegerInRange.arguments[1] == true);

      // Catch non-integer strings to avoid creating a NaN below,
      // which isn't available on JavaScript 1.0 for Windows.
      if (!isInteger(s, false)) return false;

      // Now, explicitly change the type to integer via parseInt
      // so that the comparison code below will work both on
      // JavaScript 1.2 (which typechecks in equality comparisons)
      // and JavaScript 1.1 and before (which doesn't).
      var num = parseInt (s);
      return ((num >= a) && (num <= b));
   }

   function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

   function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function postToWinkelmandje()
{
    var error = false;
    // Minimaal aantal
    $("input[minimaal!=0]").each(function(){
        var minimaal = parseInt($(this).attr("minimaal"));
        if(minimaal != "" && minimaal != 0)
            if(parseInt($(this).val()) < minimaal && parseInt($(this).val()) > 0)
            {
                alert($(this).attr("error"));
                error = true;
            }
    });
    
    if(!error)
    {
        document.aspnetForm.action = "/Winkelmandje.aspx";
        document.aspnetForm.submit();
    }
}
    