var screenW = 640, screenH = 480;
var winW = 630, winH = 460;

//On Document Ready:
$(function () {
	//Set the screenW / screenH, winW and WinH variables:
	//getWindowDimensions();
	hideAllModals();
	//Opening Modals: 
	$('#popup').live('click', function () {
		//Provide it with the form name, or use an attribute with the name in it. 
		var theForm = "specificModalID";

		//To change values in the form: 
		//$('elementIdentifier').val('value').attr('selected', true);

		/*	Use this function to cause a postback to an update panel. 
		------------------------------------------------------------------
		# You can Access the EventArgs String in the codebehind using:
		#Request.Params.Get("__EVENTARGUMENT")
		*/
		//__doPostBack('updatePanelID', EventArgsStringOrEmptyString);

		showModal(theForm);
		return false;


	});

	//Closing Modals
	//--------------------------------------------------------
	$('div.modalBackground').live('click', function () {
		hideAllModals();
	});
});


//Screen Size Functions
//**********************

function getWindowDimensions() {
	if (parseInt(navigator.appVersion) > 3) {
		screenW = screen.width;
		screenH = screen.height;
	}
	else if (navigator.appName == "Netscape"
			&& parseInt(navigator.appVersion) == 3
			&& navigator.javaEnabled()
		 ) {
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
		screenH = jScreenSize.height;
	}
	if (document.body && document.body.offsetWidth) {
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
	}
	if (document.compatMode == 'CSS1Compat' &&
    document.documentElement &&
    document.documentElement.offsetWidth) {
		winW = document.documentElement.offsetWidth;
		winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	} 
}

//Modal Form Functions
//**********************

function showModal(theForm) {
	getWindowDimensions();
	$('div.modalBackground').show()
	$('div.modalBackground').animate({ 'opacity': .6 }, 300, function () { });
	$('div.aModal.' + theForm).css('top', winH / 2 - $('div.aModal.' + theForm).height() / 2);
	$('div.aModal.' + theForm).css('left', winW / 2 - $('div.aModal.' + theForm).width() / 2);
	$('div.aModal.' + theForm).show();
	$('div.aModal.' + theForm).animate({ 'opacity': 1 }, 300, function () { });
}

function hideAllModals() {
	$('div.aModal').animate({ 'opacity': 0 }, 300, function () { $('div.aModal').hide(); });
	$('div.modalBackground').animate({ 'opacity': 0 }, 300, function () { $('div.modalBackground').hide(); });
}
