/***************************/
//@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.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//loading popup with jQuery magic!
function loadFeedback(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupFeedback").fadeIn("slow");
		popupStatus = 1;
	}
}


//loading popup with jQuery magic!
function loadRef(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupRef").fadeIn("slow");
		popupStatus = 1;
	}
}

//loading system with jQuery magic!
function loadSystem(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundSystem").css({
			"opacity": "0.7"
		});
		$("#backgroundSystem").fadeIn("slow");
		$("#popupSystem").fadeIn("slow");
		popupStatus = 1;
	}
}

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

//disabling popup with jQuery magic!
function disableFeedback(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupFeedback").fadeOut("slow");
		popupStatus = 0;
		window.location='template.php?go=home';
	}
}


//disabling popup with jQuery magic!
function disableRef(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupRef").fadeOut("slow");
		popupStatus = 0;
		window.location='template.php?go=home';
	}
}

//disabling system with jQuery magic!
function disableSystem(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundSystem").fadeOut("slow");
		$("#popupSystem").fadeOut("slow");
		popupStatus = 0;
		window.location='template.php?go=home';
	}
}

//disabling system with jQuery magic!
function disableSystemInterview(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundSystem").fadeOut("slow");
		$("#popupSystem").fadeOut("slow");
		popupStatus = 0;
		
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": (windowHeight/5+popupHeight/2)/3,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//centering popup
function centerFeedback(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupFeedback").height();
	var popupWidth = $("#popupFeedback").width();
	//centering
	$("#popupFeedback").css({
		"position": "absolute",
		"top": (windowHeight/5+popupHeight/2)/3,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//centering reference
function centerRef(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupRef").height();
	var popupWidth = $("#popupRef").width();
	//centering
	$("#popupRef").css({
		"position": "absolute",
		"top": (windowHeight/5+popupHeight/2)/3,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//centering reference
function centerSystem(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupSystem").height();
	var popupWidth = $("#popupSystem").width();
	//centering
	$("#popupSystem").css({
		"position": "absolute",
		"top": (windowHeight/5+popupHeight/2)/3,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundSystem").css({
		"height": windowHeight
	});
	
}




//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#terms_cond").click(function(){
		$.validationEngine.closePrompt(".formError",true);
		if($(this).attr('checked'))
		{
			//centering with css
			centerPopup();
			//load popup
			loadPopup();
		}
	});
	
	//Click the interview terms and condition!
	$("#terms_cond_int").click(function(){
		$.validationEngine.closePrompt(".formError",true);
		if($(this).attr('checked'))
		{
			//centering with css
			centerSystem();
			//load popup
			loadSystem();
		}
	});
				
	//CLOSING POPUP
	$("#agree").click(function(){
		disablePopup();
		$("#terms_cond").attr('checked','checked');
	});
	// Close Interview Terms
	$("#agree_interview").click(function(){
		disableSystemInterview();
		$("#terms_cond_int").attr('checked','checked');
	});
	$("#popupInterviewClose").click(function(){
		disableSystemInterview();
		$("#terms_cond_int").attr('checked','');
	});
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
		$("#terms_cond").attr('checked','checked');
	});
	
	//Click the x event!
	$("#popupRefClose").click(function(){ //alert("sdsdsdsd");
		disableRef();
		
	});
	
	//Click the x event!
	$("#popupSystemClose").click(function(){
		disableSystem();
		$("#terms_cond").attr('checked','checked');
	});
	$("#popupContactNo").click(function(){
		disablePopup();
		$("#terms_cond").attr('checked','checked');
	});
	$("#popupRefNo").click(function(){
		disableRef();
		$("#terms_cond").attr('checked','checked');
	});
	$("#popupSystemNo").click(function(){ alert("dsds");
		disableSystem();
		
	});
	$("#popupFeedbackClose").click(function(){
		disableFeedback();
		
	});
	
	
	/*//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});*/
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disableRef();
			disableSystem();
			disableFeedback();
			$("#terms_cond").attr('checked','');
		}
	});

});