//SETTING UP OUR POPUP	//0 means disabled; 1 means enabled;
var popupStatus = 0;
//loading popup with jQuery magic!
function loadExpertPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundExpertPopup").css({	"opacity": "0.7"	});
		$("#backgroundExpertPopup").fadeIn("slow");
		$("#popupExpertSelectQuestionCategory").fadeIn("slow");
		//$("#popupExpertSelectQuestionCategoryArea").innerHTML='...Loading Content...';
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disableExpertPopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundExpertPopup").fadeOut("slow");
		$("#popupExpertSelectQuestionCategory").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerExpertPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupExpertSelectQuestionCategory").height();
	var popupWidth = $("#popupExpertSelectQuestionCategory").width();
	//centering
	$("#popupExpertSelectQuestionCategory").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#backgroundExpertPopup").css({		"height": windowHeight	});
	
}
/*var AJAX_SITE_REQUEST_URL = '';
if(window.location.href.indexOf("vsharma")>0){
	AJAX_SITE_REQUEST_URL = "http://"+window.document.domain+"/bolega/ajax_actions/questions/";
}else if(window.location.href.indexOf("66.148.13.116")>0){		
	AJAX_SITE_REQUEST_URL = "http://" + window.document.domain + "/ajax_actions/user/";
}else{
	AJAX_SITE_REQUEST_URL = "http://"+window.document.domain+"/beta1/ajax_actions/questions/";
}*/
function ExpertDetailLoad(whichCategory) {
	var content_show = whichCategory; //retrieve category of link so we can load subcategories 
	$.ajax({ method: "get",
	   	 url: AJAX_SITE_REQUEST_URL+"experts.php",
		 data: "cid="+content_show ,
		 beforeSend: function(){$("#loading").show("fast");}, //show loading just when link is clicked
		 complete: function(){ $("#loading").hide("fast");}, //stop showing loading when the process is complete
		 success: function(html){ //so, if data is retrieved, store it in html
					$("#selectExpertsCategoryContent").html(html); //animation
			 }
	});
}
function ExpertLoadSubCategories(whichCategory) {
	var content_show = whichCategory; //retrieve category of link so we can load subcategories 
	AJAX_SITE_REQUEST_URL+"selectExpertCategoryBox.php";
	$.ajax({	method: "get",
		   		//url: AJAX_SITE_REQUEST_URL+"selectExpertCategoryBox1.php",
		   		url: AJAX_SITE_REQUEST_QNA_URL+"selectExpertCategoryBox1.php",
				
				data: "cid="+content_show ,
			//	beforeSend: function(){$("#loading").show("fast");}, //show loading just when link is clicked
				//complete: function(){ $("#loading").hide("fast");}, //stop showing loading when the process is complete
				success: function(html){ //so, if data is retrieved, store it in html
					$("#popupExpertSelectQuestionCategoryArea").show("slow"); //animation
					$("#popupExpertSelectQuestionCategoryArea").html(html); //show the html inside .content div
					//document.getElementById("popupExpertBreadCrumb").innerHTML = document.getElementById("popupExpertCategoryBreadCrumb").innerHTML;
					document.getElementById("popupExpertFinalCategory").innerHTML = $("#selectedExpertCategoryName").text();
						if($("#selectedExpertCategoryName").text()==""){
							$("#selectQuestionExpertCategoryTxt").text("Select Category:");
						}else{
							$("#selectQuestionExpertCategoryTxt").text("Edit:");
						}
					document.getElementById("popupExpertFinalCategoryId").value = $("#selectedExpertCategoryID").text();
				}
	});
}
$(document).ready(function(){
	// Loading Popup	// On Click selectQuestionCategory
	$("#selectExpertsCategory").click(function(){	//load popup
		if(document.getElementById("popupExpertFinalCategoryId")){
			whichCategory=document.getElementById("popupExpertFinalCategoryId").value; }else{ whichCategory=0;}
			centerExpertPopup();	loadExpertPopup();		ExpertLoadSubCategories(whichCategory);
	});
	
	$("#selectExpertQuestionCategory").click(function(){	//load popup
		if(document.getElementById("popupExpertFinalCategoryId")){
			whichCategory=document.getElementById("popupExpertFinalCategoryId").value; }else{ whichCategory=0;}
			centerExpertPopup();	loadExpertPopup();		ExpertLoadSubCategories(whichCategory);
	});
	//CLOSING POPUP	//Click the x event!
	$("#popupExpertSelectQuestionCategoryClose").click(function(){	
							if(document.getElementById("popupExpertFinalCategoryId")){		whichCategory=document.getElementById("popupExpertFinalCategoryId").value; }else{ whichCategory=0;}
							ExpertDetailLoad(whichCategory);   disableExpertPopup();	
						});
	$("#popupExpertSelectQuestionCategoryDone").click(function(){	
							if(document.getElementById("popupExpertFinalCategoryId")){		whichCategory=document.getElementById("popupExpertFinalCategoryId").value; }else{ whichCategory=0;}
							ExpertDetailLoad(whichCategory);	disableExpertPopup();	});
	//Click out event!
	$("#backgroundExpertPopup").click(function(){		ExpertDetailLoad(whichCategory); disableExpertPopup();	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			ExpertDetailLoad(whichCategory); disableExpertPopup();
		}
	});
});
