// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}


//
// Main Form Functions
//

var CurVisible = 1;

function AddField(Index)
{	
	if (CurVisible < 100) {
		UpdateForm(CurVisible);
		if (document.all) {
			document.all["div"+CurVisible].style.visibility = "visible";
			document.all["div"+CurVisible].style.top = (CurVisible * 25) +"px";
		} else {
			document.all["div"+CurVisible].style.visibility = "show";
			document.all["div"+CurVisible].style.top = "10px";
		}
		CurVisible++;
		document.forms[0].elements["uploadfile"+(CurVisible-1)].focus();
	}
}

function UpdateForm(Index)
{
	var htmlStr = '<input type="file" name="uploadfile'+Index+'" id="uploadfile'+Index+'" class="inputnormalfile" style="WIDTH: 100%"></input>';
	if (IE4plus)
	{
		document.all["div"+Index].innerHTML = htmlStr;
	}
	else if (NS4)
	{
		document["div"+Index].document.open();
		document["div"+Index].document.write(htmlStr);
		document["div"+Index].document.close();
	}
	else if (NS6)
	{	
		document.getElementById("div"+Index).innerHTML = htmlStr;
	}
}

function IncludeForm(Index)
{
	var htmlStr = GetFormHTML(Index);
	if (IE4plus || NS6)
	{
		document.write( htmlStr);
	}
	else if (NS4)
	{
		// Because NS needs floating layers, we need a placeholder graphic to force anything
		// below the layer content to leave whitespace for the layer.  The position of this
		// graphic is also used in determining the position of the layer.
		document.write('<img name="formlocation" border="0" width="100%" height="100%" src="images/spacer.gif">');
	}
}

//
// Netscape 4.x Ineptness
//
function HandleOnload()
{
	if (NS4)
	{
		var width = document.formlocation.width;
		var height = document.formlocation.height;
		
		nL=new Layer(width);
		nL.name = "formlayer";
		nL.left=document.formlocation.x;
		nL.top=document.formlocation.y;
		nL.bgColor = "white";
		nL.clip.width=width;
		nL.clip.height=height;
		nL.document.open();
		nL.document.write(GetFormHTML());
		nL.document.close();
		nL.visibility = 'show';

		document.formlayer = nL;
	}
}

function HandleResize()
{
	location.reload();
	return false;
}

if (NS4)
{
	SafeAddOnload(HandleOnload);
	window.captureEvents(Event.RESIZE);
	window.onresize = HandleResize;
}