function confirmLogout() {
    if (confirm("Weet u zeker dat u zich wilt afmelden ?")) {
      document.location='aanmelden.php?logout';
    }
}

function checkIfEmpty(field) {
 if (document.getElementById(field).value != "") {
   document.getElementById(field).style.backgroundColor = "";
   return true;
 } else {
//   alert(field + " is een verplicht veld");
//   document.getElementById(field).style.backgroundColor = "#FFCCCC";
   document.getElementById(field).focus();
	return false;
 }
}

function IsEmailValid(checkThisEmail) {
	var myEMailIsValid = true;
	var myAtSymbolAt = document.getElementById(checkThisEmail).value.indexOf('@');
	var myLastDotAt = document.getElementById(checkThisEmail).value.lastIndexOf('.');
	var mySpaceAt = document.getElementById(checkThisEmail).value.indexOf(' ');
	var myLength = document.getElementById(checkThisEmail).length;
	
	
	// at least one @ must be present and not before position 2
	// @yellow.com : NOT valid
	// x@yellow.com : VALID
	
	if (myAtSymbolAt < 1 ) 
	 {myEMailIsValid = false}
	
	// at least one . (dot) afer the @ is required
	// x@yellow : NOT valid
	// x.y@yellow : NOT valid
	// x@yellow.org : VALID
	
	if (myLastDotAt < myAtSymbolAt) 
	 {myEMailIsValid = false}
	
	// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
	// x.y@yellow. : NOT valid
	// x.y@yellow.a : NOT valid
	// x.y@yellow.ca : VALID
	
	if (myLength - myLastDotAt <= 2) 
	 {myEMailIsValid = false}
	
	
	// no empty space " " is permitted (one may trim the email)
	// x.y@yell ow.com : NOT valid
	
	if (mySpaceAt != -1) 
	 {myEMailIsValid = false}
	
	
	if (myEMailIsValid == true) {
//		document.getElementById(checkThisEmail).style.backgroundColor = "white";
		return true;
	} else {
    	//alert("email is not correct");
//    	document.getElementById(checkThisEmail).style.backgroundColor = "#FFCCCC";
		document.getElementById(checkThisEmail).focus();
		return false;
	}
}


function checkNieuwsbrief() {
    if (IsEmailValid("email")) {
        return true;            
    } else {
        alert("E-mail adres is niet correct ingevuld !");
        return false;
    }
}

function OpenWin(mypage,myname,w,h,features) {
     if(screen.width){
     var winl = (screen.width-w)/2;
     var wint = (screen.height-h)/2;
     }else{winl = 0;wint =0;}
     if (winl < 0) winl = 0;
     if (wint < 0) wint = 0;
     var settings = 'height=' + h + ',';
     settings += 'width=' + w + ',';
     settings += 'top=' + wint + ',';
     settings += 'left=' + winl + ',';
     settings += features;
     win = window.open(mypage,myname,settings);
     win.window.focus();
   }

   function IsNumeric(sText) {
     var ValidChars = "0123456789";
     var IsNumber=true;
     var Char;
      for (i = 0; i < sText.length && IsNumber == true; i++) { 
         Char = sText.charAt(i); 
         if (ValidChars.indexOf(Char) == -1){
//    	  alert('Het gekozen aantal is niet correct')
          document.getElementById(sText).focus();
             return false;
         }
      }
      if (sText > 0) {
      	return true;
      } else {
  ///    	alert('Het gekozen aantal is niet correct');
          document.getElementById(sText).focus();
          return false;
      }
    }  
        

  	function previewPic() {
        if (document.getElementById('product_image').value == "") {
         //   alert("U moet eerst een bestand selecteren.");		
        } else {
            document.getElementById('pre').src = document.getElementById('product_image').value;	
        }
    }
    
    function checkFile() {
        if (document.getElementById('product_image').value == "") {
            alert("U moet eerst een bestand selecteren.");		
            return false;
        } else {
//            document.getElementById('uploaden').style.visibility = 'visible';
  		    return true;
        }        
    }        