var ErrorString = "";
var Error=false;
var ErrorCRLF="\n";

var Good_Int_Chars = new String("0123456789-");
var Good_Real_Chars = new String("0123456789.,-");

function StripControl(control) {
  var i=control.indexOf(",",0);
  if(i>=0)return control.substring(0,i);
  else return control;
}

function StripTitle(control) {
  var i=control.indexOf(",",0);
  if(i++>0)return control.substring(i,control.length);
  else return control;
}


function Check_Chars(f,source,goodchars) {
  errcnt=0;
  for(i=0;i<source.length;i++)if(goodchars.search(source.charAt(i))<0)errcnt++;
  return(errcnt>0);
}

function Check_Int(f,control,MinVal,MaxVal) {
  var c=StripControl(control); 
  if((f[c].value == "")||(Check_Chars(f,f[c].value,Good_Int_Chars))){
    ErrorString+="  "+StripTitle(control)+ErrorCRLF;
    return true;
  }
  else {

    LocalError=false;
    if(MinVal!=null)LocalError=LocalError||(parseInt(f[c].value)<MinVal);
    if(MaxVal!=null)LocalError=LocalError||(parseInt(f[c].value)>MaxVal);
    if(LocalError){
      ErrorString+="  "+StripTitle(control)+ErrorCRLF;
      return true;
    }
    else return false;
  }
}

function Check_Real(f,control) {
  var c=StripControl(control); 
  if((f[c].value == "")||(Check_Chars(f,f[c].value,Good_Real_Chars))){
    ErrorString+="  "+StripTitle(control)+ErrorCRLF;
    return true;
  }
  else return false;
}

function Check_String(f,control) {
//  alert(StripControl(control));
  if(f[StripControl(control)].value == ""){
    ErrorString+="  "+StripTitle(control)+ErrorCRLF;
    return true;
  }
  else return false;
}

function Check_EMail(f,control) {
  var c=StripControl(control); 
  if((f[c].value == "")||(f[c].value.indexOf('@',0)==-1)||(f[c].value.indexOf('.',0)==-1)){
    ErrorString+="  "+StripTitle(control)+ErrorCRLF;
    return true;
  }
  else return false;
}

function Check_Datum(f,control) {
  var c=StripControl(control); 
  if((Check_Chars(f,f[c+"_Dag"].value,Good_Int_Chars))||(Check_Chars(f,f[c+"_Maand"].value,Good_Int_Chars))||(Check_Chars(f,f[c+"_Jaar"].value,Good_Int_Chars))||
     (f[c+"_Dag"].value < 1)||(f[c+"_Dag"].value > 31)||(f[c+"_Maand"].value < 1)||(f[c+"_Maand"].value > 12)||(f[c+"_Jaar"].value < 1900)||(f[c+"_Jaar"].value>2100)){
    ErrorString+="  "+StripTitle(control)+ErrorCRLF;
    return true;
  }
  else return false;
}

function Check_Time(f,control) {
  var c=StripControl(control); 
  
  
  if((Check_Chars(f,f[c+"_Uur"].value,Good_Int_Chars))||
     (Check_Chars(f,f[c+"_Minuut"].value,Good_Int_Chars))||
     (f[c+"_Uur"].value < 0)||
     (f[c+"_Uur"].value > 24)||
     (f[c+"_Minuut"].value < 0)||
     (f[c+"_Minuut"].value > 59)){
    ErrorString+="  "+StripTitle(control)+ErrorCRLF;
    return true;
  }
  else return false;
}


function Check_Check(f,control) {
  var OneChecked=false;
  var c=StripControl(control); 

  for(i=0;i<f[c].length;i++) 
    OneChecked=f[c][i].checked||OneChecked;
  if(! OneChecked) ErrorString+="  "+StripTitle(control)+ErrorCRLF;
  return !OneChecked;
}

function Check_Options(f,control) {
  var c=StripControl(control); 
  if(f[c].selectedIndex<0) {
    ErrorString+="  "+StripTitle(control)+ErrorCRLF;
    return true;
  }
  else {
    if(f[c][f[c].selectedIndex].value>0)return false;
    else { 
      ErrorString+="  "+StripTitle(control)+ErrorCRLF;


      return true;
    }
  }
}

function ClearListBox(f,control) {
  var c=StripControl(control); 
  while(f[c].selectedIndex>=0) 
    f[c][f[c].selectedIndex].selected=false;
}

function Check_Int_Bounds(f,control,MinVal,MaxVal) {
  var c=StripControl(control); 
  
  
  if((f[c].value == "")||(Check_Chars(f,f[c].value,Good_Int_Chars))){
    ErrorString+="  "+StripTitle(control)+ErrorCRLF;
    return true;
  }
  else return false;
}

function F_KiesKleur(f,TableName,FieldName){
  var RGB=document[TableName][FieldName].value;
  var URL="kieskleur.asp?RGB="+RGB+"&TableName="+TableName+"&FieldName="+FieldName+"&SS="+QueryDocumentDir()+"style.css";
  F_OpenWindow(URL,130,200,false);
}

function F_KiesPlaatje(f,TableName,FieldName,previewWidth,previewHeight){
  var URL="kiesplaatje.asp?ID="+eval(document[TableName].ID.value)+"&TableName="+TableName+"&FieldName="+FieldName+"&SS="+QueryDocumentDir()+"style.css&W="+eval(previewWidth)+"&H="+eval(previewHeight);
  
 F_OpenWindow(URL,550,450,true);
}

function F_AskDelete(DisplayThis,URL) {
  if(confirm(DisplayThis))document.location=URL;
}

function F_Ask(DisplayThis,URL) {
  if(confirm(DisplayThis))document.location.href=URL;
}

function F_SetColor(name,color) {
  document[name].src="scripts/ColourGif.dll?RGB="+color;
}

function F_OpenWindow(url,awidth,aheight,aresize) {
  var w = (awidth)?awidth:600;
  var h = (aheight)?aheight:400;  
  var r = (aresize)?"yes":"no";
  var S="resizable="+r+",scrollbars=yes,toolbar=no,status=yes,menubar=no,width="+eval(w)+",height="+eval(h);
  S=S.replace(/,/gi,"&");      
  var wWidth=QueryValue(S,"width")
  var wHeight=QueryValue(S,"height")
  var wLeft=(screen.width)?(screen.width-wWidth)/2:0;
  var wTop=(screen.height)?(screen.height-wHeight)/2:0;
  var D=new Date();
  S=QueryReplace(QueryReplace(S,"left",eval(wLeft)),"top",eval(wTop)).replace(/&/gi,",");
  var newWindow=window.open(url, "w"+eval(D.getTime()), S); 
  if(parseInt(navigator.appVersion) >= 4)newWindow.window.focus();
}

