// JavaScript Document
var Opera = (navigator.userAgent.indexOf("Opera")!=-1)?true:false;
var NN = (navigator.appName=='Netscape')?true:false;
var IE = (!Opera&&(navigator.appName.substring(0,9)=='Microsoft'))?true:false;
var IE6 = (IE&&(navigator.appVersion.indexOf("MSIE 6")!=-1))?true:false;
function getElement(name)
 {
 var d = document;
 if(d.getElementById(name))
   return d.getElementById(name);
 else
   if(d.all[name])
   return d.all[name];
 }
 function createElement(tag)
 {
  return document.createElement(tag)
 }

function createTextNode(text)
 {
  return document.createTextNode(text);
 } 

 function tableInsertRow(t)
  {
   var Tr;
   if(NN||Opera)
    {
         Tr = crEl("TR");
         t.appendChild(Tr);
        }        
   else         
         Tr = t.insertRow();
        return Tr; 
  }
 function tableInsertCell(Tr)
  {
  var Td;
   if(NN||Opera)
          {
           Td = crEl("TD");
           Tr.appendChild(Td);
          }
   else 
          Td = Tr.insertCell();
        return Td; 
  }

function catchEventObject(e)
{
  var obj;
  if(window.event)
    obj = window.event.srcElement;
  else
   if(e.target)
    obj = e.target;
        else obj = null;        
  return obj;  
}

function keyCode(evt)
 {
   evt = (evt)?evt:(window.event)?window.event:"";
   if(evt)
    {
         var intKey = (evt.which)?evt.which:evt.keyCode;
         return String.fromCharCode(intKey);
        }
   else return "";      
 }

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function CheckDate(obj,message,defaultValue){
        var error = false;
          if(isNaN(obj.value))
           error = true;
      else  
           error = ((parseInt(obj.value)<32)&&(parseInt(obj.value)>0))?false:true;       
          if(error){
           alert(message);      
           obj.value = defaultValue;
         }
        return !error; 
}
function CheckYear(obj,message,defaultValue){
     
      if(obj.value.trim() == "") 
          return true;
      var error = false;
          if(isNaN(obj.value))
           error = true;
      else  
       error = ((parseInt(obj.value)<3000)&&(parseInt(obj.value)>1900))?false:true;                      
      if(error){
           alert(message);      
           obj.value = defaultValue;
           obj.select();
      }
     return !error; 
}
function checkDefault(obj, message)
	    {
		  if (obj.value.trim() == '' ) {
		   alert(message);
		   obj.focus();
		   obj.select();		   
		   return false;
		  }			
		  return true;
		}
  function checkEmail(obj, message)
	    {
		  reg = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);
          if (!reg.test(obj.value)) {                                            
             alert(message);
			 obj.focus();
			 obj.select();		     	
		   return false;
		  }
		  return true;
		}
	 function checkSalary(obj, message)
	    {
		 var Salary = obj.value.trim();
		 
             if(Salary == ""){
		   alert(message);
		   obj.focus();	
		   obj.select();		   
		  return false;		  
		 } 
		 return true;
		}	
	function checkAge(obj, message, empty)
	    {
		 var Age = obj.value.trim();
		 if ((empty && Age == '') || isNaN(Age) || (parseInt(Age)<14 || parseInt(Age)>100)) {
		   alert(message);
		   obj.focus();
		   obj.select();		   	
		  return false;
		 }
		 return true;
		} 
    function checkNumber(obj, message)
     {
       if(isNaN(obj.value) || parseInt(obj.value)<0) {
          alert(message);
		  obj.focus();
		  obj.select();		   	
		  return false;		
       }
      return true;
     }
	function checkSex(obj, message)
	    {
		 if(obj.value == '1') {
		   alert(message);		
		   obj.focus();			  
		   return false;	   		     		   
		  }
		  return true;
		}		
    function checkCity(obj, message)
	    {
		  if(obj.value.trim() == '' || (obj.value == 'another' && getElement('AnotherCity').value.trim() == '') ) {
		   alert(message);		
		   if (obj.value == 'another') {
             getElement('AnotherCity').focus();	
			 getElement('AnotherCity').select();	   		     
		   } else {
		      obj.focus();
		   }   
		  return false;		  
		 }
		 return true;
		}	
 function findText(obj) 
         {
           var up = obj.parentElement;
           var on = up.previousSibling;
           var text = on.firstChild;
           var Caption = ""; 
           if(text.nodeValue == null){
              var text = text.firstChild;
               Caption = text.nodeValue;
           } else {
               Caption = text.nodeValue;
           }
           message = 'Поле "'+ Caption + '" содержит некорректное значение!'; 
           return message;
         }  
function checkSelect(obj, message)
 {
    var res = (obj.value == 1) ? false : true;
    if(!res) {
      alert(message);  
      obj.focus();   
    }
    return res;
 } 
function goBack()
 {
	 window.history.back(); 
 }
