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 = "blockTeaserBtn 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 = "blockTeaserBtn selected";
	elmLink.style.position = "absolute";
	elmLink.style.display = "block";
}

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

var timer_vip;
var current = -1;
function switch_vip(holders){
	
	var next;
	var elm;
	
	for(i=0; i<holders; i++){
		elm = document.getElementById("vip_holder_"+i);
		
		if(elm.style.display == "block"){
			current = i;
		}
		document.getElementById("vip_holder_"+i).style.display = "none";
	}

	current = (current == -1) ? Math.floor(Math.random() * holders) : current;
	next = (current+1 >= holders) ? 0 : (current+1);
	document.getElementById("vip_holder_" + next).style.display = "block";
	
	timer_vip = setTimeout("switch_vip("+holders+")", 15000)
}

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);
        }
    }
}

/*expanding window
function expandWindow(obj1,obj2){
	var txt = document.getElementById(obj1);
	var button = document.getElementById(obj2);
	if(txt.style.overflow != 'hidden'){
		txt.style.zIndex = '0';
		txt.style.background = 'none';
		txt.style.height = '74px';
		txt.style.overflow = 'hidden';
		txt.style.border = 'none';
		button.style.position = 'static';
		txt.style.position = 'static';
		
		
	}
	else{
		txt.style.overflow = 'visible';
		
		txt.style.background = '#fff';
		txt.style.border = '1px solid';
		
		if(obj1 == 7 || obj1 == 5){
			txt.style.position = 'absolute';
			txt.style.height = '370px';
			button.style.position = 'relative';
			button.style.top = '357px';
			button.style.left = '5px';
		}else if(obj1 == 1 || obj1 == 3){
			txt.style.position = 'absolute';
			txt.style.height = '260px';
			button.style.position = 'relative';
			button.style.top= '247px';
			button.style.left = '5px';
		}else if(obj1 == 4 || obj1 == 0){
			txt.style.position = 'absolute';
			txt.style.height = '250px';
			button.style.position = 'relative';
			button.style.top = '237px';
			button.style.left = '5px';
		}else{	
			txt.style.position = 'absolute';
			txt.style.height = '160px';
			button.style.position = 'relative';
			button.style.top= '147px';
			button.style.left = '5px';
		     
		}
	}
}*/

//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(email,"E-mail адресът, който сте въвели е невалиден!")==false)
            {email.focus();return false;}
        if(validate(from,"Не е въведено име!")==false)
            {from.focus(); return false;}
        if(validate(about,"Не е въведено заглавие на съобщението!")== false)
            {about.focus(); return false;}
        if(validate(comment,"Не е въведено съобщение!")== false)
            {comment.focus(); return false;}
	if(anti_spam(val,cs,"Кодът който сте въвели е грешен!")==false)
	    {val.focus(); return false;}
    }
}
