function check_submit(form, action_hidden)
{
	if(document.all || document.getElementById)
	{
		var tempobj = document.getElementById(action_hidden);
		if (tempobj && tempobj.value != "")
		{
			for (i=0; i<form.length; ++i)
			{
				var tempobj = form.elements[i];
				if (tempobj.type)
				{
					if(tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "button")
					{
						tempobj.disabled = true;
					}
				}
			}
		}
	}
}

function check_submit_names(form, action_hidden, names)
{
	if(document.all || document.getElementById)
	{
		var tempobj = document.getElementById(action_hidden);
		if (tempobj && tempobj.value != "")
		{
			if (names.length == 0)
			{
				for (i=0; i<form.length; ++i)
				{
					var tempobj = form.elements[i];
					if (tempobj.type)
					{
						if(tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "button")
						{
							tempobj.disabled = true;
						}
					}
				}
			}
			else
			{
				for (i=0; i<names.length; ++i)
				{
					var tempobj1 = document.getElementById(names[i]);
					if(tempobj1 && (tempobj1.type.toLowerCase() == "submit" || tempobj1.type.toLowerCase() == "button"))
					{
						tempobj1.disabled = true;
					}
				}
			}
		}
	}
}



function set_name(element, name)
{
	if (document.all || document.getElementById)
	{
		var tempobj = document.getElementById(name);
		tempobj.value = element.name;
	}
}

function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;//IE
     else
          key = e.which;//FF
     if(key == 13)
          return false;
     else
          return true;
}

function set_value(name, value)
{
	if(document.all || document.getElementById)
	{
		var tempobj = document.getElementById(name);
		tempobj.value = value;
	}
}


function get_value(name)
{
	if(document.all || document.getElementById)
	{
		var tempobj = document.getElementById(name);
		return tempobj.value;
	}

	return null;
}

function set_attribute(dst_element, dst_attr, value)
{
	if(document.all || document.getElementById)
	{
		var dst_obj = document.getElementById(dst_element);
		eval("dst_obj."+dst_attr+"='"+value+"';");
	}
}

function show(name)
{
	if(document.all || document.getElementById)
	{
		var element = document.getElementById(name);
		if (element)
			element.style.display='';
	}
}

function hide(name)
{
	if(document.all || document.getElementById)
	{
		var element = document.getElementById(name);
		if (element)
			element.style.display='none';
	}
}

function sw(name)
{
	if(document.all || document.getElementById)
	{
		var element = document.getElementById(name);
		if (element)
		{
			if (element.style.display == 'none')
			{
				element.style.display='';
			}
			else
			{
				element.style.display='none';
			}
		}
	}
}

function change_img(name, src1, src2)
{
	if(document.all || document.getElementById)
	{
		var element = document.getElementById(name);
		if (element.src.substr(element.src.length-src1.length, src1.length) == src1)
		{
			element.src = src2;
		}
		else
		{
			element.src = src1;
		}
	}
}

function history_back()
{
	if (history.length > 0) history.back();
}

// textarea length restriction 
function CheckTextAreaLen(ta, max_len) 
{  
	if (ta.value.length > max_len)   
	{ 
		ta.value = ta.value.substr(0, max_len);  
	}
} 

// open url in popup window
function popupOpen(title, url, width, height)
{
	var win = window.open(url, title, "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,menubar=no,toolbar=no;left=0;top=0;");
//	win.creator = self;
}

function popupOpenUnique(title, url, width, height)
{
	var date = new Date;
	var win = window.open(url, title+'_'+date.getHours()+'_'+date.getMinutes()+'_'+date.getSeconds(), "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,menubar=no,toolbar=no;left=0;top=0;");
//	win.creator = self;
}

// close popup
// flag: 0 - close, 1 - refresh parent and close, 2 - submit parent and close
function popupClose(flag)
{
   //if (flag == 1) window.opener.location.href = window.opener.location.href;
   if (flag == 1) 
   {
	window.opener.location.reload(true);
   
	if (window.opener.progressWindow)
	    window.opener.progressWindow.close();

   }
  if (flag == 2)
	window.opener.document.forms[0].submit();

   window.close();
}

// close popup and redirect parent to url
function popupCloseURL(url)
{
   window.opener.location.href = url;
   window.close();
}


function go(element, url)
{
   window.location.href = url;
}

/**
* Sets/unsets the pointer and marker in browse mode
*
* @param   object   the table row
* @param   string   the action calling this script (over, out or click)
* @param   string   the default background color
* @param   string   the color to use for mouseover
* @param   string   the color to use for marking a row
*
* @return  boolean  whether pointer is set or not
*/
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
	var theCells = null;

	// 1. Pointer and mark feature are disabled or the browser can't get the
	//    row -> exits
	if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') 
	{
	    return false;
	}
	
	// 2. Gets the current row and exits if the browser can't get it
	if (typeof(document.getElementsByTagName) != 'undefined') 
	{
	    theCells = theRow.getElementsByTagName('td');
	}
	else if (typeof(theRow.cells) != 'undefined') 
	{
	    theCells = theRow.cells;
	}
	else 
	{
	    return false;
	}
	// 3. Gets the current color...
	var rowCellsCnt  = theCells.length;
	var domDetect    = null;
	var currentColor = null;
	var newColor     = null;
	
	// 3.1 ... with DOM compatible browsers except Opera that does not return
	//         valid values with "getAttribute"
	if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') 
	{
	    currentColor = theCells[0].getAttribute('bgcolor');
	    domDetect    = true;
	}
	// 3.2 ... with other browsers
	else 
	{
	    currentColor = theCells[0].style.backgroundColor;
	    domDetect    = false;
	} // end 3
	// 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
	if (currentColor && currentColor.indexOf("rgb") >= 0)
	{
	    var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
	                                 currentColor.indexOf(')'));
	    var rgbValues = rgbStr.split(",");
	    currentColor = "#";
	    var hexChars = "0123456789ABCDEF";
	    for (var i = 0; i < 3; i++)
	    {
	        var v = rgbValues[i].valueOf();
	        currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
	    }
	}
	// 4. Defines the new color
	// 4.1 Current color is the default one
	if (!currentColor || currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) 
	{
	    if (theAction == 'over' && thePointerColor != '') 
	    {
	        newColor = thePointerColor;
	    }
	    else if (theAction == 'click' && theMarkColor != '') 
	    {
	        newColor = theMarkColor;
	    }
	}
	// 4.1.2 Current color is the pointer one
	else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
	    if (theAction == 'out') {
	        newColor = theDefaultColor;
	    }
	    else if (theAction == 'click' && theMarkColor != '') {
	        newColor = theMarkColor;
	    }
	}
	// 4.1.3 Current color is the marker one
	else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) 
	{
	    if (theAction == 'click') 
	    {
	        newColor = (thePointerColor != '')
	                 ? thePointerColor
	                 : theDefaultColor;
	    }
	}
	
	// 5. Sets the new color...
	if (newColor) 
	{
	    var c = null;
	    // 5.1 ... with DOM compatible browsers except Opera
	    if (domDetect) 
	    {
	        for (c = 0; c < rowCellsCnt; c++) 
	        {
	            theCells[c].setAttribute('bgcolor', newColor, 0);
	        }
	    }
	    // 5.2 ... with other browsers
	    else 
	    {
	        for (c = 0; c < rowCellsCnt; c++) 
	        {
	            theCells[c].style.backgroundColor = newColor;
	        }
	    }
	}

	return true;
}

