// initialization and event handling scripts

document.joining = false;
document.atindex = true;

document.loggedInHTML = "<span class=\"headlineLink\" style=\"float:right; margin-right:15px;\">Logged in as [THEIKRUSER] | <a href=\"http://www.iveknownrivers.org/community/\" class=\"headlineLink\">my settings</a> | <a href=\"#\" onclick=\"javascript:logout();\" id=\logoutbutton\" class=\"headlineLink\">logout</a></span>";

document.loggedOutHTML = "<span class=\"headlineLink\" style=\"float:right; margin-right:15px;\"><a href=\"#\" id=\"showlogin\" class=\"headlineLink\">login</a><span id=\"ajaxlogin\">: <input name=\"userlogin\" type=\"text\" class=\"loginfield\" id=\"userlogin\" size=\"10\" /> password: <input name=\"userpassword\" type=\"password\" class=\"loginfield\" id=\"userpassword\" size=\"10\" /> <span class=\"formerror\" id=\"loginerror\"></span> <a href=\"#\" onclick=\"javascript:login();\" id=\"loginbutton\" class=\"headlineLink\">go</a> | <a href=\"#\" id=\"hidelogin\" class=\"headlineLink\">cancel</a></span> | <a href=\"#\"id=\"joinikrlink\" class=\"headlineLink\">join IKR</a></span></span>";

function init() {
	
	document.getElementById("mainpanel").style.display = "block";
	
	document.getElementById("originsicon").onmouseover = hiliteIcon_on;
	document.getElementById("originsicon").onmouseout = hiliteIcon_off;
	
	document.getElementById("movementicon").onmouseover = hiliteIcon_on;
	document.getElementById("movementicon").onmouseout = hiliteIcon_off;
	
	document.getElementById("adaptationicon").onmouseover = hiliteIcon_on;
	document.getElementById("adaptationicon").onmouseout = hiliteIcon_off;
	
	document.getElementById("transformationicon").onmouseover = hiliteIcon_on;
	document.getElementById("transformationicon").onmouseout = hiliteIcon_off;

	document.getElementById("hidelogin").onclick = hidelogin;
	document.getElementById("showlogin").onclick = showlogin;

	document.getElementById("joinikrlink").onclick = joinIKR;
	
	document.getElementById("authorlinkO").onclick = fetchauthor;
	document.getElementById("authorlinkM").onclick = fetchauthor;
	document.getElementById("authorlinkA").onclick = fetchauthor;
	document.getElementById("authorlinkT").onclick = fetchauthor;
	
}

function debugme(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : null)
    if (evt) {
        // process event here
    }
}

function fetchauthor(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : null)
    if (evt) {
        // process event here
		switch (this.id) {
			case "authorlinkO": document.forms.authorget.authorname.value = document.authorO;
			break;
			
			case "authorlinkM": document.forms.authorget.authorname.value = document.authorM;
			break;
			
			case "authorlinkA": document.forms.authorget.authorname.value = document.authorA;
			break;
			
			case "authorlinkT": document.forms.authorget.authorname.value = document.authorT;
			break;
			
			default:
			break;
		}
		
		document.location.href = "#authoranchor0";
		document.getElementById('authorcontent0').innerHTML = delayDiv;
		document.getElementById('author0').style.display = "block";
	
		document.forms.authorget.authorindex.value = "0";
		document.forms.authorget.submit();
    }
	return false;
}

function hiliteIcon_on(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : null)
    if (evt) {
        // process event here
		document.getElementById(this.id).style.borderColor = "#f6a92a";
    }
}

function hiliteIcon_off(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : null)
    if (evt) {
        // process event here
		document.getElementById(this.id).style.borderColor = "#FFFFFF";
    }
}

function joinIKR(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
		// process event here	
		
		document.joining = true;	
		document.getElementById("joinpanel").style.display = "block";
		document.getElementById("thelogin").innerHTML = document.loggedOutHTML;
		document.getElementById("showlogin").onclick = showlogin;
		document.getElementById("hidelogin").onclick = hidelogin;
		document.getElementById("joinikrlink").onclick = joinIKR;

    }
	return false;
}

function showlogin(evt) {
		evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
        // process event here
		if (document.joining == true) {
			document.getElementById("joinpanel").style.display = "none";
			document.joining = false;
		}
		document.getElementById("ajaxlogin").style.display = "inline";
		
    }
	return false;
}

function hidelogin(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : null)
    if (evt) {
		// process event here	
		document.getElementById("ajaxlogin").style.display = "none";
		if (document.commenting == true) { document.commenting = false; }
		document.forms[0].userlogin.value = "";
		document.forms[0].userpassword.value = "";
		
    }
	return false;
}


function login() {
	document.forms[0].action = "javascript:sendData('lib/login-user.php',0);";
	document.forms[0].submit();
}

function logout() {
	document.forms[0].action = "javascript:sendData('lib/logout-user.php',1);";
	document.forms[0].submit();
}