var xrate = new ExitRate();

// TODO. Set true to open rates in new window, false to open in same window.
xrate.newwindow = false;

// TODO. Optional. Change new window properties, if needed.
xrate.newwindowproperties = 'width=800,height=600,top=10,left=10,screenX=0,screenY=10';

// TODO. Replace these examples with the corresponding URLs on your website.
 xrate.targetpage = {
	'mortgagerates':{'url': 'http://www.mortgage-refinance.info/mortgage-refinance.php'},
	'homefinance':{'url': 'http://www.mortgage-refinance.info/mortgage-refinance.php'}
};

// TODO. Map values as shown in the comments. If no mapping is necessary,
// xrate.valuemap = {} should be used.
xrate.valuemap = {};

// TODO. Suppress triggering offer for these HTML tags.
xrate.pageoverride = ['a','input','button'];

// TODO. Insert user submitted values for these variables. If values are
// not available, empty strings can be used.
xrate.loantype = '';
xrate.loanamount = '';
xrate.state = '';
xrate.zipcode = '';
xrate.ltv = '';
xrate.credit = '';

$(document).ready(function(){
	 $(document).keypress(function(){xrate.resetTimer();return true;});
     $(document).mousedown(function(){xrate.resetTimer();return true;});
        var n = xrate.pageoverride.length;
        for (var i = 0; i < n; i++) {
            $(xrate.pageoverride[i]).mousedown(function(){xrate.toggle = 0;});
            $(xrate.pageoverride[i]).keydown(function(){xrate.toggle = 0;});
        }xrate.resetTimer();
	
	$('#compare').submit(function(){
		window.scrollTo(0,0);
		var typeOfLoan = $('#type').val();
		var stateCode = $('#state').val();
		var homeType = $('#hometype').val();
		var creditScore = $('#creditscore').val();

		
		xrate.state = stateCode;
		xrate.loantype = typeOfLoan;
		xrate.credit = creditScore;
		
	
		$('#overlayDiv').html('').append($('<div>',{id:'overlayExit'}).html('X').click(showOverlay));
		$('<iframe />', {
				'name': 'frame1',
				'src': 'http://x.xertp.com/cgi/r?;n=203;c=699476;s=11075;x=7936;f=201010211545250;u=j;z=TIMESTAMP;'+
					   'service='+ typeOfLoan +
					   '&propertyStateCode=' + stateCode +
					   '&propertyDesc=' + homeType +
					   '&credit_rating=' + creditScore +
					   '&c_border_color=white',
				'height': 630,
				'width': 530}).appendTo('#overlayDiv');
		
		$('#overlay').show();
		$("#overlayDiv").fadeIn('slow');
		return false;	
	});	
	
});
  
$(window).load(function(){
	$.getDocHeight = function(){
		return Math.max(
			$(document).height(),
			$(window).height(),
			/* For opera: */
			document.documentElement.clientHeight
			);
	};	
	$("#overlay").css('height', $.getDocHeight());	
	$("#overlay").click(showOverlay);
});

showOverlay = function(){
	xrate.showNewWindow();
	$("#overlay").fadeOut();
	$("#overlayDiv").fadeOut();
}
