/**
* @version	$Id: easydns.page.js 797 2007-12-18 18:52:16Z awyld $
* @author Andrew Wyld <awyld@easydns.com>
* @category javascript
* @copyright Copyright (c) 2007, EasyDNS Technologies Inc.
*/

var PAGE = null;
var busyTimer = null;
var blockedFlag = false;

function Page() {	 
	/**
	* PROPERTIES
	*/
	this.ready = false;
	this.proplist = new Array({
		'url': null,
		'host': null,
		'proto': null,
		'user_ip': null,
		'script_name': null,
		'forms': null,
		'form_count': 0,
		btn_next: '#btnNext',
		'form_action': null,
		'error_box': '#error',
		'images_url': null
	});

	/**
	* METHODS
	*/
	this.set = Page__set;
	this.get = Page__get;
	this.block = Page__block;
	this.unblock = Page__unblock;
	this.busy = Page__busy;
	this.unbusy = Page__unbusy;

	/**
	* INITIATIZATION
	*/
	this.set('url', location.href);
	this.set('host', location.host);
	this.set('proto', location.protocol);

	var dynamic_dir = this.get('proto')+'//'+this.get('host')+'/js/specific/';
	this.set('dscript_root', dynamic_dir);
	// jQuery('.block_onload').blockUI();
	var nextbtn = jQuery('.positive');
	if(nextbtn.length == 1) {
		this.set('next_btn', nextbtn[0].id);
	}

	// jQuery.ajaxStop(jQuery.unblockUI);
};

function Page__set(key, value) {
	this.proplist[key] = value;
	return true;
};

function Page__get(key) {
	try {
		return this.proplist[key];
	} catch(e) {
		return fail(e);
	}
};

function Page__block(pattern, msg) {
	if(isIE()) {
		return true;
	}

	if(msg == null) {
		msg = 'Please wait';
	}

	if(blockedFlag) {
		warn('Duplicate block attempt caught');
		return false;
	}

	try {
		jQuery(pattern).block('<h1 id="busy_box">'+msg+'...</h1>', { border: '2px solid #9CA9FF' });
		blockedFlag = true;
	} catch(e) {
		return fail(e);
	}
	return true;
};

function Page__unblock(pattern, unblock) {
	jQuery(pattern).unblock();
	blockedFlag = false;
	return true;
};

function Page__busy(msg) {
	if($.browser.msie) {
		return true;
	}

	try {

		if(msg == null) {
			msg = 'Please wait...';
		}
		// busyTimer  = setTimeout('jQuery.unblockUI()', 2000);		
		jQuery.blockUI('<h1 id="busy_box">'+msg+'</h1>', { border: '2px solid #9CA9FF' });
	} catch(e) {
		return fail(e);
	}

	return true;
};

jQuery.fn.busy = function () {
	Page__busy();
};

function Page__unbusy() {
	jQuery.unblockUI();
	try {
		if(busyTimer != null) {
			clearTimeout(busyTimer);
		}
	} catch(e) {
		return fail(e);
	}

	return true;
};

jQuery(document).ready(function () {
	jQuery.blockUI.defaults.timeout = 5000;
	try {
		jQuery.blockUI.defaults.message = '<h1 id="busy_box"><span>Please wait...</span><br><img src="../images/busy2.gif"></h1>';
		//jQuery.blockUI.defaults.message = $('#busy_box');
		jQuery.blockUI.defaults.css.border = '3px solid #454F7C';
		jQuery.blockUI.defaults.css.color = '#92C000';
		jQuery.blockUI.defaults.css.textAlign = 'center';
		jQuery.blockUI.defaults.overlayCSS.backgroundColor = '#92C000';
		jQuery.blockUI.defaults.fadeIn = 500;
		jQuery.blockUI.defaults.fadeOut = 900;
		jQuery.blockUI.defaults.overlayCSS.opacity = '0.3';
		PAGE = new Page();
		jQuery.PAGE = PAGE;

	} catch(e) {
	}
});

/*
jQuery(document).unload(function () {
	try {
		var busy_timer = jQuery.PAGE.get('busy_timer');
		if(busy_timer != null) {
			log('Clearing stale busy timer', LOG_PAGE);
			clearTimeout(busy_timer);
		}
	} catch(e) {
		return fail(e);
	}


});
*/

