//**********************
// CHECKFORM
//**********************
function checkForm(param){
  // v1.01 2011-02-28
  // author: René Weteling / Caret CMS
  // currently supports check values: char, int, float, zip, tel, email, checked, date (yyyy-mm-dd)
  // needs Jquery and Jquery Color: http://plugins.jquery.com/project/color
  // set default values if none exist.
  param['inputBad'] = param['inputBad'] || '#FF0000';
  param['inputOk'] = param['inputOk'] || '#FFF'; 
  param['labelBad'] = param['labelBad'] || '#FF0000'; 
  param['labelOk'] = param['labelOk'] || '#000'; 
  var retval = true;
  var error = '';
  // check if there is a form.      
  if(param['form']){              
    // for each input field
    $('input, textarea, select', param['form']).each(function(){       
      var re = undefined;
      var tmpval = true;
      switch($(this).attr('check')){
        case 'char':
          re=/^.+$/; 
          break;          
            case 'int':
          re=/^\d+$/;
          break;
            case 'float':
          re=/^\d+\.?\d+?$/;
          break;
            case 'zip':
          re=/^\d{4}\s?\w{2}$/;
          break;
            case 'tel':
          re=/^\d{10}$/;
          break;
            case 'email':
          re= /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
          break;
            case 'date':
          re= /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
          break;
            case 'time':
          re= /^[0-9]{2}:[0-9]{2}$/;
          break;
            case 'checked':
	  re= /^/;
          if(!$(this).attr("checked")){
            tmpval = false;
          }
          break;
            default:
	    re = undefined;
          //skip becouse this one has no check
      }       
      // handle regex
      if(re != undefined){      
        if(!re.test($(this).val())){
          tmpval = false;
        }  
          
      // handle visual 
      if(tmpval){
        $(this).animate({ backgroundColor: param['inputOk']});
        $('label[for='+$(this).attr('name')+']').animate({ color: param['labelOk']});        
      }else{           
        $(this).animate({ backgroundColor: param['inputBad']});   
        $('label[for='+$(this).attr('name')+']').animate({ color: param['labelBad']});        
        if($('label[for='+$(this).attr('name')+']').attr('error')){
          error+=$('label[for='+$(this).attr('name')+']').attr('error')+"\n";
        }
        retval = false;
      }    
  }    
    });    
  }  
  if(error.length > 0){
    alert(error);
  }  
  // return if the form passed the test of not.
  return retval;
}



//ALGEMEEN 
function setSubInfo(tgt,src){

getElement(tgt).innerHTML = getElement(src).innerHTML;

}

function setDivHeight(){

    var midheight = getElement('mid').scrollHeight;
    var rightheight = getElement('tableRight').scrollHeight;    
    if (midheight > rightheight){ 
		getElement('tableRight').style.height = (midheight-20)+"px";
	}
    
}

    function showOnly(showId, parentId, tagName) {
                var parObj = document.getElementById(parentId);
                var tagType = "DIV";
                if (tagName) {
                    tagType = tagName.toUpperCase();
                }
                if (parObj) {
                    var children = parObj.childNodes;
                    // alert(db_DumpTree(children, ''));
                    for(c = 0; c < children.length; c++) {
                        if (children[c].nodeName == tagType ) {
                            if (children[c].id == showId) {
                                children[c].style.display = 'block';
                            } else {
                                children[c].style.display = 'none';
                            }
                        }
                    }
                }
            }




// HULPFUNCTIES
function getElement(id) {
    if (document.getElementById(id)) {
        return document.getElementById(id);
    } else {
        alert('Element ' + id + ' is niet gevonden!');
    }
}

function getPageHeight() {
    if (window.innerHeight && window.scrollMaxY) { // Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
    }
    return yWithScroll;
}

function inpFocus(obj, stdText) {
  if (obj.value == stdText) {
     obj.value = '';
  }
}

function inpBlur(obj, stdText) {
  if (obj.value == '') {
     obj.value = stdText;
  }
}








