var numTabs = 3;

// Get the value of the cookie with the specified name.
function GetCookie(Name){
	// cookies are separated by semicolons
	var aCookie = document.cookie.split("; ");

	for (var i=0; i < aCookie.length; i++)	{
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (Name == aCrumb[0])
			return unescape(aCrumb[1]);
	}
	// a cookie with the requested name does not exist
	return null;
}

// anketa computerworld
function PopUpShow(){
	
	if (!(GetCookie('CWD_anketa')))
	{
		document.getElementById('pop_up').style.display = "block";
		
		var popup_height = (screen.height - '520') / 2;
		
		var popup_width = (screen.width - '610') / 2;
			
		document.getElementById('pop_up').style.top = popup_height + 150;
		
		document.getElementById('pop_up').style.left = popup_width;
	}
}

function PopUpHideOpen(){
	window.open('http://computerworld.bg/anketa/?h');
	document.getElementById('pop_up').style.display = "none";
}

function PopUpHide(){
	document.getElementById('pop_up').style.display = "none";
	// set a cookie when the cancel button is pressed
	document.cookie = "CWD_anketa=CWD_cancel; expires='Mon, 1 Sep 2008 00:00:00 UTC'; path=/; domain=.computerworld.bg;";
}
// anketa computerworld

// anketa CIO
function PopUpShow_CIO(){
	if (!(GetCookie('CIO_anketa'))){
		document.getElementById('pop_up_CIO').style.display = "block";
		var popup_height = '170px';
		var popup_width = '197px';
		document.getElementById('pop_up_CIO').style.top = popup_height;
		document.getElementById('pop_up_CIO').style.left = popup_width;
	}
}

function PopUpHideOpen_CIO(){
	window.open('http://idg.bg/io/?m=add&prj=cio_&tid=724');
	document.getElementById('pop_up_CIO').style.display = "none";
}

function PopUpHide_CIO(){
	document.getElementById('pop_up_CIO').style.display = "none";
	// set a cookie when the cancel button is pressed
	document.cookie = "CIO_anketa=CIO_cancel; expires=''; path=/; domain=.cio.bg";
}
// anketa CIO

// function show for allnews.idg.bg
function show(div_id){	
	var n = div_id.split("_")[1];

	var shown_attr = document.getElementById("shown_attributes_div").getAttribute("shownid_" + n);

	if(shown_attr != ""){
		document.getElementById(shown_attr).style.display = "none";
		document.getElementById("td_" + shown_attr).className = "boxns";
	}

	document.getElementById(div_id).style.display = "block";
	document.getElementById("td_" + div_id).className = "box";
	document.getElementById("shown_attributes_div").setAttribute("shownid_" + n, div_id);
}

function show_divq(id_toshow, id_tohide, el_name, check){
	
	var error = false;
	var checked = false;

	if(check) {
		
		var els = document.getElementsByName(el_name);
		
		for(var i=0; i < els.length; i++){ 

			if(els[i].type == "text" || els[i].type == "textarea"){
				if(els[i].value == "") error = true;
			} 
			else if (els[i].type == "radio" || els[i].type == "checkbox") {
				checked = (els[i].checked) ? true : false;
				error = !checked;
			}
		}
	}
	
	if(error == true) {
		alert("Моля отговорете на въпроса, преди да продължите");
	} 
	else {
		document.getElementById(id_tohide).style.display = "none";
		document.getElementById(id_toshow).style.display = "block";
	}
} 

/*
   Milonic Flash Activation Script - insert_active_flash.js version 1.0 - May 4 2006

   Copyright 2005 (c) Milonic Solutions Limited. All Rights Reserved.
   This is a commercial software product, please visit http://www.milonic.com/ for more information.
*/

function commitFlashObject(_obj, _container, _bottomHTML){
	_output=""
	_paramoutput=""
	_src=""
	_ver=""
	for(_cO in _obj){
		_output+=_cO+"=\""+_obj[_cO]+"\" "
		_paramoutput+="<param name="+_cO+" value=\""+_obj[_cO]+"\">";
		if(_cO=="movie")_src="src=\""+_obj[_cO]+"\"";
		if(_cO=="version")_ver=_obj[_cO];
	}
	if(_ver=="")_ver="8,0,0,0"
	ihtm="<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+_ver+" "+_output+">\n"
	ihtm+=_paramoutput+"\n"
	ihtm+="<embed "+_src+" pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash "+_output+">\n";
	ihtm+="</embed>\n";
	ihtm+="</object>\n";
	
	if(_bottomHTML != '') ihtm += _bottomHTML
	document.getElementById(_container).innerHTML=ihtm	
}

// provides in general js support
// below is the implementation of
// misc. js functions

function setTabs(tabtoselect,tabtodeselect, diffr){
		// change class of front parts
		document.getElementById(tabtoselect+diffr + '_front').className = tabtoselect + "front";
		document.getElementById(tabtodeselect+diffr + '_front').className = "ina" + tabtodeselect + "front";
		
		// change class of main parts
		document.getElementById(tabtoselect+diffr).className = tabtoselect;
		document.getElementById(tabtodeselect+diffr).className = "ina" + tabtodeselect;
				
		// change style of the content
		document.getElementById(tabtoselect+diffr + '_div').style.display = "block";
		document.getElementById(tabtodeselect+diffr + '_div').style.display = "none";
}

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);
        }
    }
}

function check_form(f) {
    if(f.author && f.author.value.length > 40) {
        alert("Прекалено дълго поле за име.");
        f.author.focus(); return false;
    }
    if(f.comment.value.length > 5000) {
        alert("Прекалено дълго поле за описание.");
        f.comment.focus(); return false;
    }
    if(f.comment.value.length < 1) {
        alert("Празно поле за описание.");
        f.comment.focus(); return false;
    }
	if(f.sec_code.value.length < 1) {
        alert("Празно поле анти спам.");
        f.sec_code.focus(); return false;
    }
}

function addEmo(emo) {
	var form = document.getElementById('comments_form');
	form.comment.value += '[' + emo + ']';
}

function submitCombForm(urlReq) {
	jswords = document.combform.swords.value;

	if (urlReq == "http://navigatorwork.idg.bg/?") {
		urlReq = urlReq + "t=" + jswords;
	} else {
		urlReq = urlReq + "?call=USE~search;&swords=" + jswords;
	}
	window.location = urlReq;
}

function submitLoginForm(urlReq) {
    document.loginform.action = urlReq;
    document.loginform.submit();
}

function s_h(id){
	var _o = document.getElementById(id); 
	var _td = document.getElementById(id + '_td');
	
	var _d = (_o.style.display == "block") ? 'none' : 'block';
	var _cn = (_td.className == "twimg_d") ? 'twimg_r' : 'twimg_d';
	_o.style.display = _d;
	_td.className = _cn;
}

function chatNow(){
	var _obj = document.getElementById("chatNow");
	
	if (_obj.className == 'join_now') _obj.className = 'join_now_gr';
	else _obj.className = 'join_now';
	
	setTimeout("chatNow()", 1000);
}

// increase & decrease font

function fIncreaseTextSize () {
   if ( document.getElementById ) {
      var i = parseInt(document.getElementById("news_text").style.fontSize);
      if ( i ) {
         i++;
      } else {
         i = 14 + 1;
      }	
      fSetFontSize(document.getElementById("news_text"), i);
   }
}
function fDecreaseTextSize () {
   if ( document.getElementById ) {
      var i = parseInt(document.getElementById("news_text").style.fontSize);
      if ( i ) {
         i--;
      } else {
         i = 11 - 1;
      }
      fSetFontSize(document.getElementById("news_text"), i);
   }
}
function fSetFontSize(obj, size) {
   if ( !obj.innerHTML ) {
      return false;
   }
   var aTag = obj.getElementsByTagName("*");
   for ( var i in aTag ) {
      if ( aTag[i].style ) {
         aTag[i].style.fontSize  = size;
      }
      fSetFontSize(aTag[i], size);
   }
   if ( obj.style ) {
      obj.style.fontSize  = size;
   }
   return true;
} 

function showFAQ(n, max){
	for(var i=1; i<= max; i++)	{
		document.getElementById("faq"+i).style.display = "none";
	}
	document.getElementById("faq"+n).style.display = "block";
}


				      
function setTabsRightC(tabNo){		   
	// hide all tabs
	for(var i=1; i<=numTabs; i++){
	   document.getElementById('rctab'+i).style.display = 'none';
	   document.getElementById('rclink'+i).className = 'notselected';
	}
	// show tabNo tab
	document.getElementById('rctab'+tabNo).style.display = 'block';
	document.getElementById('rclink'+tabNo).className = 'selected';
}

function participate(){
	document.getElementById('participate').style.display = 'block';
}

function rate_haiku(hID, userID, currVote){
	callAJAX_onhaikuvote(hID, userID, currVote);
	document.getElementById('vote_'+hID).className = 'thumbUp_clear';
	document.getElementById('vote_'+hID).innerHTML = ' твоят глас беше отчетен';
	
	document.getElementById('votes_'+hID).innerHTML = parseInt(currVote) + 1;
}

$(document).ready(function() {
	if($("#wallh").is(":visible"))
		$("#body_link").attr('href', $("#wallh a").attr('href'));
});
