/* Function to validate inputs and output an error message to the next separator
 * 
 * @return void
 * @param string input //id of the field which should be validated
 * @param string exp //regular expression used
 * @param string msg //error message
 */
function checkValue(input,exp,msg){
	s = "separator"+input;
	if(document.getElementById(s) == null){
		separatorParts = s.split("_");
		id = parseInt(separatorParts[1]) + 1;
		separator = separatorParts[0] + "_" + id;
	}
	if(document.getElementById(input).value != ''){
		if (!document.getElementById(input).value.match(exp)) {
			if (msg == '')
				document.getElementById(separator).innerHTML = null;
			else
				document.getElementById(separator).innerHTML = "<p>" + msg+"</p>";
	    }else{
	    	document.getElementById(separator).innerHTML = null;
	    }
	}else{
		document.getElementById(separator).innerHTML = null;
	}
}

/* Function to count the chars of a textarea, limit it's length and output
 * the number to a given input field 
 * 
 * @return void
 * @param int maxchar //maximum number of allowed characters
 * @param string area //textarea of which the chars shall be counted
 * @param string output //input field which will show the number of left chars
 */
function CheckTA(maxchar,area,output)
      {
        var area = document.getElementById(area);
        var output = document.getElementById(output);
        var rest = maxchar - area.value.length;
        if (area.value.length > maxchar)
        {
        	area.value = area.value.substring(0,maxchar);
        }
        else
        {
          if (rest >= 0)
          {
        	  output.value=rest;
          }
          else
          {
        	  output.value='0';
          }
        }
        return false;
}
