//SET
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}



function updateCookie(thisCookie, value){
	cookieValue=value;
	setCookie(thisCookie, cookieValue, 1);
}


//GET
function getCookie(c_name){
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}


function atlas(item_num) {
	answer_url = 'answers/answer'+item_num+'.html'
    // open a welcome message as soon as the window loads
	Shadowbox.open({
        content:    answer_url,
        player:     "iframe",
        title:      "",
        height:     430,
        width:      664,
		modal: 		true
    });

}

function atlasLast() {
	answer_url = 'answers/answer5.php'
    // open a welcome message as soon as the window loads
	Shadowbox.open({
        content:    answer_url,
        player:     "iframe",
        title:      "",
        height:     608,
        width:      880,
		modal: 		true
    });

}


//based on page body ID
function getCurrentQ(){
	page_id = document.body.id;
	id_length = page_id.length;
	//alert('page_id is:'+page_id);
	qIndex = page_id.charAt(id_length-1);
	//alert('based on the page_id the current question is: '+qIndex);
	return qIndex;
}

/* highlight selected option onClick */
function highlightLink(obj) {
	var linkList = document.getElementById("quiz_options").getElementsByTagName("a");
	for (i = 0; i < linkList.length; i++) {
		linkList[i].className = "";
	}
	obj.className = "selected";
}


function loadSelectedScreen(thisQ, correct){
	uSelection = getCookie(thisQ);
	current = getCookie('current_question');
	//alert("hello "+uSelection+"!");
	if (uSelection==correct){
		//alert('you are correct!');
		document.getElementById('answer_headline').className = "label_correct";
	} else {
		//alert('you are wrong!  still wrong! and current is: '+current);
		document.getElementById('answer_headline').className = "label_incorrect";
	}
}

function loadTestScreen(){
	//do this
}
//close window, proceed to next question 	
function nextQuestion(nextIndex){
	//alert('heller!');
	current = getCookie('current_question');
	setCookie('current_question', nextIndex, 1);
	//page_current_q = getCurrentQ();
	//cookie_current_q = getCookie('current_question');
	//alert('cookie_current_q is:'+cookie_current_q);
	//window.parent.Shadowbox.close();
	nextURL = '../question_'+nextIndex+'.php';
	window.parent.location.href=nextURL;
}

//close window, proceed to next question 	
function aFin(finURL){
	window.parent.location.href=finURL;
}

