//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
//loading popup with jQuery magic!

function loadPopup1(id,user){

//loads popup only if it is disabled
if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupContact").fadeIn("slow"); 
$("#popupContact").load("./view_video.php?id="+id);
popupStatus = 1;
}
}
function loadPopup2(){

//loads popup only if it is disabled
if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupContact").fadeIn("slow"); 
$("#popupContact").load("./add_newsletter_category.php");
popupStatus = 1;
}
}

function loadPopup3(id,option){

//loads popup only if it is disabled

if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupContact").fadeIn("slow"); 
$("#popupContact").load("./add_newsletter_category.php?id="+id+"&option="+option);
popupStatus = 1;
}
}
//disabling popup with jQuery magic!
function disablePopup(obj){
	//alert(obj);
	//alert(obj.value);
	//alert(obj.getElementById('60').value);
//disables popup only if it is enabled
//document.getElementById('edit-recipient').value = "dddddd";
if(popupStatus==1){
$("#backgroundPopup").fadeOut("slow");
$("#popupContact").fadeOut("slow");
popupStatus = 0;
//location.reload(true);
}

}
function disablePopup(){
	
if(popupStatus==1){
$("#backgroundPopup").fadeOut("slow");
$("#popupContact").fadeOut("slow");
popupStatus = 0;
//location.reload(true);
}

}
function disablePopup1(id,imgid,greenid){
//	alert(id);
//alert( document.getElementById('text1').value);	
var inpVal = parseInt(document.getElementById('text1').value, 10);
        if (isNaN(inpVal)) {
		document.getElementById('warning').innerHTML = "Please enter a valid number";
		return false;
		}
		else {
		document.getElementById(id).value =  document.getElementById('text1').value;
		document.getElementById(imgid).style.display = "block";
		document.getElementById(greenid).style.display = "none";
		}

// alert(document.getElementById(id).value);
if(popupStatus==1){
$("#backgroundPopup").fadeOut("slow");
$("#popupContact").fadeOut("slow");
popupStatus = 0;
//location.reload(true);
}

}

//centering popup
function centerPopup(){
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $("#popupContact").height();
var popupWidth = $("#popupContact").width();
//centering
scroll(0,0);
//alert(document.documentElement.clientHeight);
//alert(document.body.clientHeight);
//alert(document.documentElement.clientHeight);
//alert(window.innerHeight);
$("#popupContact").css({
"position": "absolute",
"top": windowHeight-height/2-popupHeight/2,
"left": windowWidth/4-popupWidth/4
});

//only need force for IE6

$("#backgroundPopup").css({
"height": windowHeight,
"width": windowWidth
});

}
function change_stat(id)
{ 
  type="addgroups";//alert(base);
  centerPopup();  
  loadPopup1(id);  
}
function add_category()
{ 
  type="addgroups";//alert(base);
  centerPopup();  
  loadPopup2();  
}
function edit_category(id,option)
{
type="addgroups";//alert(base);
  centerPopup();  
  loadPopup3(id,option);
}
function add_groups(uid,c_id,g_ids,path,base)
{ 
  type="addgroups";//alert(base);
  centerPopup();  
  loadPopup1(uid,c_id,g_ids,path,type,base);  
}
function edit_groups(uid,c_id,g_ids,path,base)
{
  type="editgroups";//alert(base);
  centerPopup();  
  loadPopup1(uid,c_id,g_ids,path,type,base);   

}

$(document).ready(function(){
$(document).keypress(function(e){
if(e.keyCode==27 && popupStatus==1){
disablePopup();
}
});
})



