function initFontSizeAndPrint() {

	$('.fLarge').click(function(){
		var FSz = parseFloat($('.descr').css('font-size'));
		if(FSz<22){FSz += 1;increaseDecreaseFontSize(FSz)}
		
	})
	$('.fSmall').click(function(){
		var FSz = parseFloat($('.descr').css('font-size'));
		if(FSz>11){FSz -= 1;increaseDecreaseFontSize(FSz)}	
		
	})
}

function increaseDecreaseFontSize(sz) {

	$('.left .descr').css('font-size',sz+'px')
	//$('.left .title').css('font-size',sz+1+'px')
	
	if(sz==11){$('.fSmall').css({'background-position':'-30px -30px','cursor':'default'})}
	else{$('.fSmall').css({'background-position':'-30px 0px','cursor':'pointer'})}
	if(sz==19){$('.fLarge').css({'background-position':'left -30px','cursor':'default'})}	
	else{$('.fLarge').css({'background-position':'left 0px','cursor':'pointer'})}	

}

function fontResize(increase){

	if(increase){
		
		var FSz = parseFloat($('.descr').css('font-size'));
		if(FSz<19){FSz += 2;increaseDecreaseFontSize(FSz)};
		
	} else {
		
		var FSz = parseFloat($('.descr').css('font-size'));
		if(FSz>11){FSz -= 2;increaseDecreaseFontSize(FSz)};
	}
}

function slideTop100(){
	$(".slider .dot").click(function(){
		var dID = $(this).attr("id");
		var prev = $(".slider .select").attr("id");
		
		$(".slider div").removeClass("select");
		$(".slider #" + dID).addClass("select");
		
		if(prev != dID){
			$(".categories #cat_" + prev).hide("slide", { direction: "left" },"slow");
			$(".categories #cat_" + dID).show("slide", { direction: "right" },"slow");
		}
	});
}

$(document).ready(function(){
	
    $("#menu ul li").hover(
        function(){ $("ul", this).show(50); },
        function(){ $("ul", this).hide(50); }
    );
    

    if (document.all) {
        //$("#menu li").hoverClass("sfHover");
    }

	initFontSizeAndPrint();

	$("#hr_username").click(function(){
			$(this).removeClass('username');
			$(this).val('');
	});
	
	$("#hr_username").blur(function(){
		if($(this).val() == '' || $(this).val() == 'Вашето име'){
			$(this).addClass('username');
			$(this).val('Вашето име');
		}
	});
	
	$("#employer_username").click(function(){
		if($(this).val() == "Работодател") {$(this).val("");}
	});
	
	$("#employer_username").blur(function(){
        if($(this).val() == "") {$(this).val("Работодател");}
    });
	
	$("#employer_pass").click(function(){
		$(this).val("");
	});
	
	$("#srch").click(function(event){
		event.preventDefault();
		$("#srchform").attr("action", '/careerzone/search/' + $("input:checked").val() + '/' + $("#swords").val());
		$("#srchform").submit();
	});
	
	slideTop100();
	
});

function refreshimg(){
	
	var d = new Date();
	t = d.getTime();
	
	$.post('/newsession.php');
	$("#captchaimage").html('<span id="refreshimg" onclick="refreshimg();" title="Нова картинка"><img src="/image.php?' + t + '" alt="Captcha image" align="left" /></span>');
	return false;
}

function addEmoticon(commentAreaID, emoticon){
	
	var comment = document.getElementById(commentAreaID);
	comment.value += '[' + emoticon + ']';
	
}	

function validate_ITProject(){

	var sec_code = document.getElementsByName("sec_code")[0];	
	var personName = document.getElementsByName("personName")[0];
	var personWork = document.getElementsByName("personWork")[0];
	var personMail = document.getElementsByName("personMail")[0];
	var projectEnd = document.getElementsByName("projectEnd")[0];
	var projectName = document.getElementsByName("projectName")[0];
	var projectStart = document.getElementsByName("projectStart")[0];
	var projectEffect = document.getElementsByName("projectEffect")[0];
	var projectBudget = document.getElementsByName("projectBudget")[0];
	var projectEmployees = document.getElementsByName("projectEmployees")[0];
	var projectExecutor = document.getElementsByName("projectContractor")[0];
	var projectContractor = document.getElementsByName("projectContractor")[0];

	if(personName.value == ''){
		alert("Моля, попълнете вашето име и фамилия."); 
		personName.focus(); return false;
	}
	
	else if(personWork.value == ''){
		alert("Моля, попълнете полето за месторабота."); 
		personWork.focus(); return false;
	}
	
	else if(personMail.value == ''){
		alert("Не сте оставили Ваш е-мейл адрес."); 
		personMail.focus(); return false;
	}

	else if(projectName.value == ''){
		alert("Моля, попълнете името на проекта, с който кандидатствате."); 
		projectName.focus(); return false;
	}	
	
	else if(projectContractor.value == ''){
		alert("Полето за възложител е задължително.");
		projectContractor.focus(); return false;
	}
	
	else if(projectExecutor.value == ''){
		alert("Моля, оставете данни за изпълнителя / изпълнителите на проекта.");
		projectExecutor.focus(); return false;
	}
	
	else if(projectBudget.value == ''){
		alert("Необходими са данни за общия бюджет на проекта.");
		projectBudget.focus(); return false;
	}
	
	else if(projectStart.value == ''){
		alert("Моля, отбележете кога е стартиран проекта.");
		projectStart.focus(); return false;
	}
	
	else if(projectEnd.value == ''){
		alert("Моля, отбележете кога е завършен проекта.");
		projectEnd.focus(); return false;
	}
	
	else if(projectEmployees.value == ''){
		alert("Необходими са данни за броя ИТ служители, работили по проекта.");
		projectEmployees.focus(); return false;
	}
	
	else if(projectEffect.value == ''){
		alert("Моля, пояснете ефектите от завършения проект.");
		projectEffect.focus(); return false;
	}
	
	else if(sec_code.value == ''){
		alert("Необходимо е да попълните кода от антиспам полето.");
		sec_code.focus(); return false;
	}
	
	return true;
}


function switch_top(obj){
	
	var read = document.getElementById('h_read');
	var last = document.getElementById('h_last');
	var sep = document.getElementById('h_sep');
	
	last.className = (obj == 'last') ? 'sel' : '';
	read.className = (obj == 'read') ? 'sel' : '';
	
	
	if($('#lastnews').length != 0) {
		var news = document.getElementById('h_lastnews');
		news.className = (obj == 'lastnews') ? 'sel' : '';
		sep.style.backgroundPosition = (obj == 'lastnews') ? '-100px top' : (obj == 'last' ? '-2px' : '98px');
	
	} else {sep.style.backgroundPosition = obj == 'last' ? '-100px' : '-30px';}
	
	$('#lastnews').hide(0);
	$('#read').hide(0); 
	$('#last').hide(0);
		
	$("#" + obj).fadeIn(300);
}

function show_leadnews(n){
	
	for(i=1; i<=5; i++){
		var obj = document.getElementById("ln_"+i);
		var btn = document.getElementById("b" + i);
		var item = document.getElementById("item_" + i);
		
		obj.style.display = "none";
		item.style.display = "none";
		btn.className = "btn notFirst";
	}
	
	var elmPic = document.getElementById("ln_" + n);
	var elmBtn = document.getElementById("b" + n);
	var elmItem = document.getElementById("item_" + n);
	var elmLink = document.getElementById("a" + n);
	 
	
	elmPic.style.display = "block";
	elmItem.style.display = "block";
	elmBtn.className = "btn selected";
	elmLink.style.position = "absolute";
	elmLink.style.display = "block";
	
	initial = n;
}

function out_leadnews(n){

	var obj = document.getElementById("b" + n);
	var elm = document.getElementById("item_" + n);
	
	if(elm.style.display == "none"){
		obj.className = "btn notFirst";
	}
	
}

function rotate_topnews(){
	
	for(i=1; i < 6; i++){
		$("#ln_" + i).hide(0);
		$("#item_" + i).hide(0);
		$("#b" + i).removeClass('selected');
		$("#b" + i).addClass('notFirst');
		
	}
	
	$("#ln_" + initial).fadeIn(200);
	$("#a" + initial).fadeIn(200);
	$("#item_" + initial).fadeIn(200);
	$("#b" + initial).addClass('btn selected');
	
	initial = (initial == 5) ? 1 : (initial + 1);
	timerID = setTimeout('rotate_topnews()', 3600);
}

function check_email(e) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(i=0; i < e.length ;i++) {
        if(ok.indexOf(e.charAt(i))<0) {
            return (false);
        }
    }

    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)) {
            return (-1);
        }
    }
	 return true;
}

function advanced_search(){
	
	var elm = document.getElementById("options");
	var elmS = document.getElementById("search");
	
	elm.style.display = (elm.style.display == 'block') ? 'none' : 'block';
	elmS.style.height = (elm.style.display == 'none') ? '30px' : '71px';
	return false;
}

function loadBanners(val){
	alert(val);
}

function set_username(elm, isOn){
	
	alert(isOn)
	
	if(isOn && this.value != '' && this.value != 'Вашето име'){
		$(this).removeClass('username');
	} else {
		
	}
}

function validate_hrQuestion(form) {
	 
	 if(form.username && (form.username.value == '' || form.username.value == 'Вашето име')){
		alert('Моля, попълнете името си.');
		form.username.focus(); return false;
	 }
	 
	 if(form.question.value == ''){
		alert('Попълването на въпрос е задължително.');
		form.question.focus(); return false;
	 }
	 
	 if(form.sec_code && form.sec_code.value == ''){
		alert('Не сте въвели кода от антиспам полето.');
		form.sec_code.focus(); return false;
	 }
	 
	 return true;
}

function switch_hr(elm){

	$("#hrprofile").removeClass('sel');
	$("#hrquestions").removeClass('sel');
	$("#hrvideo").removeClass('sel');
	
	$("#info_hrprofile").fadeOut(0);
	$("#info_hrvideo").fadeOut(0);
	$("#info_hrquestions").fadeOut(0);
	
	$(elm).addClass("sel");
	$("#info_" + elm.id).fadeIn(100);
	
}

//form validation

//check e-mail
function validate_email(field,alerttxt)
{
    with (field)
    {
        apos=value.indexOf("@");
        dotpos=value.lastIndexOf(".");
        if (apos<1||dotpos-apos<2)
        {alert(alerttxt);return false;}
         else {return true;}
    }
}

//check fields
function validate(field,alerttxt){
    with(field)
    {
        if(value== null || value =="")
         {alert(alerttxt); return false;}
    }
    return true;
}

//check antispam
function anti_spam(field_1,field_2,alerttxt){
    
    var real= field_1.value;
    var hid = field_2.value;
    
    if(real!=(hid*3-159))
    {alert(alerttxt);  return false;}
    
   return true; 
}

//main function
function validate_form(thisform)
{
    with (thisform)
    {
        if (validate_email(source,"E-mail адресът, който сте въвели е невалиден!")==false)
            {source.focus();return false;}
        if(validate(from,"Не е въведено име!")==false)
            {from.focus(); return false;}
        if(validate(subject,"Не е въведено заглавие на съобщението!")== false)
            {subject.focus(); return false;}
        if(validate(body,"Не е въведено съобщение!")== false)
            {body.focus(); return false;}
	if(anti_spam(val,cs,"Кодът който сте въвели е грешен!")==false)
	    {val.focus(); return false;}
    }
}

//check quiz answers
function validate_answer(thisfield)
{
    for (i = 0; i < thisfield.length; i++){
	if(thisfield[i].checked == true){
		return true;
	}
    }
    
    alert('Не сте отговорили на въпроса');
    thisfield[0].focus();
    return false;
}

//newsflash register validation
function validate_se(field,alerttxt){
    with(field)
    {
      if(value==0)
       {alert(alerttxt); return false;}
    }
    return true;
}

function validate_reg(thisform){
	with (thisform)
    {
        if (validate_email(mail,"Please, enter a valid e-mail.")==false)
            {mail.focus();return false;}
        if(validate(name,"Please, fill in your name.")==false)
            {name.focus(); return false;}
	if(validate(cmp,"Please, fill in your company.")==false)
            {cmp.focus(); return false;}
	if(validate_se(pos,"Please, choose your position.")==false)
            {pos.focus(); return false;}
	if(validate_se(sector,"Please, choose your sector of work.")==false)
            {sector.focus(); return false;}
	if(validate_se(staff,"Please, choose your staff size.")==false)
            {staff.focus(); return false;}
       
    }
}

