/***************************/
//@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;
var ratesPopupStatus = 0;
var returnStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(document.getElementById("typeOfLoan")[document.getElementById("typeOfLoan").selectedIndex].value != "REFI") returnStatus = 1;
	if(document.getElementById("propertyDesc")[document.getElementById("propertyDesc").selectedIndex].value != "0") returnStatus = 1;
	if(document.getElementById("credit_rating")[document.getElementById("credit_rating").selectedIndex].value != "1") returnStatus = 1;

	if(returnStatus == 1) return true;

	if(popupStatus==0){
		$("#popupContact").fadeIn("fast");
		popupStatus = 1;
	}
}

//loading popup with jQuery magic!
function loadRates(){
	//loads popup only if it is disabled
	if(returnStatus == 1) return true;

	$("#terms_swf").fadeOut("fast");

	$("#backgroundPopup").css({
		"opacity": "0.5"
	});

	if(ratesPopupStatus==0){
		$("#popupRates").fadeIn("fast");
		$("#popupRatesBottom").fadeIn("fast");
		$("#popupRatesLeft").fadeIn("fast");
		$("#popupRatesRight").fadeIn("fast");
		$("#popupRatesTop").fadeIn("fast");
		$("#popupRatesXout").fadeIn("fast");
		$("#backgroundPopup").fadeIn("fast");
		ratesPopupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	return false;
}

//disabling popup with jQuery magic!
function disableHardRatesPopup(){
	//disables popup only if it is enabled
	if(ratesPopupStatus==1){
		$("#popupRates").fadeOut("slow");
		$("#popupRatesBottom").fadeOut("slow");
		$("#popupRatesLeft").fadeOut("slow");
		$("#popupRatesRight").fadeOut("slow");
		$("#popupRatesTop").fadeOut("slow");
		$("#popupRatesXout").fadeOut("slow");
		$("#backgroundPopup").fadeOut("slow");
		ratesPopupStatus = 0;
		document.cookie = "JQ_rates=1; domain="+cookieDomain+"; path=/;";

		setTimeout('$("#terms_swf").fadeIn("fast"); historyChange();', 500);
	}
}

//disabling popup with jQuery magic!
function disableSoftRatesPopup(){
	//disables popup only if it is enabled
	if(ratesPopupStatus==1){
		$("#popupRates").fadeOut("slow");
		$("#popupRatesBottom").fadeOut("slow");
		$("#popupRatesLeft").fadeOut("slow");
		$("#popupRatesRight").fadeOut("slow");
		$("#popupRatesTop").fadeOut("slow");
		$("#popupRatesXout").fadeOut("slow");
		$("#backgroundPopup").fadeOut("slow");
		ratesPopupStatus = 0;

		setTimeout('$("#terms_swf").fadeIn("fast"); historyChange();', 500);
		
	}
}

//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/2-popupHeight/2,
		"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!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	$("#popupRatesXout").click(function(){
		disableHardRatesPopup();
	});

	//$("#backgroundPopup").click(function(){
		//disableSoftRatesPopup();
	//});
});

