var ModalWindows = {};

ModalWindows.darkBackgroundScreen;

/**
* Darken the background behind the Modal Window.
*/
ModalWindows.blurBackground = function()
{
	if (!ModalWindows.darkBackgroundScreen)
	{
		ModalWindows.darkBackgroundScreen = document.body.appendChild(document.createElement("div"));
		ModalWindows.darkBackgroundScreen.id = "darkBackgroundScreen";
	}
	ModalWindows.darkBackgroundScreen.style.width = document.documentElement.scrollWidth + "px";
	ModalWindows.darkBackgroundScreen.style.height = ModalWindows.getDocumentHeight() + "px";
	ModalWindows.darkBackgroundScreen.style.display = "block";
}

/**
* Create a blank Modal Window.
*
* @param int width Size in pixels.
* @param int height Size in pixels.
* @param string title Text to display in title bar.
* @return DOMElement
*/
ModalWindows.createModalWindow = function(width, height, title)
{
	var modalWindow = document.createElement("div");
	modalWindow.className = "modalWindow";
	modalWindow.style.width = width + "px";
	modalWindow.style.height = height + "px";
	modalWindow.style.top = ModalWindows.getClientHeight() / 2 - height / 2 + "px";
	modalWindow.style.left = ModalWindows.getClientWidth() / 2 - width / 2 + "px";
	
	var titleBarLeft = modalWindow.appendChild(document.createElement("div"));
	titleBarLeft.className = "titleBarLeft";
	var titleBarLeft_png_ie6_alpha_left = titleBarLeft.appendChild(document.createElement("div"));
	titleBarLeft_png_ie6_alpha_left.className = "png_ie6_alpha_left";
	
	var titleBarRight = titleBarLeft.appendChild(document.createElement("div"));
	titleBarRight.className = "titleBarRight";
	var titleBarRight_png_ie6_alpha_right = titleBarRight.appendChild(document.createElement("div"));
	titleBarRight_png_ie6_alpha_right.className = "png_ie6_alpha_right";
	
	var titleBarCenter = titleBarRight.appendChild(document.createElement("div"));
	titleBarCenter.className = "titleBarCenter";
	var closeButton = titleBarCenter.appendChild(document.createElement("a"));
	closeButton.className = "closeButton";
	closeButton.appendChild(document.createTextNode("X"));
	closeButton.href = "javascript:";
	closeButton.onclick = function() { ModalWindows.focusBackground(); modalWindow.style.display = "none"; return false; };
	titleBarCenter.appendChild(document.createTextNode(title));
	
	var content = modalWindow.content = modalWindow.appendChild(document.createElement("div"));
	content.className = "content";
	
	var footerLeft = modalWindow.appendChild(document.createElement("div"));
	footerLeft.className = "footerLeft";
	var footerLeft_png_ie6_alpha_left = footerLeft.appendChild(document.createElement("div"));
	footerLeft_png_ie6_alpha_left.className = "png_ie6_alpha_left";
	
	var footerRight = footerLeft.appendChild(document.createElement("div"));
	footerRight.className = "footerRight";
	var footerRight_png_ie6_alpha_right = footerRight.appendChild(document.createElement("div"));
	footerRight_png_ie6_alpha_right.className = "png_ie6_alpha_right";
	
	var footerCenter = footerRight.appendChild(document.createElement("div"));
	footerCenter.className = "footerCenter";
	
	return modalWindow;
}

/**
* Restore the background behind the Modal Window.
*/
ModalWindows.focusBackground = function()
{
	if (ModalWindows.darkBackgroundScreen)
	{
		ModalWindows.darkBackgroundScreen.style.display = "none";
	}
}

/**
* Return the height of the browser's viewport.
*
* @return int
*/
ModalWindows.getClientHeight = function()
{
	if (window.innerHeight)
	{
		return window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		return document.documentElement.clientHeight;
	}
	else
	{
		return document.body.clientHeight;
	}
}

/**
* Return the width of the browser's viewport.
*
* @return int
*/
ModalWindows.getClientWidth = function()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		return document.documentElement.clientWidth;
	}
	else
	{
		return document.body.clientWidth;
	}
}

/**
* Return the full height of the web page.
*
* @return int
*/
ModalWindows.getDocumentHeight = function()
{
	return Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
		Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
		Math.max(document.body.clientHeight, document.documentElement.clientHeight));
}

/**
* Display the Job Seeker Login Window.
*/
ModalWindows.launchJobseekerLogin = function()
{
	ModalWindows.blurBackground();
	if (!ModalWindows.jobseekerLogin)
	{
		ModalWindows.jobseekerLogin = document.body.appendChild(ModalWindows.createModalWindow(400, 200, "Login"));
		ModalWindows.jobseekerLogin.content.innerHTML = '<div class="login_page_box"><p class="registration_link"><a href="registerJobseeker.php">Not Registered? Register here.</a></p><form action="login.php?jobseeker" method="post"><label for="login_email">E-mail Address</label><input type="text" class="text" name="login" id="login_email" /><label for="login_password">Password</label><input type="password" class="text" name="password" id="login_password" /><p><a href="forgot_password.php">Forgot Password?</a></p><div class="submit"><button class="green_square_button" type="submit"><span class="green_button_center">Login</span></button></div></form></div>';
	}
	ModalWindows.jobseekerLogin.style.display = "block";
	document.getElementById("login_email").focus();
	return false;
}

/**
* Display the Recruiter Login Window.
*/
ModalWindows.launchEmployerLogin = function()
{
	ModalWindows.blurBackground();
	if (!ModalWindows.jobseekerLogin)
	{
		ModalWindows.recruiterLogin = document.body.appendChild(ModalWindows.createModalWindow(400, 200, "Login"));
		ModalWindows.recruiterLogin.content.innerHTML = '<div class="login_page_box"><p class="registration_link"><a href="products.php">Not Registered? Register here.</a></p><form action="login.php?employer" method="post"><label for="login_email">E-mail Address</label><input type="text" class="text" name="login" id="login_email" /><label for="login_password">Password</label><input type="password" class="text" name="password" id="login_password" /><p><a href="forgot_password.php?employer">Forgot Password?</a></p><div class="submit"><button class="green_square_button" type="submit"><span class="green_button_center">Login</span></button></div></form></div>';
	}
	ModalWindows.recruiterLogin.style.display = "block";
	document.getElementById("login_email").focus();
	return false;
}

/**
* Update the size of the screen after a browser window resize.
*/
/*
ModalWindows.updateBackgroundScreen = function(event)
{
	ModalWindows.darkBackgroundScreen.style.width = document.documentElement.scrollWidth + "px";
	ModalWindows.darkBackgroundScreen.style.height = ModalWindows.getDocumentHeight() + "px";
}
*/
