var allCookies = document.cookie;
var cookieUserId = cookieValue(allCookies.indexOf("user_id=") +8);
var cookiePassword = cookieValue(allCookies.indexOf("password=") +9);

var signInContent = 
'<script>function goodFunc () {alert(\'accepted!\')}; function badFunc () {alert(\'rejected!\')} </script>' +
'	<form action="cgi-bin/erecaps.dll/login" method="post" style="float:right; clear:right" >'+
'		<span><input type="text"  size="20" id="user" name="user"><br/>Username or Email:</span>'+
'		<span><input type="password" id="password" size="8" name="password"><br/>Password:</span>'+
'		<span><input type="button" value="Sign In" onclick="dojo.cookie(\'user\', dojo.byId(\'user\').value, {expires: 1});dojo.cookie(\'password\', dojo.byId(\'password\').value, {expires: 1});dojo.xhrGet({url:\'cgi-bin/erecaps.dll/login\',load:goodFunc,error:badFunc, handleAs:\'text\',timeout: 90000})"></span>'+
'		<input type="hidden" name="redirectok" value="../../../listing.htm">'+
'		<input type="hidden" name="redirectfail" value="../../../signinhelp.htm">'+
'	</form>'+
'	<div style="float:right; margin-top:-5px;clear:right "><a href="registration.htm">or register</a></div>'+
'';

var signedInContent =
'	<form name="signoutfrm" action="cgi-bin/erecaps.dll/base/signout" method="post">'+
'		<div style="float:right; margin-top:10px;clear:right;">'+
'			Welcome '+
'			<a href="../../../listing.htm?sellerid='+ cookieUserId +'" title="Show all of my Erecaps">'+ cookieUserId +'</a> | '+
'			<input type="hidden" name="redirectok" value="../../../index.htm">'+
//'			<a href="cgi-bin/erecaps.dll/manage" title="Manage my Erecaps">My Erecaps</a> |'+ 
'			<a href="#" onClick="document.signoutfrm.submit()">'+
'			Sign Out</a> '+
'		</div>'+
'	</form>'+
'';

function cookieValue(pos) {
	if (pos != -1) {
		var start = pos;
		var end = allCookies.indexOf(";", start);
		if (end == -1) end = allCookies.length;
		var value = allCookies.substring(start, end);
		return decodeURIComponent(value);
	} else {return null;}
};

if (!cookieUserId || !cookiePassword) {
	document.write('<div id="signinbox">'+ signInContent +'</div>');
} else {
	document.write('<div id="signinbox">'+ signedInContent +'</div>');
};


