var content
var board_colour
var board_name
var board_fontColour
var board_size


function uppercase(field)
{
	var name = field.value.toUpperCase()
	field.value = name
}


// initialises the text colour of the board
function letterColour(mycolour)
{
	board_fontColour = mycolour
}


// initialises the board colour
function boardColour(myboard)
{
	board_colour = myboard
}


// check if the radios and text field has values in them
function check(myform2)
{
	var count = 0;
	
	for (var i = 0; i < myform2.board.length; i++)
	{
		if (myform2.board[i].checked)
		{
			count++
		}
	}
	
	for (var j = 0; j < myform2.text.length; j++)
	{
		if (myform2.text[j].checked)
		{
			count++
		}
	}
	
	if (count < 2)
	{
		alert('Please choose a board and lettering colour')
		return false
	}
	
	if (myform2.name.value == "")
	{
		alert('Please enter a name for the board')
		return false
	}
	
	return checkDesign(myform2);	
}

// check if the board and font colour designs are compatible, does not allow black text on black boards etc..
function checkDesign(form)
{
	if ((form.board[0].checked) && (form.text[3].checked))
	{
		alert ('This design is not allowed, Please try again');
		return false;
	}
	
	if ((form.board[1].checked) && (form.text[4].checked))
	{
		alert ('This design is not allowed, Please try again');
		return false;
	}
	
	if ((form.board[2].checked) && (form.text[5].checked))
	{
		alert ('This design is not allowed, Please try again');
		return false;
	}
	
	if ((form.board[2].checked) && (form.text[0].checked))
	{
		alert ('This design is not allowed, Please try again');
		return false;
	}
	
	else 
	{
		return boardSize();
	}
	
}


// retrives the value on the boardname on the text field and assigns a 
// size to the board by retrieving the length properties of the text field value
// it also determines what board will be displayed by assigning a value to the "content" variable
function boardSize()
{
	board_size = document.forms[0].name.value.length
	board_name = document.forms[0].name.value
	
	if (board_size <= 5)
	{
		content = '<html>'
		content += '<head><title>Southcoast Nameboards</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>'
		content += '<body bgcolor="#FFFFFF"><div align="center">  <table width="190" height="51" border="0" cellpadding="0" cellspacing="0">'
		content += '<tr><td background="../../images/boards/' + board_colour + '5.gif"><div align="center"><strong><font color="#' + board_fontColour + '" size="6" face="Arial">' + board_name + '</font></strong></div></td></tr>'
		content += '</table><p><font face="Arial" size="2"><b><font color="#0000FF">[ <a href="javascript:window.close()">close window</a> ]</font></b></font></p>'
		content += '</div></body>'
		content += '</html>'
	}
	
	if ((board_size > 5) && (board_size <= 10))
	{
		content = '<html>'
		content += '<head><title>Southcoast Nameboards</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>'
		content += '<body bgcolor="#FFFFFF"><div align="center">  <table width="310" height="51" border="0" cellpadding="0" cellspacing="0">'
		content += '<tr><td background="../../images/boards/' + board_colour + '10.gif"><div align="center"><strong><font color="#' + board_fontColour + '" size="6" face="Arial">' + board_name + '</font></strong></div></td></tr>'
		content += '</table><p><font face="Arial" size="2"><b><font color="#0000FF">[ <a href="javascript:window.close()">close window</a> ]</font></b></font></p>'
		content += '</div></body>'
		content += '</html>'
	}
	
	if ((board_size > 10) && (board_size <= 15))
	{
		content = '<html>'
		content += '<head><title>Southcoast Nameboards</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>'
		content += '<body bgcolor="#FFFFFF"><div align="center">  <table width="410" height="51" border="0" cellpadding="0" cellspacing="0">'
		content += '<tr><td background="../../images/boards/' + board_colour + '15.gif"><div align="center"><strong><font color="#' + board_fontColour + '" size="6" face="Arial">' + board_name + '</font></strong></div></td></tr>'
		content += '</table><p><font face="Arial" size="2"><b><font color="#0000FF">[ <a href="javascript:window.close()">close window</a> ]</font></b></font></p>'
		content += '</div></body>'
		content += '</html>'
	}	
	
	deadWindow("",445,120)	
}



// this function initiates the values of the new window and when opened centres the window on the screen
function deadWindow(url,mywidth,myheight)
{
	
	
	var iMyWidth;
	var iMyHeight;
	//gets top and left positions based on user's resolution so hint window is centered.
	iMyWidth = (window.screen.width/2) - ((mywidth/2) + 10); //half the screen width minus half the new window width (plus 5 pixel borders).
	iMyHeight = (window.screen.height/2) - ((myheight/2) + 50); //half the screen height minus half the new window height (plus title and status bars).
	var win2 = window.open(url,"Window3","status,height=" + myheight + ",width=" + mywidth + ",resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=no,titlebar=no");
	win2.focus();
	display(win2)
}


// displays the design of the board in the new window
function display(win2)
{
	var newWindow = win2	
	newWindow.document.write(content)
}