/* 

	JavaScript Document

	Jayvin Duong
	
*/

// Generates a random image to used for the header.
function displayHeaderImage() {
	
	// Defines the maximum number of images that can be used.
	var backgroundImages = 4;
	
	// Generate a random number between 0-3 and add one.
	var image_choice = Math.floor(Math.random() * backgroundImages) + 1;
	
	// Display image.
	document.getElementById("header-left").style.background = "url(/images/head"+image_choice+".jpg) no-repeat";
}

// Displays the hidden text area and hides the "Was this page helpful" and radio buttons.
function displayCommentTextArea(choice) {

	// Hide the "Was this page helpful" and radio buttons.
	document.getElementById("select_suggestion").style.display = "none";
	
	// Display the textarea using JQuery.
	$("#submission").slideToggle();

	// Determine if the user selected either yes or no.
	if (choice == "Y") {
		document.getElementById("comment_id").innerHTML = "What did you like about the page?";
	}
	
	else {
		document.getElementById("comment_id").innerHTML = "What didn't you like about the page?";
	}

}

// Display hidden block elements.
function display() {
    $(".hide").slideToggle('slow');
}

// Display hidden block elements with a parameter to identify which block needs to be displayed.
function display(blockID) {
    $("."+blockID).slideToggle('slow');
}

// -------------  Show live page

function show_live_page() {
	
	// Get URL string.
	var preURL = location.href;
	var liveURL = "http://nrh.ca"+preURL.substring(27);
	
	// Display the current page from the staging server to the live server.
	window.location = liveURL;
}

// -------------  Show staging server page

function show_staging_page() {
	
	// Get URL string.
	var liveURL = location.href;
	var preURL = "http://nrh.niagararegion.ca"+liveURL.substring(13);
	
	// Display the current page from the live page to the staging server page.
	window.location = preURL;
}

document.onkeyup = KeyCheck;

var www_pressed = 0; // counts www

var pre_pressed = 0; // counts PRE

var how_many_keys_pressed = 0; // For form codes


function KeyCheck()
{
	var KeyID = window.event.keyCode;
	
	if (KeyID == 87 && www_pressed == 0)
	{
		++www_pressed;
	}

	else if (KeyID == 87 && www_pressed == 1)
	{
		++www_pressed;
	}

	else if (KeyID == 87 && www_pressed == 2)
	{
		++www_pressed;
	}
	else
	{
		www_pressed = 0;
	}
	if (www_pressed == 3) {
		show_live_page();
		www_pressed = 0;
	}
	
	

	if (KeyID == 80 && pre_pressed == 0)
	{
		++pre_pressed;
	}

	else if (KeyID == 82 && pre_pressed == 1)
	{
		++pre_pressed;
	}

	else if (KeyID == 69 && pre_pressed == 2)
	{
		++pre_pressed;
	}
	
	if (pre_pressed == 3) {
		show_staging_page();
		pre_pressed = 0;
	}
}

