// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function isInteger(s){
      var i;
			s = s.toString();
      for (i = 0; i < s.length; i++){
         var c = s.charAt(i);
         if (isNaN(c)) {
				alert("Given value is not a number");
				return false;
				 }
      }
      return true;
}

function isHour(s){
	if(isInteger(s)){
		if( s < 0 || s > 23) {
			alert("Hour is must 0-23");
			return false;
		}
		return true;
	}
}

function isMinute(s){
	if(isInteger(s)){
		if( s < 0 || s > 59) {
			alert("Hour is must 0-59");
			return false;
		}
		return true;
	}
}

function fill_hidden_from_array(source,target,sourceValues,targetValues) {
	source = $(source);
	target = $(target);
 
	var index = 0;
	var target_id = -1;
	while (index < sourceValues.length) {
		if (source.value == sourceValues[index]) {
			target_id = index;
			break;
		}
		index++;
	}
 
	if (target_id >= 0 && source.value != ""){
		target.value = targetValues[target_id];
	}
	else {
		target.value = "";
	}
}
