function chktel(buf)
{
  	var re = new RegExp('^[0-9 ()-\\/]+$');
  	if ((buf.match(re)) && (buf.length>=7)) return true; else return false;
}


function trim(e) {return e.replace(/(^\s*)|(\s*$)/g, "");}

function isemptystr(e)
{
  if (trim(e)=='') return true; else return false;
}

function isnumeric(e)
{
  if ((trim(e)!='') && (isNaN(trim(e))==false)) return true; else return false;
}

function isnumbers(buf)
{
	buf = trim(buf);
	if (buf=='') return false;
  	var re = new RegExp('^[0-9]+$');
  	if (buf.match(re)) return true; else return false;
}

function isdate(buf)
{
	buf = trim(buf);
	if (buf=='') return true;
  	var re = new RegExp('^[1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]$');
  	if (!buf.match(re)) return false;
	var ayear  = buf.substr(0,4);
	var amonth = buf.substr(5,2)-1;
	var aday   = buf.substr(8,2);
	var d = new Date(ayear,amonth,aday);
	if ( d.getYear()!=ayear) return false;
	if ( d.getMonth()!=amonth) return false;
	if ( d.getDate()!=aday) return false;
	return true;
}

function ncheckEmail(a) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(a)){
		return (true)
	}		
	return (false)
}


function submitbutton(f,n)
{
   theform  = eval('document.'+f);	
   theform.btnstate.value = n;
   theform.submit();
}

function contact_process(n)
{
	theform  = eval('document.contacts');	
	
	if (isemptystr(theform.contact.value))	{alert(err_contact); theform.contact.focus(); return; }     		
	if ((!chktel(theform.phone.value)) && (!isemptystr(theform.phone.value))) {alert(err_phone);	 theform.phone.focus(); return; }     		   		
	if ((!ncheckEmail(theform.mail.value)) && (!isemptystr(theform.mail.value))) {alert(err_mail); theform.mail.focus(); return; } 
	if ( (isemptystr(theform.phone.value)) && (isemptystr(theform.mail.value)) ) {alert(err_mail_or_phone); theform.phone.focus(); return; }
	
	theform.btnstate.value = n;
	theform.submit();
}


function lengthControll(fname,rname,length) 
{
        
	var a = eval("document."+fname+"."+rname);
	if (a.value.length > length) {
        a.value = a.value.substr(0,length);
        alert(err_smslength);
                        }
}

function chkdate(fname)
{
  var a = eval("document."+fname);
  var ndate = new Date(a.year.value, a.month.value-1, a.day.value);
  var ndate2 = new Date(a.year2.value, a.month2.value-1, a.day2.value);
  if ((	ndate.getFullYear()!=a.year.value) || (ndate.getMonth()!=a.month.value-1) || (ndate.getDate()!=a.day.value)) 
  {	
	alert(err_date);
	return;
  }
  if ((	ndate2.getFullYear()!=a.year2.value) || (ndate2.getMonth()!=a.month2.value-1) || (ndate2.getDate()!=a.day2.value)) 
  {	
	alert(err_date);
	return;
  }  
  if( ((ndate2-ndate)/86400000>60) || (ndate2-ndate<0) )
  {
	alert(err_date);
	return;
  }
  a.submit();}
