function setCookie(name, value, expires, path, domain, secure) {

  var curCookie = name + "=" + escape(value) +

      ((expires) ? "; expires=" + expires.toGMTString() : "") +

      ((path) ? "; path=" + path : "") +

      ((domain) ? "; domain=" + domain : "") +

      ((secure) ? "; secure" : "");

  document.cookie = curCookie;

}





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 deleteCookie(name, path, domain) {

  if (getCookie(name)) {

    document.cookie = name + "=" + 

    ((path) ? "; path=" + path : "") +

    ((domain) ? "; domain=" + domain : "") +

    "; expires=Thu, 01-Jan-70 00:00:01 GMT";

  }

}



function validLogin() {

	var raw_login = getCookie('login');

	var login = Array();

	if(raw_login) {

		login = raw_login.split('|');

		if(login[2]) {

			return true;

		}

	}

	return false;

}





function setLogin() {

	var the_form = document.sublogin;

	var raw_login = getCookie('login');

	if(raw_login) {

		var login = Array();

		login = raw_login.split('|');

		// only log them in if it's been verified

		if(login[2] == 1) {

			the_form.login.value = login[0];

			the_form.passwd.value = login[1];

			//the_form.save.checked = true;

			the_form.submit();

		}

	}

}



function rememberMe() {

	var the_form = document.sublogin;

	var login = the_form.login.value;

	var pass = the_form.passwd.value;

	//var state = the_form.save.checked;

	//var state = true;



	if(login && pass) {

		var exp = new Date;

		// one month

		exp.setTime(exp.getTime() + (30*24*60*60*1000));

		// login name, password, is valid login (set to 'true' in panel_users) 

		setCookie('login', login +'|'+ pass +'|1', exp, '/', 'prmia.org');



	} else {

		deleteCookie('login');

	}

	

}

