function PageQuery(q){if(q.length>1){this.q=q.substring(1,q.length);}else{this.q=null;}this.keyValuePairs=new Array();if(this.q){for(var i=0;i<this.q.split("&").length;i++){this.keyValuePairs[i]=this.q.split("&")[i];}}this.getKeyValuePairs=function(){return this.keyValuePairs;};this.getValue=function(s){for(var j=0;j<this.keyValuePairs.length;j++){if(this.keyValuePairs[j].split("=")[0]==s)return this.keyValuePairs[j].split("=")[1];}return"";};this.getParameters=function(){var a=new Array(this.getLength());for(var j=0;j<this.keyValuePairs.length;j++){a[j]=this.keyValuePairs[j].split("=")[0];}return a;};this.getLength=function(){return this.keyValuePairs.length;}}
function queryString(key){var page=new PageQuery(window.location.search);return unescape(page.getValue(key));}
function displayItem(key){if(queryString(key)=='false'){alert("you didn't enter a ?name=value querystring item.");}else{return queryString(key);}}
function rightUrl(){loc= window.location.toString();if(loc.indexOf('?') != -1)  var loc = loc.substring(0, loc.indexOf('?'));with(document.getElementsByTagName("title")) var mytitle=length>0?item(0).innerHTML:false;window.location="http://tom.office.liga.net:8080/pagestatistic?days=7&url="+loc+"&title="+mytitle;}
$(document).ready(function(){
	if(window.location.pathname.indexOf("/faq/question/")!=-1) get_List(0);
	if(window.location.pathname.indexOf("/form/")!=-1) initFormEvent();
});
function printVersion(){
    var content = document.getElementById("center");
    $(content+" .pod_news_box_left").empty();
    mywindow = window.open ("", "mywindow","menubar=1,resizable=1, scrollbars=1,location=0, width=850,height=650px");
    mywindow.moveTo(0,0);
    var tmp = mywindow.document;
    var id = window.location.pathname.slice("6","-5");
    tmp.write("<html><head><title>"+document.title+"</title>"+"<script type='text/javascript' src='http://www.ligazakon.ua/fragments/js/jquery/jquery.pack.js'></script><link rel='stylesheet' href='/fragments/css/style.Print.css'></head><body>");
    tmp.write("<div id='printHeader'><a href='http://www.ligazakon.ua' target='_blank'><img src='/images/gfx/lz_print.gif' border='0' align='left' /></a><span><a href='http://www.ligazakon.ua/news/'>Новости ЛІГА:ЗАКОН</a></span></div><div class='break'></div><div id='content'>");
    tmp.write(content.innerHTML);
    tmp.write("</div>");
    tmp.write("<script>$('.blockContentTitle').remove();$('.pod_news_box_left').remove();$('#bottom_banner').remove();$('#allNewsButton').remove();</script>");
    tmp.write('</body></html>');
    tmp.close();
}

function googleSearch(){
    var radio = $(".ln > .select");
    $("#g_cx").val($(radio[0]).attr("type"));
    $("#cse-search-box").submit();
}

function beforeSend(){var inputs = $(".enc");$.each(inputs,function(i,v){$(v).css("color","#FFFFFF");$(v).val(escape($(v).val()));});document.forms[0].submit();}
function clearForm(){$(".enc").val("");}
function getPagination(str){
    $(str).hide();
    var root = $(str);
	var children = $(root).children();
    var spanIndex = 0;
    var start = 0;
    var end = 10;
    $.each(children,function(i,v){if(v.tagName=="SPAN"){spanIndex = i;}});
    if(spanIndex>=5) {start=spanIndex-5;end=spanIndex+6;}
	$(".brdOut").append("<div class='pagination'></div>");
	if(children[spanIndex-1]) $(".pagination").append("<a href='"+children[spanIndex-1]+"' class='prev'></a>");
    for(var n=start;n<end;n++){if(children[n]){$(".pagination").append(children[n]);$(children[n]).html(n+1);}}
	if(children[spanIndex+1]) $(".pagination").append("<a href='"+children[spanIndex+1]+"' class='next'></a>");
	var rootWidth = $(".pagination").width()+5;
	$(".pagination").css({width:rootWidth,margin:"0px auto;"});
	$(".pagination").show();
}
function parseNews(){
    var date_time = $(".firstheader .date_time").html();
    $(".firstheader .date_time").remove();
    if(date_time){$(".firstheader").prepend("<div align='right' style='color:#999999;font-size:12px;font-weight:normal;'>"+date_time+"</div>");} 
    $(".recomend .header_r").html("<b style='font-size:12px;'><span style='padding-right:2px;'>Р</span>ЕКОМЕНДАЦИИ</b>");
    $(".print_menu TR").append("<td style='background:url(/images/gfx/icons/print_gray.gif) no-repeat left center;padding-left:22px;'> <a href='#print' onclick='printVersion()'>печать</a></td>");
    $(".date_time> BR").remove();
}
function combineList(){
    var datebox = $(".n_l .d");
	$.each(datebox,function(v,i){var next = $(i).next();$(this).height($(next).height());});
}
function formElements(obj){
$(obj+" .checkbox").click(function(){
	var child = $(this).children();
	if($(this).attr("style")){
		$(this).removeAttr("style");
		$(child[0]).remove();
	}
	else{
		$(this).append("<input type='hidden' name='f_subscribe' value='"+$(this).attr('value')+"' />");
		$(this).css({background:"url(/images/gfx/forms/checkbox_s.gif) no-repeat 1px center"});
	}
});
$(obj+" .radio").click(function(){
	var hid = $(this).parent().children();
	$(obj+" .radio").removeAttr("style");
	$(hid[0]).val($(this).attr("value"));
	$(this).css({background:"url(/images/gfx/forms/radio_s.gif) no-repeat left center"});
});
}
function initFormEvent(){
    $(":radio").click(function(){
	    $(this).parent().css({background:"#FFFFFF"});
		if($("input[name='"+this.name+"']:last:radio:checked")[0]){
			var name = $(this).attr("name").replace("answid","");
			$("#"+name+"_0").addClass("CheckIt");
		}
		else{
			var name = $(this).attr("name").replace("answid","");
			$("#"+name+"_0").removeClass("CheckIt");
		}
	});
	$(":checkbox").click(function(){
        $(this).parent().css({background:"#FFFFFF"});
	});
}
function checkForm(){
	if(window.document.formlz.SRCURL){
        window.document.formlz.SRCURL.value = document.location;
    }
	var errors = false;
	var formBox = $("#formlz");
	if(!formBox[0]) return;
    var checkIt = $(".CheckIt");
    var emptyCss = {background:"#FAD3D3 url(/images/gfx/!.gif) no-repeat 98%"};
    var fillCss = {background:"#FFFFFF"};
	$.each(checkIt,function(i,v){
	    if(v.type=="radio" && $("input[name='"+v.name+"']:radio:checked").length==0){
            errors = true;$(v).parent().css({background:"#FAD3D3"});
		}
		else if(v.type=="radio" && $("input[name='"+v.name+"']:radio:checked").length>=1){
            $(v).parent().css({background:"#FFFFFF"});
        }
		if(v.type=="checkbox" && $("input[name='"+v.name+"']:checkbox:checked").length==0){
            errors = true;
            $(v).parent().css({background:"#FAD3D3"});
        }
		
        else if(v.type=="checkbox" && $("input[name='"+v.name+"']:checkbox:checked").length>=1){
            $(v).parent().css({background:"#FFFFFF"});
        }
		
        if(document.formlz[v.name].value==""){
            errors = true;
            $(v).css(emptyCss);
        }
    });
	$(checkIt).keyup(function(e){if($.trim($(this).val()).length == 0){$(this).css(emptyCss);}else{$(this).css(fillCss);}});
	$(checkIt).change(function(){if($(this).val()=="") {$(this).css(emptyCss);}else{$(this).css(fillCss);}});
	if(errors==true){location.href="#formlz";}
    if(errors==false){$(formBox).submit();}
	return false;
}
function styleRadio(name){
	if(!name) return;
	$("span[name='"+name+"'].radio_n").click(function(){
		var v = $(this).attr("value");
		var n = $(this).attr("name");
		$("input[name='"+name+"']").remove();
		$("span[name='"+name+"'].radio_n").removeClass("radio_s");
		$(this).prepend("<input type='hidden' name='"+n+"' value='"+v+"'>");
		$(this).addClass("radio_s");
	});
}
function styleCheckbox(name){
	if(!name) return;
	$("span[name='"+name+"'].checkbox_n").click(function(){
		var v = $(this).attr("value");
		var n = $(this).attr("name");
		$("input[name='"+name+"']").remove();
		$("span[name='"+name+"'].radio_n").removeClass("checkbox_s");
		$(this).prepend("<input type='hidden' name='"+n+"' value='"+v+"'>");
		$(this).addClass("checkbox_s");
	});
}