function javaPopupPrint( wParent, sPath, sName)
{				// 3 1/8"	= 300 px		(2*12px gap 	= 276px)
				// 2 7/16"= 226 px 		(2* 6px gap		= 214px)
				// 2 1/4"	= 216 px 		(2* 4px gap		= 208px)
				var xWidth=317; //plus 17 for scrollbars
				var xHeight=600;
				
        xTop = (screen.availHeight - xHeight) /2;
        xLeft = (screen.availWidth - xWidth ) /2;
        
        if (wParent==null){        
	        mywin=window.open( sPath, sName, 'width=' + xWidth + ',height=' + xHeight + ',top=' + xTop + ', left=' + xLeft + ',titlebar=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,directories=no,channelmode=no');
        } else {
	       	mywin=wParent.open( sPath, sName, 'width=' + xWidth + ',height=' + xHeight + ',top=' + xTop + ', left=' + xLeft + ',titlebar=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,directories=no,channelmode=no');
	    	}
	mywin.focus();
}

function javaPopupMain( wParent, sPath, sName, wndWidth, wndHeight, XScale, YScale, hasTitle, hasStatus)
{

        var xTop = ((YScale - 1) / (2 * YScale));
        var xLeft = ((XScale - 1) / (2 * XScale));
        
        xTop = (wndHeight * xTop);
        xLeft = (wndWidth * xLeft);
        
        var xWidth = (wndWidth / XScale);
        var xHeight = (wndHeight / YScale);
        if (wParent==null){        
	        mywin=window.open( sPath, sName, 'width=' + xWidth + ',height=' + xHeight + ',top=' + xTop + ', left=' + xLeft + ',status=' + hasStatus + ',toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,directories=no,channelmode=no');
        } else {
	       	mywin=wParent.open( sPath, sName, 'width=' + xWidth + ',height=' + xHeight + ',top=' + xTop + ', left=' + xLeft + ',status=' + hasStatus + ',toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,directories=no,channelmode=no');
	    	}
	mywin.focus();
	return mywin;
}

function javaPopupR( wParent, sPath, sName )
{
	return javaPopupMain( wParent, sPath, sName, screen.availWidth, screen.availHeight, 2, 2, 'no', 'no');
}
function javaPopup( wParent, sPath, sName )
{
	javaPopupMain( wParent, sPath, sName, screen.availWidth, screen.availHeight, 2, 2, 'no', 'no');
}
function javaPopupBig( wParent, sPath, sName )
{
	javaPopupMain( wParent, sPath, sName, screen.availWidth, screen.availHeight, 1.3, 1.3, 'no', 'no');
}
function javaFullWindow( sPath, sName )
{
	var pw=window.open( sPath, sName, 'width=' + (screen.availWidth-10) + ',height=' + (screen.availHeight-57) + ',top=' + 0 + ', left=' + 0 + ',status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,directories=no,channelmode=no');
	pw.focus();
}
function javaOpenWindow( sPath, sName ){
	var pw=window.open( sPath, sName );
}
function processPic( name, upl ){
	//get button value...
	btn=window.document.getElementById(name+"_btn1");
	if (btn.value=="Upload"){
		javaPopup(window, upl+'?f='+encodeURIComponent(name), '_blank');
	} else {
		btn.value="Upload";
		
		processSaveUndo( 0, window, name );
		
		fld=window.document.getElementById(name);
		fld.value='';

		window.document.getElementById(name+"_icon").value='images/nopic.gif';
		window.document.getElementById(name+"_img").src='images/nopic.gif';
		window.document.getElementById(name+"_show").value='';
		var lnk=window.document.getElementById(name+"_lnk");
		lnk.href='';
		lnk.removeAttribute('href');
		window.document.getElementById(name+"_real").value='';
		window.document.getElementById(name+"_new").value='';
	}
	
}

function processSaveUndo ( dir, win, name ){
	var fld=win.document.getElementById(name);

	if (fld.value!==''){
		sep=String.fromCharCode(255);
	
		myundo=fld.value;
		fld.value='';
		fld=win.document.getElementById(name+"_icon");
		myundo=myundo+sep+fld.value;
		fld.value='images/nopic.gif';
		fld=win.document.getElementById(name+"_show");
		myundo=myundo+sep+fld.value;
		fld.value='';
		fld=win.document.getElementById(name+"_real");
		myundo=myundo+sep+fld.value;
		fld.value='';
		fld=win.document.getElementById(name+"_new");
		myundo=myundo+sep+fld.value;
		fld.value='';
		
		sundo=win.document.getElementById(name+"_undo");
		

		if (sundo.value==''){
			sundo.value=myundo;
		} else {
			sundos= sundo.value.split(String.fromCharCode(254));
			found=0;
			for (i=0; i<sundos.length; i++){
				if (sundos[i]==myundo){
					found=1;
					break;
				}
			}
			if (found==0){
				if (dir==0)
					sundos.unshift(myundo);
				else
					sundos[sundos.length]=myundo;
			}
			
			sundo.value=sundos.join(String.fromCharCode(254));			

		}
	}
		processUndoState(win, name);
}

function processUndo( name ){
	//see if undo is empty or not
	var sundo=window.document.getElementById(name+"_undo");
	if (sundo.value=='')
		return;
	processSaveUndo(1, window, name);
	
	// else...
	// check if we have this in undo
		sep=String.fromCharCode(255);

	sundos= sundo.value.split(String.fromCharCode(254));
	
	sarr = sundos.shift().split(sep);
	window.document.getElementById(name).value=sarr[0];
	window.document.getElementById(name+"_icon").value=sarr[1];
	window.document.getElementById(name+"_img").src=sarr[1];
	window.document.getElementById(name+"_show").value=sarr[2];

	var lnk=window.document.getElementById(name+"_lnk");
	lnk.href=sarr[2];
	if (sarr[2]=='') lnk.removeAttribute('href');
		
	window.document.getElementById(name+"_real").value=sarr[3];
	window.document.getElementById(name+"_new").value=sarr[4];
	
	if (sundos=='')
		sundo.value='';
	else
		sundo.value=sundos.join(String.fromCharCode(254));
		
	btn=window.document.getElementById(name+"_btn1");
	if (sarr[0]=='')
		btn.value='Upload';		
	else
		btn.value='Delete';		

	processUndoState(window, name);
	
}

function processUndoState( win, name ){
	btn=win.document.getElementById(name+"_btn2");
	sundo=win.document.getElementById(name+"_undo");
	if (sundo.value=='')
		btn.disabled='disabled';		
	else
		btn.disabled='';		
}

function processUpload( win, name, fname, show, icon, real, rfname ){
	processSaveUndo(0, win, name);
	
	win.document.getElementById(name).value=fname;
	win.document.getElementById(name+'_icon').value=icon;
	win.document.getElementById(name+'_img').src=icon;
	win.document.getElementById(name+'_show').value=show;
	win.document.getElementById(name+'_lnk').href=show;
	win.document.getElementById(name+'_real').value=real;
	win.document.getElementById(name+'_fname').value=rfname;
	win.document.getElementById(name+'_new').value=1;

	win.document.getElementById(name+'_btn1').value='Delete';	
}

function unsetOpener(){
	if (window.opener){
		if (! window.opener.closed) {
			//window.opener.blur();
			window.opener.focus();
		}
		window.opener=null;
	} 
}
function closeWindow(){
	if (window.onunload) window.onunload=null;
	unsetOpener();
	window.close();
}


function hide_div( id ){
	var div=document.getElementById(id);
	if (div) {
		if (div.style) {
			div.style.display='none';
		}
	}
}

function show_div( id ){
	var div=document.getElementById(id);
	if (div) {
		if (div.style) {
			div.style.display='';
		}
	}
}
function showhide_div( id ){
	var div=document.getElementById(id);
	if (div) {
		if (div.style) {
			if (div.style.display=='none') div.style.display=''; else div.style.display='none';
		}
	}
}


function myTimestamp(){    tstmp = new Date();        return tstmp.getTime();} 

function loadXMLDoc(url)
{
		try {// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
 		} catch (e1)  {// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 		}
 		
 		if (xmlhttp){
				xmlhttp.open("GET",url,false);
				xmlhttp.send(null);
		
				return xmlhttp.responseText;
		}
}

function autoloadXMLDoc(url, elm, msg)
{
		try {// code for IE7+, Firefox, Chrome, Opera, Safari
  			var xmlhttp=new XMLHttpRequest();
 		} catch (e1)  {// code for IE6, IE5
  		var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 		}
		
		if (xmlhttp){
					xmlhttp.onreadystatechange=function(){
 								if (xmlhttp.readyState==4){
  									if (xmlhttp.status==200 || window.location.href.indexOf("http")==-1){
   											if (elm) elm.innerHTML=xmlhttp.responseText;
  									} else {
  											if (msg) window.alert(msg);
  									}
 								}
						}

					xmlhttp.open("GET",url,true);
					xmlhttp.send(null);
		}
}
function javapopups (win){
		if (! win) win=window;
		var el;
   	for(i=0; i<win.document.links.length; i++){
   			el=win.document.links[i];
   			if (el.className.indexOf('javapopup')>-1) {
   					el.target='';
   					el.href='javascript:javaPopup(window, \''+el.href+'\');';
   			}
   	}
}
function setValue( elm, val ){
		if (elm.value) elm.value=val;
		return true;
}
function clearValue( elm, val ){
		if (elm.value) elm.value='';
		return true;
}
function setValueOn( elm, val, val2 ){
		if (elm.value==val) elm.value=val2;
		return true;
}
function clearValueOn( elm, val ){
		if (elm.value==val) elm.value='';
		return true;
}
