﻿function display_no(id) {
	$("#"+id).css("display")=='none' ? $("#"+id).css("display", "block") : $("#"+id).css("display", "none");
}

function js_citizenship() {
	if ($("#citizenship option[@value='Казахстан']").attr("selected")==true) {
		$("#resident option[@value='Да']").attr("selected", "1");
		$("#citizenship_text").attr("disabled", "disabled");
		$("#citizenship_text").css("background", "#ebebeb");
		$("#resident").attr("disabled", "disabled");
		//change_resident();
		return true;
	} else {
		$("#citizenship_text").attr("disabled", "");
		$("#citizenship_text").css("background", "#fff");
		$("#resident option[@value='']").attr("selected", "selected");
		$("#resident").attr("disabled", "");
		//change_resident();
		return false;
	}
}

function js_oput() {
	if ($("#oput option[@value='yes']").attr("selected")==true) {
		$("#year").attr("disabled", "");
		$("#year").css("background", "#fff");
		$("#month").attr("disabled", "");
		$("#month").css("background", "#fff");
		$("#main_area").attr("disabled", "");
		$("#main_area").css("background", "#fff");
		return true;
	} else {
		$("#year").attr("disabled", "disabled");
		$("#year").css("background", "#ebebeb");
		$("#month").attr("disabled", "disabled");
		$("#month").css("background", "#ebebeb");
		$("#main_area").attr("disabled", "disabled");
		$("#main_area").css("background", "#ebebeb");
		return false;
	}
}

function change_resident() {
	var arr = new Array('identity', 'issue_identity_1', 'issue_identity_2', 'issue_identity_3', 'who_issued_identity', 'rnn', 'sik');
	if ($("#resident option[@value='Да']").attr("selected")==true || $("#resident option[@value='']").attr("selected")==true) {
		for (i=0; i<arr.length;i++) {
			$("#"+arr[i]).attr("disabled", "");
			$("#"+arr[i]).css("background", "#fff");
		}
	} else {
		//$("#resident option[@value='']").attr("selected", "selected");
		for (i=0; i<arr.length;i++) {
			$("#"+arr[i]).attr("disabled", "disabled");
			$("#"+arr[i]).css("background", "#ebebeb");
		}
	}
}

function change_work() {
	var arr = new Array('organization', 'direction', 'address_work', 'unit', 'name_post', 'start_work', 'end_work', 'end_work', 'acting', 'month_start_work', 'month_end_work');
	
	if ($("#oput_work option[@value='Да']").attr("selected")==true) {
		for (i=0; i<arr.length;i++) {
			$("#"+arr[i]).attr("disabled", "");
			$("#"+arr[i]).css("background", "#fff");
		}
	return true;
	} else {
		for (i=0; i<arr.length;i++) {
			$("#"+arr[i]).attr("disabled", "disabled");
			$("#"+arr[i]).css("background", "#ebebeb");
		}
	return false;
	}
}

var count_vuz=1, quan_vuz=0; vuzs = new Array();
function add_vuz() {
	var full_name = $("#full_name").val(), 
		full_name_text = $("#full_name_text").val(),
		country = $("#country").val(),
		country_text = $("#country_text").val(),
		city = $("#city").val(),
		city_text = $("#city_text").val(),
		start_training = $("#start_training").val(),
		end_training = $("#end_training").val(),
		speciality_text = $("#speciality_text").val(),
		speciality = $("#speciality").val(),
		bug = '', 
		error=0;
		
		full_name=='' ? full_name_text=='' ? bug +='full_name||' : full_name=full_name_text : '';
		speciality=='' ? speciality_text=='' ? bug +='speciality||' : speciality=speciality_text : '';
		city=='' ? city_text=='' ? bug +='city||' : city=city_text : '';
		country=='' ? country_text=='' ? bug +='country||' : country=country_text : '';
		
		filed_all =  Array('full_name', 'full_name_text', 'country', 'country_text', 'city', 'city_text', 'start_training', 'end_training', 'speciality', 'speciality_text');
		filed =  Array(Array('full_name',full_name) , Array('country',country), Array('city', city), Array('start_training', start_training), Array('end_training',end_training), Array('speciality', speciality));
		
		for (i=0; i<filed.length; i++) {
			if (filed[i][1]=='') {
				error++;
				$("#"+filed[i][0]).css("background", "#ffc5c3");
			} else {
				$("#"+filed[i][0]).css("background", "#fff");
			}
		}
		
		if ($("#start_training").val() > $("#end_training").val()) {
			$("#start_training").css("background", "#ffc5c3");
			$("#end_training").css("background", "#ffc5c3");
			error++;
		} else {
			$("#start_training").css("background", "#fff");
			$("#end_training").css("background", "#fff");
		}
		
		if (error==0) {
			vuzs[count_vuz]=filed;
			$("#educations"+count_vuz).html('<table style="margin-top:20px; border-bottom:1px solid #d6d6d6; width:90%;"><tr><td width="150"><strong>Полное название<br/>учебного заведения</strong></td><td>'+full_name+'</td></tr><tr><td><strong>Местонахождение</strong></td><td>'+country+', '+city+'</td></tr><tr><td><strong>Годы обучения</strong></td><td>c '+start_training+' по  '+end_training+'</td></tr><tr><td><strong>Специальность</strong></td><td>'+speciality+'</td><td rowspan="4" align="right"><span onclick="dell_vuz('+count_vuz+')" class="dell">Удалить запись</span></td></tr></table><input type="hidden" name="full_name[]" value="'+full_name+'"><input type="hidden" name="country[]" value="'+country+'"><input type="hidden" name="city[]" value="'+city+'"><input type="hidden" name="start_training[]" value="'+start_training+'"><input type="hidden" name="end_training[]" value="'+end_training+'"><input type="hidden" name="speciality[]" value="'+speciality+'">');
			$("#quan_vuz").append('<div id="educations'+(count_vuz+1)+'"></div>');
			for (i=0; i<filed_all.length; i++) {
				$("#"+filed_all[i]).val('');
			}
		count_vuz++;
		quan_vuz++;
		
		if (quan_vuz>6) {
			$("#traning").css("display", "none");
			error++;
		} else {
			$("#traning").css("display", "block");
		}
		}
}

function dell_vuz(id) {
	vuzs[id]='';
	quan_vuz--;
	quan_vuz < 3 ? $("#traning").css("display", "block") : '';
	$("#educations"+id).html('');
}


var count_course=1, quan_course=0; course = new Array();
function add_course() {
	var full_name_kurs = $("#full_name_kurs").val(), 
		date_training = $("#date_training").val(),
		name_course = $("#name_course").val(),
		error=0;
		
		filed_all =  Array('full_name_kurs', 'full_name_kurs', 'name_course');
		filed =  Array(Array('full_name_kurs',full_name_kurs) , Array('date_training',date_training), Array('name_course', name_course));
	
		for (i=0; i<filed.length; i++) {
			if (filed[i][1]=='') {
				error++;
				$("#"+filed[i][0]).css("background", "#ffc5c3");
			} else {
				$("#"+filed[i][0]).css("background", "#fff");
			}
		}
		
		
		if (error==0) {
			course[count_course]=filed;
			$("#course"+count_course).html('<table style="margin-top:20px; border-bottom:1px solid #d6d6d6; width:90%;"><tr><td width="150"><strong>Название учебного<br/>заведения</strong></td><td>'+full_name_kurs+'</td></tr><tr><td><strong>Год прохождения</strong></td><td>'+date_training+'</td></tr><tr><td><strong>Название курса</strong></td><td>'+name_course+'</td><td rowspan="3" align="right"><span onclick="dell_course('+count_course+')" class="dell">Удалить запись</span></td></tr></table><input type="hidden" name="full_name_kurs[]" value="'+full_name_kurs+'"><input type="hidden" name="date_training[]" value="'+date_training+'"><input type="hidden" name="name_course[]" value="'+name_course+'">');
			$("#quan_course").append('<div id="course'+(count_course+1)+'"></div>');
			for (i=0; i<filed_all.length; i++) {
				$("#"+filed_all[i]).val('');
			}
		count_course++;
		quan_course++;
		
		if (quan_course>8) {
			$("#tbl_course").css("display", "none");
			error++;
		} else {
			$("#tbl_course").css("display", "block");
		}
		}
}

function dell_course(id) {
	course[id]='';
	quan_course--;
	quan_course < 3 ? $("#tbl_course").css("display", "block") : '';
	$("#course"+id).html('');
}

var count_sem=1, quan_sem=0; sem = new Array(), muzh=zhena=mat=otec=sun=doch='n';
function add_sem() {
	var what_here = $("#what_here").val(), 
		name_semya = $("#name_semya").val(),
		surname_semya = $("#surname_semya").val(),
		patronymic_semya = $("#patronymic_semya").val(),
		date_of_birthd_sem_1 = $("#date_of_birthd_sem_1").val(),
		date_of_birthd_sem_2 = $("#date_of_birthd_sem_2").val(),
		date_of_birthd_sem_3 = $("#date_of_birthd_sem_3").val(),
		error=0;
		
		filed_all =  Array('what_here', 'name_semya', 'surname_semya', 'date_of_birthd_sem_1', 'date_of_birthd_sem_2', 'date_of_birthd_sem_3');
		filed =  Array(Array('what_here',what_here) , Array('name_semya',name_semya), Array('surname_semya', surname_semya), Array('date_of_birthd_sem_1', date_of_birthd_sem_1), Array('date_of_birthd_sem_2', date_of_birthd_sem_2), Array('date_of_birthd_sem_3', date_of_birthd_sem_3));
	
		for (i=0; i<filed.length; i++) {
			if (filed[i][1]=='') {
				error++;
				$("#"+filed[i][0]).css("background", "#ffc5c3");
			} else {
				$("#"+filed[i][0]).css("background", "#fff");
			}
		}
		
		
		if (error==0) {
			if (what_here == 'Муж') {
				muzh = 1;
			} else if (what_here == 'Жена') {
				zhena = 2;
			} else if (what_here == 'Мать') {
				mat = 7;
			} else if (what_here == 'Отец') {
				otec = 8;
			}
		
			change_sostav();
			sem[count_sem]=filed;
			$("#sem"+count_sem).html('<table style="margin-top:20px; border-bottom:1px solid #d6d6d6; width:90%;"><tr><td><strong>'+ucwords(surname_semya)+' '+ucwords(name_semya)+' '+ucwords(patronymic_semya)+'</strong>, '+what_here+', '+date_of_birthd_sem_1+'.'+date_of_birthd_sem_2+'.'+date_of_birthd_sem_3+' г.р.</td><td rowspan="1" align="right"><span onclick="dell_sem('+count_sem+')" class="dell">Удалить запись</span></td></tr></table><input type="hidden" name="what_here[]" value="'+what_here+'"><input type="hidden" name="name_semya[]" value="'+ucwords(name_semya)+'"><input type="hidden" name="surname_semya[]" value="'+ucwords(surname_semya)+'"><input type="hidden" name="patronymic_semya[]" value="'+ucwords(patronymic_semya)+'"><input type="hidden" name="date_of_birthd_sem_1[]" value="'+date_of_birthd_sem_1+'"><input type="hidden" name="date_of_birthd_sem_2[]" value="'+date_of_birthd_sem_2+'"><input type="hidden" name="date_of_birthd_sem_3[]" value="'+date_of_birthd_sem_3+'">');
			$("#quan_sem").append('<div id="sem'+(count_sem+1)+'"></div>');
			for (i=0; i<filed_all.length; i++) {
				$("#"+filed_all[i]).val('');
			}
		count_sem++;
		quan_sem++;
		if (quan_sem>12) {
			$("#tbl_sem").css("display", "none");
			error++;
		} else {
			$("#tbl_sem").css("display", "block");
		}
		}
}

function dell_sem(id) {
	sem[id]='';
	quan_sem--;
	quan_sem < 12 ? $("#tbl_sem").css("display", "block") : '';
	
	var div_menu = $("#sem"+id), 
		div = $("input", div_menu);
		for (i=0; i<div.length; i++ ) {
			if ($(div[i]).attr("name")=='what_here[]') {
				what_here = $(div[i]).attr("value");
				
				if (what_here == 'Муж') {
					muzh = 'n';
				} else if (what_here == 'Жена') {
					zhena = 'n';
				} else if (what_here == 'Мать') {
					mat = 'n';
				} else if (what_here == 'Отец') {
					otec = 'n';
				}
			change_sostav();
			}
		}
	
	$("#sem"+id).html('');
}



var count_work=1, quan_work=0; work = new Array();
function add_work() {
	if (change_work()==true) {
	var organization = $("#organization").val(), 
		direction = $("#direction").val(),
		address_work = $("#address_work").val(),
		unit = $("#unit").val(),
		name_post = $("#name_post").val(),
		start_work = $("#start_work").val(),
		end_work = $("#end_work").val(),
		acting = $("#acting").val(),
		month_start_work = $("#month_start_work").val(),
		month_end_work = $("#month_end_work").val(),
		error=0;
		
		filed_all =  Array('organization', 'direction', 'address_work', 'unit', 'name_post', 'start_work', 'end_work', 'acting', 'month_start_work', 'month_end_work');
		filed =  Array(Array('organization',organization) , Array('direction',direction), Array('address_work', address_work), Array('name_post', name_post), Array('start_work', start_work), Array('end_work', end_work), Array('acting', acting), Array('month_start_work', month_start_work), Array('month_end_work', month_end_work));
		
		for (i=0; i<filed.length; i++) {
			if (filed[i][1]=='') {
				error++;
				$("#"+filed[i][0]).css("background", "#ffc5c3");
			} else {
				$("#"+filed[i][0]).css("background", "#fff");
			}
		}
		
		if ($("#start_work").val() > $("#end_work").val() || $("#start_work").val()=='' || $("#end_work").val()=='') {
			$("#start_work").css("background", "#ffc5c3");
			$("#end_work").css("background", "#ffc5c3");
			error++;
		} else {
			$("#start_work").css("background", "#fff");
			$("#end_work").css("background", "#fff");
		}
		
		if ($("#start_work").val() == $("#end_work").val() && (month_start_work == month_end_work || month_start_work >= month_end_work) || $("#month_start_work").val()=='' || $("#month_end_work").val()=='') {
			$("#month_start_work").css("background", "#ffc5c3");
			$("#month_end_work").css("background", "#ffc5c3");
			error++;
		} else {
			$("#month_start_work").css("background", "#fff");
			$("#month_end_work").css("background", "#fff");
		}
		
		/*if (quan_work>2) {
			alert('Вы не можете добавлять больше трех мест работ.');
			error++;
		}*/
		if (error==0) {
			work[count_work]=filed;
			$("#div_work"+count_work).html('<table style="margin-top:20px; border-bottom:1px solid #d6d6d6; width:90%;"><tr><td width="150"><strong>Название<br/>организации</strong></td><td>'+organization+'</td></tr><tr><td><strong>Направление<br/>деятельности<br/>организации</strong></td><td>'+direction+'</td></tr><tr><td><strong>Адрес</strong></td><td>'+address_work+'</td></tr><tr><td><strong>Структурное<br/>подразделение</strong></td><td>'+unit+'</td></tr><tr><td><strong>Название<br/>должности</strong></td><td>'+name_post+'</td></tr><tr><td><strong>Период работы</strong></td><td>c '+start_work+' по '+end_work+'</td></tr><tr><td><strong>Должностные<br/>обязанности</strong></td><td>'+acting+'</td><td rowspan="5" align="right"><span onclick="dell_work('+count_work+')" class="dell">Удалить запись</span></td></tr></table><input type="hidden" name="organization[]" value="'+organization+'"><input type="hidden" name="direction[]" value="'+direction+'"><input type="hidden" name="address_work[]" value="'+address_work+'"><input type="hidden" name="unit[]" value="'+unit+'"><input type="hidden" name="name_post[]" value="'+name_post+'"><input type="hidden" name="start_work[]" value="'+start_work+'"><input type="hidden" name="end_work[]" value="'+end_work+'"><input type="hidden" name="acting[]" value="'+acting+'"><input type="hidden" name="month_start_work[]" value="'+month_start_work+'"><input type="hidden" name="month_end_work[]" value="'+month_end_work+'">');
			$("#quan_work").append('<div id="div_work'+(count_work+1)+'"></div>');
			for (i=0; i<filed_all.length; i++) {
				$("#"+filed_all[i]).val('');
			}
		count_work++;
		quan_work++;
		
		quan_work > 0 ? $("#td_oput_work").css("display", "none") : '';
		}
	}
}

function dell_work(id) {
	work[id]='';
	quan_work--;
	quan_work == 0 ? $("#td_oput_work").css("display", "block") : '';
	$("#div_work"+id).html('');
}

function change_lang() {
	var arr = new Array('other_reading', 'other_letter', 'other_speaking', 'other_terminology');
	if ($("#other_lang option[@value='']").attr("selected")==true) {
		for (i=0; i<arr.length;i++) {
			$("#"+arr[i]).attr("disabled", "disabled");
			$("#"+arr[i]).css("background", "#ebebeb");
		}
	} else {
		for (i=0; i<arr.length;i++) {
			$("#"+arr[i]).attr("disabled", "");
			$("#"+arr[i]).css("background", "#fff");
		}
	}
}

function change_lang_text() {
	var arr = new Array('other_reading', 'other_letter', 'other_speaking', 'other_terminology');
	if ($("#other_lang_text").val()=='') {
		for (i=0; i<arr.length;i++) {
			$("#"+arr[i]).attr("disabled", "disabled");
			$("#"+arr[i]).css("background", "#ebebeb");
		}
	} else {
		for (i=0; i<arr.length;i++) {
			$("#"+arr[i]).attr("disabled", "");
			$("#"+arr[i]).css("background", "#fff");
		}
	}
}

function checked_str(evt, id, lang) {
	var keyCode = undefined == evt.which ? evt.keyCode : evt.which;
	
	if (keyCode != 37 && keyCode != 39) {
		if (lang=='ru') {
			var re = /[^а-яА-Я]/g;
		} else if (lang=='en') {
			var re = /[^a-zA-Z]/g;
		} else if (lang=='kz') {
			var re = /[^iа-яА-Яі????????????????]/g;
		}
		
		var len = $("#"+id).val();
		end = len.replace(re, "");
		$("#"+id).attr("value", end);
	}
}

function ucwords(str) {
	str_new = str.toLowerCase();
    return str_new.replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase ( ); } );
}

function send_form() {
	var filed = new Array('kz_name', 'kz_surname', 'kz_patronymic', 'ru_name', 'ru_surname', 'ru_patronymic', 'en_name', 'en_surname', 'en_patronymic');
	for (i=0; i<filed.length; i++) {
		$("#"+filed[i]).val(ucwords($("#"+filed[i]).val()));
	}
	
	
	var filed_one = new Array('children', 'resident', 'marital', 'ru_surname', 'ru_name', 'en_name', 'en_surname', 'date_of_birth_1', 'date_of_birth_2', 'date_of_birth_3', 'address', 'sex_div', 'mesto_birth');
	
	var other_lang = $("#other_lang").val(), 
		other_lang_text = $("#other_lang_text").val();
	var bug='';
	other_lang=='' ? other_lang_text=='' ? bug +='full_name||' : other_lang=other_lang_text : '';
	$("#hidden_other_lang").attr("value", other_lang);
	
	var  error=0;
	
	if ($("#level_post1").attr("checked")==undefined && $("#level_post2").attr("checked")==undefined && $("#level_post3").attr("checked")==undefined) {
		error++;
		$("#level_post1").css("background", "#ffc5c3");
		$("#level_post2").css("background", "#ffc5c3");
		$("#level_post3").css("background", "#ffc5c3");
	} else {
		$("#level_post1").css("background", "#fff");
		$("#level_post2").css("background", "#fff");
		$("#level_post3").css("background", "#fff");
	}
	
	if (change_image('jpg', 'photo')==false) {
		error++;
		$("#photo").css("background", "#ffc5c3");
	} else {
		$("#photo").css("background", "#fff");
	}
	
	var filed_qwert = new Array('year', 'month', 'main_area');
	if (js_oput()==true) {
		for (i=0; i<filed_qwert.length; i++) {
			if ($("#"+filed_qwert[i]).val()=='') {
				error++;
				$("#"+filed_qwert[i]).css("background", "#ffc5c3");
				}
		}
	} else {
		for (i=0; i<filed_qwert.length; i++) {
			$("#"+filed_qwert[i]).css("background", "#fff");
		}
	}
	
	/*if (change_image('doc', 'word')==false) {
		error++;
		$("#word").css("background", "#ffc5c3");
	} else {
		$("#word").css("background", "#fff");
	}*/
	
	var email = $("#email").val();
	if (email!='') {
		var re = /[a-zA-Z0-9_\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]/i;
    	if (!re.test(email)) {
			$("#email").css("background", "#ffc5c3");
			error++;
		} else {
			$("#email").css("background", "#fff");
		}
	}
	
	var rnn = $("#rnn").val();
	if (rnn!='' && rnn.length!=12) {
		$("#rnn").css("background", "#ffc5c3");
		error++;
	} else {
		$("#rnn").css("background", "#fff");
	}
	
	var sik = $("#sik").val();
	if (sik!='' && sik.length!=16) {
		$("#sik").css("background", "#ffc5c3");
		error++;
	} else {
		$("#sik").css("background", "#fff");
	}
	
	for (i=0; i<filed_one.length; i++) {
		if ($("#"+filed_one[i]).val()=='') {
			$("#"+filed_one[i]).css("background", "#ffc5c3");
			error++;
		} else {
			$("#"+filed_one[i]).css("background", "#fff");
		}
	}
	
	if ($("#citizenship option[@value='']").attr("selected")==true && $("#citizenship_text").val()=='') {
		$("#citizenship").css("background", "#ffc5c3");
		error++;
	} else {
		$("#citizenship").css("background", "#fff");
	}
	
	phone_work = $("#phone_work").val(), 
	phone_home = $("#phone_home").val(),
	phone_mobile_1 = $("#phone_mobile_1").val(),
	phone_mobile_2 = $("#phone_mobile_2").val();
		
	if (phone_work=='' && phone_home=='' && phone_mobile_1=='' && phone_mobile_2=='') {
		$("#phone_work").css("background", "#ffc5c3");
		$("#phone_home").css("background", "#ffc5c3");
		$("#phone_mobile_1").css("background", "#ffc5c3");
		$("#phone_mobile_2").css("background", "#ffc5c3");
	} else {
		$("#phone_work").css("background", "#fff");
		$("#phone_home").css("background", "#fff");
		$("#phone_mobile_1").css("background", "#fff");
		$("#phone_mobile_2").css("background", "#fff");
	}
	
	/*var filed_identity = new Array('identity', 'issue_identity_1', 'issue_identity_2', 'issue_identity_3', 'who_issued_identity');
	var identity = $("#identity").val(),
		issue_identity_1 = $("#issue_identity_1").val(),
		issue_identity_2 = $("#issue_identity_2").val(),
		issue_identity_3 = $("#issue_identity_3").val(),
		who_issued_identity = $("#who_issued_identity").val();
	if (identity!='' || issue_identity_1!='' || issue_identity_2!='' || issue_identity_3!='' || who_issued_identity!='') {
		if (identity!='' && issue_identity_1!='' && issue_identity_2!='' && issue_identity_3!='' && who_issued_identity!='')  {
			for (i=0; i<filed_identity.length; i++) {
				$("#"+filed_identity[i]).css("background", "#fff");
			}
		} else {
			for (i=0; i<filed_identity.length; i++) {
				$("#"+filed_identity[i]).css("background", "#ffc5c3");
				error++;
			}
		}
	}  else {
		for (i=0; i<filed_identity.length; i++) {
			$("#"+filed_identity[i]).css("background", "#fff");
		}
	}
	
	
	var filed_passport = new Array('passport', 'issue_passport_1', 'issue_passport_2', 'issue_passport_3', 'who_issued_passport');
	var passport = $("#passport").val(),
		issue_passport_1 = $("#issue_passport_1").val(),
		issue_passport_2 = $("#issue_passport_2").val(),
		issue_passport_3 = $("#issue_passport_3").val(),
		who_issued_passport = $("#who_issued_passport").val();
	if (passport!='' || issue_passport_1!='' || issue_passport_2!='' || issue_passport_3!='' || who_issued_passport!='') {
		if (passport!='' && issue_passport_1!='' && issue_passport_2!='' && issue_passport_3!='' && who_issued_passport!='')  {
			for (i=0; i<filed_passport.length; i++) {
				$("#"+filed_passport[i]).css("background", "#fff");
			}
		} else {
			for (i=0; i<filed_passport.length; i++) {
				$("#"+filed_passport[i]).css("background", "#ffc5c3");
				error++;
			}
		}
	} else {
		for (i=0; i<filed_passport.length; i++) {
			$("#"+filed_passport[i]).css("background", "#fff");
		}
	}*/
	
	if ($("#level_post option[@value='']").attr("selected")==true) {
		$("#level_post").css("background", "#ffc5c3");
	} else {
		$("#level_post").css("background", "#fff");
	}
	
	
	var filed_three = new Array('full_name', 'country', 'city', 'start_training', 'end_training', 'speciality');
	if (quan_vuz==0) {
		error++;
		for (i=0; i<filed_three.length; i++) {
			$("#"+filed_three[i]).css("background", "#ffc5c3");
		}
	} else {
		for (i=0; i<filed_three.length; i++) {
			$("#"+filed_three[i]).css("background", "#fff");
		}
	}
		
	filed_four = new Array('organization', 'direction', 'address_work', 'name_post', 'start_work', 'end_work','acting');
	if (change_work()==true && quan_work==0) {
		error++;
		for (i=0; i<filed_four.length; i++) {
			$("#"+filed_four[i]).css("background", "#ffc5c3");
		}
	} else {
		for (i=0; i<filed_four.length; i++) {
			$("#"+filed_four[i]).css("background", "#fff");
		}
	}
	
	filed_seven = new Array('what_here', 'name_semya', 'surname_semya', 'date_of_birthd_sem_1', 'date_of_birthd_sem_2','date_of_birthd_sem_3');
	if (quan_sem==0) {
		error++;
		for (i=0; i<filed_seven.length; i++) {
			$("#"+filed_seven[i]).css("background", "#ffc5c3");
		}
	} else {
		for (i=0; i<filed_seven.length; i++) {
			$("#"+filed_seven[i]).css("background", "#fff");
		}
	}
	
	filed_five = new Array('lang_kz_1', 'lang_kz_2', 'lang_kz_3', 'lang_kz_4', 'lang_ru_1', 'lang_ru_2', 'lang_ru_3', 'lang_ru_4', 'lang_en_1', 'lang_en_2', 'lang_en_3', 'lang_en_4');
		for (i=0; i<filed_five.length; i++) {
			if ($("#"+filed_five[i]+" option[@value='']").attr("selected")==true) {
				$("#"+filed_five[i]).css("background", "#ffc5c3");
				error++;
			} else {
				$("#"+filed_five[i]).css("background", "#fff");
			}
		}
	
	if ($("#other_reading option[@value='']").attr("selected")==false) {
		filed_six = new Array('other_reading', 'other_letter', 'other_speaking', 'other_terminology');
		for (i=0; i<filed_six.length; i++) {
			if ($("#"+filed_six[i]+" option[@value='']").attr("selected")==true) {
				$("#"+filed_six[i]).css("background", "#ffc5c3");
				error++;
			} else {
				$("#"+filed_six[i]).css("background", "#fff");
			}
		}
	}
	
	if ($("#other_programms").val()==''  && $("#p1").attr("checked")==undefined && $("#p2").attr("checked")==undefined && $("#p3").attr("checked")==undefined && $("#p4").attr("checked")==undefined && $("#p5").attr("checked")==undefined && $("#p6").attr("checked")==undefined && $("#p7").attr("checked")==undefined && $("#p8").attr("checked")==undefined && $("#p9").attr("checked")==undefined && $("#p10").attr("checked")==undefined) {
		$("#text_pr1").css("background", "#ffc5c3");
		$("#text_pr2").css("background", "#ffc5c3");
		$("#text_pr3").css("background", "#ffc5c3");
		error++;
	} else {
		$("#text_pr1").css("background", "#fff");
		$("#text_pr2").css("background", "#fff");
		$("#text_pr3").css("background", "#fff");
	}
	
	
	if (error>0) {
		$("#step1").css("display", "block");
		$("#step2").css("display", "none");
		$("#step3").css("display", "none");
		location.href='#top';
		alert("Форма подачи резюме заполнена не верна. Проверьте поля отмеченные красным маркером.")
		return false;
	} else {
		$("#send_form").attr("disabled", "1");
		return true;
	}
}

function default_combo(id) {
	$("#"+id+" option[@value='']").attr("selected", "selected");
}

function textCounter(field, maxlimit) {
if (field.value.length > maxlimit) {
	field.value = field.value.substring(0, maxlimit);
} /*else {
cntfield.value = maxlimit - field.value.length;
}*/
}

function change_image(format, id) {
	if ($("#"+id).val()!='') {
	var raz = $("#"+id).val().substr(($("#"+id).val().length-4), 4);
	raz = raz.replace(".", "");
	if (raz != format) {
		alert("Выберите файл формата " + format);
		//$("#"+id).attr("value", "");
		return false;
	}
	}
}


function ajax_upload_resume() {
	$("#error_message").html("<img src=\"/_img/indicator.gif\"/> Загрузка файла...<br/>");
	$("#form_add_sites").ajaxStart(function() {

	}).ajaxComplete(function(){

	});
	$.ajaxFileUpload ({
		url:'/ajax_add_resume.php',
		secureuri:false,
		fileElementId:'photo',
		dataType: 'xml',
		success: function (data, status) {
			var accept = $("accept", data).text();
			if (accept == 0) {
				$("#error_message").text($("glob_message", data).text());
			} else if (accept == 1) {
				$("#file_resume").val($("file_resume", data).text());
				$("#div_photo").css("display", "none");
				$("#hidden_photo").attr("value", $("glob_message", data).text());
				$("#error_message").html("");
				$("#div_photo_img").html("<img src='/_tmp_photo/"+ $("glob_message", data).text() +"' width='100' height='150' align='left'/><div style='margin-right:40px; float:right; font-weight:normal' onclick=\"$('#div_photo_img').html(''); display_no('div_photo'); $('#hidden_photo').attr('value', '');\" class='dell'>Удалить файл</div>");
			}
		},
		error: function (data, status, e) {
			alert(e);
		}
	})
}

function checked_data(id) {
	var len = $("#"+id).val();
	var re = /[^0-9]/g;
	end = len.replace(re, "");
	$("#"+id).attr("value", end);
}

function show_win(id) {
	myWin=window.open('/show_win.php?id='+id, "win1", "width=500, height=500, resizable=yes, scrollbars=yes, menubar=no");
}

function change_sostav() {
	var sostav_array = new Array('', 'Муж', 'Жена', 'Сын', 'Дочь', 'Брат', 'Сестра', 'Мать', 'Отец');
	$("#what_here").empty();
	for (i = 0; i < sostav_array.length; i++) {
		if (sostav_array[i]!=sun && sostav_array[i]!=doch && i!=muzh && i!=zhena && i!=otec && i!=mat) {
			$('<option value="'+sostav_array[i]+'">'+sostav_array[i]+'</option>').appendTo("#what_here");
		}
	}
}