//-----------------------------------------------------------------------------
// fa01.js
//
// FutureArts Core Scripts
// Version 1
//
// Authors:	Stephen Detwiler
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
var g_isIE;
var g_isWin;
var g_dlgOpen;		// flag if a dialog is currently open
var ttLocatorPath = null;
var ttLocatorPathType = null;

//-----------------------------------------------------------------------------
// BrowserDetect();
//-----------------------------------------------------------------------------
function BrowserDetect()
{
	g_isIE = navigator.appVersion.indexOf("MSIE")>0;
	g_isWin = navigator.appVersion.indexOf("Win")>0;
}

//-----------------------------------------------------------------------------
// FaError()
//-----------------------------------------------------------------------------
function FaError( msg )
{
	alert( "FutureArts Form Processing Error\r\n\r\n" + msg );
	return false;
}

//-----------------------------------------------------------------------------
// FormFieldClr( f, thefield )
//
// This function clears the entry for the passed form name and field name
//
// This only works for IE
//-----------------------------------------------------------------------------
function FieldReset( thefield )
{
	thefield.value="";
}

//-----------------------------------------------------------------------------
// FormValidate( f )
//
// This function validates the passed form to ensure each field value is within
// range of the max and min values specified.
//
// This only works for IE
//-----------------------------------------------------------------------------
function FormValidate( f )
{
	if( !g_isIE )
	{
		FaError( "You are not using IE" );
		return true;
	}


	for( i=0; i<f.elements.length; i++ )
	{
		if( f.elements[i].min > f.elements[i].value.length )
		{
			FaError( "Not enough data was provided for " + f.elements(i).name );
			return false;
		}

		if( f.elements[i].max < f.elements[i].value.length )
		{
			FaError( "Too much data was provided for " + f.elements(i).name );
			return false
		}
	}

	return true;
}


//-----------------------------------------------------------------------------
// Required( forn, szField )
//
//	Requires the field exists, but any/no value is valid
//-----------------------------------------------------------------------------
function Required( form, szField )
{
	if( form[szField] == null )
	{
		FaError( szField + " is missing from the form" );
		return false;
	}

	if( form[szField].value.length < 1 )
	{
		FaError( szField + " requires a value" );
		return false;
	}

	return true;

}


//-----------------------------------------------------------------------------
// Optional( forn, szField )
//
//	Requires the field exists, but any/no value is valid
//-----------------------------------------------------------------------------
function Optional( form, szField )
{
	if( form[szField] == null )
	{
		FaError( szField + " is missing from the form" );
		return false;
	}

	return true;

}

//-----------------------------------------------------------------------------
// function FutureArtsValidate( srcform, dtfunct )
//-----------------------------------------------------------------------------
function FutureArtsValidate( srcform )
{
	if( Required( srcform, "MfcIsapiCmd" ) == false )
		return false;
	if( Required( srcform, "coid" ) == false )
		return false;
	if( Required( srcform, "loc" ) == false )
		return false;
	return true;
}

//-----------------------------------------------------------------------------
// Reads variable passed within url
//-----------------------------------------------------------------------------
function GetVarInURL( thevar )
{
	var theurl = window.location.href;
	intvar = thevar + "=";
	s = theurl.indexOf(intvar);
	if( s == -1 )
		return null;

	s+= intvar.length;

	e = theurl.indexOf("&", s);
	if( e == -1 )
		e = theurl.length;

	return (theurl.substring(s,e) );	
}

//-----------------------------------------------------------------------------
// Clears form element
//-----------------------------------------------------------------------------
function ResetField( name )
{
f[name].value="";
}

//-----------------------------------------------------------------------------
// Initializes state
//-----------------------------------------------------------------------------
function Init()
{
	BrowserDetect();
	g_dlgOpen = false;
}

//-----------------------------------------------------------------------------
// User Audit Popup
//-----------------------------------------------------------------------------
function AuditUserDlg( loc, un )
{
	var strUn = new String( un );
	
	theurl = "/cp/audit/indexaudituser.fsp?loc=" + loc;
	if(strUn.length )
		theurl+= "&un=" + un;
	window.open( theurl, "_blank", "directories=no,toolbar=no,height=350,width=500,location=no,menubar=no,resizable=no,scrollbars=auto,status=no,toolbar=no", false );
	
}

//-----------------------------------------------------------------------------
// Item Audit Popup
//-----------------------------------------------------------------------------
function AuditItemDlg( loc, id )
{
	theurl = "/cp/audit/indexaudititem.fsp?loc=" + loc + "&id=" + id;
	window.open( theurl, "_blank", "directories=no,toolbar=no,height=350,width=500,location=no,menubar=no,resizable=no,scrollbars=auto,status=no,toolbar=no", false );
	
}

//-----------------------------------------------------------------------------
// Functions to call on load
//-----------------------------------------------------------------------------
Init();
