//browser_check_login.js

var BrowserOk=(document.getElementById || (!document.getElementById && document.all)) ;

function onEnter(event)
{
	//For a full list of key codes go to
	//http://www.js-x.com/beginners/key_codes.php3

	var bolOldBrowser = (document.layers) ? true : false;
	var intKeyCode = 0;
	if (bolOldBrowser)
		intKeyCode = event.which;
	else
		intKeyCode = event.keyCode;
	if (intKeyCode == 13)
		document.Login.submit();
}

function RunOnLoad ()
{
	if (BrowserOk && document.Login)
	{
		document.Login.EmailAddress.focus();
	}

}

function UpgradeBrowser() {
	document.write('<P style="margin:20px">');
	document.write('This site requires a version 5 or better browser. The main');
	document.write(' ones are <a href="http://www.microsoft.com/windows/ie/downloads/ie6/download.asp" target="_blank">') ;
	document.write('Microsoft (Internet Explorer 6)</a>, <a href="http://www.netscape.com/computing/download/" target="_blank">');
	document.write('Netscape</a>, or <a href="http://www.opera.com/" target="_blank">');
	document.write('Opera</a>. Those links will open in a seperate window.</P>');
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function WriteLoginForm(SessionNameValue,ActionVarName,PHPPath,PHPScript, URLArgs) {

	if (SessionNameValue != '') {
		URLParameter='?'+SessionNameValue ;
		SessionNameArray=SessionNameValue.split('=') ;
		SessionName=SessionNameArray[0] ;
		SessionValue=SessionNameArray[1] ;
	} else {
		URLParameter='' ;
	}
	var URLParts ;
	var URLExtras='';
	if (URLArgs != '')
	{
		URLParts=URLArgs.split('&') ;
		for (i=0;i<URLParts.length;i++)
		{
			var URLArgBits=URLParts[i].split('=') ;
			URLExtras+='<input type="hidden" name="'+URLArgBits[0]+'" value="'+URLArgBits[1]+'">' ;
		}
	}

	// look for a cookie
	var usernameDefault=getCookie('site_login') ;
	var passwordDefault=getCookie('site_password') ;

document.write('<TABLE>');
document.write('<tr>') ;

// create the registration section
document.write('<td height="0" valign="top" align="center"><div align="center">') ;

document.write('<FORM METHOD="POST" ACTION="./registration_module.php" name="register">');
document.write('<p align="center"><img align="center" src="images/meetakiwi_11.gif" width=114 height=71 alt="" onClick="register.submit();"><br>') ;

if (SessionNameValue != '') {
	document.write('<INPUT TYPE="hidden" name="'+SessionName+'" value="'+SessionValue+'">');
}
document.write('<INPUT TYPE="hidden" name="'+ActionVarName+'" value="edit">');
document.write('<INPUT TYPE="hidden" name="module" value="registration_module">');

document.write('</FORM>');

document.write('</p>') ;
document.write('</div></td>') ;
document.write('</tr>') ;

// this is the login section
document.write('<tr><td>') ;
document.write('<form method="POST" name="Login" action="./'+PHPScript+'">');
document.write(URLExtras) ;
document.write('<table><tr>') ;

document.write('<td valign="top"><div align="center"><img src="images/meetakiwi_23.gif" width=114 height=21 alt=""></div></td>') ;
document.write('</tr>') ;
document.write('<tr>') ;
document.write('<td valign="top"><img src="images/email_28.gif" width="114" height="8"></td>') ;
document.write('</tr>') ;
document.write('<tr>') ;
document.write('<td valign="top"><input type="text" name="EmailAddress" style="width:120px" onkeypress="onEnter(event);"') ;
if ( usernameDefault != null ) {
	document.write(' value="'+usernameDefault+'"') ;
}
document.write('></td></tr>') ;
document.write('<tr>') ;
document.write('<td valign="top"><img src="images/meetakiwi_31.gif" width=114 height=11 alt=""></td>') ;

document.write('</tr>') ;
document.write('<tr>') ;
document.write('<td valign="top"><input type="password" name="Password" style="width:120px" onkeypress="onEnter(event);"') ;
if ( passwordDefault != null ) {
	document.write(' value="'+passwordDefault+'"') ;
}
document.write('> <br> </td>') ;
document.write('</tr>') ;
document.write('<tr>') ;
document.write('<td valign="top"><div align="center"><img src="images/meetakiwi_36.gif" width=114 height=28 alt="" onClick="Login.submit();"></div></td>') ;
document.write('</tr></table></form>');
document.write('</td></tr>') ;

// the forgotten password section
document.write('<tr>') ;
document.write('<td>') ;
document.write('<FORM METHOD="POST" ACTION="./forgot_password.php" name="forgot" onkeypress="onEnter(event)">');
if (SessionNameValue != '') {
	document.write('<INPUT TYPE="hidden" name="'+SessionName+'" value="'+SessionValue+'">');
}
document.write(URLExtras) ;
document.write('<table><tr>') ;
document.write('<td valign="top"><div align="center"><img src="images/spacer.gif" width="1" height="10"><br>') ;
document.write('<img src="images/forgot_40.gif" width="114" height="22"></div></td>') ;
document.write('</tr>') ;
document.write('<tr>') ;
document.write('<td valign="top"> <img src="images/email_28.gif" width="114" height="8">') ;
document.write('</td>') ;
document.write('</tr>') ;
document.write('<tr>') ;
document.write('<td valign="top" align="center"><input type="text" style="width:120px" name="InEmailAddress"></td>') ;
document.write('</tr>') ;
document.write('<tr>') ;
document.write('<td valign="top"><div align="center"><img src="images/send.gif" width="53" height="24" onClick="forgot.submit();"></div></td>') ;
document.write('</tr></table></form></td>') ;
document.write('</tr>') ;
document.write('</table>') ;

return ;

}
