$(document).ready(function(){
	$('a').click(function(){
				leaving = 0;
				return  true;
			});

	$('input[type=submit]').click(function(){
				leaving = 0;
				return  true;
			});

	$(':button').click(function(){
				leaving = 0;
				return  true;
			});
});

var leaving = 1;
var send_popunder = 1;

function popwindow(showurl, wd, ht) {
	settings = "titlebar=1,toolbar=1,location=1,menubar=1,scrollbars=1,resizable=1,channelmode=0,directories=0,status=1,width=" + wd + ",height=" + ht + ",top=200,left=250";
	window.open(showurl, "test_win1", settings);
}

function leaving_site(){
	if(leaving){
		leaving = 0;
		send_popunder = 0;
		if(function_exists('collect_partial')){
			collect_partial();
		}
		/*
			if(location.href.indexOf('signup_step1.php') == -1 && location.href.indexOf('signup_step1_affs.php') == -1){
				coupon_func(50, 'open');
			}
		*/

		return "You're only minutes away from getting your own website up and running online.\r\nRemember, with reliable web hosting with Justonehost.com you get:\r\n\r\n     	- Top Class Web Hosting\r\n     	- Free Instant Setup\r\n     	- Free Site-Building Tools\r\n     	- Unlimited Disk Space\r\n     	- Unlimited Email Accounts\r\n     	- Best Cpanel\r\n\r\nPlus more than $700 worth of free self installing scripts when you sign up today!  These bonuses are only available for a limited time, so sign up today!";
	}
}


function non_onbeforeunload_browser(){
	if(leaving && send_popunder){
		if(function_exists('collect_partial')){
			collect_partial();
		}
		//popwindow('coupon.html',800,600);
	}
}

window.onbeforeunload = leaving_site;
window.onunload = non_onbeforeunload_browser;

function function_exists(function_name) {
    if (typeof function_name == 'string'){
        return (typeof this.window[function_name] == 'function');
    } else{
        return (function_name instanceof Function);
    }
}

function coupon_func(val, opt){

	if(!val){
		var val = 50;
	}

	if(!opt){
		var opt = 'open';
	}

	if(opt == 'open'){
		//$('#coupon_'+val+'_off').fadeIn().blur();
		g('coupon_'+val+'_off').style.display='block';
		g('overlay').style.display = 'block';
	}else{
		//g('coupon_'+val+'_off').style.display='none';
		$('#coupon_'+val+'_off').fadeOut().blur();
		g('overlay').style.display = 'none';
		g('exit_coupon').value= 'EXIT'+val+'OFF';
	}

	//window.location.hash='body_tag';
	$('html, body').animate({scrollTop:0}, 'slow');
	return true;
}
