
// JavaScript Document

function formHint(frm){
	tpos = jQuery('#'+frm).position().top;
	lpos = jQuery('#'+frm).position().left;
	jQuery('#'+frm+'-hint').css('top', tpos+"px").css('left', lpos+jQuery('#'+frm).width()+6+"px").show();
}

function formHide(frm) {
	jQuery('#'+frm+'-hint').hide();
}


function sPop(frm){
	var obj = jQuery('#'+frm);
	var pos = obj.position();
	jQuery('#'+frm+'-pop').css('top', 16+pos.top+obj.height()+"px").css("left", (pos.left-140)+'px').show();
}

function hidePop(block) {
	jQuery('#'+block).hide();
}

function sSuggest(frm) {
	var obj = jQuery('#predmet');
	var pos = obj.position();
	jQuery('#'+frm+'-pop').css('top', 16+pos.top+obj.height()+"px").css("left", (pos.left-16)+'px').show();
}


function getElementPositionx(elemId)
{
    var elem = document.getElementById(elemId);

    var w = elem.offsetWidth;
    var h = elem.offsetHeight;

    var l = 0;
    var t = 0;

    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}

function popForm(frm) {
	var pos = getElementPositionx(frm);
	jQuery('#'+frm+'-pop').css('top', 4+pos.top+jQuery("#"+frm).height()+"px").css("left", (pos.left-6)+'px').show();
}

function popAtest(frm) {
	var pos = getElementPositionx(frm);
	jQuery('#'+frm+'-pop').css('top', pos.top-14+"px").css("left", (pos.left)-11+'px').show();
}
function popCena(frm) {
	jQuery("#srcena a").show();
	jQuery("#srcena #"+frm).hide();
	jQuery("#srcena strong").hide();
	jQuery("#srcena #"+frm+'-cena').show();
}

function selAutor(chk) {
	if (chk.checked == true) {
		jQuery("label",jQuery(chk).parent().parent()).css("font-weight",'bold');
	}
	else {
		jQuery("label",jQuery(chk).parent().parent()).css("font-weight",'normal');
	}
}

function overDell() {
	ztb = jQuery(".zlistover");
	ztb.mouseover(function(){
		jQuery(".dell",jQuery(this)).show();
	});
	ztb.mouseout(function(){
		jQuery(".dell",jQuery(this)).hide();
	});
}

function shAcc(obj) {
	tt = jQuery("#"+obj+"-title");
	bk = jQuery("#"+obj+"-block");
	if (bk.css("display")=='none') {
		bk.show();
		tt.removeClass("acc-close").addClass("acc-open");
	}
	else {
		bk.hide();
		tt.removeClass("acc-open").addClass("acc-close");
	}
}

function showType(tp){
	obj = jQuery("#"+tp);
	th = jQuery("#lnk-"+tp);
	jQuery('.pred-list').removeClass("dblock").addClass("dnone");
	obj.removeClass("dnone").addClass("dblock");
	pleft = th.position().left;
	tleft = obj.position().left;
	jQuery(".pred-st", obj).css('left', (pleft-tleft)+(th.width()/2-12)+"px");
}

function hideWT(hh) {
	jQuery("#"+hh).removeClass("dblock").addClass("dnone");
}

function addType(ch, name, type) {
	th = jQuery(this);
	id = jQuery(ch).attr("id");
	chk = jQuery("#"+type+" input");
	sqty = jQuery('#'+type+'-td span');
	if (ch.checked == true) {
		jQuery('#'+type+'-td').append('<span class="wdell" id="'+id+'-dett"> '+name+'<em onclick="dellType(\''+id+'\',\''+type+'\')">&nbsp;</em>,</span>');
		jQuery('#'+type+'-first').hide();
		/*if (sqty.length>1) {
			sqty.eq(sqty.length-1).append('<ins>,</ins>');
		}*/
	}
	else {
		dellType(id,type);
	}
}


function dellType(tt, type){
	jQuery("#"+tt+"-dett").remove();
	document.getElementById(tt).checked = false;
	if (jQuery('#'+type+'-td span').length==1) {
		jQuery('#'+type+'-first').show();
	}
}

function overAddBett() {
	ztb = jQuery(".zslist tr.brd");
	ztb.mouseover(function(){
		jQuery(".addbett",jQuery(this)).css("visibility",'visible');
	});
	ztb.mouseout(function(){
		jQuery(".addbett",jQuery(this)).css("visibility",'hidden');
	});
}

function shComm(lnk) {
	th = jQuery(lnk);
	obj = jQuery("#shcomment");
	if (obj.hasClass("dnone")) {
		obj.removeClass("dnone").addClass("dblock");
		th.removeClass("acommopen").addClass("acommhide");
	}
	else {
		obj.removeClass("dblock").addClass("dnone");
		th.removeClass("acommhide").addClass("acommopen");
	}
}

function showPart() {
	jQuery('.wtd .part span').toggle(
		function(){
			jQuery(this).css("background-position", '0 -9px');
			jQuery(this).parent(0).parent(0).parent(0).parent(0).parent(0).next().removeClass("dnone").addClass("dblock");
		},
		function(){
			jQuery(this).css("background-position", '0 0');
			jQuery(this).parent(0).parent(0).parent(0).parent(0).parent(0).next().removeClass("dblock").addClass("dnone");
	});
}

function showZadanie(){
	jQuery(".tgzadanie a").click(function(){
		if (jQuery(".zadanie").css("display")=='none') {
			jQuery(".zadanie, .editzadanie").show(500);
			jQuery(".tgzadanie a em").css("background-position", '0 -9px');
			jQuery(".tgzadanie a").css("font-weight",'bold');
		}
		else {
			jQuery(".zadanie, .editzadanie").hide(500);
			jQuery(".tgzadanie a em").css("background-position", '0 0');
			jQuery(".tgzadanie a").css("font-weight",'normal');
		}
		return false;
	});
}


function selChat () {
	var sell = jQuery('#selects .sell-item');
	var sell_list = jQuery('#selects .sell-list');
	sell.click(function(){
		sell_list.css("top", sell.height()+11);
		sell_list.slideToggle(300);
		var list_item = jQuery('#selects .sell-list li');
		list_item.mouseover(function(){
			jQuery(this).css("background", '#e3e9ef');
		});
		list_item.mouseout(function(){
			jQuery(this).css("background", '');
		});
		list_item.click(function(){
			sell.children().remove();
			sell.html(jQuery(this).children().clone());
			sell_list.slideUp(300);
		});
	});
}

function sOffer(){
	off = jQuery("#offer-list table tbody tr");
	off.mouseover(function(){
		th = jQuery("#user-"+jQuery(this).attr("id")).css("width",jQuery("#offer-list").width()+'px');
		th.css("visibility",'hidden').show();
		th.css({"top": ((jQuery("#"+jQuery(this).attr("id")).position().top+(jQuery(this).height()/2))-(jQuery('div',th).height()/2))+'px',"visibility":'visible'});
	});
	off.mouseout(function(){
		jQuery("#offer-list .boffer").hide();
	});
}

function showPred(lnk) {
	bk = jQuery(lnk).parent().next();
	if (bk.hasClass("dnone")) {
		bk.removeClass("dnone").addClass("dblock");
		jQuery(lnk).removeClass("adott");
		jQuery("em", jQuery(lnk)).css("background-position",'0 -9px');
	}
	else {
		bk.removeClass("dblock").addClass("dnone");
		jQuery(lnk).addClass("adott");
		jQuery("em", jQuery(lnk)).css("background-position",'0 0px');
	}
}

function showPass(lnk) {
	bk = jQuery(lnk).parent().next();
	if (bk.hasClass("dnone")) {
		bk.removeClass("dnone").addClass("dblock");
		jQuery(lnk).removeClass("adott");
	}
	else {
		bk.removeClass("dblock").addClass("dnone");
		jQuery(lnk).addClass("adott");
	}
}


function showArbitr(arid) {
	jQuery(".arbblock").addClass("dnone");
	jQuery(".arbtab-d").removeClass("arbtab-a");
	jQuery("#abrtab-"+arid).parent().addClass("arbtab-a");
	jQuery("#arbblock-"+arid).removeClass("dnone");
}

function cTabs(tab) {
	jQuery("#ctabs li").removeClass("ctab-a");
	jQuery("#ctabs li a").addClass("adott");
	jQuery("#ctabs-block").children(0).addClass("dnone");
	jQuery("#"+tab).removeClass("adott").parent().parent().parent().addClass("ctab-a");
	jQuery("#"+tab+"-block").removeClass("dnone");
	return false;
}

function ShowEnter(th) {
	vh = jQuery("#vhod");
	if (parseInt(vh.css("width")) == 1) {
		jQuery(th).wrapInner('<b></b>');
		vh.animate({width: '278px'}, 500);
	}
	else {
		txt = jQuery('b', jQuery(th)).text();
		jQuery('b', jQuery(th)).remove();
		jQuery(th).text(txt);
		vh.animate({width: '1px'}, 500);
	}
}


function checkForPay(){
	var cpay = jQuery("#payworks :checkbox");
	cpay.click(function(){
		if (this.checked == true) {
			if (jQuery(this).attr("id") == 'selectallworks') {
				cpay.attr({checked: 'checked'}).parent().parent().addClass("bgba");
			}
			else {
				jQuery(this).parent().parent().addClass("bgba");
			}
		}
		else {
			if (jQuery(this).attr("id") == 'selectallworks') {
				cpay.removeAttr("checked").parent().parent().removeClass("bgba");
			}
			else {
				jQuery(this).parent().parent().removeClass("bgba");
			}
		}
	});
}

function showPayMetod(acc){
	jQuery("#paytype .tb").removeClass("bgba");
	jQuery("#paytype a.anone").addClass("adott").removeClass("anone");
	jQuery("#paytype .tb .acsh").addClass("dnone");
	jQuery(acc).removeClass("adott").addClass("anone").parent().parent().parent().parent().addClass("bgba");
	jQuery(".acsh",jQuery(acc).parent().parent().parent()).removeClass("dnone");
}


function showNewMessages() {
	var mn = jQuery("#b-messages");
	var str = jQuery(".all-messages p span i");
	if (mn.hasClass("messheight")) {
		mn.removeClass("messheight");
		str.addClass("str-a");
	}
	else {
		mn.addClass("messheight");
		str.removeClass("str-a");
	}
}

function popArtical() {
	jQuery().bind("click", function(event){
		var t = jQuery(event.target);
		if(t.is("img.art-link")) {
			if (!document.getElementById('art-pop')) {
				jQuery("body").append("<div id='art-loading' class='pop-art' style='display: none;'><div class='bloading'>&nbsp;</div></div><div id='art-pop' class='pop-art2' style='display:none'><div></div><div class='artclose'></div></div>");
			}
			jQuery("#art-loading").hide();
			jQuery("#art-pop").hide();
			pos = getElementPositionx(t.attr("id"));
			jQuery("#art-loading").css({"top":(pos.top+t.height()/2)-33+'px', "left":(pos.left+t.width()/2)-33+'px'}).show();
			var imgPreload = new Image();
			imgPreload.src = t.parent().attr("href");
			jQuery("#art-pop div").eq(0).html('');
			jQuery("#art-pop div").eq(0).append('<img src="'+imgPreload.src+'" alt="" />');
			jQuery(imgPreload).load(function(){
				jQuery("#art-pop").css("visibility",'hidden').show();
				jQuery("#art-loading").hide();
				if ((pos.left+t.width()/2)-(imgPreload.width+12)/2<0){
					pleft = 0+'px';
				}
				else if ((pos.left+t.width()/2)+(imgPreload.width+12)/2>jQuery().width()){
					pleft = jQuery().width()-(imgPreload.width+12)+'px';
				}
				else {
					pleft = (pos.left+t.width()/2)-(imgPreload.width+12)/2+'px';
				}
				ptop = (pos.top+t.height()/2)-(imgPreload.height+12)/2+'px';
				jQuery("#art-pop").css({"top":ptop, "left":pleft, "visibility":'visible'});

			});
  		}
		else {
			if (document.getElementById('art-pop')) {
				jQuery("#art-loading").hide();
				jQuery("#art-pop").hide();
			}
		}
	});
}

function sCont(fid) {
	jQuery(".flags td").removeClass("flag-this");
	jQuery("#"+fid).parent().addClass("flag-this");
	jQuery("#leflcontacts .ctacts").addClass("dnone");
	jQuery("#"+fid+"-contacts").removeClass("dnone");
}

function soDetails(soblock) {
	bt = jQuery("#"+soblock);
	if (bt.css("height")=='2.4em') {
		bt.css("height",'auto');
		jQuery("i.downup",bt).css("background-position",'-13px 0');
	}
	else {
		bt.css("height",'2.4em');
		jQuery("i.downup",bt).css("background-position",'0 0');
	}
}





function loadPages(uid)
{	$('#pageslist').html('Загрузка страниц...');
	sel = $('#domain').attr('value');
	a = sel.split('_');


	if ((a[1] == 0) && (uid != 0))
		$('#domainbtndiv').css({display: 'block'});
	else
	    $('#domainbtndiv').css({display: 'none'});

	$('#pageslist').load('/addon/pages.php?id=' + a[0]);

 	//alert(a);}


