function showHint(hintURL) {
	var winHint = window.open(hintURL,'win','top=100,left=100,width=600,height=400,resizable=yes');
	winHint.focus();
}

function checkAnswer() {
	// this routes user to answer page - 
	// with a qid if it's the right answer
	//
	// also check to see if any have been checked - and warn accordingly
	var clicked = 0;
	var correct = 0;
	var radios = document.forms.answers.answerCd;
	for ( var i = 0; i < radios.length; i++ ) {
		if (radios[i].checked) {
			// they did choose an answer
			clicked  = 1;
			if (radios[i].value == 1) {
				// they chose the right answer
				correct = 1;
			}
			break;
		}
	}
	
	// warn if no option chosen
	if (!clicked) {
		alert('Please choose an answer');
		return false;
	} 
}

function toggle_ans(n){
	hints  = document.getElementById('hideShowHint');
	
	n.innerHTML = (n.innerHTML.indexOf('Show')!=-1) ? n.innerHTML.replace('Show','Hide') : n.innerHTML.replace('Hide','Show');
	
	if((n.parentNode.className.indexOf('vShow') == -1) && (n.parentNode.className.indexOf('vHide') == -1)){
		n.parentNode.className+=' vShow';
		hints.style.display = 'block';
	}
	else if(n.parentNode.className.indexOf('vShow') != -1){
		n.parentNode.className = n.parentNode.className.replace('vShow','vHide');
		hints.style.display = 'none';
	}
	else{
		n.parentNode.className = n.parentNode.className.replace('vHide','vShow');
		hints.style.display = 'block';
	}
	return false;
}

function ValidDate() {
	var qmonth = document.getElementById("qotdmonth");
	var qday = document.getElementById("qotdday");
	var qyear = document.getElementById("qotdyear");
	
	if ((qmonth.value == "")||(qday.value == "")||(qyear.value == "")){
		alert ("Please select the month, day and year.");
		return false;
	}
	else if (((qmonth.value == "04")||(qmonth.value == "06")||(qmonth.value == "09")||(qmonth.value == "11"))&&(qday.value == "31")||((qmonth.value == "02")&&((qday.value == "30")||(qday.value == "31")))) {
		alert ("Please enter proper day for this month.");
		return false;
	}
	else if ((qmonth.value == "02")&&(qday.value == "29")&&(qyear.value != "04")&&(qyear.value != "08")){
		alert ("Febuary 29 doesn't exist for this year");
		return false;
	}
return true;
}

function fixHeights(y,z,h){
	if(h > 0){h = h - 25}
		if(y.offsetHeight > z.offsetHeight){
			z.style.height =  -25 + y.offsetHeight + h +'px';
			y.style.height =  -25 + y.offsetHeight + h +'px';
		}
		else{
			y.style.height =  -25 + z.offsetHeight + h +'px';
			z.style.height =  -25 + z.offsetHeight + h +'px';
		}
}

function resizeElements(){
	a  = document.getElementById('middle');
	b  = document.getElementById('rightresponses');
	hints  = document.getElementById('hideShowHint');
	if(hints){
		h = hints.offsetHeight;
		hints.style.display = 'none';
	}
	else{h = 0;}
	if(a && b){fixHeights(a,b,h)}
}

function expandHints(){
	hints  = document.getElementById('hideShowHint');
	if(hints && window.name == "printview"){
		hints.parentNode.className +=' vShow';
		hints.style.display = 'block';
		hints.previousSibling.previousSibling.innerHTML = (hints.previousSibling.previousSibling.innerHTML.indexOf('Show')!=-1) ? hints.previousSibling.previousSibling.innerHTML.replace('Show','Hide') : hints.previousSibling.previousSibling.innerHTML.replace('Hide','Show');
	}
}

/*setting hover states for ie5 and 6*/				
function setIEHoverState(id) {
	el	= document.getElementById(id);
	if(el) {
		 	el.onmouseover	= function(){
				this.className ? this.className	+= ' printover' : this.className = 'printover';
			}
			el.onmouseout	= function(){
				this.className		= this.className.match(/ printover/) ? this.className.replace(/ printover/,'') : this.className.replace(/^printover/,'');
			}
	 }
}

window.onload = function(){
	resizeElements();
	expandHints();	
	if(is_ie5up && is_ie6down){setIEHoverState('print-button');}
}

if(window.name == "printview"){document.write('<link rel="stylesheet" media="screen,print" type="text/css" href="css/qotd-printFriendly.css" />');}


//popup
function popup(url,title,w,h,r,s,m,t,l) {
	//if vars aren't provided, use these defaults
	if (title==null) {
		title = 'popup';
	} if (w==null) {
		w=600;
	} if (h==null) {
		h=400;
	} if (r==null) {
		r='yes';
	} if (s==null) {
		s='yes';
	} if (m==null) {
		m='no';
	} if (t==null) {
		t='no';
	} if (l==null) {
		l='no';
	}
	vars = 'width='+w+',height='+h+',resizable='+r+',scrollbars='+s+',menubar='+m+',toolbar='+t+',location='+l;
	var newWin = window.open(url,title,vars);
	newWin.focus();
	return false;
}