function Validator(){}
Validator.prototype.isEmpty = function(str)
{   
    if(this.getLength(str))
        return false;
    return true;
}
Validator.prototype.getLength = function(str)
{
    if(str != "" && str != null && str != undefined)
        return str.length;
    return 0;
}
Validator.prototype.isEMail = function(str)
{
    str = this.trim(str)
    email_re1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/
    email_re2 = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
    if (this.isEmpty(str) || email_re1.exec(str) || !email_re2.exec(str))
        return false
    return true
}
Validator.prototype.isPhone = function(str)
{
    str = this.trim(str)
    phone = /^[0-9]*$/;
    if (this.isEmpty(str) || phone.exec(str))
        return false
    return true
}

Validator.prototype.trim = function(str) {
    return str.toString().replace(/(^\s+)|(\s+$)/g, "");
}
Validator = new Validator();
function CheckForm()
{      
  error_message = "";
  for (i=0;i<inputArray.length;i++){
    if (  document.getElementById(inputArray[i][0])  != null ) {   
      obj = document.getElementById(inputArray[i][0]).value;                                                 
      if (inputArray[i][1] == 'text' && Validator.isEmpty(obj)){  
	  error_message += "Введите  " + inputArray[i][2] + "\n";
      }                                                              
	  
      if (inputArray[i][1] == 'textarea' && Validator.isEmpty(obj)) {                                                                              
	  error_message += "Введите " + inputArray[i][2] + "\n";
      }
			
      if (inputArray[i][1] == 'tinymce' ) {
	  var textareat = tinyMCE.getInstanceById(inputArray[i][0]).getBody().innerHTML;
	  if (  textareat == '')
	      error_message += "Введите " + inputArray[i][2] + "\n";
      }
      
      if (inputArray[i][1] == 'password') {    
	  if ( Validator.isEmpty(obj) )
	      error_message += "Пароли не должны быть пустыми\n"; 
	  else if ( obj.length < 6 )
	      error_message += "Пароли должны быть больше 6 символов\n"; 
	  obj1 = document.getElementById(inputArray[i][2]).value;
	  if ( obj != obj1)
	      error_message += "Пароли должны совпадать и не быть пустыми\n";
      }

      if (inputArray[i][1] == 'email' && ( Validator.isEmpty(obj) || !Validator.isEMail(obj)))
	  error_message += "Неверный " + inputArray[i][2] + "\n"

      if (inputArray[i][1] == 'phone' && ( Validator.isEmpty(obj) || Validator.isPhone(obj)) )
	  error_message += "Неверный " + inputArray[i][2] + "\n"
      } else {
	error_message += "Неверный " + inputArray[i][2] + "\n"
      }
  }                  
  if (!Validator.isEmpty(error_message)) {
    error_message = "При заполнении формы был допущены ошибки:\n" + error_message;
    alert(error_message);
    return false;
  }
 return true;
}  
              
function isDigit(val){ 
  var intre = /^\d+$/;
  return intre.test(val);
}           
function isFloat(val){
  var floatre = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
  return floatre.test(val);
}

function checkDigit(id){
 var digitvalue = document.getElementById(id).value;
 if ( !isDigit(digitvalue) )
    document.getElementById(id).value = 0;
}
function checkFloat(id){
 var floatvalue = document.getElementById(id).value;
 if (!isFloat(floatvalue) )
    document.getElementById(id).value = 0;                                             
}