function storeGuest(){
//-------------------
// This function stores the user details into a cookie called guest.
var today = new Date()
var expiry = new Date()
expiry.setHours( today.getHours() + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 + 999 )
firstField= document.forms[0].elements[0].value
payload = firstField
for (var i = 1; i < 3; i++) {
fieldValue = document.forms[0].elements[i].value
payload = payload + ":" + fieldValue
}
BD_SetCookie( 'guest', payload, expiry)
}
function showGuest(){
//------------------
// This function shows the enter entry if theres no cookie and doesnt if theres a cookie.
var guestCookie = BD_GetCookie('guest')
with (document) {
// if theres not a user cookie just display empty input boxes.
if(! guestCookie){
document.write('<form method="post" name="guestform" autocomplete="off" >\n'
+ '<table width="773" border="0" cellspacing="0" cellpadding="0">\n'
+ ' <tr>\n'
+ ' <td width="90" align="left" valign="top" class="guestBookB">Message Title: </td>\n'
+ ' <td width="683"><input name="title" type="text" maxlength="20" /></td>\n'
+ ' </tr>\n'
+ ' <tr>\n'
+ ' <td align="left" valign="top" class="guestBookB">User: </td>\n'
+ ' <td><input name="user" type="text" maxlength="20" /></td>\n'
+ ' </tr>\n'
+ ' <tr>\n'
+ ' <td align="left" valign="top" class="guestBookB">Message: </td>\n'
+ ' <td><textarea name="message" cols="60"/></textarea></td>\n'
+ ' </tr>\n'
+ ' </table>\n'
+ ' <br/>\n'
+ ' <input name="guestSubmit" value="Submit" onclick="return validate1(this.form)" type="submit"/>\n'
+ ' <input type="reset" name="Reset" value="Reset Message" />\n'
+ ' </form>\n'
+ ' <hr/>\n')
return false; // to indicate no form started, no need to end it
}
else{ // else if there is a guest cookie.
document.write('\n <p>Thanks for your post!</p>\n')
}
}
}
//VALIDATION CODE
function validate1(form){
//-----------------------
// This function validates if any of the input boxes have a value in.
var bad = false
if (form.title.value == ""){
bad =true;
form.title.focus();
}
else if (form.user.value == ""){
bad =true;
form.user.focus();
}
else if (form.message.value == ""){
bad =true;
form.message.focus();
}
if (form.title.value == "" ) {
alert('Please Input the message title.')
form.title.focus();
return false;
}
if (form.user.value == "" ) {
alert('Please input your user name.')
form.user.focus();
return false;
}
if (form.message.value == "" ) {
alert('Please Input a message.')
form.message.focus();
return false;
}
storeGuest()
return (true)
}
//BILL DORTCH CODE
// code in the functions BD_GetCookie, BD_SetCookie() and BD_DeleteCookie
// is based on code written by Bill Dortch and placed in the public domain
// It was modified by Martin Webb and is available from
// <URL:http://tech.irt.org/articles/js016/index.htm>
// these functions are the accepted standard way of handling cookies in JScript
// The layout has been altered by Peter Scott, but nothing else has been
// interfered with! Make sure you leave them alone too!!
function BD_GetCookie( name) {
//----------------------------
var start = document.cookie.indexOf( name + '=')
var len = start + name.length + 1
if ((!start) && (name != document.cookie.substring(0,name.length)))
return null
if (start == -1)
return null
var end = document.cookie.indexOf( ';',len)
if (end == -1)
end = document.cookie.length
return unescape( document.cookie.substring( len,end))
}
function BD_SetCookie( name, value, expires, path, domain, secure) {
//------------------------------------------------------------------
document.cookie = name + '=' + escape( value)
+ ( (expires) ? ';expires=' + expires.toGMTString() : '')
+ ( (path) ? ';path=' + path : '')
+ ( (domain) ? ';domain=' + domain : '')
+ ( (secure) ? ';secure' : '')
}
function BD_DeleteCookie( name, path, domain) {
//---------------------------------------------
if (BD_GetCookie( name))
document.cookie = name + '='
+ ( (path) ? ';path=' + path : '')
+ ( (domain) ? ';domain=' + domain : '')
+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT'
}