function eprofile() {

	if(document.e1.CompanyName.value=="")
	{
		alert('Въведете името на фирмата.');
		document.e1.CompanyName.focus();
		return false;
	}
	
	if(document.e1.address_2.value=="")
	{
		alert('Въведете адрес за кореспонденция на фирмата.');
		document.e1.address_2.focus();
		return false;
	}

	if(document.e1.address.value=="")
	{
		alert('Въведете адреса на регистрация на фирмата.');
		document.e1.address.focus();
		return false;
	}
	
	if(document.e1.mol.value=="")
	{
		alert('Въведете Материално Отговорно Лице (МОЛ) на фирмата.');
		document.e1.mol.focus();
		return false;
	}
	
	if(document.e1.ContactName_2.value=="")
	{
		alert('Въведете лице за контакт с кандидати.');
		document.e1.ContactName_2.focus();
		return false;
	}

	if(document.e1.ContactName.value=="")
	{
		alert('Въведете лице за контакт с Rabota.bg.');
		document.e1.ContactName.focus();
		return false;
	}
	
	document.e1.submit();
}

function CheckNewOffer() {

	if(document.of1.branch_id.value==0)
	{
		alert('Изберете бранш.');
		document.of1.branch_id.focus();
		return false;
	}
	
	arr=document.of1.elements["offer_categories[]"];
	
	var cat=false;

	for(i=0;i<arr.length;i++) {
		if (arr[i].checked) {
			cat=true;
			break;
		}
	}
	
	if (!cat) {
		alert("Изберете поне една категория!");
		return false;
		
	}
	
	if(document.of1.PositionTitle.value=="")
	{
		alert('Въведете името на позицията.');
		document.of1.PositionTitle.focus();
		return false;
	}

	arr=document.of1.elements["select_city[]"];
	
	var city=false;

	for(i=0;i<arr.length;i++) {
		if (arr[i].checked) {
			city=true;
			break;
		}
	}
	
	if (!city) {
		alert("Въведете града за тази позиция.");
		return false;
	}
	
	if(document.of1.PositionDetails.value=="")
	{
		alert('Въведете информацията за тази позиция.\n\nОпиши подробно задълженията, изискванията и отговорностите.');
		document.of1.PositionDetails.focus();
		return false;
	}
	
	document.of1.submit();

}

function PublOffer() {
	document.of1.publish.value=1;
	CheckNewOffer();
}

function populate_city(inForm,selected,checked) 
{  
	if (selected == 'Друг') 
	{
		if (checked==true) {
			
			newgrad = "";
			while (newgrad == "")
			{
				newgrad=prompt ("Въведи името на града:", "");
			}
		
			if (newgrad != null) 
			{
				document.getElementById('other_city').innerHTML='<input type="text" name="select_city[]" class="epost_input" style="width:100px;" value="'+newgrad+'" />';
		    }
		}
		else {
			document.getElementById('other_city').innerHTML='';
		}

	}

}

function populate_city2(inForm,selected) 
{  
	if (selected == 'Друг') 
	{
		newgrad = "";
		while (newgrad == "")
		{
			newgrad=prompt ("Въведи името на града:", "");
		}
	
		if (newgrad != null) 
		{
			inForm.select_city.options[(inForm.select_city.options.length-1)]=new Option(newgrad,newgrad,true,true);
			inForm.select_city.options[inForm.select_city.options.length]=new Option('Друг','Друг');
	   }

	}

}

function buildCategories(branch_id, sel, cats_id) {
	var r,t='<select id="'+cats_id+'" name="'+cats_id+'[]" multiple="multiple" size="8"' + (cats_id=='offer_categories'?' style="width:270px"': '') + '>';
	if (branch_id!=0)
		for (r in branches[branch_id]) t+='<option value="'+r+'"'+(sel==r?'selected="selected">':'>')+branches[branch_id][r]+'<\/option>';
	inner('epost_cat',t+'<\/select>');
	if (cats_id=='offer_categories') {
		ic='';
		oc='';
		ns='';
	}
	else {
		ic='search_cv_select';
		oc='search_cv_city';
		ns='изберете категория';
	}
	$("#"+cats_id).multiSelect({selectAll: false,noneSelected:ns,oneOrMoreSelected: '*',inputClass: ic,optionsClass: oc});
}

function check_price(value) {
	
	//var services=new Array();
	var duration=document.getElementById("offer_duration").value;

	if (!value) {
		arr=document.offer_type_form.offer_type;
//		var e_type=false;
		for(i=0;i<arr.length;i++) {
			if (arr[i].checked) {
//				e_type=true;
				value=arr[i].value;
				break;
			}
		}
	}
	
	document.getElementById("price").innerHTML=service[value][duration];

}

function CheckType() {
	arr=document.offer_type_form.offer_type;
	var o_type=false;
	for(i=0;i<arr.length;i++) {
		if (arr[i].checked) {
			o_type=true;
			break;
		}
	}
	if (!o_type) {
		alert("Изберете вид обява.");
		return false;
	}
	
	document.offer_type_form.submit();
}

function CheckOrder() {
	arr=document.cv_order_form.order_type;
	var o_type=false;
	for(i=0;i<arr.length;i++) {
		if (arr[i].checked) {
			o_type=true;
			break;
		}
	}
	if (!o_type) {
		alert("Изберете вид абонамент.");
		return false;
	}
	
	document.cv_order_form.submit();
}

function CheckNote() {
	note=el('add_note_border').value;
	
	if (!note) {
		alert("Бележката е празна!");
		el('add_note_border').focus();
		return false;
	}
	
	document.add_note_form.submit();
}

function CheckInvitation() {
	inviteDate = document.invite_form.date;
	if (inviteDate.value=="попълнете дата" || !inviteDate.value) {
		alert("Попълнете дата!");
		inviteDate.focus();
		return false;
	}
	
	inviteTime = document.invite_form.time;
	if (inviteTime.value=="попълнете час" || !inviteTime.value) {
		alert("Попълнете час!");
		inviteTime.focus();
		return false;
	}
	
	inviteAddr = document.invite_form.address;
	if (inviteAddr.value=="попълнете адрес" || !inviteAddr.value) {
		alert("Попълнете адрес!");
		inviteAddr.focus();
		return false;
	}
	
	document.invite_form.submit();
}

function input_text() {
	inviteDate = document.invite_form.date;
	inviteDate.onfocus = function() {
		if (inviteDate.value=="попълнете дата")
			inviteDate.value="";
		inviteDate.focus();
	}
	inviteDate.onblur = function() {
		if(this.value=='') inviteDate.value="попълнете дата";
	}
	
	inviteTime = document.invite_form.time;
	inviteTime.onfocus = function() {
		if (inviteTime.value=="попълнете час")
			inviteTime.value="";
		inviteTime.focus();
	}
	inviteTime.onblur = function() {
		if(this.value=='') inviteTime.value="попълнете час";
	}
	
	inviteAddr = document.invite_form.address;
	inviteAddr.onfocus = function() {
		if (inviteAddr.value=="попълнете адрес")
			inviteAddr.value="";
		inviteAddr.focus();
	}
	inviteAddr.onblur = function() {
		if(this.value=='') inviteAddr.value="попълнете адрес";
	}
}

function PublCourse() {
	document.of1.publish.value=1;
	CheckNewCourse();
}
function course_type_focus(value) {
	if (value=="Или въведете свободен текст тук")
		document.of1.other_type.value = '';
}
function course_type_blur(value) {
	if (value=="")
		document.of1.other_type.value = 'Или въведете свободен текст тук';
}

function jup1() {

	if(document.jnewemail.jpass1.value == "")
	{
		alert("Въведете паролата.");
		document.jnewemail.jpass1.focus();
		return false;
	}

	if(document.jnewemail.jpass2.value == "")
	{
		alert("Потвърдете паролата.");
		document.jnewemail.jpass2.focus();
		return false;
	}

	if(document.jnewemail.jpass1.value != "" && document.jnewemail.jpass2.value != "" && document.jnewemail.jpass1.value != document.jnewemail.jpass2.value)
	{
		alert("Има разлика между въведената парола и потвърдената парола.\n\nВъведете и потвърдете паролата отново.");
		document.jnewemail.jpass1.value= "";
		document.jnewemail.jpass2.value= "";

		document.jnewemail.jpass1.focus();
		return false;
	}

	document.jnewemail.submit();
}

function showOfferInfo(id) {
	if($('#row'+id).attr('class') == 'r' || $('#row'+id).attr('class') == 'r t') {
		$('#info'+id).css('display','block');
		if (id % 2 == 1) $('#row'+id).removeClass('r');
		else $('#row'+id).removeClass('t');
		$('#row'+id).removeClass('r t');
		$('#row'+id).addClass('sel');
	}
	else {
		$('#info'+id).css('display','none');
		$('#row'+id).removeClass('sel');
		if (id % 2 == 1) $('#row'+id).addClass('r');
		else $('#row'+id).addClass('r t');
	}
}

function CheckNewCourse() {
	var cat = parseInt(document.of1.category_id.value);
	var title = document.of1.course_title.value;
	var price = document.of1.price_value.value;
	var type = parseInt(document.of1.course_type.value);
	var other = document.of1.other_type.value.replace('Или въведете свободен текст тук','');
	var start = document.of1.start_date.value;
	var end = document.of1.end_date.value;
	var descr = document.of1.course_description.value;
	var city = document.of1.course_city.value;
	var addr = document.of1.course_address.value;
	var phone = document.of1.phone.value;
	var person = document.of1.contact_name.value;
	
	if (!cat) {
		alert('Моля попълнете категорията на курса');
		return false;
	}	
	
	if (!title) {
		alert('Моля попълнете заглавието на курса');
		return false;
	}
	
	if (!price) {
		alert('Моля попълнете цената на курса');
		return false;
	}
	
	if (!type && !other) {
		alert('Моля попълнете типа на курса');
		return false;
	}	
	
	if (!start) {
		alert('Моля попълнете началната дата на курса');
		return false;
	}	
	
	if (!end) {
		alert('Моля попълнете крайната дата на курса');
		return false;
	}	
		
	if (!descr) {
		alert('Моля попълнете описанието на курса');
		return false;
	}	
	
	if (!city) {
		alert('Моля попълнете града, в който ще се провежда курса ');
		return false;
	}	
	
	if (!addr) {
		alert('Моля попълнете адреса, където ще се провежда курса ');
		return false;
	}	
	
	if (!phone) {
		alert('Моля попълнете телефон за контакти');
		return false;
	}	
	
	document.of1.submit();
}

function PublNewCourse() {
	var cat = parseInt(document.of1.category_id.value);
	var title = document.of1.course_title.value;
	var type = parseInt(document.of1.course_type.value);
	var other = document.of1.other_type.value.replace('Или въведете свободен текст тук','');
	var start = document.of1.start_date.value;
	var end = document.of1.end_date.value;
	var descr = document.of1.course_description.value;
	var city = document.of1.course_city.value;
	var addr = document.of1.course_address.value;
	var phone = document.of1.phone.value;
	var person = document.of1.contact_name.value;
	
	if (!cat) {
		alert('Моля попълнете категорията на курса');
		return false;
	}	
	
	if (!title) {
		alert('Моля попълнете заглавието на курса');
		return false;
	}	
	
	if (!type && !other) {
		alert('Моля попълнете типа на курса');
		return false;
	}	
	
	if (!start) {
		alert('Моля попълнете началната дата на курса');
		return false;
	}	
	
	if (!end) {
		alert('Моля попълнете крайната дата на курса');
		return false;
	}	
		
	if (!descr) {
		alert('Моля попълнете описанието на курса');
		return false;
	}	
	
	if (!city) {
		alert('Моля попълнете града, в който ще се провежда курса ');
		return false;
	}	
	
	if (!addr) {
		alert('Моля попълнете адреса, където ще се провежда курса ');
		return false;
	}	
	
	if (!phone) {
		alert('Моля попълнете телефон за контакти');
		return false;
	}	
	
	if (!person) {
		alert('Моля попълнете лице за контакти');
		return false;
	}	
	
	document.of1.submit();
}

function changeCourse(id,type) {
	$.get("set_status.php?id="+id+"&type="+type);
	alert("Промяната беше успешна.");
	document.location.reload();
}

function toggle_line(checked) {
	if (checked==true) el('emails_msg').style.visibility='hidden';
	else el('emails_msg').style.visibility='';
}
