var pw = new Array("test","piano");
var area = new Array("Test", "celebration");

function resetForm(form) {
	eval('document.'+form+'.reset()');
}

function loginTo(id, where) {
	syspass = pw[id];
	pass = document.loginForm.pass.value;
	if (syspass && pass && where && syspass == pass) {
		writeCookie(area[id], pass, '24');
		location.href = where;
	} else {
		alert ('Sorry...incorrect password');
		return false;
	}	
}

function readCookie(name) {
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0) { 
    offset = document.cookie.indexOf(search);
    if (offset != -1) { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      	cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours) {
  var expire = "";
  if(hours != null) {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function checkCookie(id) {
	var pass = pw[id];
	var cookie = readCookie(name);
	if (cookie.length > 0 && cookie == pass) {
		return true;
	} else {
		location.href='./';
	}
}

var popUpWin=0;
function popUpWindow(URLStr, winWidth, winHeight) {
  if(popUpWin) {
    if(!popUpWin.closed) popUpWin.close();
  }
	winTop = ((screen.availHeight/2) - (winHeight/2)) - 25;
	winLeft = (screen.availWidth/2) - (winWidth/2);
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+winWidth+',height='+winHeight+',left='+winLeft+', top='+winTop+',screenX='+winLeft+',screenY='+winTop+'');
}