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();
}

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 ){
	//get button value...
	btn=window.document.getElementById(name+"_btn1");
	if (btn.value=="Upload"){
		javaPopup(window, 'admin_upload.php?f='+escape(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='';
		window.document.getElementById(name+"_lnk").href='';
		window.document.getElementById(name+"_real").value='';
		window.document.getElementById(name+"_new").value='';
	}
	
}

function processSaveUndo ( dir, win, name ){
	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
	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];
	window.document.getElementById(name+"_lnk").href=sarr[2];
	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 ){
	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+'_new').value=1;

	win.document.getElementById(name+'_btn1').value='Delete';	
}

function expandImg(win, id){
	img=win.document.getElementById('img'+id);

	if (img){
		if (img.style.position==''){
			img.style.position='relative';
			img.style.width='';
		} else {
			img.style.position='';
			img.style.width=(img.width/2)+'px';
		}

		img2=win.document.getElementById('imgz'+id);
		if (img2){
			if (img.style.position=='')
				img2.src='images/ftl_attach.gif';
			else 
				img2.src='images/ft_attach.gif';
		}

	}
}

function expandFixImg(win, id, rsrc){
	img=win.document.getElementById('img'+id);
	if (img){
		if (!img.complete){
			var img1=new Image();
			img1.src=rsrc;
			img.style.width=(img1.width / 2)+'px';
		}else
			img.style.width=(img.width / 2)+'px';
	}
}
