// pop-up
function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;

   return w ? w : 0;
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;

   return h ? h : 0;
}




function center(id){
    w = $(id).width();
    h = $(id).height();
    $(id).css('top', getScrollHeight() + $(window).height()/14);
    $(id).css('left', $(window).width()/2-w/2);
}

function popup(url){
    center('#popup');
    show_loader();
    $("#popup > .content").load(url,null,function (){
            center('#popup');
            hide_loader();
        }
    );
    $("#popup").fadeIn(300);
    $('#gray').css('top', getScrollHeight());
    $("#gray").fadeIn(300);
    log(url);
}



function popup_event(event){
	//alert(event.screenX+"---"+event.screenY);
	popup(this.id);	
}
	
function popup_mini(url,event){
	$('#minipopup').css('top', event.pageY);
	$('#minipopup').css('left', event.pageX);
	$("#minipopup").fadeIn(30);
	 $("#minipopup > .content").load(url,null,function (){
	     	
	 	}
	 );
}
function mini(event){
	//alert(event.screenX+"---"+event.screenY);
	
	$('#minipopup').css('top', event.pageY);
	$('#minipopup').css('left', event.pageX);
	$("#minipopup").fadeIn(30);
	
	 $("#minipopup > .content").load(this.id,null,function (){
	     	
	 	}
	 );
}
function popup_close(){
	$("#popup > .content").empty();
    $("#gray").fadeOut(300);
    $("#popup").fadeOut(300);

}
function close_mini(){
	$("#minipopup > .content").empty();
	$("#minipopup").fadeOut(30);
	
	
}


function activateForm(id,el,onready){
	var options  = {
			target: id,
			beforeSubmit: function(){
							return $(id).valid();
						},
			success:function(r,stat){ 
							if (r!='OK')
								alert(r);
							else{
								if ( el == undefined )
									reload('#sidebar');
								else
									reload(el);
								if (onready!=undefined)
									onready(r);
								if (el != '#popup')
									popup_close();
							}
							
							
						}
	};
	$(id).ajaxForm(options);
	
}


function simpleGet(url,callb){
	$.get(url,
		function(data){
			if (data != 'OK')
				alert(data);
			if (callb)
				callb();
		}
	);
}
function toggleCheck(chid,url){
	$.getJSON(url,
			function(data){
				alert(data);
	});
}

function activateAjaxToggle(chid){
	$(chid).click("toggleCheck");	
}



