// CONFIGURATION

// AJAX Configuration
var Config_Ajax_Script = "http://www.radio.bg/actions/ajax/";

// Comments Show/Hide status
var CommentFormStatus="hidden";
var AllCommentsStatus="visible";

// Questions (Experts)
var QuestionFormStatus="hidden";
var AllQuestionsStatus="visible";


// ListenNow Flag
var ListenNowFlag = false;

// Comment Flag
var CommentFlag = false;

function get_radio_value(element) {
	for (var i=0; i < element.length; i++){
	if (element[i].checked) {var rad_val = element[i].value;}
    }

	return (rad_val);
}

function get_checks_value_array(element,joiner) {
	
	var tempArray=new Array();
	
	for (var i=0; i < element.length; i++){
		if (element[i].checked) {
		tempArray.push(element[i].value);
		}
    }
	return (tempArray.join(joiner));
}

// --------------------------------------------------

function getPageSize() {
	        
     var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

// --------------------------------------------------

function loadAjaxContent() {

	// --------------------------------------------------
	// On the homepage we would show blog... elsewhere we will show the news
	if (window.location.pathname=="/") {
		// Loading Right Top - BLOG
		ClickRightTop('blog');
	} else {
		// Loading Right Top - Novini
		ClickRightTop('novini');
	}
	// --------------------------------------------------
	
	// Loading Right Middle - Online Radia
	ClickRightMid('online');
	
	// Loading Right Middle - Online Radia
	ClickRightBot('publications');
	
}

function ClickRightTop(keyword) {
	
	tempArray = new Array();
	
	if (keyword=="novini") {
		tempArray.push('<li class="box_navigation_element_on">НОВИНИ</li>');
	} else {
		tempArray.push('<li class="box_navigation_element_off"><a href="javascript:ClickRightTop(\'novini\')" class="box_navigation">НОВИНИ</a></li>');
	}
	
	if (keyword=="anketa") {
		tempArray.push('<li class="box_navigation_element_on">АНКЕТА</li>');
	} else {
		tempArray.push('<li class="box_navigation_element_off"><a href="javascript:ClickRightTop(\'anketa\')" class="box_navigation">АНКЕТА</a></li>');
	}
	
	if (keyword=="blog") {
		tempArray.push('<li class="box_navigation_element_on">НОВО&nbsp;в&nbsp;<b>Radio.bg</b></li>');
	} else {
		tempArray.push('<li class="box_navigation_element_off"><a href="javascript:ClickRightTop(\'blog\')" class="box_navigation">НОВО&nbsp;в&nbsp;<b>Radio.bg</b></a></li>');
	}
	
	
	
	
	$('right_top_header').innerHTML="<ul>"+tempArray.join('<li class="box_navigation_element_divider">&nbsp;</li>')+"</ul>";

	// Ajax Calling
	switch(keyword) {
		// ***********************************************
		case "novini": 
			new Ajax.Updater('right_top_container', Config_Ajax_Script, { parameters: {action: 'get_novini_listing'} }); 
		break;
		// ***********************************************
		case "anketa": 
			new Ajax.Updater('right_top_container', Config_Ajax_Script, { parameters: {action: 'get_anketa'} });
		break;
		// ***********************************************
		case "blog": 
			new Ajax.Updater('right_top_container', Config_Ajax_Script, { parameters: {action: 'get_blog'} });
		break;
		// ***********************************************
	}
	
	
	// Bottom Options
	switch(keyword) {
		// ***********************************************
		case "novini": 
			$('right_top_bottom').innerHTML='&nbsp;<a href="/news" class="right_column_bottomlink">виж всички новини</a>';
		break;
		// ***********************************************
		case "anketa": 
			$('right_top_bottom').innerHTML='&nbsp;<a href="javascript:ajax_getAnketaAnswers();" class="right_column_bottomlink">виж резултати</a>';
		break;
		// ***********************************************
		case "blog": 
			$('right_top_bottom').innerHTML='&nbsp;<a href="/blog" class="right_column_bottomlink">виж всички новости</a>';
		break;
		// ***********************************************		
		
		
	}
}



// **********************************************************************************
// RIGHT MID AREA
// **********************************************************************************

function ClickRightMid(keyword) {
	
	tempArray = new Array();
	
	if (keyword=="online") {
		tempArray.push('<li class="box_navigation_element_on"><b>Radio.bg</b>&nbsp;ПРЕПОРЪЧВА</li>');
	} else {
		tempArray.push('<li class="box_navigation_element_off"><a href="javascript:ClickRightMid(\'online\')" class="box_navigation"><b>Radio.bg</b>&nbsp;ПРЕПОРЪЧВА</a></li>');
	}
	
	if (keyword=="chat") {
		tempArray.push('<li class="box_navigation_element_on">ЧАТ</li>');
	} else {
		tempArray.push('<li class="box_navigation_element_off"><a href="javascript:ClickRightMid(\'chat\')" class="box_navigation">ЧАТ</a></li>');
	}
	
	if (keyword=="pozdrav") {
		tempArray.push('<li class="box_navigation_element_on">ПОЗДРАВИ</li>');
	} else {
		tempArray.push('<li class="box_navigation_element_off"><a href="javascript:ClickRightMid(\'pozdrav\')" class="box_navigation">ПОЗДРАВИ</a></li>');
	}
	
	$('right_mid_header').innerHTML="<ul>"+tempArray.join('<li class="box_navigation_element_divider">&nbsp;</li>')+"</ul>";

	// Stop/Start ChatUpdater
	if (keyword=="chat") {
		new Ajax.Updater('chat_window',Config_Ajax_Script, {
		 parameters: {action: 'getLatestChat'}});
		ChatUpdater.start();
		
	} else {
		ChatUpdater.stop();
	}
	

	// Ajax Calling
	switch(keyword) {
		// ***********************************************
		case "online": 
			//new Ajax.Updater('right_mid_container', Config_Ajax_Script, { parameters: {action: 'get_online'} }); 
			new Ajax.Updater('right_mid_container', Config_Ajax_Script, { parameters: {action: 'get_listennow'} }); 
		break;
		// ***********************************************
		case "chat": 
			new Ajax.Updater('right_mid_container', Config_Ajax_Script, { parameters: {action: 'get_chat'} });
		break;
		// ***********************************************
		case "pozdrav": 
			new Ajax.Updater('right_mid_container', Config_Ajax_Script, { parameters: {action: 'get_pozdrav'} });
		break;
	}
	
	
	
}

// **********************************************************************************
// RIGHT BOT AREA
// **********************************************************************************

function ClickRightBot(keyword) {
	
	// Ajax Calling
	switch(keyword) {
		// ***********************************************
		case "publications": 
			new Ajax.Updater('right_bot_container', Config_Ajax_Script, { parameters: {action: 'get_publications_listing'} }); 
		break;
	}
	
	// Bottom Options
	switch(keyword) {
		// ***********************************************
		case "publications": 
			$('right_bot_bottom').innerHTML='&nbsp;<a href="/publications" class="right_column_bottomlink">виж всички публикации</a>';
		break;
		// ***********************************************
	}

	
}


// ***********************************************************************
// CHAT
function addSmiley(code) {
	$('chat_text').value=$('chat_text').value+code;
}


// ***********************************************************************

/*
ChatUpdater = new Ajax.PeriodicalUpdater('chat_window',Config_Ajax_Script, {
 parameters: {action: 'getLatestChat'}, method: 'post', frequency: 3, decay: 2
});
*/
// ***********************************************************************

function chatKeypress(e) {
	
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
  	{
  	keynum = e.keyCode;
  	}
	else if(e.which) // Netscape/Firefox/Opera
  	{
  keynum = e.which;
  	}
  
  	if (keynum==13) {
  		
		postToChat($('chat_text').value);
		
	}
  
}

function postToChat(text) {

	new Ajax.Updater('chat_window', Config_Ajax_Script, { parameters: {action: 'postToChat', value:text} });
	
	
	// Clear the textbox
	$('chat_text').value='';
	
}





// ************************************************************************
// Registration Ajax
function RegistrationAjax(keyword, value, target_element) {
	
	new Ajax.Updater(target_element, Config_Ajax_Script, { parameters: {action: keyword, value: value} });
	
}
// ************************************************************************


// ************************************************************************
// NewMessage Ajax
function NewMessageAjax(keyword, value, target_element) {
	
	new Ajax.Updater(target_element, Config_Ajax_Script, { parameters: {action: keyword, value: value} });
	
}
// ************************************************************************



// ************************************************************************
function ajax_postAnketaAnswer() {

	anketaAnswer=get_radio_value(document.getElementsByName('anketa_answer'));

	if (anketaAnswer==undefined) {
		alert("Моля изберете отговор от анкетата");
	} else {
		new Ajax.Updater('right_top_container', Config_Ajax_Script, { parameters: {action: 'anketa_answer',value: anketaAnswer} });
	}

}
// ************************************************************************



// ************************************************************************
function ajax_getAnketaAnswers() {

	new Ajax.Updater('right_top_container', Config_Ajax_Script, { parameters: {action: 'get_anketa_answers'} });

}
// ************************************************************************


// CHecking the registration form for filled in data
function CheckRegistrationForm() {


	var ErrorArray = new Array();
	toFocus = "";
	

	if ($('email').value=="") {ErrorArray.push('* Email'); if (toFocus=="") {toFocus="email";}}
	if ($('password1').value=="") {ErrorArray.push('* Парола'); if (toFocus=="") {toFocus="password1";}}
	if ($('password2').value=="") {ErrorArray.push('* Повтори паролата'); if (toFocus=="") {toFocus="password2";}}
	if ($('username').value=="") {ErrorArray.push('* Потребителско име'); if (toFocus=="") {toFocus="username";}}
	if ($('captcha').value=="") {ErrorArray.push('* Код'); if (toFocus=="") {toFocus="captcha";}}
	if ($('iagree').checked!=true) {ErrorArray.push('* Декларирам, че съм се запознал ...'); if (toFocus=="") {toFocus="iagree";}}

	// Check if the passwords match
	if (($('password1').value!="") && ($('password2').value!="")) {
		if ($('password1').value!=$('password2').value) {ErrorArray.push('\n\n - Въведените пароли не съвпадат'); if (toFocus=="") {toFocus="password2";}}
	}
	

	if (ErrorArray.length>0) {
		alert("Има невъведени данни: \n\n"+ErrorArray.join("\n"));
		// Focus on the missing filed
		$(toFocus).activate();
		return false;
	} else {
		return true;
	}
	
}



// MyProfile Ajax
function MyProfileAjax(keyword, value, target_element) {

	new Ajax.Updater(target_element, Config_Ajax_Script, { parameters: {action: keyword, value: value} });
	
}





// CHecking the my profile form for filled in data
function CheckMyProfileForm() {


	var ErrorArray = new Array();
	toFocus = "";
	
	if ($('username').value=="") {ErrorArray.push('Потребителско име'); if (toFocus=="") {toFocus="username";}}
	if ($('name').value=="") {ErrorArray.push('Име'); if (toFocus=="") {toFocus="name";}}
	
	if (ErrorArray.length>0) {
		alert("Има невъведени данни: \n\n"+ErrorArray.join("\n"));
		// Focus on the missing filed
		$(toFocus).activate();
		return false;
	} else {
		return true;
	}
	
}


// CHecking the my profile form for filled in data
function CheckNewMessageForm() {


	var ErrorArray = new Array();
	toFocus = "";
	
	if ($('rec_username').value=="") {ErrorArray.push('Потребителско име'); if (toFocus=="") {toFocus="rec_username";}}
	if ($('rec_message').value=="") {ErrorArray.push('Съобщение'); if (toFocus=="") {toFocus="rec_message";}}
	
	if (ErrorArray.length>0) {
		alert("Има невъведени данни: \n\n"+ErrorArray.join("\n"));
		// Focus on the missing filed
		$(toFocus).activate();
		return false;
	} else {
		return true;
	}
	
}

// **********************************************************************************

function DisplayConfirmation(message) {
	
	
	if (confirm(message)) {
		return true;
	} else {
		return false;
	}
	
}

// **********************************************************************************



// CHecking the registration form for filled in data
function CheckForgotPasswordForm() {


	var ErrorArray = new Array();
	toFocus = "";
	
	
	if ($('email').value=="") {ErrorArray.push('* Email'); if (toFocus=="") {toFocus="email";}}


	if (ErrorArray.length>0) {
		alert("Има невъведени данни: \n\n"+ErrorArray.join("\n"));
		// Focus on the missing filed
		$(toFocus).activate();
		return false;
	} else {
		return true;
	}
	
}

// *********************************************************************************
// COMMENTS 
// *********************************************************************************

function toggleNewCommentForm() {
	if (CommentFormStatus=="hidden") {
		$('new_comment_form').show();
		$('new_comment_link').innerHTML="Скрий Формуляра &raquo;";
		CommentFormStatus="visible";
	} else {
		$('new_comment_form').hide();
		$('new_comment_link').innerHTML="Напиши коментар &raquo;";	
		CommentFormStatus="hidden";
	}
}

function hideNewCommentForm() {
	$('new_comment_form').hide();
}



function toggleComments() {
	if (AllCommentsStatus=="hidden") {
		$('all_comments').show();
		$('hide_comments_link').innerHTML="Скрий коментарите &raquo;";
		AllCommentsStatus="visible";
	} else {
		$('all_comments').hide();
		$('hide_comments_link').innerHTML="Покажи коментарите &raquo;";	
		AllCommentsStatus="hidden";
	}
}



// *********************************************************************************
// QUESTIONS (EXPERTS) 
// *********************************************************************************

function toggleNewQuestionForm() {
	if (QuestionFormStatus=="hidden") {
		$('new_question_form').show();
		$('new_question_link').innerHTML="Скрий Формуляра &raquo;";
		QuestionFormStatus="visible";
	} else {
		$('new_question_form').hide();
		$('new_question_link').innerHTML="Задай въпрос &raquo;";	
		QuestionFormStatus="hidden";
	}
}

function hideNewQuestionForm() {
	$('new_question_form').hide();
}



function toggleQuestions() {
	if (AllQuestionsStatus=="hidden") {
		$('all_questions').show();
		$('hide_questions_link').innerHTML="Скрий въпросите &raquo;";
		AllQuestionsStatus="visible";
	} else {
		$('all_questions').hide();
		$('hide_questions_link').innerHTML="Покажи въпросите &raquo;";	
		AllQuestionsStatus="hidden";
	}
}


// Checking feedback form
function CheckFeedbackForm() {


	var ErrorArray = new Array();
	toFocus = "";
	
	if ($('email').value=="") {ErrorArray.push('Email'); if (toFocus=="") {toFocus="email";}}
	if ($('name').value=="") {ErrorArray.push('Име'); if (toFocus=="") {toFocus="name";}}
	if ($('opinion').value=="") {ErrorArray.push('Въпрос/Мнение'); if (toFocus=="") {toFocus="opinion";}}
	if ($('captcha').value=="") {ErrorArray.push('Код'); if (toFocus=="") {toFocus="captcha";}}
	
	if (ErrorArray.length>0) {
		alert("Има невъведени данни: \n\n"+ErrorArray.join("\n"));
		// Focus on the missing filed
		$(toFocus).activate();
		return false;
	} else {
		return true;
	}
	
}


// Comments Limitation
function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}


// Rate functions
function RollOverRate(number) {
	
	//alert("RollOverRate("+number+")");
	
	// active stars
	for (r=1; r<=number; r++) {
	$("rate_star_"+r).className="radios_rating_star_on_blue_big";
	}

	//inactive stars
	for (r=number+1; r<=5; r++) {
	$("rate_star_"+r).className="radios_rating_star_off_blue_big";
	}
	
	$("ocenka").innerHTML=number;
}

// ----------------------------------------------------
// Text Up / Text Down functions

function tsplus(element_id){	
	if(document.getElementById(element_id).style.fontSize==""){
		document.getElementById(element_id).style.fontSize='13px';
	} else {
		var oldsize = document.getElementById(element_id).style.fontSize;
		if(oldsize.length==4){
			oldsize = oldsize.slice(0,2);
		} else {
			oldsize = oldsize.slice(0,1);	
		}
		oldsize=oldsize-(-1);
		if((oldsize<25)){
			document.getElementById(element_id).style.fontSize=oldsize+'px';
		}
	}
}

function tsminus(element_id){	
	if(document.getElementById(element_id).style.fontSize==""){
		document.getElementById(element_id).style.fontSize='11px';
	} else {
		var oldsize = document.getElementById(element_id).style.fontSize;
		if(oldsize.length==4){
			oldsize = oldsize.slice(0,2);
		} else {
			oldsize = oldsize.slice(0,1);	
		}
		oldsize=oldsize-(1);
		if((oldsize>7)){
			document.getElementById(element_id).style.fontSize=oldsize+'px';
		}
	}
}	






// -----------------------------	


function addToFavorites() { 


	if (window.sidebar) {// firefox
		window.sidebar.addPanel("Radio.bg", "http://www.radio.bg", "");
	} else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',"http://www.radio.bg");
		elem.setAttribute('title',"Radio.bg");
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) { // ie
		window.external.AddFavorite("http://www.radio.bg", "Radio.bg");
	}


}



// -----------------------------	
// TOP RADIOS Functions

var TopRadios = Array();
var MaxTopRadios = 5;
var TopRadioElementTemplate = new Template('<li class="topradios_holder" id="radio_#{id}"><div style="height: 60px; display: block;"><img border="0" align="absleft" style="max-height: 50px; max-width: 80px; margin-top: 3px;" title="Radio.bg" alt="Radio.bg" src="http://www.radio.bg/Admin/upload/#{logo}"/></div><span class="r2_profile_mytopradios_radname" style="text-align: center;">#{name}</span><a style="margin-left: 10px;" href="javascript:void(0);" onclick="RemoveTopRadio(#{id});" class="topradios_remove"></a></li>');

var TopRadioElementTemplateString = '<li class="topradios_holder" id="radio_{id}"><div style="height: 60px; display: block;"><img border="0" align="absleft" style="max-height: 50px; max-width: 80px;margin-top: 3px;" title="Radio.bg" alt="Radio.bg" src="http://www.radio.bg/Admin/upload/{logo}"/></div><span class="r2_profile_mytopradios_radname">{name}</span><a href="javascript:void(0);" style="margin-left: 10px;" onclick="RemoveTopRadio({id});" class="topradios_remove"></a></li>';


function AddTopRadio(id, name, logo) {

	if (TopRadios.length>=MaxTopRadios) {
		alert('Вие неможете да имате повече от '+MaxTopRadios+' топ радиа.\nЗа да прибавите това радио първо трябва да премахнете поне едно радио от топ списъка.');
		
		return false;
	
	} else {

		// -------------------------------------------------
		// Check for existance
	
		exists_flag=false;
		TopRadios.each(function(item) {
			if (item.id==id) {exists_flag=true;}
		});

		// -------------------------------------------------
		// Adding the new element
		if (exists_flag==false) {

			TopRadios.push({"id":id, "name":name, "logo":logo});

			// Rebuild the list
			BuildTopRadiosList();

		} else {
			alert('Това радио е вече в списъка с топ радиа');
		}
		// -------------------------------------------------
		

	}


}

function RemoveTopRadio(id) {
	
	newTopRadios = Array();
	// -------------------------------------------------
	TopRadios.each(function(item) {
		if (item.id!=id) {newTopRadios.push({"id":item.id,"name":item.name,"logo":item.logo});}
	});
	// -------------------------------------------------
	TopRadios=newTopRadios;

	// Rebuild the list
	BuildTopRadiosList();
}

function updateOrder() {
	
	newTopRadiosIds=Array();
	newTopRadios=Array();
	
	if (Sortable.sequence('sortable_list')) {

		Sortable.sequence('sortable_list').each(function (element) {
			//alert(element);
			newTopRadiosIds.push(parseInt(element));
		 });

		//alert(newTopRadiosIds.join(','));
		newTopRadiosIds.each(function(item) {
			CurrentTopRadio = getTopRadioById(item);
			newTopRadios.push({"id":CurrentTopRadio.id,"name":CurrentTopRadio.name,"logo":CurrentTopRadio.logo});
		});
		TopRadios=newTopRadios;

	}

	$('top_radios').value=newTopRadiosIds.join("|");
	// Rebuild the list
	// BuildTopRadiosList();
	

}

function getTopRadioById(id) {
	
	//alert("getTopRadioById("+id+")");
	
	TopRadios.each(function(item) {
		if (item.id==id) {curItem=item;}
	});

	return curItem;

}


function BuildTopRadiosList() {

	newString = "";
	
	newTopRadiosIds = Array();
	TopRadios.each(function(item) {
		
		newTopRadiosIds.push(item.id);
		newString=newString+TopRadioElementTemplate.evaluate(item);

	});
	
	$('sortable_list').innerHTML=newString;

	// Make the list scrollabale again
	Sortable.create('sortable_list', {
		overlap: 'horizontal',
		constraint: "horizontal",
		format: /(\d+)$/,
		onChange:updateOrder
	});
	
	$('top_radios').value=newTopRadiosIds.join("|");


}

// -----------------------------

function SendtofriendOpen() {
	
	//alert('Фунцията е в процес на изграждане');
	
	
	//PopupOpen('html','<h1 align="center">Фунцията е в процес на изграждане</h1><h2 align="center"><a href = "javascript:void(0)" onclick = "PopupClose();">затвори</a></h2>');
	PopupOpen('ajax','get_emailtofriend');
	

}	

function PopupOpen(type,extra) {
	
	switch(type) {

		case "html":
			$('popup_window').innerHTML=extra;
		break;
	
		case "ajax":
			new Ajax.Updater('popup_window', Config_Ajax_Script, { parameters: {action: extra} });
		break;

	}


	// open the popup
	$('popup_window').style.display='block';
	$('fade').style.display='block'

	// stretch overlay to fill page and fade in
    var arrayPageSize = getPageSize();
    $('fade').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });

}

function PopupClose() {
	$('popup_window').style.display='none';
	$('comment_window').style.display='none';
	$('fade').style.display='none'
	
	
	// nulirame flaga na listennow
	ListenNowFlag=false;
	CommentFlag=false;
	$('listennow_window').style.display='none';
}


// ************************************************************************
function ajax_postSendtofriend(link) {


	if ($('sendtofriend_email').value=="") {
		alert("Моля попълнете поне email адреса във формата");
	} else {
		new Ajax.Updater('popup_window', Config_Ajax_Script, { parameters: {action: 'emailtofriend_send',sendtofriend_email: $('sendtofriend_email').value, sendtofriend_name: $('sendtofriend_name').value, sender_name: $('sender_name').value, link: link} });
	}

}
// ************************************************************************


function loadVoteButton(_radio_id, _button_style, target, code_target) {
	
	var generated_html="";
	var generated_code="";

   switch (_button_style) {
	case "visitsbutton_big"				: frame_width=73; frame_height=41; break;
	case "visitsbutton_big_logo"		: frame_width=83; frame_height=41; break; 
	case "visitsbutton_big_logo_title"	: frame_width=83; frame_height=51; break; 
	case "visitsbutton_small"			: frame_width=58; frame_height=30; break;
  }
  
  generated_html = "<iframe src='http://www.radio.bg/actions/showVisitsButton/"+_button_style+"/"
      + _radio_id+ "' height='"+frame_height+"' width='"+frame_width+"' marginwidth='0' marginheight='0' frameborder='0' scrolling='no'></iframe>";

  // place the button
	$(target).innerHTML = generated_html;

	// Generiran kod
	generated_code = "<script type='text/javascript'>\nradiobg_radio_id="+_radio_id+";\nradiobg_button_style='"+_button_style+"';\n</script>\n<script src='http://www.radio.bg/includes/votesButton.js' type='text/javascript'></script>";

	
	$(code_target).value = generated_code;
	
	
}

// -----------------------------

function ListenNowToggle(obj) {
	
	if (ListenNowFlag==false) {
		// otwariame go
		ListenNowFlag=true;
		// open the popup
		
		
		// Finding and position of the popup
		var BodyCoors=getPageCoords($$('body'));

		var ElementHeight=31;
		var HorizontalOffset=0;
		
		if (BodyCoors.x>0) {offsetX=BodyCoors.x;} else {offsetX=0;}

		var coords = getPageCoords(obj);
		corX=coords.x-offsetX+HorizontalOffset;
		corY=coords.y+ElementHeight;
	
		//alert("corX="+corX);
		//alert("corY="+corY);
	
		$('listennow_window').setStyle({
			left: corX+'px',
			top: corY+'px'
		});

		
		
		$('listennow_window').style.display='block';
		$('fade').style.display='block'
		// stretch overlay to fill page and fade in
    	var arrayPageSize = getPageSize();
   		$('fade').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	} else {
		// zatwariame go
		ListenNowFlag=false;
		
		$('listennow_window').style.display='none';
		$('fade').style.display='none'
	}
	
}	
// -----------------------------

function findPos(obj) {

	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];

}

function getPageCoords (el) {
  var coords = {x: 0, y: 0};
  do {
    coords.x += el.offsetLeft;
    coords.y += el.offsetTop;
  }
  while ((el = el.offsetParent));
  return coords;
}  

// CHecking the Invitation form for filled in data
function CheckNewInviteForm() {


	var ErrorArray = new Array();
	toFocus = "";
	
	if ($('invite_name').value=="") {ErrorArray.push('Попълнете Име на получателя'); if (toFocus=="") {toFocus="invite_name";}}
	if ($('invite_email').value=="") {ErrorArray.push('Попълнете Емайл на получателя'); if (toFocus=="") {toFocus="invite_email";}}
	if (validateEmail($('invite_email').value)==false) {ErrorArray.push('Невалиден Емайл на получателя'); if (toFocus=="") {toFocus="invite_email";}}
	
	
	if (ErrorArray.length>0) {
		alert("Моля коригирайте следните проблеми: \n\n"+ErrorArray.join("\n"));
		// Focus on the missing filed
		$(toFocus).activate();
		return false;
	} else {
		return true;
	}
	
}


function validateEmail(strEmail) {

	rtrn=true;
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		
	if (strEmail) {
		if (strEmail.search(validRegExp) == -1) {rtrn=false;}
	} else {rtrn=false;}
	
	return rtrn;

}



// -----------------------------

function CommentToggle(obj, parent_type, parent_id, back_url) {
	
	if (CommentFlag==false) {
		// otwariame go
		CommentFlag=true;
		// open the popup
		
		
		// Finding and position of the popup
		var BodyCoors=getPageCoords($$('body'));

		var ElementHeight=-360;
		var HorizontalOffset=150;
		
		if (BodyCoors.x>0) {offsetX=BodyCoors.x;} else {offsetX=0;}

		var coords = getPageCoords(obj);
		corX=coords.x-offsetX+HorizontalOffset;
		corY=coords.y+ElementHeight;
	
		//alert("corX="+corX);
		//alert("corY="+corY);
	
		$('comment_window').setStyle({
			left: corX+'px',
			top: corY+'px'
		});

		// Load the comment window content
		new Ajax.Updater('comment_window', Config_Ajax_Script, { parameters: {action: 'comment_window', parent_type: parent_type, parent_id: parent_id, back_url:back_url} });
		
		$('comment_window').style.display='block';
		$('fade').style.display='block'
		// stretch overlay to fill page and fade in
    	var arrayPageSize = getPageSize();
   		$('fade').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	} else {
		// zatwariame go
		CommentFlag=false;
		
		$('comment_window').style.display='none';
		$('fade').style.display='none'
	}
	
}	
// -----------------------------


// -----------------------------

function ExpertQuestionToggle(obj, expert_name, expert_id, back_url) {
	
	if (CommentFlag==false) {
		// otwariame go
		CommentFlag=true;
		// open the popup
		
		
		// Finding and position of the popup
		var BodyCoors=getPageCoords($$('body'));

		var ElementHeight=-360;
		var HorizontalOffset=150;
		
		if (BodyCoors.x>0) {offsetX=BodyCoors.x;} else {offsetX=0;}

		var coords = getPageCoords(obj);
		corX=coords.x-offsetX+HorizontalOffset;
		corY=coords.y+ElementHeight;
	
		//alert("corX="+corX);
		//alert("corY="+corY);
	
		$('comment_window').setStyle({
			left: corX+'px',
			top: corY+'px'
		});

		// Load the comment window content
		new Ajax.Updater('comment_window', Config_Ajax_Script, { parameters: {action: 'expert_question_window', expert_name: expert_name, expert_id: expert_id, back_url:back_url} });
		
		$('comment_window').style.display='block';
		$('fade').style.display='block'
		// stretch overlay to fill page and fade in
    	var arrayPageSize = getPageSize();
   		$('fade').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	} else {
		// zatwariame go
		CommentFlag=false;
		
		$('comment_window').style.display='none';
		$('fade').style.display='none'
	}
	
}	
// -----------------------------