//jQuery.noConflict();

//инициализация
$(document).ready(init);

function init(){

	CheckTableHeight();

	/*
  $("table.formtable tr:even td").attr("className", "greybackground");

  if ( $.browser.opera ){
    $('div.smallimages').css('marginLeft', '3px');
  } */
/*
  var ie = 0;
	var needheight = 400;
	if ($.browser.msie){
	 ie = 1;
	 needheight = 360;
	}

  checkelementheight(ie, needheight);

  $(window).resize(function(){
  	checkelementheight(ie, needheight);
  });
*/
}


//составление емайла из частей
function startmessage(e1, el, e2){
	if (!el)
	  return;
	var m = e2+'@'+e1;
	el.href = 'mai'+'lto:'+m;
}


//обрезаем контент текстового блока
function setcontent(th, cnt, set){
  if (set)
	  $(th).attr('value', $(th).attr('value').substring(0, cnt));
	$('#currentsymbolsnumber').html($(th).attr('value').length);
}

//заголовок меняем в документе
function settitle(st, add){
	if (add)
	  document.title = document.title+" | "+st;
	else
	  document.title = st;
}

// Проверка всех элементов .treecols
//и выставление всех дивов в такую же высоту
function CheckTableHeight(){

  $('table.threecols').each(
    function(i){
    	var h = $(this).height();

    	if (h){
    		//h = h - 31;
    		h = h - 29;
                       /*
    		$(this).find('div.borderblock').each(
    		  function(j){
    		  	//alert($(this).html());
    		  	$(this).css('height', h+"px");
    		  	$(this).height(h);
    		  	alert($(this).css('height'));
    		  }
    		);
                        */
    		$(this).find('div.borderblock').css('height', ""+h+'px');
    		$(this).find('div.redborderblock').css('height', ""+h+'px');
    	}
  });
}


//Голосование
function StartVotingFunc(id){
   /*
	var main_div = GetById("vote_block_id");
	//получаем строку с идентификаторами выбранных пунктов
	var checked_array = "";
	if (main_div){
    var el = document.getElementsByName("poll_answer");
    if (el){
      for (i = 0; i < el.length; i++){
        frm1 = el[i];
        if (frm1.checked)
           checked_array = checked_array+parseInt(frm1.value)+"_";
      }
    }

	}

  if (id > 1) if (!checked_array) {
    alert("Необходимо выбрать ответ для голосования");
    return false;
  }

  var req = new JsHttpRequest();

	req.onreadystatechange = function() {
	if (req.readyState == 4) {
     main_div.innerHTML = req.responseJS.divtext;
	}
	}

	req.open(null, "/includes/js/StartVotingFunc.php", true);
	req.send( {id: id, checked_array:checked_array} );
  */

  var main_div = $('#vote_block_id');
  var checked_array = "";
  if (main_div){
    var el = $(main_div).find("input[@name='poll_answer']:checked").each(
      function(i){
      	checked_array = checked_array+parseInt($(this).attr('value'))+"_";
      }
    );
  }

  if (id > 1) if (!checked_array) {
    alert("Необходимо выбрать ответ для голосования");
    return false;
  }

  $.get('/jslib/StartVotingFunc.php?id=' + id + '&checked_array='+checked_array, function(data) {
  	 alert(data);
  });

  return false;
}

// Показывваем и прячем форму задать вопрос
function AskQuestion(){     var div = $('#askquestion');
    if (div){
    	if ($(div).css('display') == 'none')
    	  $(div).css('display', 'block');
    	else
    	  $(div).css('display', 'none');

    }

	return false;
}

// Показывваем и прячем форму задать вопрос
function getcaptchareload(th){
	var i = parseInt($(th).attr('rel')) + 1;
	$(th).attr('rel', i);
	$('#getcaptchaimg').attr('src', '/faq/getcaptcha.php?'+i);

	return false;
}

//Очистка формы faq
function ClearFaqForm(){
	var div = $('#askquestion');
	if (!div)
	 return false;

  $(div).find("input[@type='text']").attr('value', '');
  //$(div).find("textarea").html('1 ');
  $(div).find("textarea").attr('value', '');

	return false;
}