var mx=0;
var my=0;
var clb;
$.fn.centerInClient = function(options) {
    /// <summary>Centers the selected items in the browser window. Takes into account scroll position.
    /// Ideally the selected set should only match a single element.
    /// </summary>    
    /// <param name="fn" type="Function">Optional function called when centering is complete. Passed DOM element as parameter</param>    
    /// <param name="forceAbsolute" type="Boolean">if true forces the element to be removed from the document flow 
    ///  and attached to the body element to ensure proper absolute positioning. 
    /// Be aware that this may cause ID hierachy for CSS styles to be affected.
    /// </param>
    /// <returns type="jQuery" />
    var opt = { forceAbsolute: false,
                container: window,    // selector of element to center in
                completeHandler: null
              };
    $.extend(opt, options);
   
    return this.each(function(i) {
        var el = $(this);
        var jWin = $(opt.container);
        var isWin = opt.container == window;

        // force to the top of document to ENSURE that 
        // document absolute positioning is available
        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        // have to make absolute
        el.css("position", "absolute");

        // height is off a bit so fudge it
        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        el.css("top", y + jWin.scrollTop());

        // if specified make callback and pass element
        if (opt.completeHandler)
            opt.completeHandler(this);
    });
}
function showhint(id) {
	document.getElementById(id).className="hintShow";
}
function hidehint(id) {
        document.getElementById(id).className="hint";
}
function debug(msg) {
alert(msg);
}
function loc() {
	return location.href;
}
function echo(str) {
	alert(str);
}
function postajax(div) {
        d = document.getElementById(div);
	if (d!=null) {
        	var st = d.getElementsByTagName("script");
		try {
        		for (var i=0;i<st.length;i++) {
                		eval(st[i].innerHTML);
        		}
		} catch(err) {
		// nopI
		}
	}
}


function bookmark(id,type) {
	$.get("/ajx/bookmark",{id:id,type:type},function(data) { if (data=="OK") { alert("Added to Saved Content."); }});
}
function unbookmark(id,after) {
	$.get("/ajx/unbookmark",{id:id},function(data) { location.href=after; });
}
function rate(id,type,vote) {
	$.get("/ajx/bookmark",{id:id,type:type},function(data) { $('#rating_'+id).html(data); });
}

function toggle_children(id) {
        var x = document.getElementById(id);
        if (x) {
                if (x.style.display=="block") {
                        x.style.display="none";
                } else {
                        x.style.display="block";
                }
        }
}
function openup(id) {
        var z=document.getElementById("cat"+id);
        if (z) {
                var zp = z.getAttribute("parent");
                toggle_children("cat"+zp+"_children");
                openup(zp);
        }
}

function popjax(url,params) {
	if (clb!=null) {
		clearTimeout(clb);
	}
	if (params==null) {
		params={popjax_request:1};
	} else {
		params.popjax_request=1;
	}
	$("#global_popup").hide();
	feed_popup($("#global_popup_loading").html());
	$.post(url,params,function(data) { feed_popup(data); });
	
}
function feed_popup(data) {
	if (data=="DONE") {
		close_global_popup();
		return;
	 }
	$("#global_popup_content").html(data);
	d = document.getElementById("global_popup_content");
        if (d!=null) {
                var st = d.getElementsByTagName("script");
                try {
                        for (var i=0;i<st.length;i++) {
                                eval(st[i].innerHTML);
                        }
                } catch(err) {
                // nopI
                }
        }


	$("#global_popup").show();
	document.getElementById("global_popup").className="popup_shown";
	var cw = $("#global_popup_content").outerWidth();// document.getElementById("global_popup_content").clientWidth;
	$("#global_popup").show();
	$("#global_popup").centerInClient({forceAbsolute:true,container:window,completed:function(el) { alert("cdsd");} });
	$("#global_popup").draggable({ handle: '#window_handle' });
	//start_closer_mon();
}
function centered(ob) {
	alert(ob.id);
}

function start_closer_mon() {
	clb = setTimeout("place_closer()",Math.floor(1000/12));
}

function place_closer() {


	if (document.getElementById("global_popup").style.display!=="none") {
		if ($("#global_popup_closer_button")!=null) {
			$("#global_popup_closer_button").width($("#putb").outerWidth()+17+8);
			clb = setTimeout("place_closer()",Math.floor(1000/12));
		}
	}
}

function recprv(id) {
	popjax("/ajx/recprv",{id:id});
}

function snaprev(filename,id) {
	popjax("/ajx/snaprev",{id:id,filename:filename});
}

function close_global_popup() {
	document.getElementById("global_popup").className="popup_none";
	$("#global_popup").hide();
	$("#global_popup_content").html("");
	document.getElementById("global_popup").className="popup_none";
	if (clb!=null) {
		clearTimeout(clb);
		clb=null;
	}
}
function debug(txt) {
	document.getElementById("debugger").innerHTML=txt;
}
function wind(url,width,height) {
	var w = window.open(url,"neeee","width="+width+",height="+height+",scrolling=yes,scrollbars=yes,status=no");
	w.moveTo((screen.availWidth/2)-(width/2),(screen.availHeight/2)-(height/2));
}
function reportmessage(id) {
	location.href="/members/mail/report_abuse?id="+id;
}
function banuser(id) {
	location.href="/members/banset?id="+id;
}

function selected(name,type,output) {
	var opt = "<ul>";	
	var arr = document.getElementsByTagName(type);
	for (var i=0;i<arr.length;i++) {
		if (arr[i].name==name) {
			if (arr[i].checked) {
				opt+="<li>"+arr[i].getAttribute("label")+"</li>";
			}
		}
	}
	opt+="</ul>";
	document.getElementById(output).innerHTML=opt;
}
	

if(!window.captureEvents) document.onmousemove=getMousePos
if (window.captureEvents) {
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=getMousePos //e should not be defined
}

function getMousePos(e) {
//NS
if (document.layers||document.getElementById&&!document.all) {
	mx = e.pageX
	my = e.pageY
}
//IE
else if (document.all) {
	mx = event.clientX
	my = event.clientY
}
} 
