function collectForm(formname)
{
	form = document.getElementById(formname);

	var myArray = new Array();
	for(i=0;i<form.length;i++)
	{
		name = form.elements[i].name;
		val = form.elements[i].value;
		//alert(name +  "  " + val);
		myArray[name] = val;
	}
	return myArray;
}

function setError(error, element)
{
	var error2 = "";
	
	if (element == null)
		element = "error";

	if (error != '')
	{
		document.getElementById(element).innerHTML = error;
		document.getElementById(element).style.visibility= '';
		setTimeout("resetHTML('"+element+"')", 3000);
		
		if (element != "error2")
		{
			error2 = document.getElementById("error2");
			
			if (error2!=null)
			{
				document.getElementById("error2").innerHTML = error;
				document.getElementById("error2").style.visibility= '';
				setTimeout("resetHTML('error2')", 3000);
			}
		}

		return false;
	}
}

function resetHTML(obj_name) 
{
	document.getElementById(obj_name).innerHTML = "";
	document.getElementById(obj_name).style.visibility= 'hidden';
}

function redirect(url)
{
	location.href = url;
}

function openImageWindow(imageSrc,imageTitle)
{
    var l = Math.floor((screen.width)/2);
    var t = Math.floor((screen.height)/2);

_CONTENT="";
_CONTENT += "<HTML>\n";
_CONTENT += "<head>\n";
_CONTENT += "<title>"+imageTitle+"</title>\n";
_CONTENT += "<SCRIPT>\n";
_CONTENT += "var NS = (navigator.appName=='Netscape')?true:false;\n";
_CONTENT += "function fitPic() {\n";
_CONTENT += " iWidth = (NS)?window.innerWidth:document.body.clientWidth;\n";
_CONTENT += " iHeight = (NS)?window.innerHeight:document.body.clientHeight;\n";
_CONTENT += " iWidth = document.images[0].width - iWidth;\n";
_CONTENT += " iHeight = (document.images[0].height - iHeight)-12;\n";
_CONTENT += " window.resizeBy(iWidth, iHeight);\n";
_CONTENT += " self.focus(); }\n";

_CONTENT += "function replaceWindow() { \n"
_CONTENT += "w=document.images[0].width+25;\n";
_CONTENT += "h=document.images[0].height+25;\n";
_CONTENT += "window.moveTo( (screen.width - w) / 2, (screen.height - h) / 2); \n";
_CONTENT += "}\n"

_CONTENT+="</"+"SCRIPT>\n";
_CONTENT += "</head>\n";

//_CONTENT += "<BODY onLoad='setTimeout(\"fitPic();\", 250);' style='margin:0px;'>\n";
_CONTENT += "<BODY onLoad='fitPic();' style='margin:0px;'>\n";
_CONTENT += "<IMG SRC='" + imageSrc + "' border='0' style='cursor:hand;cursor:pointer;' onClick='window.close();' onLoad='replaceWindow();'> \n";
_CONTENT += "<SCRIPT>\n";
//_CONTENT += "setTimeout(\"replaceWindow()\", 500);\n";
_CONTENT += "</SCRIPT>\n";
_CONTENT += "</BODY>\n";
_CONTENT += "</HTML>\n";

  var _parms = 'directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,height=100,width=100'; //,top=' + t + ',left=' + l
  var _windowName = "PicViewer";
  
  myWindowHandle=window.open("",_windowName,_parms);
  myWindowHandle.document.open();
  myWindowHandle.document.write(_CONTENT);
  myWindowHandle.document.close();
  myWindowHandle.focus();
}


function visibilityOff(objectName)
{
	document.getElementById(objectName).style.visibility= 'hidden';
}

function visibilityOn(objectName)
{
	document.getElementById(objectName).style.visibility= '';
}

function hideControl(object_name)
{
	var obj = document.getElementById(object_name);
	if (obj != null)
	{
		disableControl(object_name);
		obj.style.display = 'none';
	}
}

function showControl(object_name)
{
	var obj = document.getElementById(object_name);
	if (obj != null)
	{
		enableControl(object_name);	
		obj.style.display = '';
	}
}

var myControlColor = new Array();

function disableControl(object_name)
{
	var obj = document.getElementById(object_name);
	if (obj != null)
	{
		myControlColor[object_name] = getStyle(object_name, 'backgroundColor'); 
		obj.disabled = true;		
		obj.style.background = '#E5E5E5';
	}
}

function enableControl(object_name)
{

	var obj = document.getElementById(object_name);
	if (obj != null)
	{
		obj.disabled = false;		
		obj.style.background = myControlColor[object_name];
	}
}

function getStyle(el, styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function getPropertyNameForBackgroundColor()
{
	var val = '';
	if (navigator.userAgent.indexOf("MSIE")!=-1)
		val = 'backgroundColor';
	else
		val = 'background-color';
	return val;
}


function getControl(object_name)
{
	return document.getElementById(object_name);
}

function addElement(objectName, title, value, selected)
{
	var object = document.getElementById(objectName);
	var option = new Option(title,value,selected,selected);
	
	if (validObj(object))
	{
		//var option = document.createElement('option');
		//option.text = title;
		//option.value = value;

		//option.text = title;
		//option.value = value;

		try 
		{
			object.add(option); // standards compliant; doesn't work in IE
		}
		catch(ex) 
		{
			object.add(option, null); // IE only
		}
	}
}

function removeAllOptions(objectName)
{
	var obj = document.getElementById(objectName);

	if (obj!=null && obj.options!=null)
		document.getElementById(objectName).options.length = 0;
}

function validObj(objToTest) 
{
	if (objToTest == null || objToTest == undefined) 
		return false;
	else
		return true;
}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

