/*banner_loader.js*/
            $(document).ready(function(){
    $(".tblock .close").click(function(){
        $(this).parents(".tblock:first").hide("fast");
        var exp = new Date();
        var oneMinute = exp.getTime() + (60 * 1000 * 10);
        exp.setTime(oneMinute);
        setCookie('hide' + $(this).parents(".tblock:first").attr("id"), '1', exp, '/');
    });
});

var flInstalled = false;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if (plugin) {
    plugin = parseInt(plugin.description.substring(plugin.description.indexOf(".") -
    2)) >=
    6;
}
else 
    if (navigator.userAgent &&
    navigator.userAgent.indexOf("MSIE") >= 0 &&
    (navigator.userAgent.indexOf("Windows 95") >= 0 ||
    navigator.userAgent.indexOf("Windows 98") >= 0 ||
    navigator.userAgent.indexOf("Windows NT") >=
    0)) {
        document.write('<SCRIPT LANGUAGE=VBScript\> \n');
        document.write('on error resume next \n');
        document.write('plugin=( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
        document.write('</SCRIPT\> \n');
    }
if (plugin) {
    flInstalled = true;
}
else {
    flInstalled = false;
}

function fltxt(w, h, p, fv){
    return '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" WIDTH=' +
    w +
    ' HEIGHT=' +
    h +
    '> <PARAM NAME=wmode VALUE=opaque> <PARAM NAME=movie VALUE="' +
    p +
    '"> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=flashvars VALUE="' +
    fv +
    '"> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="' +
    p +
    '" menu=false wmode=opaque quality=high bgcolor=#FFFFFF flashvars="' +
    fv +
    '" swLiveConnect=FALSE WIDTH=' +
    w +
    ' HEIGHT=' +
    h +
    ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
}

function LoadBanner(el, burl, w, h, bsrc, fl){
    if (fl) {
        $("#" + el).html(fltxt(w, h, bsrc, "nhref=" + burl));
    }
    else {
        $("#" + el).html('<a href="' + burl + '" target="_blank"><img src="' +
        bsrc +
        '" width="' +
        w +
        '" height="' +
        h +
        '" /></a>');
    }
}

/*green_form.js*/
            $(document).ready(function(){
    $(".green_form button").attr("disabled", "disabled");
    
	$(".green_form .chkbx").focus(function(event){
        ititle = $(this).attr("value");
        if (ititle == "chat") {
            $("#iclient_identify").slideUp();
            $("#iclient_identify").attr("value", "");
            $(".green_form button").attr("disabled", "");
        }
        else {
            ident = "";
            $(".green_form button").attr("disabled", true);
            switch (ititle) {
                case "sms":
                    ident = "Ваш номер мобильного телефона";
                    break;
                case "icq":
                    ident = "Ваш номер ICQ";
                    break;
                case "email":
                    ident = "Ваш E-mail";
                    break;
                case "skype":
                    ident = "Ваш E-mail или логин в Skype";
                    break;
                default:
                    $(this).attr("selected", "");
                    break;
            }
            $("#iclient_identify").attr("value", ident);
            $("#iclient_identify").attr("title", ident);
            $("#iclient_identify").css("display", "block");
            $("#iclient_identify").addClass("clear");
            $("#iclient_identify").slideDown("fast");
            $("#iclient_identify").focus(function(){
                if (($(this).attr("title")) == ($(this).attr("value"))) {
                    $(this).attr("value", "");
                    $(this).removeClass("clear");
                    $(".green_form button").attr("disabled", "");
                }
            });
        }
    });
    
    if ($(".green_form textarea").text() == "") {
        $(".green_form textarea").text($(".green_form textarea").attr("title"));
        $(".green_form textarea").addClass("clear");
    }
    
    $(".green_form textarea").focus(function(){
        if ($(this).attr("value") == $(this).attr("title")) {
            $(this).attr("value", "");
            $(this).removeClass("clear");
        }
        elt = $(".green_form #iclient");
        if (($(elt).attr("value") == "")) {
            $(elt).addClass("clear");
            $(elt).attr("value", $(".green_form #iclient").attr("title"));
        }
        $(elt).slideDown("fast");
    });
    
    $(".green_form #iantispam input").focus(function(){
        if ($(this).attr("value") == $(this).attr("title")) {
            $(this).attr("value", "");
            $(this).removeClass("clear");
        }
        $(".green_form button").attr("disabled", "");
    });
    
    
    $(".green_form #iclient").focus(function(){
        if ($(this).attr("value") == $(this).attr("title")) {
            $(this).attr("value", "");
            $(this).removeClass("clear");
        }
        
        $(".green_form fieldset").slideDown("fast");
        $(".green_form #iantispam").slideDown("fast");
        $(".green_form button").attr("disabled", "");
    });
    
    
    $(".green_form form").submit(function(event){
        $(".green_form form button").focus();
        var errs = new Array();
        i = 0;
		$(".green_form :input:not(button)").each(function(){
            if (
			(($(this).attr("value")) == "") ||
            (($(this).attr("value")) == ($(this).attr("title"))) 
			)
			{
                if (($(this).attr("name") == "client_identify") &&
                ($("#iuse_channel input:checked").attr("value") == "chat")) {
                
                }
                else {
                    errs[i] = $(this).attr("title");
                    $(this).addClass("clear");
                    $(this).attr("value", $(this).attr("title"));
                    i++;
                }
            }
        });
		
        if (errs.length > 0) {
            event.preventDefault();
			if (errs.length > 1) {
                alert("Пожалуйста, заполните поля: «" + errs.join("», «") + "»");
            }
            else 
                if (errs.length == 1) {
                    alert("Пожалуйста, заполните поле: «" + errs.join("», «") + "»");
                }
        }
    });
    $(".green_form_expanded").each(function(){
        $(".green_form fieldset").show();
        $(".green_form #iclient").show();
        $(".green_form #iantispam").show();
    });
    
	
    $(".green_form form").keydown(function(event){
        if ((event.ctrlKey) || (event.ctrlLeft)) {
            if (event.keyCode == 13) {
                $(".green_form_chat form").submit();
            }
        }
    });
	
    $(".green_form").css("display", "block");	
});

/*common.js*/
            $(document).ready(function() {
    $(".root li a.haschild").click(function(event) {
        event.preventDefault();
        event.stopPropagation();
        elt = $(this).parent("li");
        if ($(elt).hasClass("iclick")) {
            $(elt).removeClass("iclick");
        }
        else {
            $(".root li.iclick").removeClass("iclick");
            $(document).click(function(event) {
                $(".root li.iclick").removeClass("iclick");
            });
            $(elt).addClass("iclick");
        }
    });
});

$(document).ready(function() {
    $(".chat span").click(function(event) {
        event.preventDefault();
        event.stopPropagation();
        location = $("base").attr("href") + 'service/chat/';
    });
});

$(document).ready(function() {
    prev = '1';
    $(".zebra").attr("border", 0);
    $(".zebra").attr("cellspacing", 0);
    $(".zebra").attr("cellpadding", 0);
    $(".zebra tr").each(function(event) {
        $(this).hover(function(event) {
            $(this).addClass("hover");
        }, function() {
            $(this).removeClass("hover");
        });
        $(this).click(function() {
            $(this).toggleClass("click");
        });
        if (prev == 1) {
            $(this).addClass("dark");
            prev = 0;
        }
        else {
            $(this).addClass("light");
            prev = 1;
        }
        
    });
});

$(document).ready(function() {
    $(".sponsor_rubric ul li a").click(function(event) {
        event.preventDefault();
        $(this).parents("li").children("p").fadeIn("fast");
        $(this).parents("li").children("a.ilogo").fadeIn("fast");
        $(this).parents("li").addClass("visible");
        $(this).unbind("click");
    });
});

function SetCookieForNMinuts(name, value, minuts, path, domain, secure) {
    var today = new Date();
    expires = new Date(today.getTime() + minuts * 60 * 1000);
    document.cookie = name + "=" + escape(value) + "; expires=" +
    expires.toGMTString() +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}


function GetCookieValueByName(name) {
    var beg = document.cookie.indexOf(name + "=");
    if (beg == -1) return false;
    var end = document.cookie.indexOf(";", beg + name.length);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(beg + name.length + 1, end));
}


$(document).ready(function() {
    $(".disabled").click(function(event) {
        event.preventDefault();
    });
    $('.rounded div.ititle').hover(function(event) {
        $(this).addClass("ihover");
    }, function() {
        $(this).removeClass("ihover");
    });
    $('.rounded div.ititle').click(function(event) {
        frm = $(this).parents("div.rounded");
        $(frm).toggleClass("collapsed");
        fid = $(frm).attr("id");
        if ($(frm).hasClass("collapsed")) {
            SetCookieForNMinuts('collapsed_' + fid, 1, 100, '/');
        }
        else {
            SetCookieForNMinuts('collapsed_' + fid, 99, 100, '/');
        }
    });
});

/*list.js*/
            $(document).ready(function() {
    $('.qlist h2').addClass("clickable");
    $('.qlist h2 a').click(function(event) {
        event.preventDefault();
		$(this).unbind("click");
		$(this).parents("h2").removeClass("clickable");
        loadto = $(this).parents("li").children("div.answ");
        $(loadto).addClass("preload");
        elt = $(this);
        $(loadto).load($(this).attr("href") + "?aj=1", function() {
            $(elt).click(function(event) {
                event.preventDefault();
                event.stopPropagation();
                location = $(elt).attr("href");
                return false;
            });
            $(loadto).removeClass("preload");
			$(elt).addClass("clicked");
        });
    });
});

$(document).ready(function() {
    $('.vote').addClass("clickablea");
    $('.vote').click(function(event) {
        event.preventDefault();
        $(this).unbind("click");
        $(this).click(function(event) {
            event.preventDefault();
            return false;
        });
        $(this).addClass("preload");
        elt = $(this).parents(".subdescription");
        lnl = $(this);
        $(elt).find(".votescount").load($(lnl).attr("href") + "&aj=1", function() {
            $(lnl).removeClass("preload");
            $(lnl).removeClass("clickablea");
            $(lnl).css("cursor", 'default');
            $(lnl).css("text-decoration", "none");
            $(lnl).text("Голос учтен!");
        });
    });
});

/*green_form_chat.js*/
            $(document).ready(function(){
    $(".green_form_chat textarea").attr("value", $(".green_form textarea").attr("title"));
    $(".green_form_chat textarea").addClass("clear");
    $(".green_form_chat textarea").focus(function(){
        $(this).removeClass("error");
    });
    $(".green_form_chat .client").focus(function(){
        $(this).removeClass("error");
    });
    $(".green_form_chat form").keydown(function(event){
        if ((event.ctrlKey) || (event.ctrlLeft)) {
            if (event.keyCode == 13) {
                $(".green_form_chat form").submit();
            }
        }
    });
	
    $(".green_form_chat form").submit(function(event){
        $(".green_form_chat form button").focus();
        var errs = new Array();
        i = 0;
        $(".green_form_chat :input:not(button)").each(function(){
            if ((($(this).attr("value")) == "") ||
            (($(this).attr("value")) == ($(this).attr("title")))) {
                errs[i] = $(this).attr("title");
                $(this).addClass("error");
                i++;
            }
        });
        if (errs.length > 0) {
            if (errs.length > 1) {
                alert("Пожалуйста, заполните поля: «" + errs.join("», «") + "»");
            }
            else 
                if (errs.length == 1) {
                    alert("Пожалуйста, заполните поле: «" + errs.join("», «") + "»");
                }
            event.preventDefault();
        }
    });
});

function refreshChat(){
    $("ul.chat li span.qid").each(function(){
        $(this).parents("li").addClass("loading");
        qid = $(this).text();
        if (qid != "") {
            $(this).parents("li").load("service/chat/?rf=1&qid=" + qid, function(){
                $(this).removeClass("loading");
                $(this).removeClass("wait");
                $(this).find("span.qid").each(function(){
                    $(this).parent("li").addClass("wait");
                    var cnt = $("ul.chat li span.qid").length;
                    if (cnt == 0) {
                        clearInterval(intervalID);
                        $(".green_form_chat").show();
                        $(".green_form_chat textarea").focus();
                    }
                })
            });
        }
    });
    var cnt = $("ul.chat li span.qid").length;
    if (cnt == 0) {
        clearInterval(intervalID);
        $(".green_form_chat").show();
        $(".green_form_chat textarea").focus();
    }
}

var intervalID = 0;
$(document).ready(function(){
    refreshChat();
    intervalID = setInterval(function(){
        refreshChat();
    }, 3000);
});




function refreshInformerChat(){
    $(".chat_informer span.qid").each(function(){
        $(this).parents("div.wait:first").addClass("loading");
        qid = $(this).text();
        if (qid != "") {
            $(this).parents("div.wait:first").load("service/chat/?rfi=1&qid=" + qid, function(){
                $(this).removeClass("loading");
                $(this).removeClass("wait");
                $(this).find("span.qid").each(function(){
                    $(this).parent("div:first").addClass("wait");
                    var cnt = $(".chat_informer span.qid").length;
                    if (cnt == 0) {
                        clearInterval(informer_intervalID);
                    }
                })
            });
        }
    });
    var cnt = $(".chat_informer span.qid").length;
    if (cnt == 0) {
        clearInterval(informer_intervalID);
    }
}

var informer_intervalID = 0;
$(document).ready(function(){
    refreshInformerChat();
    informer_intervalID = setInterval(function(){
        refreshInformerChat();
    }, 5000);
});



/*themes.js*/
            function switchStyleSheet(theme_id){
    $("link[rel='alternate stylesheet']").each(function(){
        $(this).attr("disabled", true);
    });
    if ($("#" + theme_id).length != 0) {
        $("#" + theme_id).attr("disabled", false);
        SetCookieForNMinuts('theme_id', theme_id, 100, '/');
    }
}

$(document).ready(function(){
    if (GetCookieValueByName('theme_id') != "") {
        switchStyleSheet(GetCookieValueByName('theme_id'));
    }
});

