function enabletextfield(theTextField, dropDownID)
{
	var textfield = document.getElementById(theTextField);
	var dropdown = document.getElementById(dropDownID);
	if(dropdown.value == "NEW")
	{
		textfield.style.visibility = 'visible';
		textfield.disabled = false;
	}
	else
	{
		textfield.style.visibility = 'hidden';
		textfield.disabled = true;
	}
}
				
function startCallback() 
{
	return true;
}

function completeCallback(response) 
{
	document.getElementById('subform').innerHTML = response;
}

AIM = 
{
	frame : function(c) 
	{
		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') 
		{
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}

var xmlHttp

function fetchFile(filename,divID)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url=filename;
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById(divID).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

var hh=new Array();
var lol;
var inter;

function submitAvy(decision,avybuttonID)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if(decision == 'accept')
	{
		var buttonID = ('Accept' + avybuttonID);
		var buttonID2 = ('Decline' + avybuttonID);
		disableButton(buttonID,'Accepting');
		disableButton(buttonID2,'Decline');
		var url='setAvy.php?set=yes&avy=' + avybuttonID;
		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4)
			{
				if(xmlHttp.responseText == 'done')
				{
					hh[avybuttonID]=120;
					lol = 1;
					var inter=setInterval('smoothHideBox('+avybuttonID+')',10);
					return false;
				}
				else
				{
					document.getElementById(avybuttonID).innerHTML = ('Error Ocurred: ' + xmlHttp.responseText);
				}
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	if(decision == 'decline')
	{
		var buttonID = ('Decline' + avybuttonID);
		var buttonID2 = ('Accept' + avybuttonID);
		disableButton(buttonID,'Removing');
		disableButton(buttonID2,'Accept');
		var url='setAvy.php?set=no&avy=' + avybuttonID;
		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4)
			{
				if(xmlHttp.responseText == 'done')
				{
					hh[avybuttonID]=120;
					lol = 1;
					var inter=setInterval('smoothHideBox('+avybuttonID+')',10);
					return false;
				}
				else
				{
					document.getElementById(avybuttonID).innerHTML = ('Error Ocurred: ' + xmlHttp.responseText);
				}
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function smoothHideBox(objectID)
{
	obj = document.getElementById(objectID);

	if(hh[objectID]<=1)
	{
		obj.style.visibility = 'hidden';
		obj.style.height = '0.1em';
		clearInterval(inter);
		return;
	}
	
	hh[objectID]-=Math.round(lol);
	if(lol < 10 && hh[objectID] > 40)
	{
		lol = lol + 0.1;
	}
	if(hh[objectID] < 40 && lol > 1)
	{
		
		lol = lol - 0.1;
	}
	obj.style.height = hh[objectID] + 'px';
}

function clearForm(divname) 
{ 
	document.getElementById(divname).innerHTML="";
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	  	// Internet Explorer
	  	try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  	catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function disableButton(buttonID,message)
{
	var button = document.getElementById(buttonID);
	button.value = message;
	button.disabled = true;
}

function showBox(objectID)
{
	obj = document.getElementById(objectID);
	obj.style.visibility = 'visible';
	obj.style.height = 'auto';
}

function hideBox(objectID)
{
	obj = document.getElementById(objectID);
	obj.style.visibility = 'hidden';
	obj.style.height = '0px';
}

function swapBox(objectID,init)
{
	obj = document.getElementById(objectID);
	if(init == 'hid')
	{
		if(obj.style.visibility == 'visible')
		{
			obj.style.visibility = 'hidden';
			obj.style.height = '0px';
		}
		else
		{
			obj.style.visibility = 'visible';
			obj.style.height = 'auto';
		}
	}
	if(init == 'vis')
	{
		if(obj.style.visibility == 'hidden')
		{
			obj.style.visibility = 'visible';
			obj.style.height = 'auto';
		}
		else
		{
			
			obj.style.visibility = 'hidden';
			obj.style.height = '0px';
		}
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}