// JavaScript Document

var changed = false;


/*var preload = Array("../images/banner_2_03.jpg", 
					"../images/banner_2_04.jpg", 
					"../images/banner_2_05.jpg", 
					"../images/banner_2_06.jpg");

for (i = 0; i < preload.length; i++)
{
	tmp_pic = new Image();
	tmp_pic.src = preload[i];
}*/

function set_focus (id)
{
	var elem = document.getElementById(id);
	
	if (elem)
	{
		elem.focus();
	}
}

last_elem_name = "";
function border_focus (name)
{
	var elem = document.getElementsByName(name).item(0);
	var last_elem = document.getElementsByName(last_elem_name).item(0);
	
	if (last_elem)
	{
		last_elem.style.borderColor = "#999999";
		last_elem.style.color = "#333333";
	}
		
	if (elem)
	{
		elem.style.borderColor = "#005fa9";
		elem.style.color = "#000000";
		last_elem_name = name;
	}
}

var popUpWin=0;
function pop_up (URLStr, left, top, width, height)
{
  	if(popUpWin)
	{
		if(!popUpWin.closed) popUpWin.close();
  	}
	popUpWin = window.open(URLStr, 'popUpWin', 'toolbar=0,location=no,directories=0,statusbar=0,menubar=no,scrollbar=0,resizable=0,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

last_id = 0;
function row_hover(id)
{
	var last_row = document.getElementById(last_id);
	var row = document.getElementById(id);
	
	if (last_row)
	{
		//last_row.style.background = "transparent";
		last_row.style.cursor = "";
	}
	
	if (row)
	{
		//row.style.background = "#f6f6f6";
		row.style.cursor = "hand";
		row.style.cursor = "pointer";
			
		last_id = id;
	}
}

function toggle_row (row)
{
	var box = document.getElementById("cb_" + row.id);
	
	if (box.checked)
	{
		box.checked = false;
		row.style.background = "white";
		
	}
	else
	{
		box.checked = true;
		row.style.background = "#EEEEEE";
	}
}

function confirm_delete ()
{
	var del = confirm("Are you sure you want to delete this?\n\nOnce deleted, it is NON-RECOVERABLE and is removed from the system entirely.");
	
	if (del)
	{
		reset_change();
		return true;
	}
	else
		return false;
}

function confirm_flush ()
{
	return confirm("Are you sure you want to remove all records?\n\nThis is a NON-RECOVERABLE action and is removed from the system entirely.");
}

function confirm_submit ()
{
	if (confirm("Are you sure you want to submit this puzzle?"))
	{
		document.getElementById("submit_seconds").value = sec;
		document.getElementById("submit_minutes").value = mn;
		document.getElementById("submit_hours").value = hr;
		
		if (check_puzzle())
		{
			puzzle_changed = false;
			document.getElementById('puzzle_form').submit();
		}
		else
		{
			alert("Puzzle is not complete!");
			return false;
		}
	}
	else
		return false;
}

function redirect (url)
{
	document.location.href = url;
}

function lead (x)
{
	y=(x>9) ? x : '0' + x;
	
   	return y;
}

function mark_change ()
{
	changed = true;	
}