// ******* Close window after 20 seconds *************************************************
function closeWin() {
setTimeout(window.close, 20000);
}

// ******* GoTo Menu Handler *******************************************************
// *******if '*' is 1st char, open in new window **********
function formHandler(formname){
if (document.forms[formname].site.selectedIndex != ""){
 var URL = document.forms[formname].site.options[document.forms[formname].site.selectedIndex].value;
document.forms[formname].site.selectedIndex = 0;}
if (URL.match(/^\*/)){
	URL = URL.slice(1);
	window.open(URL);
}
else window.location.href = URL;
}
//********************************************************************************
//********************************************************************************
	var windowName="subWindow";
	var myWin=null;

		function closeMyWin(){
//			alert(myWin);
			if (myWin && myWin.open && !myWin.closed) {myWin.close();}
		}

	
// ******* Open html in subwindow in middle of screen ***********************************
// **** Example: <A href="sample.html" onclick="openWindow(this,450,250)">Sample Document</A>
// ***** where desired subwindow width=450, height=250
	
	
	
  function openWindowMid(myLink,W,H)
  {
  if(! window.focus)return;
	if (myWin && myWin.open && !myWin.closed) {myWin.close();}
  var maxW = screen.availWidth-5;
	var xpos = (maxW - W-1)/2;
	if (xpos < 0)  {
		xpos = 0;
		var popupwidth = maxW;
	}
	else { var popupwidth = W;}

	var maxH = screen.availHeight-25;
	var ypos = (maxH - H - 1)/2;
	if ( H > maxH ) {
		ypos = 0;
		popupheight = maxH ;
	}
	else { popupheight = H;}
    var winfeatures="height="+popupheight+",width="+popupwidth+",screenX="+xpos+",left="+xpos+",screenY="+ypos+",top="+ypos+",dependant=yes,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes";
    myWin=window.open(myLink,windowName,winfeatures);
    myLink.target=windowName;
    myWin.focus();
    }

// ******* Open html in subwindow at X,Y *******************************
	  function openWindow(myLink,windowName,X,Y,H)
  {
  if(! window.focus)return;
  	if (myWin && myWin.open && !myWin.closed) {myWin.close();}

    var popupwidth=280;

    if ((Y+H)<(screen.availHeight-20)) {var ypos=Y;}
    else { var ypos=screen.availHeight-H-20;}

    if ((X+popupwidth)<(screen.availWidth-20)) {var xpos=X;}
    else { var xpos=screen.availWidth-20-popupwidth;}

    if (X<0) { var xpos=screen.availWidth+X-popupwidth;}

 var winfeatures="height="+H+",width="+popupwidth+",screenX="+xpos+",left="+xpos+",screenY="+ypos+",top="+ypos+",dependant=yes,scrollbars=yes";
  myWin=window.open("",windowName,winfeatures);
//  myWin.focus();
  myLink.target=windowName;
  myWin.focus();
  }

// *************** open picture in subwindow **************
// **** Example: <a href="pictures/picture.jpg" onclick="return openPicWin(this,600,400,'Sample Caption')">
// ****   where actual picture dimension is 600x400.
////var pictureWin = null;
function openPicWin(myLink,picWidth,picHeight,caption)
  {
  if(! window.focus)return;
  	if (myWin && myWin.open && !myWin.closed) {myWin.close();}
	if(!caption){caption = "";}
	W = picWidth + 40;
	H = picHeight + 40;

	var maxW = screen.availWidth-5;
	var myX = (maxW - W-1)/2;
	if (myX < 0)  {
		myX = 0;
		myW = maxW;
	}
	else { myW = W;}

	var maxH = screen.availHeight-25;
	var myY = (maxH - H - 1)/2;
	if ( H > maxH ) {
		myY = 0;
		myH = maxH ;
	}
	else { myH = H;
	}

	var winfeatures="height="+myH+",width="+myW+",screenX="+myX+",left="+myX+",screenY="+myY+",top="+myY +",dependant=yes,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes";

	myWin = window.open("","picWin",winfeatures);

	var winText = '<html><head><title>Picture</title></head>';
	winText += '<body bgcolor="#99ccff" text="#000000" onLoad="self.focus()" topmargin="10" leftmargin="10" marginheight="10" marginwidth="10">';
		winText += '<center><img src='+myLink+' width="'+picWidth+'" height="'+picHeight+'" alt="Picture" lowsrc="img/please_wait.gif"><BR><font face="arial,helvetica,sans-serif"><small>'+caption;
	winText += '</small></font></center></body></html>';

	var wd = myWin.document;
	wd.open();
	wd.write(winText);
	wd.close();
	return false;
}
/*

Author: Alex Osipov (alex@acky.net)
Publisher: ACKY.NET

*/
// Function to save a field.
function save_field(obj) {
	var cookie_value = '';
	var objType = new String(obj.type);

	switch(objType.toLowerCase()) {
		case "checkbox" :
			if (obj.checked) cookie_value = obj.name + '=[1]'
			else cookie_value = obj.name + '=[0]'
			break;
		case "undefined" :
			// a.k.a. radio field.
			for (var i = 0; i < obj.length; i++) {
				if (obj[i].checked) cookie_value = obj[i].name + '=[' + i + ']'
			}
			break;
		case "select-one" :
			cookie_value = obj.name + '=[' + obj.selectedIndex + ']';
			break;
		case "select-multiple" :
			cookie_value = obj.name + '=[';
			for (var i = 0; i < obj.options.length; i++) {
				if (obj.options[i].selected) cookie_value += '+' + i
			}
			cookie_value += ']';
			break;
		default :
			// We assume all other fields will have
			// a valid obj.name and obj.value
			cookie_value = obj.name + '=[' + escape(obj.value) + ']';

}

	if (cookie_value) {
		var expires = new Date();
		var theYear = expires.getYear()
		theYear += (theYear < 1900) ? 1900 : 0
		expires.setYear(theYear + 1);
		document_cookie = cookie_value +
		((domain.length > 0) ? ';domain=' + domain : '') +
		((path) ? ';path=' + path : '') +
		((secure) ? ';secure' : '') +
		';expires=' + expires.toGMTString();
		document.cookie = document_cookie;
	}
	return 1;
}

// Function to retrieve a field.
function retrieve_field(obj) {
	var cookie = '', real_value = '';
	cookie = document.cookie;
	var objType = new String(obj.type);
	if (obj.name)
		var objName = new String(obj.name);
	else
		var objName = new String(obj[0].name);
	var offset_start = cookie.indexOf(objName + '=[');
	if (offset_start == -1) return 1;
	var offset_start_length = objName.length + 2;
	offset_start = offset_start + offset_start_length;
	var offset_end = cookie.indexOf(']', offset_start);
	real_value = cookie.substring(offset_start, offset_end);
	switch(objType.toLowerCase()) {
		case "checkbox" :
			if (real_value == '1') obj.checked = 1
			else obj.checked = 0
			break;
		case "undefined" :
			obj[real_value].checked = 1;
			break;
		case "select-one" :
			obj.selectedIndex = real_value;
			break;
		case "select-multiple" :
			for (var i = 0; i < obj.options.length; i++) {
				if ((real_value.indexOf('+' + i)) > -1)
					obj.options[i].selected = 1;
				else
					obj.options[i].selected = 0;
			}
			break;
		default :
			obj.value = unescape(real_value);
			break;
	}
	return 1;
}

