// Fuctions to do with the login procedure

function writeloginbox() {
// keep page out of frames
if (top.location!=self.location) { top.location.replace(self.location) }
// update or delete cookie
	document.write("<table class=\"loginbox\"><tr><td width=\"14\">&nbsp;</td><td>")
	if (document.cookie.substring(0,15)!="ProductionGuild") {
		document.write("<form action=\"FMPro\" method=\"post\" name=\"loginform\" onSubmit=\"return empties()\">")
		document.write("<input type=\"hidden\" name=\"-db\" value=\"PGSecurity.fp5\">")
		document.write("<input type=\"hidden\" name=\"-format\" value=\"login.asp\">")
		document.write("<input type=\"hidden\" name=\"-script\" value=\"derek\">")
		document.write("<input type=\"hidden\" name=\"-op\" value=\"bw\">")
		document.write("<input id=\"useridbox\" name=\"UserId\" class=\"loginid\" type=\"text\" value=\"User Id\" maxlength=\"20\" onFocus=\"useridclick()\"><br>")
		document.write("<input id=\"passwordbox\" name=\"Password\" class=\"loginpassword\" type=\"password\" value=\"Password\" maxlength=\"12\" onFocus=\"passwordclick()\">")
		document.write("<input name=\"-find\" type=\"submit\" class=\"loginbutn\" value=\"LOG IN\"></form>")		
	}
	else {
		expireDate = new Date
		expireDate.setMinutes(expireDate.getMinutes()+30)
		for (i=16 ; i<document.cookie.length ; i++) {
			if (document.cookie.substring(i,(i+1))=="#") { var n = i ; break }
		}
		for (i++ ; i<document.cookie.length ; i++ ) {	
			if (document.cookie.substring(i,(i+1))=="#") { var nn = i ; break }
		}
		var thisuid = document.cookie.substring(16,n)
		var thisstatus = document.cookie.substring(n+1,nn)
		document.cookie = ( "ProductionGuild=" + thisuid + "#" + thisstatus + "#; expires=" + expireDate.toGMTString() )		
		document.write("<form action=\"FMPro\" method=\"post\" name=\"logoutform\" onSubmit=\"logout()\">")
		document.write("<input type=\"hidden\" name=\"-db\" value=\"PGSecurity.fp5\">")
		document.write("<input type=\"hidden\" name=\"-format\" value=\"login.asp\">")
		document.write("<input type=\"hidden\" name=\"-script\" value=\"derek\">")
		document.write("<input type=\"hidden\" name=\"-op\" value=\"bw\">")
		document.write("<input type=\"hidden\" name=\"UserId\" value=\"guest\">")
		document.write("<input type=\"hidden\" name=\"Password\" value=\"guest\">")
		document.write("<input name=\"-find\" type=\"submit\" class=\"loginbutn\" value=\"LOG OUT\">")
		if (thisstatus=="Deity") { document.write("<p class=\"smalltext\"><a href=\"FMPro?-DB=PGlauncher.fp5&-Script=listopnedb&-Format=admin.asp&-sortfield=date&-sortorder=descend&-sortfield=time&-sortorder=descend&-max=20&-FindAll\">" + thisuid + "<br>Logged in as " + thisstatus + "</a></p></form>") }
		else { document.write("<p class=\"smalltext\">" + thisuid + "<br>Logged in as " + thisstatus + "</p></form>") }
	}
	document.write("</td></tr></table>")
}		

function validate(thisuid, thisstatus) {
	expireDate = new Date
	if (thisstatus=="Deity"||thisstatus=="Member"||thisstatus=="User") {
		expireDate.setMinutes(expireDate.getMinutes()+30)
		document.cookie = ( "ProductionGuild=" + thisuid + "#" + thisstatus + "#; expires=" + expireDate.toGMTString() )		
	}
	else {
		expireDate.setDate(expireDate.getDate()-1)		
		document.cookie = ( "ProductionGuild=''; expires=" + expireDate.toGMTString() )
	}		
setTimeout('window.location="FMPro?-DB=PGNews.fp5&-Format=news.asp&-sortField=Rank&-sort0rder=Ascend&-sortField=StoryDate&-sort0rder=Ascend&Publish=Show&-Op=lte&Prosthesis="+getStatusNum()+"&-max=All&-Find";',500)
}

function ironlung(thisseclevel) {
	for (i=16 ; i<document.cookie.length ; i++) {
		if (document.cookie.substring(i,(i+1))=="#") { var n = i ; break }
	}
	for (i++ ; i<document.cookie.length ; i++ ) {	
		if (document.cookie.substring(i,(i+1))=="#") { var nn = i ; break }
	}
	var thisuid = document.cookie.substring(16,n)
	var thisstatus = document.cookie.substring(n+1,nn)
	if (thisseclevel==3&&thisstatus!="Deity") { loginerror() }
	if (thisseclevel==2) { if (thisstatus!="Member"&&thisstatus!="Deity") { loginerror() } }
	if (thisseclevel==1) { if (thisstatus!="User"&&thisstatus!="Member"&&thisstatus!="Deity") { loginerror() } }
}

function loginerror() { window.location="loginerror.html" }
function useridclick() { if (loginform.useridbox.value=="User Id") { loginform.useridbox.value="" } }
function passwordclick() { if (loginform.passwordbox.value=="Password") { loginform.passwordbox.value="" } }

function empties() { 
	if (!loginform.useridbox.value||!loginform.passwordbox.value) { return false }
	else { loginform.useridbox.value = "==" + loginform.useridbox.value }
}

function logout() { expireDate = new Date ; expireDate.setDate(expireDate.getDate()-1) ; document.cookie = ( "ProductionGuild=''; expires=" + expireDate.toGMTString() ) }

function getUID() {
	for (i=16 ; i<document.cookie.length ; i++) {
		if (document.cookie.substring(i,(i+1))=="#") { var n = i ; break }
	}
	for (i++ ; i<document.cookie.length ; i++ ) {	
		if (document.cookie.substring(i,(i+1))=="#") { var nn = i ; break }
	}
	var thisuid = document.cookie.substring(16,n)
	return (thisuid)
}

function getStatusNum() {
	for (i=16 ; i<document.cookie.length ; i++) {
		if (document.cookie.substring(i,(i+1))=="#") { var n = i ; break }
	}
	for (i++ ; i<document.cookie.length ; i++ ) {	
		if (document.cookie.substring(i,(i+1))=="#") { var nn = i ; break }
	}
	var thisstatus = document.cookie.substring(n+1,nn)
	if (thisstatus=="Deity") { return(3) }
	else if (thisstatus=="Member") { return(2) }
	else if (thisstatus=="User") { return(1) }
	else { return(0) }
}



