<!--
/**
* YamzBrowser 2.0 beta
*
* @author 
*
* This script is based on YamzBrowser 1.2 beta (http://sourceforge.net/projects/yamzbrowser/).  It has been
* modified slightly and documented heavily.
*
* Because this script is so heavily documented, you may save 6-7k by removing all of the comments.
*
* The basic functionality of this component is as follows:
*
*	1.	The YamzBrowser component calls this script's browseEnabled() method when the "browse" button is rolled 
*		over.
*	2.	This script dynamically positions an invisible html file input element directly under the cursor as long 
*		as the cursor position is over the Flash button element; to see this in action, remove the "invisibility"
*		attribute from the browseLayer <div> tag, and disable the stylesheet.
*	3.	Clicking "browse" actually clicks the "browse" button in the html element and opens the file browser, as 
*		expected.
*	4.	After selecting a file and clicking "Open" in the file browser, this script's browse() method is called.
*		YamzBrowserConnect.swf is loaded into an <iFrame>.  The name of the selected file is passed to 
*		YamzBrowserConnect.swf via the flashVars attribute of the object/embed tags.  YamzBrowserConnect.swf 
*		uses a LocalConnection object to pass the file name to the YamzBrowser component's getFile() method.
*	5.	The "upload" button in the component is enabled; clicking it calls the script specified in the component's
*		parameters.  This is "up.php", by default.  The script is loaded into the <iFrame> from step 4.
*	6.	The upload script handles the file upload; on completion it calls this script's upLoadEnd() method (e.g.,
*		by calling window.top.upLoadEnd(...)).
*	7.	upLoadEnd() causes YamzBrowserConnect.swf to be loaded into the <iFrame> again, this time passing details
*		of the upload to the YamzBrowser component's getUpload() method.
*/

window.onerror = function ( pMes,pUrl,pLine )
{ 
	return true;
};

// ::: "PRIVATE" PROPERTIES

var _xmouse, _ymouse;
var box		= {};
var lcFile	= "";
var lcTemp	= "";
var blStyle, blClassName;
var txtFileInput;
var embFlashLayer, objFlashLayer;
var lcActive;


// ::: "PUBLIC" METHODS

/**
* Performs some browser detection and initializes the page elements
*
* @access public
* @return Void
*/
function init() 
{
	createEmptyWindow();

	
	b=document.getElementById("browseLayer").style;
	c=document.getElementById("browseLayer").className;
	
	f = document.getElementById("flashLayer");
	w = document.getElementById("file");
	d = document.flashLayer;

	/*	
	b = blStyle
	c = blClassName
	d = embFlashLayer
	f = objFlashLayer
	w = txtFileInput
	*/

	blStyle			= document.getElementById( "browseLayer" ).style;
	blClassName		= document.getElementById( "browseLayer" ).className;
	txtFileInput	= document.getElementById( "file" );
	embFlashLayer	= document.flashLayer;
	objFlashLayer	= document.getElementById("flashLayer");
	
	lWin = (window.navigator.appName=="Microsoft Internet Explorer");
	var lVendor = (window.navigator.vendor=="");
	var lUser = window.navigator.userAgent;
	var lPos = lUser.indexOf("rv:");
	var lOldMoz = (lPos!=-1 && parseFloat(lUser.substr(lPos+3,3))<1.4);
	
	if (!lWin && lVendor && lOldMoz) {
		document.getElementById("browseLayer").className="invisible2";
		document.getElementById("ifr").className="invisible2";
	}	
	
	if (window.navigator.platform!="MacPPC") 
	{
		if (lWin)
			txtFileInput.onchange = browse;
		else	
			txtFileInput.onclick = browse;
		txtFileInput.onfocus = lcChoice;
	}
	else 
	{
		txtFileInput.onclick = lWin ? browseIE : browse;
		txtFileInput.onfocus= lWin ? null : lcChoice;
	}
	
	window.document.upload.reset();
}

/**
* Enables the input box and sets up the positioning parameters for the "browse" button; 
* called from the YamzBrowser component's browse() method
*
* @access public
* @param pLC String The name of the LocalConnection string of the calling YamzBrowser component
* @param pMode String Stage.scaleMode of the swf calling this method
* @param pAlign String Stage.align of the swf calling this method
* @param pXflash Number The width of the swf calling this method
* @param pYflash Number The height of the swf calling this method
* @param pXmin Number The left edge of the bounding box of the browse button in the swf
* @param pYmin Number The top edge of the bounding box of the browse button in the swf
* @param pXmax Number The right edge of the bounding box of the browse button in the swf
* @param pYmax Number The bottom edge of the bounding box of the browse button in the swf
* @param pXm Number The x-position of the mouse
* @param pYm Number The y-position of the mouse
* @param pCursor Boolean The useHandCursor property of the browse button in the swf
* @return Void
*/

function browseEnabled ( pLC,pMode,pAlign,pXflash,pYflash,pXmin,pYmin,pXmax,pYmax,pXm,pYm,pCursor ) 
{
	var offsetW = embFlashLayer.offsetWidth;
	var offsetH = embFlashLayer.offsetHeight;

	
	lScaleX = lScaleY = Math.min( offsetW/pXflash, offsetH/pYflash );
	var lX = ( offsetW-pXflash*lScaleX )/2;
	var lY = ( offsetH-pYflash*lScaleY )/2;
			

	txtFileInput.style.cursor = pCursor ? "hand" : "default";
	blStyle.visibility = 'visible';
	lcTemp = pLC;

	var lLeft	= ( !lWin && objFlashLayer.style.left!="" ) ? parseInt( objFlashLayer.style.left ) : 0;
	var lTop	= ( !lWin && objFlashLayer.style.top!="" ) ? parseInt( objFlashLayer.style.top ) : 0;
	var offsetL = embFlashLayer.offsetLeft;
	var offsetT = embFlashLayer.offsetTop;
	
	if(lWin){
	box.xmin	 = lLeft + offsetL + pXmin * lScaleX - 2 + lX;
	box.ymin	 = lTop + offsetT + pYmin * lScaleY - 2 + lY;
	box.xmax	 = lLeft + offsetL + pXmax * lScaleX + 4 + lX;
	box.ymax	 = lTop + offsetT + pYmax * lScaleY + 4 + lY;
	blStyle.left = offsetL + pXm * lScaleX + lX - 20;
	blStyle.top	 = offsetT + pYm * lScaleY + lY + 30;
	}else{
	blStyle.left = screen.width/2 - 200
	blStyle.top = screen.height/2 - 20
	}


	document.onmousemove = mousePos;
}

/**
* Hides the html file input
* 
* @access public
* @return Void
*/
function browseDisabled() 
{
	//blStyle.visibility = 'hidden';
	document.onmousemove = null;
}

/**
* Called by the YamzBrowser component; calls the specified upload script and begins the upload
*
* @access public
* @param pLC String The LocalConnection string of the component
* @param pScript String The url of the script that will handle uploading
* @param pData String The data array of the component; see the Parameter's pane in Flash for more info
* @return Void
*/
function upLoadFile( pLC,pScript,pData ) 
{
	lcActive = pLC;
	window.document.upload.action=pScript+"?browseLC="+pLC+"&dataLC="+pData;
	createEmptyWindow();
	window.document.upload.submit();
}

/**
* Called by the upload script when the upload has been completed successfully.
*
* @access public
* @param pLC String The LocalConnection string of the component that started all this
* @param pStatus The status of the file upload; see up.php (or the user-specified script) for more info
* @param pFile The name of the file that was uploaded
* @param pData Any data passed to the upload script from the component's "data" property; see the
*	Parameter's pane in Flash for more info
* @return Void
*/
function upLoadEnd (pLC,pStatus,pFile,pData) 
{
	wp = window.open("","pop");
	setTimeout("onUpLoadEnd('"+pLC+"',"+pStatus+",'"+pFile+"','"+pData+"')",100);
}


// ::: "PRIVATE" METHODS

/**
* Positions the html file input under the mouse while rolled over the Flash element
*
* @access private
* @return Void
*/
function mousePos(e) 
{


	if (e) {
		//netscape
		_xmouse=e.pageX;
		_ymouse=e.pageY;
	} else {
		//xplorer
		_xmouse=event.x;
		_ymouse=event.y;
	}
	
	if (lWin) {
		//explorer

		var mouseX=_xmouse+document.body.scrollLeft;
		var mouseY=_ymouse+document.body.scrollTop;
	} else {
		//netscape
		
		var mouseX=_xmouse;
		var mouseY=_ymouse;
	}

	if (mouseX>box.xmin && mouseX<box.xmax && mouseY>box.ymin && mouseY<box.ymax) 
	{
		blStyle.left=mouseX-70;
		blStyle.top=mouseY-10;
	}
	else 
	{
		browseDisabled();
	}
}

/**
* Called by upLoadEnd; creates a new window with YamzBrowserConnect.swf which passes variables via 
* LocalConnection to the calling YamzBrowser component.
*
* @access private
* @param pLC String The LocalConnection string of the component that started all this
* @param pStatus The status of the file upload; see up.php (or the user-specified script) for more info
* @param pFile The name of the file that was uploaded
* @param pData Any data passed to the upload script from the component's "data" property; see the 
*	Parameter's pane in Flash for more info
* @return Void
*/
function onUpLoadEnd( pLC,pStatus,pFile,pData ) 
{
	createWindow( "getUpload", pLC, pStatus, pFile, pData );
	if (!(lWin && window.navigator.platform!="MacPPC")) window.document.upload.reset();
}

/**
* Creates a blank document in the <iFrame>; used to initialize the frame before the upload script is
* loaded in
*
* @access private
* @return Void
*/
function createEmptyWindow () 
{
	wp = window.open("","pop");
	wp.document.open();
	wp.document.write('<HTML><BODY bgcolor="#999999"  scroll="no"></BODY></HTML>');
	wp.document.close();
}

/**
* Creates a document in the <iFrame> containing a copy of YamzBrowserConnect.swf and passes variables to
* it via the flashVars attribute of the embed/object tags.  These variables are used to open a 
* LocalConnection with the YamzBrowser component to transmit data.
*
* @access private
* @param pMeth String The name of the method on the YamzBrowser's LocalConnection obejct to invoke 
*	(either getFile or getUpload)
* @param pBrowse String The name of the LocalConnection string of the YamzBrowser component
* @param pTxt String If getFile, the name of the file browsed to or uploaded; if getUpload, the upload 
*	status (see up.php or the user-specified upload script)
* @param pFile String Only passed from onUpLoadEnd(); the name of the uploaded file
* @param pData String Only passed from onUpLoadEnd(); any data passed to the upload script from the
*	component (see the Parameter's pane in Flash)
* @return Void
*/
function createWindow ( pMeth,pBrowse,pTxt,pFile,pData ) 
{
	// alert( "createWindow -> pMeth: " + pMeth + ", pBrowse: " + pBrowse + ", pTxt: " + pTxt + ", pFile: " + pFile + ", pData: " + pData );
	wp.document.open();
	if (typeof pData=="undefined") pData="";
	var lTemp='<HTML><BODY scroll="no" bgcolor="#999999"><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="1" HEIGHT="1" id="browse">';
	lTemp+= '<PARAM NAME=movie VALUE="YamzBrowserConnect.swf">';
	lTemp+= '<PARAM NAME=FlashVars VALUE="methLC='+pMeth+'&browseLC='+pBrowse+'&txtLC='+pTxt+'&fileLC='+pFile+'&paramLC='+pData+'">';
	lTemp+= '<EMBED src="YamzBrowserConnect.swf" flashVars="methLC='+pMeth+'&browseLC='+pBrowse+'&txtLC='+pTxt+'&fileLC='+pFile+'&paramLC='+pData+'" WIDTH="1" HEIGHT="1" NAME="browse" ';
	wp.document.write(lTemp+ 'TYPE="application/x-shockwave-flash"></EMBED></OBJECT></BODY></HTML>');
	wp.document.close();
}


// ::: EVENTS

/**
* Scoped to the html file input field's click event
*
* @access public
* @return Void
*/
function browse() 
{
	if (txtFileInput.value!="") 
	{
		wp = window.open("","pop");
		setTimeout( "createWindow('getFile',lcActive,txtFileInput.value)",100 );
	}
	browseDisabled();
}

/**
* If platform==MacPPC and is in IE, this is scoped to the html file input field's click event
* 
* @access public
* @return Void
*/
function browseIE() 
{
	setTimeout( "browse()",200 );
}

/**
* Scoped to the onFocus event of the html file input field
*/
function lcChoice ()
{
	lcActive = lcTemp;
}


-->
