function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages(imgid,pathtoimg) {
	if (document.images && (preloadFlag == true)) {
		document.getElementById(imgid).src = pathtoimg;
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		home_over = newImage("images/postit1_over.gif");
		comic_over = newImage("images/postit2_over.gif");
		suggest_over = newImage("images/postit3_over.gif");
		logout_over = newImage("images/postit4_over.gif");
		go_over = newImage("images/go_over.gif");
		preloadFlag = true;
	}
}

function expandComments(num,dsbl) {
	if (document.images) {
		if (state[num]) {
			if ((dsbl == '0') || (dsbl == '9')) {
				document.getElementById("img"+num).src = "images/closed_dsbl.gif";
			} else {
				document.getElementById("img"+num).src = "images/closed.gif";
			}
			document.getElementById("comment"+num).style.display = "none";
			state[num] = !state[num];
		} else {
			if ((dsbl == '0') || (dsbl == '9')) {
				document.getElementById("img"+num).src = "images/open_dsbl.gif";
			} else {
				document.getElementById("img"+num).src = "images/open.gif";
			}
			document.getElementById("comment"+num).style.display = "inline";
			state[num] = !state[num];
		}
	}
}

function expandAnswers(num,dsbl) {
	if (document.images) {
		if (state[num]) {
			document.getElementById("img"+num).src = "images/closed.gif";
			document.getElementById("answer"+num).style.display = "none";
			state[num] = !state[num];
		} else {
			document.getElementById("img"+num).src = "images/open.gif";
			document.getElementById("answer"+num).style.display = "inline";
			state[num] = !state[num];
		}
	}
}

function expandSF(elementID,flag) {
	if (flag) {
		document.getElementById(elementID).style.display = "none";
		document.getElementById(elementID+"_txt").style.color = "#A3B0BA";
	} else {
		document.getElementById(elementID).style.display = "inline";
		document.getElementById(elementID+"_txt").style.color = "#004A80";
	}
}

function suggestChk(thisForm) {
	if ((thisForm.title.value == "") || (thisForm.title.value == null)) {
                alert("Please suggest a title.");
                thisForm.title.focus();
                return false;
        }
	var desc = thisForm.description.value;	
	if ((desc == null) || (desc.replace(/^(\s+)/, '') == "")) {
                alert("Please describe your suggestion.");
		thisForm.description.value = "";
                thisForm.description.focus();
                return false;
        }	
	if ((thisForm.ideatype.value == "0") || (thisForm.ideaType.value == null) || (thisForm.ideatype.value == "")) {
		alert("Please select the type of idea.");
		thisForm.ideatype.focus();
		return false;
	}
	return true;
}

function adminChk(thisForm) {
	if ((thisForm.alias.value == "") || (thisForm.alias.value == null)) {
                alert("Please suggest an alias.");
                thisForm.alias.focus();
                return false;
        }
	if ((thisForm.name.value == "") || (thisForm.name.value == null)) {
                alert("Please suggest an name.");
                thisForm.name.focus();
                return false;
        }
	return true;
}

function quizChk(thisForm) {
	var ques = thisForm.question.value;	
	if ((ques == null) || (ques.replace(/^(\s+)/, '') == "")) {
                alert("Please enter your question.");
		thisForm.question.value = "";
                thisForm.question.focus();
                return false;
        }	
	if ((thisForm.answ_a.value == "") || (thisForm.answ_a.value == null)) {
                alert("Please enter an answer for A)");
                thisForm.answ_a.focus();
                return false;
        }
	if ((thisForm.answ_b.value == "") || (thisForm.answ_b.value == null)) {
                alert("Please enter an answer for B)");
                thisForm.answ_b.focus();
                return false;
        }
	if ((thisForm.answ_c.value == "") || (thisForm.answ_c.value == null)) {
                alert("Please enter an answer for C)");
                thisForm.answ_c.focus();
                return false;
        }
	if ((thisForm.answ_d.value == "") || (thisForm.answ_d.value == null)) {
                alert("Please enter an answer for D)");
                thisForm.answ_d.focus();
                return false;
        }
	if ((thisForm.answer.value == "0") || (thisForm.answer.value == null) || (thisForm.answer.value == "")) {
		alert("Please select the correct answer to the question.");
		thisForm.answer.focus();
		return false;
	}
	if ((thisForm.cat_id.value == "0") || (thisForm.cat_id.value == null) || (thisForm.cat_id.value == "")) {
		alert("Please select a category.");
		thisForm.cat_id.focus();
		return false;
	}
	if ((thisForm.dif_id.value == "0") || (thisForm.dif_id.value == null) || (thisForm.dif_id.value == "")) {
		alert("Please select a difficulty.");
		thisForm.dif_id.focus();
		return false;
	}
	return true;
}

function editQuesChk(thisForm) {
	var ques = thisForm.question.value;	
	if ((ques == null) || (ques.replace(/^(\s+)/, '') == "")) {
                alert("Please enter your question.");
		thisForm.question.value = "";
                thisForm.question.focus();
                return false;
        }	
	if ((thisForm.answ_a.value == "") || (thisForm.answ_a.value == null)) {
                alert("Please enter an answer for A)");
                thisForm.answ_a.focus();
                return false;
        }
	if ((thisForm.answ_b.value == "") || (thisForm.answ_b.value == null)) {
                alert("Please enter an answer for B)");
                thisForm.answ_b.focus();
                return false;
        }
	if ((thisForm.answ_c.value == "") || (thisForm.answ_c.value == null)) {
                alert("Please enter an answer for C)");
                thisForm.answ_c.focus();
                return false;
        }
	if ((thisForm.answ_d.value == "") || (thisForm.answ_d.value == null)) {
                alert("Please enter an answer for D)");
                thisForm.answ_d.focus();
                return false;
        }
	if ((thisForm.answer.value == "0") || (thisForm.answer.value == null) || (thisForm.answer.value == "")) {
		alert("Please select the correct answer to the question.");
		thisForm.answer.focus();
		return false;
	}
	if ((thisForm.cat_id.value == "0") || (thisForm.cat_id.value == null) || (thisForm.cat_id.value == "")) {
		alert("Please select a category.");
		thisForm.cat_id.focus();
		return false;
	}
	if ((thisForm.dif_id.value == "0") || (thisForm.dif_id.value == null) || (thisForm.dif_id.value == "")) {
		alert("Please select a difficulty.");
		thisForm.dif_id.focus();
		return false;
	}
	var cnt = -1;
	var i=0;
	for (i=0; i < thisForm.approved.length; i++) {
   		if (thisForm.approved[i].checked) cnt = 1;
   	}
	if (cnt == -1) {
		alert("Please select an approval.");
		thisForm.approved.focus();
		return false;
	}
	cnt = -1;
	for (i=0; i < thisForm.status.length; i++) {
   		if (thisForm.status[i].checked) cnt = 1;
   	}
	if (cnt == -1) {
		alert("Please select a status.");
		thisForm.status.focus();
		return false;
	}
	return true;
}

function commentsChk(thisForm) {
	if ((thisForm.commentTxt.value == "") || (thisForm.commentTxt.value == null)) {
		alert("Please type in your comment.");
		thisForm.commentTxt.focus();
		return false;
	}
	return true;
}

function openWindow(url) {
        var w = window.open (url, "view", "height=600,width=500,resizable=1,scrollbars=1");
        w.focus();
}

function openSmWindow(url) {
        var w = window.open (url, "view", "height=200,width=250");
        w.focus();
}

function reloadAndClose() {
	window.opener.location.reload();
	var StayAlive = 2; // Number of seconds to keep window open
	setTimeout("self.close()",StayAlive * 1000);
}

function redirect(page) {
	var StayAlive = 2;
	setTimeout("window.location = "+page,StayAlive * 1000);
}

function setText(txt,elemID,search) {
	if ((document.getElementById(elemID).value == "") || ((txt == "") && (document.getElementById(elemID).value == search))) {
		document.getElementById(elemID).value = txt;
	}
}

