function checkNum(num,len){
	if(num=='') return false;
	if(num.gsub(/[0-9]/,'').length>0) return false;
    if(num.length!=len) return false;
 return true;
}
function checkNumPhone(num){
	if(num=='') return false;
	if(num.gsub(/[0-9+\-()\s]/,'').length>0) return false;
 return true;
}

function echeck(str) {
	if(str=='') return false;
	if(str.gsub(/([a-z_\-\.\d]+)+@+([a-z\d]+)+\.+([a-z]{2,3})/i,'').length>0) return false;
	return true;
}
function checkEmptyText(str) {
	if(str=='') return false;
	if(str.gsub(/[\s]/,'').length>0) return true;
	return false;
}
function getFileExt(str) {
	if(str=='') return false;
	str=str.split(".");
	ext=str[str.length-1];
	return ext.toLowerCase();
}

function destroyEClass(obj){
	var VRegExp = new RegExp(/(\s?error+)/);
	obj.className = obj.className.replace(VRegExp, "");
}
function checkVacancies(){
inpCol=jQuery(".expand").get();
var VRegExp = new RegExp(/(\s?error+)/);
for(i=0;i<inpCol.length;i++){
	inpCol[i].className = inpCol[i].className.replace(VRegExp, "");
}

var status=1;
var o = null;
			o = jQuery('#vacancie').get(0);
			if (o != null) {
				if (o.options[o.selectedIndex].value==0) {
						o.className=o.className+' error';
						status=0;
				}
			} else status=0;
			o = jQuery('#fio').get(0);
			if (o != null) {
				if (!checkEmptyText(o.value)) {
						o.value='ВВЕДИТЕ КОРРЕКТНОЕ ИМЯ';
						o.className=o.className+' error';
						status=0;
				}
			} else status=0;

			o = jQuery('#email').get(0);
			if (o != null) {
				if (!echeck(o.value)) {
					o.value='ВВЕДИТЕ КОРРЕКТНЫЙ E-MAIL'
					o.className=o.className+' error';
					status=0;
				}
			} else status=0;

			o = jQuery('#fakeText').get(0);
			if (o != null) {
			ext=getFileExt(o.value);
				if (ext!="doc" && ext!="docx" && ext!="pdf" && ext!="rtf") {
					o.value="ФОРМАТА РЕЗЮМЕ - DOC ИЛИ PDF";
					o.className=o.className+' error';
					status=0;
				}
			}

			o = jQuery('#captcha_str').get(0);
		      var c = jQuery('#captcha_md5').get(0);
		      if ((o != null) && (c != null)) {
		        if (hex_md5(o.value) != c.value) {
					o.value='ВВЕДИТЕ КОД';
					//SmartyAjax.update('div_c', '/index.php', 'get', 'tpl=captcha&f=read_tpl');
					o.className=o.className+' error';
		          status=0;
		        }
		      } else status=0;

			if(status==1){
				document.vacancies.submit();
			}
}

function checkContacts(){
inpCol=jQuery(".expand").get();
var VRegExp = new RegExp(/(\s?error+)/);
for(i=0;i<inpCol.length;i++){
	inpCol[i].className = inpCol[i].className.replace(VRegExp, "");
}

var status=1;
var o = null;
			
			o = jQuery('#fio').get(0);
			if (o != null) {
				if (!checkEmptyText(o.value)) {
						o.value='ВВЕДИТЕ КОРРЕКТНОЕ ИМЯ';
						o.className=o.className+' error';
						status=0;
				}
			} else status=0;
			
			o = jQuery('#phone').get(0);
			if (o != null) {
				if (!checkNumPhone(o.value)) {
						o.value='ВВЕДИТЕ КОРРЕКТНЫЙ НОМЕР ТЕЛЕФОНА';
						o.className=o.className+' error';
						status=0;
				}
			} else status=0;
			
			o = jQuery('#email').get(0);
			if (o != null) {
				if (!echeck(o.value)) {
					o.value='ВВЕДИТЕ КОРРЕКТНЫЙ E-MAIL'
					o.className=o.className+' error';
					status=0;
				}
			} else status=0;
			
			o = jQuery('#subject').get(0);
			if (o != null) {
				if (!checkEmptyText(o.value)) {
						o.value='ВВЕДИТЕ ТЕМУ СООБЩЕНИЯ';
						o.className=o.className+' error';
						status=0;
				}
			} else status=0;
			
			o = jQuery('#message').get(0);
			if (o != null) {
				if (!checkEmptyText(o.value)) {
						o.value='ВВЕДИТЕ СООБЩЕНИЕ';
						o.className=o.className+' error';
						status=0;
				}
			} else status=0;
			o = jQuery('#captcha_str').get(0);
		      var c = jQuery('#captcha_md5').get(0);
		      if ((o != null) && (c != null)) {
		        if (hex_md5(o.value) != c.value) {
					o.value='ВВЕДИТЕ КОД';
					//SmartyAjax.update('div_c', '/index.php', 'get', 'tpl=captcha&f=read_tpl');
					o.className=o.className+' error';
		          status=0;
		        }
		      } else status=0;

			if(status==1){
				document.contacts.submit();
			}
}
