//popup functions

/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.85",
			"background-color": "#FFFFFF"
		});
		
		$("#backgroundPopup").show();
		$("#popup").show();
		popupStatus = 1;
	}
	
	
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").hide();
		$("#popup").hide();
		popupStatus = 0;
	}
	
	file_list.deselectAll();
}

//centering popup
function centerPopup(){

	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	//centering
	$("#popup").css({
		"position": "fixed",
		//"top": (windowHeight/2-popupHeight/2) - 30,
		"top": "25%",
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}



//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {
	
	//LOADING POPUP
	//Click the button event!
	$("#files_popup_delete").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#upload").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	
	$("#files_popup_email").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
		
		
	$("#files_popup_move").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#groups_invite").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#groups_invite_side").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#new_announcement").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#new_news").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#delete_announcement").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#delete_post").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#view_employee_data").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
		
		
			
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupXClose").click(function(){
		disablePopup();
	});
	
	//Click out event!
	//$("#backgroundPopup").click(function(){
	//	disablePopup();
	//});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

















function hideDiv( id )
{
//	alert(id);
// document.getElementById(id).style.display='none';
 

 //document.getElementsByTagName("body")[0].removeChild(document.getElementById(id));
	//$(id).remove();
	//$('#'+id).remove();;
	$('#'+id).hide();
}

function get_div( id , flag , callback)
{

 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
   {
 	  alert ("Your browser does not support AJAX!");
		 return;
 	 } 
	 var url="/popup.php";
	 url=url+"?action="+id+"&flag="+flag+"&sid="+Math.random();
	 xmlHttp.onreadystatechange=function()
	 {
	 	 		 if (xmlHttp.readyState==4)
				 {
	
				 var popup = document.createElement('div');
				 popup.id = id;

				 popup.style.position="fixed";
				// popup.style.backgroundColor = "#FFFFFF";
				// popup.style.border="1px solid #B80000";
				 popup.style.left='32%';
				 popup.style.top='29%';
				 popup.style.width='300px';
				 popup.style.align='center';
		   	 	 
				 popup.innerHTML=xmlHttp.responseText;
				 
				 //document.getElementsByTagName("body")[0].appendChild(popup);
				 $(popup).show();
				 //$('#files_box').append(popup);
				 eval(callback);
				 }
	 
	 }
	 xmlHttp.open("GET",url,true);
	 xmlHttp.send(null);

}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
  


