﻿//Selects the submit button depending on what control is selected
function doClick(buttonName, e) {
	var key;

	if(window.event)
		key = window.event.keyCode;	//IE
	else
		key = e.which;							//Firefox

	if (key == 13) {
		//Get the button the user wants to have clicked
		var btn = document.getElementById(buttonName);
		
		//If we find the button click it
		if (btn != null) {
			btn.click();
			event.keyCode = 0
		}
	}
}

function showArticle(container) {
    articlelength = container.getElementsByTagName('div').length;
    bodyCopy = container.getElementsByTagName('div')[articlelength-1];
    if (bodyCopy.style.display != "block") {
        bodyCopy.style.display = "block";
    } else {
        bodyCopy.style.display = "none";
    }
}

function hideArticle(container) {
    articlelength = container.getElementsByTagName('div').length;
    bodyCopy = container.getElementsByTagName('div')[articlelength-1];    
    bodyCopy.style.display = "none";
}

function popBox(boxName) {

if( window.innerHeight && window.scrollMaxY ) // Firefox 
{
pageWidth = window.innerWidth + window.scrollMaxX;
pageHeight = window.innerHeight + window.scrollMaxY;
}
else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
{
pageWidth = document.body.scrollWidth;
pageHeight = document.body.scrollHeight;
}
else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
{ 
pageWidth = document.body.offsetWidth + document.body.offsetLeft; pageHeight = document.body.offsetHeight + document.body.offsetTop; 
}
	document.getElementById('screenBox').style.height = pageHeight + 'px';
	document.getElementById('screenBox').style.display = 'block';
	document.getElementById(boxName).style.left = ((pageWidth/2) - 325) + 'px';	
	document.getElementById(boxName).style.display = 'block';	
}

function hideBox(closeLink) {
	closeLink.parentNode.parentNode.style.display = 'none';
	document.getElementById('screenBox').style.display = 'none';
}

//Check the user's age for being 21 or above
function AgeCheck(controlToCheck) {
	var err = "Sorry, you must be at least 21 years of age to take the WineAnswers.com quiz.";
	var obj = document.getElementById(controlToCheck);

	if (obj.value.replace(/^\\s+|\\s+$/g,'') != ""		//Check for empty value
		&& parseFloat(obj.value,10)==(obj.value*1)			//Check for input being a digit
		&& obj.value.replace(/^\\s+|\\s+$/g,'') > 20) {	//Validate the age
	} else {
		alert(err);
		obj.focus();
		return false;
	}
}