/* Code by: Jake Bradley	02/04/01
/* Setup some variables */
img1src='images/fld/new_field2.jpg';
img2src='images/lbw_mnu_soundoff.gif';
img3src='images/lbw_mnu_soundon.gif';
closetime = 0;

/* Image Changer */
function changeImage(imgName,imgSrc) {
document.images[imgName].src = imgSrc;
}

function PopupWin(URL, WIDTH, HEIGHT) {
windowprops = "left=5,top=5,width=" + WIDTH + ",height=" + HEIGHT;
if (!window.preview1 || chgSoundVAR==1) { preview1 = window.open(URL, "preview1", windowprops); }
// if (closetime) setTimeout("preview1.close();", closetime*1000);
}

function doPopup() {
	userbgsound = getCookie("userbgsound")
	if (userbgsound==3) {	
	// changeImage('SndImg1',img3src);
	url = "mplayer.html";
	width = 229;  // width of window in pixels
	height = 96; // height of window in pixels
	delay = 1;    // time in seconds before popup opens
	timer = setTimeout("PopupWin(url, width, height)", delay*1000);
	} else {
	if (window.preview1) { preview1.close(); }
	// changeImage('SndImg1',img2src);
	}
}

function chgSound() {
	userbgsound = getCookie("userbgsound")
	if (userbgsound==2) {
	userbgsound = 3;
	chgSoundVAR = 1;
	} else {
	userbgsound = 2;
	}
	
	// create an instance of the Date object
	var now1 = new Date();
	// fix the bug in Navigator 2.0, Macintosh
	fixDate(now1);
	// cookie expires in one year (actually, 365 days)
	// 365 days in a year
	// 24 hours in a day
	// 60 minutes in an hour
	// 60 seconds in a minute
	// 1000 milliseconds in a second
	now1.setTime(now1.getTime() + 365 * 24 * 60 * 60 * 1000);

	// set the new cookie
	setCookie("userbgsound", userbgsound, now1);
	doPopup();
}

function chgSound2() {
	userbgsound = getCookie("userbgsound")
	if (userbgsound==2) {
	// changeImage('SndImg1',img2src);
	}	

	// create an instance of the Date object
	var now1 = new Date();
	// fix the bug in Navigator 2.0, Macintosh
	fixDate(now1);
	// cookie expires in one year (actually, 365 days)
	// 365 days in a year
	// 24 hours in a day
	// 60 minutes in an hour
	// 60 seconds in a minute
	// 1000 milliseconds in a second
	now1.setTime(now1.getTime() + 365 * 24 * 60 * 60 * 1000);

	// set the new cookie
	setCookie("userbgsound", userbgsound, now1);
}

/* Cookie Functions */
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
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;
}

// name - name of the desired cookie
// * return 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));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
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";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
/* End Cookie Functions */


/* StartUp Function: Check Screen Res & Change Img if Needed */
function StartUpTesting() {

	// Check Screen Size & Change Header IMG if Nec.
	sw1 = screen.width
	if (sw1 < 1024) {
	FldImg1.width=580;
	FldImg1.height=95;
	changeImage('FldImg1',img1src);
	}

	// Check Sound Cookie & Play Sound if Nec.
	
	// create an instance of the Date object
	var now = new Date();
	// fix the bug in Navigator 2.0, Macintosh
	fixDate(now);

	// cookie expires in one year (actually, 365 days)
	// 365 days in a year
	// 24 hours in a day
	// 60 minutes in an hour
	// 60 seconds in a minute
	// 1000 milliseconds in a second
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

	var userbgsound = getCookie("userbgsound");
	// if the cookie wasn't found, ask for the name
	if (!userbgsound) {
	  userbgsound = 3;
	}
	// set the new cookie
	setCookie("userbgsound", userbgsound, now);

	// *** doPopup();
}


