//**********************
// INPUT VALUE FIELDS
//**********************
function inpFocus(obj, stdText) {
  if (obj.value == stdText) {
    obj.value = '';
  }
}

function inpBlur(obj, stdText) {
  if (obj.value == '') {
    obj.value = stdText;
  }
}

//**********************
// 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:
          //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;
}


