var showpopup = 'waiting';
var submit = 'no';
function redir(){
	window.location = './';
}

function goHome(){
	checkIfPopup();
}

function checkIfPopup() {
	AJAXRequest('?p=j&s=popcheck',popupCheckReturn);
}

function popupCheckReturn() {
	var responseVal = httpRequest.responseText;
	if(responseVal == 'a1'){
		initialPopup();
	}else{
		redir();
	}
}

function showPop(popup) {
        document.getElementById(popup).className = 'showsurvey';
}

function closePop(popup) {
        document.getElementById(popup).className = 'hidesurvey';
}
function showDimmer() {
        document.getElementById('dimmer').className = 'showsurvey';
}
function closeDimmer() {
        document.getElementById('dimmer').className = '';
}

function initialPopup() {
	showPop('survey1');
	showDimmer();
}

function surveyOptIn() {
	closePop('survey1');
	showPop('survey2');
}

function surveyOptOut(){
	helpful(0);
	redir();
}
function helpful(level) {
	if(level == 0 || level == 2 || level == 3){
		AJAXRequest('?p=j&s=surveyparse&h='+level,helpfulReturn);
	}else{
		if(submit == 'yes'){
			if(document.getElementById('imp_nav').checked){var imp_nav = 1;}else{var imp_nav = 0;}
			if(document.getElementById('imp_equip').checked){var imp_equip = 1;}else{var imp_equip = 0;}
			if(document.getElementById('imp_edu').checked){var imp_edu = 1;}else{var imp_edu = 0;}
			if(document.getElementById('imp_news').checked){var imp_news = 1;}else{var imp_news = 0;}
			if(document.getElementById('imp_employ').checked){var imp_employ = 1;}else{var imp_employ = 0;}
			if(document.getElementById('imp_other').checked){var imp_other = 1;}else{var imp_other = 0;}
			var comments = document.getElementById('comments').value;
			var uri = '?p=j&s=surveyparse&h='+level+'&ina='+imp_nav+'&ieq='+imp_equip+'&ied='+imp_edu+'&ine='+imp_news+'&iem='+imp_employ+'&iot='+imp_other+'&c='+comments
			AJAXRequest(uri,helpfulReturn);
		}else{
			closePop('survey2');
			showPop('survey3');
			submit = 'yes'
		}
	}
}

function helpfulReturn() {
	thankYou();
}

function thankYou() {
	closePop('survey2');
	closePop('survey3');
	closePop('survey1');
	showPop('thankyou');
	setTimeout('redir()', 1500);
}
