function setImageWidth(obj){
//	alert(obj.parentNode.offsetWidth);
	var maxWidth = document.body.clientWidth/3;
	if (obj.width>maxWidth) obj.width=maxWidth;
//	alert(obj.parentNode.offsetWidth);
}

function setHeight(){
    var head,body,foot,clHeight,sumHeight,newHeight;
    head = document.getElementById('headtable');
    body = document.getElementById('middletable');
    foot = document.getElementById('foottable');
    clHeight =document.body.clientHeight;
    sumHeight = head.offsetHeight + body.offsetHeight + foot.offsetHeight;
    if (sumHeight < clHeight) {
	newHeight = clHeight + body.offsetHeight - sumHeight;
	body.style.height = newHeight;
    }
//    alert(document.body.clientHeight + ' '+ sumHeight);
}
function ShowIm(obj){
	var jbo = document.getElementById('issuehid');
}

function Pop2(obj, speed, className, wid, hei){
        PopEx(obj, obj.offsetLeft + obj.offsetWidth - 315, obj.offsetTop, null, null, speed, className, false);
}
function SetShoetPoll(id,tid){
    var frm = document.getElementById('shortPollForm'+tid);
    if (frm){
        frm.answer.value = id;
        frm.submit();
    }
}
function popups(val){
    if(val == '1')
	window.open('http://www.fhplus.ru/short.php?action=Votes','Голосование','width=350,height=175,toolbar=0,resizable=1,scrollbars=1');
}
function windRes(obj){
	window.sizeToContent();
//	alert(document.body.scrollHeight + ' ' + document.body.clientHeight);

}
function goComment(url){
    url = "/short.php?shortparam="+url;
//    alert(url);
    $.get(url,{},function(html){$("div#comm").html(html);},'html');
    return false;
}
function SetFormLogin(obj){
    if (obj.checked){
	$("#usuallogin").css("display","none");
	$("#openidlogin").css("display","");
	$("#loginmode").attr("value","openid");
    }else{
	$("#usuallogin").css("display","");
	$("#openidlogin").css("display","none");
	$("#loginmode").attr("value","usual");
    }
}
function CleanField(obj){
	if (obj.value =='Логин' || obj.value =='Пароль')
	obj.value = '';
}
function SetDates(name){
    var value = '';
    name = "#" + name;
    var day = $(name+"_day").attr("value");
    day = SetZero(day.toString(), 2);
    var month = $(name+"_month").attr("value");
    month = SetZero(month.toString(), 2);
    var year = $(name+"_year").attr("value");
    year = SetZero(year.toString(), 4);
    value = year + "-" + month + "-" + day; 
    $(name+"_hid").attr("value",value);

}
function SetZero(val,max){
    if (val.length < max){
	var c = val.length;
	for (i = c; i < max; i++)
	    val = "0" + val;
    }
    return val;
}

function addComment(id,action){
	var text = $("#commentmessage").val();
//	alert(text);
	var url = "/Service/addcomment.php"
	$.post(url,{id:id,act:action,txt:text},function(html){
//		alert(html);
		RebuildComment(html,action,id)
	});
}
function actionComment(id,newsid,action,method){
	var url = "/Service/actioncomment.php";
	$.post(url,{id:id,act:action,method:method},function(html){
	    RebuildComment(html,action,newsid)
	});
}
function RebuildComment(html,action,id){
	    if (html == 'tr'){
		url = "/comments/caction_" + action + "/cid_"+ id +"/";
		goComment(url);
		$("#commentmessage").val("");
	    }
}
function BigVideo(id){
	var ids = "videocontain"+id;
	var copy = $("#"+ids).html();
	$("#"+ids+" .object").dialog({
        position: ["center","center"],
        close: function(event, ui) {
    	    $(this).dialog("destroy");
        	$("#"+ids).html(copy);
        },
        buttons: {
    	    "Закрыть": function() {
        	$(this).dialog("destroy");
        	$("#"+ids).html(copy);
            }
        },
        width: 640,
        height: 510,
        resizable: false,
        modal: true,
        dialogClass: "dialog"
	});	
	
}
$(document).ready(function(){
        var obj = document.getElementsByTagName('OBJECT'),p;
        for (i=0;i<obj.length;i++){
    	    p = document.createElement('param');
    	    p.setAttribute('name','wmode');
    	    p.setAttribute('value','opaque');
    	    obj[i].appendChild(p);
    	    obj[i].setAttribute('wmode','opaque');
	}
});
 
function add_favorite(a) {
	var title=document.title, url=document.location;
        try {
            // IE
            window.external.AddFavorite(url, title);
	}catch (e) {
    	    try {
        	// Mozilla
                window.sidebar.addPanel(title, url, "");
            }catch (e) {
        	// Opera
                if (typeof(opera)=="object") {
            	    a.rel="sidebar";
                    a.title=title;
                    a.url=url;
                    return true;
                }else {
            	    // Unknown
                    alert('Нажмите Ctrl-D чтобы добавить страницу в закладки');
                }
            }
        }
        return false;
}

/*GNU GPL*/ 
