//functies voor Form-validatie..
function replaceQuots (obj) {
  for (var i=0;  i < obj.value.length ;i++ )  {
    obj.value = obj.value.replace('"','`');
    obj.value = obj.value.replace("'","`");
  }
}


function isNumber(string) {
  var illegalChars = /\D/;

  if ( (illegalChars.test(string)) || (string=="")) {
    return false;
  } 
  else {
    return true;
  }
}


function checkAC(string) {
  if(isNumber(string) && (string.length==10) && (string.substr(0,1)==2)){
    return true
  }
  else{
    return false;
  }
}


function isNonEmpty(string) {
  if (string.length<2) {
    return false;
  } 
  else {
    return true;
  }
}


function isNumberFixed(string, lengte) {
  if ( (string.length==lengte) && (isNumber(string)) ) {
    return true;
  }
}


function isNumberShorter(string, lengte) {
  if ( (string.length<=lengte) && (string.length>0) && (isNumber(string)) ) {
    return true;
  }
}


function isShorter(string, lengte) {
  if ( (string.length<=lengte) && (string.length>0) ) {
    return true;
  }
}


function checkPostcode(string) {
  // postcode moet zijn: 4 nummers, al dan niet een spatie, en dan twee letters.
  var illegalChars = /\d{4}\s?\w{2}/;

  //alert("zip = "+string);
  if (illegalChars.test(string)) {
    //alert("Ok");
    return true;
  } 
  else {
    //alert("nOk");
    return false;
  }
}


function checkDate(DateValue){
  //alert("sjek");
  var checkstr = "0123456789";
	
  var Datevalue = "";
  var DateTemp = "";
  var seperator = "-";
  var day;
  var month;
  var year;
  var leap = 0;
  var err = 0;
  var i;

  //alert("checkdate");
  /* Delete all chars except 0..9 */
  for (i = 0; i < DateValue.length; i++) {
    if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
      DateTemp = DateTemp + DateValue.substr(i,1);
    }
  }
  DateValue = DateTemp;

  /* Always change date to 8 digits - string*/
  /* if year is entered as 2-digit / always assume 20xx */
  if (DateValue.length == 6) {
    DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }

  if (DateValue.length != 8) { err = 1; }
  
  /* year is wrong if year = 0000 */
  year = DateValue.substr(4,4);

  if (year == 0) { err = 1; }

  /* Validation of month*/
  month = DateValue.substr(2,2);
  if ((month < 1) || (month > 12)) { err = 1; }

  /* Validation of day*/
  day = DateValue.substr(0,2);
  if (day < 1) { err = 1; }

  /* Validation leap-year / february / day */
  if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; }
  if ((month == 2) && (leap == 1) && (day > 29)) { err = 1; }
  if ((month == 2) && (leap != 1) && (day > 28)) { err = 1; }

  /* Validation of other months */
  if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) { err = 1; }
  if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) { err = 1; }

  /* if 00 is entered, no error, delete the entry */
  if ((day == 0) && (month == 0) && (year == 00)) { err = 1; day = ""; month = ""; year = ""; seperator = ""; }

  /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
  if (err == 0) {
    return true;
  } 
  else {		
    return false;
  }
}


function checkDateBlur(DateValue, field){
  var checkstr = "0123456789";
  var Datevalue = "";
  var DateTemp = "";
  var seperator = "-";
  var day;
  var month;
  var year;
  var leap = 0;
  var err = 0;
  var i;

  /* Delete all chars except 0..9 */
  for (i = 0; i < DateValue.length; i++) {
    if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
      DateTemp = DateTemp + DateValue.substr(i,1);
    }
  }
  DateValue = DateTemp;

  /* Always change date to 8 digits - string*/
  /* if year is entered as 2-digit / always assume 20xx */
  if (DateValue.length == 6) {
    DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }

  if (DateValue.length != 8) { err = 1; }
  /* year is wrong if year = 0000 */
  year = DateValue.substr(4,4);
  if (year == 0) { err = 1; }

  /* Validation of month*/
  month = DateValue.substr(2,2);
  if ((month < 1) || (month > 12)) { err = 1; }

  /* Validation of day*/
  day = DateValue.substr(0,2);
  if (day < 1) { err = 1; }

  /* Validation leap-year / february / day */
  if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; }
  if ((month == 2) && (leap == 1) && (day > 29)) { err = 1; }
  if ((month == 2) && (leap != 1) && (day > 28)) { err = 1; }

  /* Validation of other months */
  if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) { err = 1; }
  if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) { err = 1; }

  /* if 00 is entered, no error, delete the entry */
  if ((day == 0) && (month == 0) && (year == 00)) { err = 0; day = ""; month = ""; year = ""; seperator = ""; }

  /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
  if (err == 0) {
  field.value = day + seperator + month + seperator + year;
  //form1.f_date.value = day + seperator + month + seperator + year;
  }
}


function checkEmballage(embal) {
  // emballage moet integer zijn, tussen 1 en 999
  if ((isNumber(embal))&&(embal>0)&&(embal<1000)) {
    return true;
  } 
  else {
    return false;
  }
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
var today = new Date();
var overjaar = new Date(today.getTime() + (56 * 86400000));

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
  ((expires) ? "; expires=" + expires.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } 
  else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


function store(name,value) {
  //alert("was van "+name+" en is: "+value);
  setCookie(name, value, overjaar);
}


function getkoekjes() {
  //alert("ja")
  if (getCookie("naam")) { document.Aanvraag.a_naam.value=getCookie("naam"); }
  if (getCookie("inadres")) { document.Aanvraag.b_adres.value=getCookie("inadres"); }
  if (getCookie("inplaats")) { document.Aanvraag.c_plaats.value=getCookie("inplaats"); }
  if (getCookie("inpc")) { document.Aanvraag.c_pc.value=getCookie("inpc"); }
  if (getCookie("intel")) { document.Aanvraag.d_tel.value=getCookie("intel");	}
  if (getCookie("infax")) { document.Aanvraag.e_geb.value=getCookie("infax"); }
  if (getCookie("inemail")) { document.Aanvraag.f_email.value=getCookie("inemail"); }
}


function dateString (str) {
  var date;

  date = new Date(str.substr(6,4), str.substr(3,2)-1, str.substr(0,2));
  return date;
}



function dateWeekend (date) {
  if ( (date.getDay()== 0) || (date.getDay() == 6)) {
    return true;
  } 
  else {
    return false;
  }
}


function dateEmbal (deliverydate, currentdate) {
  currentdate.setDate(currentdate.getDate()+6);

  if (deliverydate > currentdate){
    return false;
  } 
  else {
    return true;
  }
}


function checkTime(time_1, time_2) {
  var time_1 = time_1.replace(':','');
  var time_2 = time_2.replace(':','');

  if (time_1 >= time_2) {
    return false;
  } 
  else {
    return true;
  }  
}

function newDate (date,addDays) {
  var date;
  var addDays;
  var actualDate;
  var day;
  var month;
  var year;

  actualDate = date;   
  actualDate = new Date(actualDate.substr(6,4), actualDate.substr(3,2)-1, actualDate.substr(0,2));
  actualDate.setDate(actualDate.getDate()+ addDays);

  day = actualDate.getDate();
  month = actualDate.getMonth()+1;
  year = actualDate.getYear();

  if (String(day).length == 1) {
   day = "0"+day
  }
  if (String(month).length == 1) {
   month = "0"+month
  }

  date = day+'-'+month+'-'+year;

  return date;
}


function secure(){
}