function redirect(url) { window.location = url; }

function select_el(el_id) { $(el_id).focus(); $(el_id).select(); }

function show_video_cat(cat)
  {
	redirect("main.php?video_gallery&sort="+cat+"#content");  
  }
  
function sb_show_video_cat(cat,star_id)
  {
	redirect("main.php?sb_star="+star_id+"&sb_videos&sort="+cat+"#content");  
  }
  
function toggle_accept()
  {
	if ($("accept_rules").checked == true)
	  {
		$("submit_btn").style.display = "block";  
		$("cancel_btn").style.display = "none";  
	  }
	else
	  {
		$("cancel_btn").style.display = "block";  
		$("submit_btn").style.display = "none"; 
	  }
  }
  
function valid_email(email) 
  {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email)) { return false; }
	else { return true; }
  }    
  
function check_signup_form()
  {
    var username     = $F("username");
	var password     = $F("password");
	var pass_confirm = $F("password_confirm");
	var email        = $F("email");
	
	if (username.length < 3 || username.length > 25) { $("username").focus(); return false; }
	else if (password.length < 3 || password.length > 25) { $("password").focus(); return false; }
	else if (pass_confirm.length < 3 || pass_confirm.length > 25) { $("password_confirm").focus(); return false; }
	else if (password != pass_confirm) { $("password_confirm").focus(); return false; }
	else if (!valid_email(email)) { $("email").focus(); return false; }
	else $("signup_form").submit();
  }
  

var display = 1;

function toggle_image_fields()
  {
	if (display==1)
	  {
		for (i=6;i<=10;i++)
		  {
			$("space_"+i).style.display = 'table-row';  
			$("field_"+i).style.display = 'table-row';  
		  }
		$("toggle_link").update("Убрать дополнительнные поля");
		display = 2;
	  }
	else if (display==2)
	  {
		for (i=6;i<=10;i++)
		  {
			$("space_"+i).style.display = 'none';  
			$("field_"+i).style.display = 'none';  
		  }
		$("toggle_link").update("Добавить еще поля");
		display = 1;
	  }
  }
  
function check_topic_form()
  {
    var author  = $F("author");
	var title   = $F("title");
	var content = $F("content");
	
	if (author=="" || author=="Имя")
	  {  
	    $("error_create_topic").update("Все поля обезательны!!");
		$("author").focus();
		setTimeout('$("error_create_topic").update("")',3000);
	  }
	else if (title=="" || title=="Название")
	  {
		$("error_create_topic").update("Все поля обезательны!!");
		$("title").focus();
		setTimeout('$("error_create_topic").update("")',3000);
	  }
	else if (content=="" || content=="Сообщение")
	  {
		$("error_create_topic").update("Все поля обезательны!!");
		$("content").focus();
		setTimeout('$("error_create_topic").update("")',3000);
	  }
	else { $("new_topic_form").submit(); }
  }



function vote()
  {
	var option_id = 0;
	
	$$('input.poll_option').each(function(el) {
	  if (el.checked == true) { option_id = el.value; }
	});
	  
	if (option_id > 0)
	  {
		$("poll_container").update("<br><br><br><br>"
								   + "<center><img src='images/loading.gif' alt='' title='Loading...'></center>");   
		var url = 'vote.php';
        new Ajax.Request(url, {
          method: 'post',
	      parameters: { action:'vote', option:option_id },
          onSuccess: function(result) 
	        {
              $("poll_container").update(result.responseText);
			  $("poll_link").replace("<a href='main.php?all_polls#content'><b>Все Опросы</b></a>");
            }
        });
	  }
	else { alert("Выберите вариант."); }
  }
 
 
function check_length(el_id,length,info_el)
  {
	if ($F(el_id).length > length) 
	  { 
	    var limit = (length+1) - $F(el_id).length;
		var str = $F(el_id);
		$(info_el).update(limit);
		$(el_id).value = str.substr(0,length);
	  }  
	else
	  {
		var limit = length - $F(el_id).length;
		$(info_el).update(limit);
	  }
  } 
  
function set_limit(length)
  {
	$("limit").update(length);
	$("comment_content").setAttribute("onChange",'check_length("comment_content",'+length+',"limit");');
	$("comment_content").setAttribute("onkeypress",'check_length("comment_content",'+length+',"limit");');
  }
 
function update_article_link()
  {
	if ($F("link_article") != "0") { $("article_link").value = $F("link_article"); } 
	else { $("article_link").value = ""; } 
  }
  
function update_video_link()
  {
	if ($F("link_video") != "0") { $("video_link").value = $F("link_video"); } 
	else { $("video_link").value = ""; } 
  }
  
function update_music_link()
  {
	if ($F("link_music") != "0") { $("music_link").value = $F("link_music"); } 
	else { $("music_link").value = ""; } 
  }
  
function update_foto_link()
  {
	if ($F("link_foto") != "0") { $("foto_link").value = $F("link_foto"); } 
	else { $("foto_link").value = ""; } 
  }
 
function submit_form(form_id)
  {
	if ($F("comment_content").length >= 5) { $(form_id).submit(); }  
	else { alert("Введите минимум 5 символов."); }
  }

function submit_message_form(form_id)
  {
	if ($F("title").length >= 0 && $F("message_content").length >= 0) { $(form_id).submit(); }  
	else { alert("Вы должны ввесть тему и сообщение."); }
  }

var curent_num_fields = 5;

function add_field()
  {
	curent_num_fields += 1;   
	$("new_field").replace('<tr id="field_'+curent_num_fields+'"><td align="right" width="25%">Картинка '+curent_num_fields+':&nbsp;&nbsp;</td><td><input type="file" name="image_'+curent_num_fields+'" size="30"></td></tr><tr id="new_field"><td colspan="2">&nbsp;</td></tr>');
	$("total_images").value = $F("total_images") + 1;
  }
  
function remove_field()
  {
	if (curent_num_fields > 1)
	  {  
	    $("field_"+curent_num_fields).replace(""); 
		curent_num_fields -= 1;
		$("total_images").value = $F("total_images") - 1;
	  }
	else { alert("Нельзя удалить все поля!"); }
  }
 
function select_el(el_id) { $(el_id).focus(); $(el_id).select(); }


function open_window(url)
  {
	window.open("image_preview.php?image="+url,"","top=20,left=200,width=400,height=300,menubar=no,toolbar=yes,scrollbars=yes,resizable=yes,status=no");
	return false;
  }
  
function open_chat()
  {
	window.open("http://concert.md/chat_popup.php","","top=20,left=200,width=620,height=450,menubar=no,toolbar=no,scrollbars=no,resizable=yes,status=no");   
	return false;
  }  
  
function toggle_display(el)
  {
	if ($(el).style.display == "none") 
	  { $(el).style.display = "block"; $("toggle_link").src = image2; }  
    else { $(el).style.display = "none"; $("toggle_link").src = image1; }
  }
  
function show_hide(el_id)
  {
	var el = $(el_id); 
	if (el.style.display == "none") { el.style.display = "block"; }
	else { { el.style.display = "none"; } }
  }
  
  
function vote_star(star)
  {  
    var url = 'vote_star.php';
    new Ajax.Request(url, {
        method: 'post',
	    parameters: { star_id:star },
        onSuccess: function(result) 
	        {
              $("star_poll_container").update(result.responseText);
            }
        });
  }  
  
function load_track(id)
  {  
    var url = 'load_track.php';
    new Ajax.Request(url, {
        method: 'post',
	    parameters: { track_id:id },
        onSuccess: function(result) 
	        {
              $("player_container").update(result.responseText);
            }
        });
  }    
  
function load_genres(g)
  {  
    var genre_type = $F("genre_type");
    if (genre_type > 0)
	  {
		var url = 'genres.php';
        new Ajax.Request(url, {
            method: 'post',
	        parameters: { gt:genre_type,gen:g },
            onSuccess: function(result) 
	          {
                $("genres_container").update(result.responseText);
              }
          });  
	  }
	else { $("genres_container").update(""); }
  } 
  
function check_search_type(default_txt)
  {
	var d = "none";  
	
	if ($F("search_in") == "star_base") { d = "block"; }
	
	$("gen_type_1").style.display = d;  
	$("gen_type_2").style.display = d; 
	$("gen_type_3").style.display = d;   
	$("gen_type_4").style.display = d;   
	
	$("gen_type_0").selected = true;
	
	$("genres_container").innerHTML = '<select name="genre" style="width:150px"><option value="0">&nbsp;'+default_txt+'</option></select>&nbsp;&nbsp;';
  }
  
function load_search_genres(default_txt)
  {
	var genre_type = $F("genre_type");
    if (genre_type > 0)
	  {
		var url = 'search_genres.php';
        new Ajax.Request(url, {
            method: 'post',
	        parameters: { gt:genre_type },
            onSuccess: function(result) 
	          {
                $("genres_container").innerHTML = result.responseText;
              }
          });  
	  }
	else { $("genres_container").innerHTML = '<select name="genre" style="width:150px"><option value="0">&nbsp;'+default_txt+'</option></select>&nbsp;&nbsp;'; }  
  }
  
  
function update_informer()
  {
    var at = ["t_events","t_reports","t_contests","t_news","t_showbizz","t_movies"];
	var width = parseInt($F("width"));
	var height = parseInt($F("height"));
	var fscroll = $F("scroll");
	var border = parseInt($F("border"));
	var num_news = parseInt($F("num_news"));
	var language = $F("language");
	var date = parseInt($F("date"));
	var image = parseInt($F("image"));
	var image_width = parseInt($F("image_width"));
	var title = parseInt($F("title"));
	var desc = parseInt($F("description"));
	var font_size = parseInt($F("font_size"));
	var bg_color = $F("bg_color");
	var text_color = $F("text_color");
	var link_color = $F("link_color");
	
	var news_selected = false;
	nt = [];
	
	at.each(function (t) {
	  if ($(t).checked) { nt.push($F(t)); news_selected = true; }			  
	});
	
	if (news_selected)
	  {
		$("informer_container").update('<iframe src="http://showbizness.md/rss.php?nt='+nt.join(':')+'&nn='+num_news+'&d='+date+'&img='+image+'&title='+title+'&desc='+desc+'&bg='+bg_color+'&tc='+text_color+'&ts='+font_size+'&lc='+link_color+'&iw='+image_width+'&ln='+language+'" name="INFORMER" height="'+height+'" width="'+width+'" marginwidth="0"  marginheight="0" scrolling="'+fscroll+'" frameborder="'+border+'"></iframe>');  
		
		$("informer_code_container").update('<textarea rows="5" cols="60" readonly="readonly"><iframe src="http://showbizness.md/rss.php?nt='+nt.join(':')+'&nn='+num_news+'&d='+date+'&img='+image+'&title='+title+'&desc='+desc+'&bg='+bg_color+'&tc='+text_color+'&ts='+font_size+'&lc='+link_color+'&iw='+image_width+'&ln='+language+'" name="INFORMER" height="'+height+'" width="'+width+'" marginwidth="0"  marginheight="0" scrolling="'+fscroll+'" frameborder="'+border+'"></iframe></textarea>');
	  }
	else { alert("Выберите минимум одну категорию новостей."); }
  }
  
  
function load_main_items()
  {
	var search_in = parseInt($F("search_in"));  
	
	if (search_in >= 0)
	  {
		var url = 'search_items.php?t=main';
        new Ajax.Request(url, {
            method: 'post',
	        parameters: { si:search_in },
            onSuccess: function(result) 
	          {
                $("main_items_container").innerHTML = result.responseText;
				$("sub_items_container").innerHTML = '<select name="main_items" id="sub_items" style="width:130px;"><option value="-1">--------------------</option></select>';
              }
          });  
	  }
	else 
	  { 
	    $("main_items_container").innerHTML = '<select name="main_items" id="main_items" style="width:130px;"><option value="-1">--------------------</option></select>'; 
		$("sub_items_container").innerHTML = '<select name="main_items" id="sub_items" style="width:130px;"><option value="-1">--------------------</option></select>'; 
      }
  }
  
function load_sub_items()
  {
	var search_in = parseInt($F("search_in"));  
	var main_item = parseInt($F("main_items"));  
	
	if (main_item >= 0)
	  {
		var url = 'search_items.php?t=sub';
        new Ajax.Request(url, {
            method: 'post',
	        parameters: { si:search_in, mi:main_item },
            onSuccess: function(result) 
	          {
                $("sub_items_container").innerHTML = result.responseText;
              }
          });  
	  }
	else 
	  { 
	    $("sub_items_container").innerHTML = '<select name="main_items" id="sub_items" style="width:130px;"><option value="-1">--------------------</option></select>'; 
      }
  }

function check_default_value(el_id,value) 
  {
	if ($F(el_id)==value) { $(el_id).value = ""; }  
  }

function check_default_search_value(el_id,value) 
  {
	if ($F(el_id)==value) { $(el_id).value = ""; } 
	
	if (parseInt($F("search_in")) == -1) 
	  {
		$("google_search_box").value = $(el_id).value;
		$("search_site_id").value = "partner-pub-4166890839794833:" + $F("search_site");
		$("cse-search-box").submit();
		return false;
	  }
  } 

  
  
  
  
  
  
  