//**********************
// 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;
}



// TOPFOTO
   $(function(){
	setTimeout(function(){
	    $('#topfotoHolder .toplogo').fadeIn(1500);
	},500);
    });


function switchMenu(obj) 
{
    var el = document.getElementById(obj);
    if(el) {
	if ( el.style.display != "none" ) 
	{
	    el.style.display = 'none';
	}
	else {
	    el.style.display = '';
	}
    }
}

// Indien P element leeg is dan wordt class checkEmptyP niet getoond
$(document).ready(function() {
    //check of checkEmpty leeg is
    $('.checkEmpty').each(function(){
	var inhoud = $('.checkEmptyP' ,this).html();
      if(inhoud){
	  inhoud = inhoud.toLowerCase().replace(/\s/g,'');
	  
	  if(inhoud == '<p></p>' || inhoud == '<p>-</p>'){
	      $(this).hide();
	  }
      }
  });
    
});

function printMain(){
    $('body').html($('#main').html());
    setTimeout(function(){
	print();
	document.location.href = document.location.href;
    },250);
    return false;
}

