// JavaScript Document

window.onerror = null // supress all errors.
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 60 * 60 * 60);
// Sets the value of the textfield from the dropdown value
// Calls the setCookie func.
function setValue( num)	{
	var sForm = document.forms['form'];
	var sElem = sForm.elements[num];
	var sElem2 = sForm.elements[num + 1];

	if( sElem2.value != "")	{
	 	sElem.value = sElem2.options[sElem2.selectedIndex].value;
 		setCookie( sElem.name, sElem.value, now);
		sElem.focus();
	} else {
		sElem.value ="";
	}
}
// Sets the cookie
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;
}
// Sets the cookie for fields that do not have an index.
function setField ( thisControl) {
	setCookie(thisControl.name, thisControl.value, now)
}
// Gets the name of the cookie
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf(prefix);
  if (begin == -1)
    return null;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
// Deletes a cookie
function deleteCookie(name, path, domain) {
	var sForm = document.forms['form'];
 // alert('delete');
	for ( var i = 0; i < 190; i++) {
		if ( sForm.elements[i])	{
		  if (getCookie(sForm.elements[i].name)) {
		    document.cookie = sForm.elements[i].name + "=" +
		    ((path) ? "; path=" + path : "") +
		    ((domain) ? "; domain=" + domain : "") +
		    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		  }
		}
	}
	// formatSearchQuery('form');
	sForm.submit();
}
// Fixes date due to a browser bug.
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
// Sets the values of all textfields from the cookie file, if a value exists for that textfield.
function setAll() {
	var sForm = document.forms['form'];

	if (document.cookie) {
		for ( var p = 0; p < 190; p++) {
			var sElem = sForm.elements[p];
			if ( sElem)	{
				if ( getCookie(sElem.name)) {
					sElem.value = getCookie(sElem.name);
				}
			}
		}
	}
}

