var errorMsg0   = 'strFormEmpty';
var errorMsg1   = 'strNotNumber';
var errorMsg2   = 'strNotValidNumber';


/*
reqargs.requesturi	// someurl |type: string |default: null |eg: './responsegateway.url'
reqargs.requestmethod	// get/post |type: string |default: null |eg: 'post'
reqargs.responsemethod	// text/xml/body/stream |type: string |default: xml |eg:'xml'
reqargs.sendstring // send arguments |type: string |default: null |eg: 'arg1=val1&arg2=val2'
reqargs.initfunc // init function name |type: function name(string) |default: null |eg: mydefinedinit
reqargs.initfuncargs // init function arguments object |type: object |default: null |eg: mydefinedinitargs
reqargs.responsefunc // response function name |type: function name(string) |default: null |eg: mydefinedresponse
reqargs.responsefuncargs // response function arguments object |type: object |default: null |eg: mydefinedresponseargs
reqargs.errorhandlerfunc // error handler function name |type: function name(string) |default: null |eg: mydefinederrorhandler
reqargs.errorhandlerfuncargs // errorhandler function arguments object |type: object |default: null |eg: mydefinederrorhandlerargs
*/
function sendXMLHttpRequest(reqargs)
{
    //requesturi,requestmethod,responsemethod,sendstring,initfunc,initfuncargs,responsefunc,responsefuncargs,errorhandlerfunc,errorhandlerfuncargs

	requesturi=reqargs.requesturi;
	requestmethod=reqargs.requestmethod;
	responsemethod=reqargs.responsemethod;
	sendstring=reqargs.sendstring;
	initfunc=reqargs.initfunc;
	initfuncargs=reqargs.initfuncargs;
	responsefunc=reqargs.responsefunc;
	responsefuncargs=reqargs.responsefuncargs;
	errorhandlerfunc=reqargs.errorhandlerfunc;
	errorhandlerfuncargs=reqargs.errorhandlerfuncargs;
	var xmlhttp = new XMLHttpRequest();
	if (xmlhttp.overrideMimeType)
	{
		xmlhttp.overrideMimeType('text/xml');
	}
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4)
		{
			if(xmlhttp.status == 200)
			{
				
                var responseobj = xmlhttp.responseXML;
                switch(responsemethod.toLowerCase())
                {
                    case 'text':
                        responseobj = xmlhttp.responseText;
                        break;
                    case 'xml':
                        responseobj = xmlhttp.responseXML;
                        break;
                    case 'body':
                        responseobj = xmlhttp.responseBody;
                        break;
                    case 'stream':
                        responseobj = xmlhttp.responseStream;
                        break;
                    default:
                    responseobj = xmlhttp.responseXML;
                }
				if(responsefunc)
				{
					if(responsefuncargs)
					{
						responsefunc(responseobj,responsefuncargs);
					}
					else
					{
						responsefunc(responseobj);
					}
				}
			}
			else
			{
				if(errorhandlerfunc)
				{
					if(errorhandlerfuncargs)
					{
						errorhandlerfunc(errorhandlerfuncargs);
					}
					else
					{
						errorhandlerfunc();
					}
				}
			}
		}
		else
		{
			if(initfunc)
			{
				if(initfuncargs)
				{
					initfunc(initfuncargs);
				}
				else
				{
					initfunc();
				}
			}
		}
    }
	thisrequestmethod=requestmethod.toUpperCase();

    var thisrequesturi=requesturi;
	if(thisrequestmethod=='GET')
	{
		getresargstagpos=requesturi.indexOf('?');
		if(getresargstagpos!=-1)
		{
			if(getresargstagpos==requesturi.length-1)
			{
				thisrequesturi=requesturi+sendstring;
			}
			else
			{
				thisrequesturi=requesturi+'&'+sendstring;
			}
		}
		else
		{
			thisrequesturi=requesturi+'?'+sendstring;
		}
		
	}
	else
	{
		thisrequesturi=requesturi;
	}
	xmlhttp.open(thisrequestmethod, thisrequesturi);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	xmlhttp.setRequestHeader('If-Modified-Since','Sun,3 Jun 1973 00:00:00 GMT');
    xmlhttp.send(sendstring);
}

// argument 0 requese form
// argument 1 info div id
// argument 2 response function name

function requestAction()
{
    var thismargestring=foreachform(arguments[0]);
    var theform = document.getElementById(arguments[0]);
	//var thismethod=theform.method;
	var thismethod=theform.attributes["method"].value;
	var thisaction=theform.attributes["action"].value;
    var theinfodiv = document.getElementById(arguments[1]);
	var theresponsefuncname=arguments[2];

	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() 
	{
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
            theresponsefuncname(xmlhttp.responseXML,theinfodiv);
        }
    }
    xmlhttp.open(thismethod, thisaction);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
    xmlhttp.send(thismargestring);
}


function foreachform()
{
    var thismargestring='';
    var theform = document.getElementById(arguments[0]);
    for (i = 0; i < theform.length; i++) 
    {
		switch(theform.elements[i].tagName)
		{
			case "INPUT":
				switch(theform.elements[i].type)
				{
					case "text":
					case "password":
					case "hidden":
						thismargestring+='&'+theform.elements[i].name+'='+escape(theform.elements[i].value);
					break;
					case "submit":
					case "reset":
					case "button":
						thismargestring+='&'+theform.elements[i].name+'='+escape(theform.elements[i].value);
					break;
					case "checkbox":
						if(theform.elements[i].checked)
						{
							thismargestring+='&'+theform.elements[i].name+'='+escape(theform.elements[i].value);
						}
					break;
					case "radio":
						if(theform.elements[i].checked)
						{
							thismargestring+='&'+theform.elements[i].name+'='+escape(theform.elements[i].value);
						}
					break;
					case "file":
						thismargestring+='&'+theform.elements[i].name+'='+escape(theform.elements[i].value);
					break;
					default:  
				}
			break;
			case "SELECT":
				if(theform.elements[i].length>0)
				{
					if(theform.elements[i].getAttribute('multiple'))
					{
						for(var j=0;j<theform.elements[i].length;j++)
						{
							if(theform.elements[i].selectedIndex!=-1)
							{
								if(theform.elements[i].options[j].selected==true)
								{
									thismargestring+='&'+theform.elements[i].name+'='+escape(theform.elements[i].options[j].value);
								}
							}
						}
					}
					else
					{
						if(theform.elements[i].selectedIndex!=-1)
						{
							thismargestring+='&'+theform.elements[i].name+'='+escape(theform.elements[i].options[theform.elements[i].selectedIndex].value);
						}
					}
				}
			break;  
			case "TEXTAREA":
						thismargestring+='&'+theform.elements[i].name+'='+escape(theform.elements[i].value);
			break;   
			default:
			break;
		}
    }
	thismargestring=thismargestring.substring(1,thismargestring.length);
	return thismargestring;
}

// xml get doc selectednode innertext
function getNodeText(doc, xpath)
{
  var retval = "";
  var value = doc.selectSingleNode(xpath);
  if (value) retval = value.text;
  return retval;
}


function getXMLObj()
{

	var xmlDoc = XmlDocument.create();
	xmlDoc.async = false;
	xmlDoc.load(arguments[0]);
    xmlObj=xmlDoc.documentElement;
    return xmlObj;
}

function loadmainmenu(xmlurl,cntMainObj,cntSubObj,xmlmainlabelattrib,xmlmainvalueattrib)
{
    var thexmlobj=getXMLObj(xmlurl);
    var themainobj=document.getElementById(cntMainObj);
    var thesubobj=document.getElementById(cntSubObj);

    // clear mainclass
    for (var i = themainobj.options.length; i >= 0; i--)
    {
        themainobj.options[i] = null;
    }

    // clear subclass
    for (i = thesubobj.options.length; i >= 0; i--)
    {
        thesubobj.options[i] = null;
    }

    for (i=0;i<thexmlobj.childNodes.length;i++)
    {
        thelabel=thexmlobj.childNodes(i).getAttribute(xmlmainlabelattrib);
        thevalue=thexmlobj.childNodes(i).getAttribute(xmlmainvalueattrib);
        themainobj.options[i] = new Option(thelabel,thevalue);
    }

}

function setsubmenu(xmlurl,mainObj,subObj,xmlmainvalueattrib,xmlsubvalueattrib)
{
    var thisxmlobj=getXMLObj(xmlurl);
    var thismainobj=document.getElementById(mainObj);
    var thissubobj=document.getElementById(subObj);
    var cntmainobj;
    var mainexist=false;
    var thismainid=thismainobj[thismainobj.selectedIndex].value;

    // clear subclass
    for (i = thissubobj.options.length; i >= 0; i--)
    {
        thissubobj.options[i] = null;
    }

    if((thismainid == null)||(thismainid == "")||(thismainid == "undefined"))
    {
        return false;
    }

    // get cnt main class
    for (i=0;i<thisxmlobj.childNodes.length;i++)
    {
        if(thisxmlobj.childNodes(i).getAttribute(xmlmainvalueattrib)==thismainid)
        {
            cntmainobj=thisxmlobj.childNodes(i);
            mainexist=true;
            break;
        }
    }
    if(!mainexist)
    {
        return false;
    }

    // set sub class
    for (j=0;j<cntmainobj.childNodes.length;j++)
    {
        cntsubclasslabel=cntmainobj.childNodes(j).text;
        cntsubclassvalue=cntmainobj.childNodes(j).getAttribute(xmlsubvalueattrib);
        if((cntsubclassvalue == null)||(cntsubclassvalue == "")||(cntsubclassvalue == "undefined")||(cntsubclasslabel == null)||(cntsubclasslabel == "")||(cntsubclasslabel == "undefined"))
        {
            return false;
            break;
        }
        thissubobj.options[j] = new Option(cntsubclasslabel,cntsubclassvalue);
    }
}

function redirecturl()
{
	url=(arguments[0])?arguments[0]:'about:blank';
	target=(arguments[1])?arguments[1]:'self';
	if(target.toLowerCase()=='self')
	{
		self.location.href=url;
	}
	else
	{
		top.window[target].location.href=url;
	}
}

function ctlent(obj) {
	if((event.ctrlKey && window.event.keyCode == 13) || (event.altKey && window.event.keyCode == 83)) {
		//if(validate(this.document.input)) 
		this.document.obj.submit();
	}
}

function checkAll(str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  for (var i=0; i<n; i++)
  a[i].checked = window.event.srcElement.checked;
}

function checkItem(str)
{
  var e = window.event.srcElement;
  var all = eval("document.all."+ str);
  if (e.checked)
  {
    var a = document.getElementsByName(e.name);
    all.checked = true;
    for (var i=0; i<a.length; i++)
    {
      if (!a[i].checked){ all.checked = false; break;}
    }
  }
  else all.checked = false;
}

function RadioCheckedArray()
{
    this.theradioele = document.getElementsByName(arguments[0]);
	var returnvalue = null;
	this.returnarray = new Array();
    for (i = 0; i < this.theradioele.length; i++) 
    {
		if(this.theradioele[i].checked)
		{
			this.returnarray.push(i,this.theradioele[i].value);
			break;
		}
	}
}

function CheckBoxCheckedArray()
{
    this.thecheckboxele = document.getElementsByName(arguments[0]);
	this.returnarray = new Array();
    for (i = 0; i < this.thecheckboxele.length; i++) 
    {
		if(this.thecheckboxele[i].checked)
		{
			this.returnarray.push(new Array(i,this.thecheckboxele[i].value));
		}
	}
}

function getRadioCheckedValue()
{
    var theradioele = document.getElementsByName(arguments[0]);
	var returnvalue = null;
    for (i = 0; i < theradioele.length; i++) 
    {
		if(theradioele[i].checked)
		{
			returnvalue=theradioele[i].value;
			break;
		}
	}
	return returnvalue;
}

function getCheckBoxCheckedValueArray()
{
    var thecheckboxele = document.getElementsByName(arguments[0]);
	var returnarray = new Array();
    for (i = 0; i < thecheckboxele.length; i++) 
    {
		if(thecheckboxele[i].checked)
		{
			returnarray.push(thecheckboxele[i].value);
		}
	}
	return returnarray;
}

function writeOptions()
{
	var i,start,step,len,a,args=showOptions.arguments;
	a = args[0];
	len = a.length;
	start = (args.length>=2)?args[1]:0;
	step = 2;
	for(i=start;i<len;i+=step)
	{
		document.writeln("<option value="+a[i]+">"+a[i+1]+"</option>");
	}
}

// Element Get Focus
function getfocus(obj)
{
	var thisobj=findObj(obj);
		thisobj.focus();
} 

function checkall(form)
{
	for(var i = 0;i < form.elements.length; i++)
	{
		var e = form.elements[i];
		if (e.name != 'chkall')
		{
			e.checked = form.chkall.checked;
		}
	}
}

function findObj(n, d)
{
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function copyElementText(obj)
{
	var thisobj=findObj(obj);
	if (thisobj)
	{ 
		thisobj.select();
		js=obj.createTextRange();
		js.execCommand("Copy");
	}
}

function copycode(obj)
{
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.scrollIntoView();
	rng.select();
	rng.execCommand("Copy");
	rng.collapse(false);
}

function GetCookieVal(offset) 
//get unescaped cookie value
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value) 
//set cookie value
{ 
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
} 

function DelCookie(name)
//delete Cookie
{ 
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

function GetCookie(name) 
//get cookie org value

{ 
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}


// table backgroundcolor change
function mOvr(src,clrOver)
{ 
	if (!src.contains(event.fromElement))
	{
		src.style.cursor = 'hand'; src.bgColor = clrOver;
	}
}
function mOut(src,clrIn)
{
	if (!src.contains(event.toElement))
	{
		src.style.cursor = 'default'; src.bgColor = clrIn;
	}
}
function mClk(src)
{
	if(event.srcElement.tagName=='TD')
	{
		src.children.tags('A')[0].click();
	}
}

// clear Div layer innerhtml
function clearDivHTML(divname)
{
	var thisdivobj=document.getElementById(divname);
	thisdivobj.innerHTML='';
}
// show / hide layer
function opencloselayer(id, show)
{
	var elem = document.getElementById(id);
	if (elem) 
	{
		if (show) 
		{
			elem.style.display = 'block';
			elem.style.visibility = 'visible';
			//elem.filters.alpha.opacity=100;
		} 
		else
		{
			elem.style.display = 'none';
			elem.style.visibility = 'hidden';
			//elem.filters.alpha.opacity=0;
		}
	}
}
// changelayeropacity(IE)
function changelayeropacity(id,opa)
{
　var elem = document.getElementById(id);
　if (elem && opa>0 && opa<=100) 
　{
　　　elem.filters.alpha.opacity=opa;
　}
}

// popupWindow

function popupWindow(url,name,width,height)
{
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen)
	{ 
		var ah = screen.availHeight - 30; 
		var aw = screen.availWidth - 10; 
		var xc = (aw - width) / 2; 
		var yc = (ah - height) / 2; 
		str += ",left=" + xc + ",screenX=" + xc; 
		str += ",top=" + yc + ",screenY=" + yc; 
	}
	str += ", titlebar=no, toolbar=no, menubar=no, scrollbars=auto, resizable=yes,location=no, status=no";
	return window.open(url, name, str); 
}


// popupModalDialog
function popupModalDialog(url,param,width,height)
{
	var str='dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;';
	if (window.screen)
	{ 
		var ah = screen.availHeight - 30; 
		var aw = screen.availWidth - 10; 
		var xc = (aw - width) / 2; 
		var yc = (ah - height) / 2; 
		str +='dialogLeft:' + xc + 'px;dialogTop:' + yc + 'px;';
	}
	str +='center:yes;help:no;resizable:yes;status:no;';
	return window.showModalDialog(url,param, str); 
}

// popupModelessDialog
function popupModelessDialog(url,param,width,height)
{
	var str='dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;';
	if (window.screen)
	{ 
		var ah = screen.availHeight - 30; 
		var aw = screen.availWidth - 10; 
		var xc = (aw - width) / 2; 
		var yc = (ah - height) / 2; 
		str +='dialogLeft:' + xc + 'px;dialogTop:' + yc + 'px;';
	}
	str +='center:yes;help:no;resizable:yes;status:no;';
	return window.showModelessDialog(url,param, str); 
}



/**
* reference to PMA
*/



/**
 * Ensures a value submitted in a form is numeric and is in a range
 *
 * @param   object   the form
 * @param   string   the name of the form field to check
 * @param   integer  the minimum authorized value
 * @param   integer  the maximum authorized value
 *
 * @return  boolean  whether a valid number has been submitted or not
 */
function checkFormElementInRange(theForm, theFieldName, min, max)
{
    var theField         = theForm.elements[theFieldName];
    var val              = parseInt(theField.value);

    if (typeof(min) == 'undefined') {
        min = 0;
    }
    if (typeof(max) == 'undefined') {
        max = Number.MAX_VALUE;
    }

    // It's not a number
    if (isNaN(val)) {
        theField.select();
        alert(errorMsg1);
        theField.focus();
        return false;
    }
    // It's a number but it is not between min and max
    else if (val < min || val > max) {
        theField.select();
        alert(val + errorMsg2);
        theField.focus();
        return false;
    }
    // It's a valid number
    else {
        theField.value = val;
    }

    return true;
} // end of the 'checkFormElementInRange()' function

/**
 * Displays an confirmation box before doing some action 
 *
 * @param   object   the message to display 
 *
 * @return  boolean  whether to run the query or not
 */
function confirmAction(theMessage)
{
    // TODO: Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(theMessage);

    return is_confirmed;
} // end of the 'confirmAction()' function


/**
  * Checks/unchecks all options of a <select> element
  *
  * @param   string   the form name
  * @param   string   the element name
  * @param   boolean  whether to check or to uncheck the element
  *
  * @return  boolean  always true
  */
function setSelectOptions(the_form, the_select, do_check)
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    } // end for

    return true;
} // end of the 'setSelectOptions()' function


/**
 * Displays an error message if an element of a form hasn't been completed and
 * should be
 *
 * @param   object   the form
 * @param   string   the name of the form field to put the focus on
 *
 * @return  boolean  whether the form field is empty or not
 */
function emptyFormElements(theForm, theFieldName)
{
    var isEmpty  = 1;
    var theField = theForm.elements[theFieldName];
    // Whether the replace function (js1.2) is supported or not
    var isRegExp = (typeof(theField.value.replace) != 'undefined');

    if (!isRegExp) {
        isEmpty      = (theField.value == '') ? 1 : 0;
    } else {
        var space_re = new RegExp('\\s+');
        isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
    }
    if (isEmpty) {
        theForm.reset();
        theField.select();
        alert(errorMsg0);
        theField.focus();
        return false;
    }

    return true;
} // end of the 'emptyFormElements()' function

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  the row number
 * @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, theRowNum, 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.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.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 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);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

/*
 * Sets/unsets the pointer and marker in vertical browse mode
 *
 * @param   object    the table row
 * @param   integer   the column number
 * @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
 *
 * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
 */
function setVerticalPointer(theRow, theColNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
    var theCells = null;
    var tagSwitch = 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;
    }

    if (typeof(document.getElementsByTagName) != 'undefined') {
        tagSwitch = 'tag';
    } else if (typeof(document.getElementById('table_results')) != 'undefined') {
        tagSwitch = 'cells';
    } else {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (tagSwitch == 'tag') {
        theRows     = document.getElementById('table_results').getElementsByTagName('tr');
        theCells    = theRows[1].getElementsByTagName('td');
    } else if (tagSwitch == 'cells') {
        theRows     = document.getElementById('table_results').rows;
        theCells    = theRows[1].cells;
    }

    // 3. Gets the current color...
    var rowCnt         = theRows.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[theColNum].getAttribute) != 'undefined') {
        currentColor = theCells[theColNum].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        domDetect    = false;
        currentColor = theCells[theColNum].style.backgroundColor;
    } // end 3

    var c = null;

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor1.toLowerCase()
        || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        } else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theColNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() &&
             (typeof(marked_row[theColNum]) == 'undefined' || !marked_row[theColNum]) || marked_row[theColNum] == false) {
            if (theAction == 'out') {
                if (theColNum % 2) {
                    newColor              = theDefaultColor1;
                } else {
                    newColor              = theDefaultColor2;
                }
            }
            else if (theAction == 'click' && theMarkColor != '') {
                newColor              = theMarkColor;
                marked_row[theColNum] = true;
            }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : ((theColNum % 2) ? theDefaultColor1 : theDefaultColor2);
            marked_row[theColNum] = false;
        }
    } // end 4

    // 5 ... with DOM compatible browsers except Opera

    for (c = 0; c < rowCnt; c++) {
        if (tagSwitch == 'tag') {
            Cells = theRows[c].getElementsByTagName('td');
        } else if (tagSwitch == 'cells') {
            Cells = theRows[c].cells;
        }

        Cell  = Cells[theColNum];

        // 5.1 Sets the new color...
        if (newColor) {
            if (domDetect) {
                Cell.setAttribute('bgcolor', newColor, 0);
            } else {
                Cell.style.backgroundColor = newColor;
            }
        } // end 5
    } // end for

     return true;
 } // end of the 'setVerticalPointer()' function


/**
 * Checks/unchecks all rows
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 * @param   string   basename of the element
 * @param   integer  min element count
 * @param   integer  max element count
 *
 * @return  boolean  always true
 */
// modified 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
// - set the other checkboxes (if available) too
function setCheckboxesRange(the_form, do_check, basename, min, max)
{
    for (var i = min; i < max; i++) {
        if (typeof(document.forms[the_form].elements[basename + i]) != 'undefined') {
            document.forms[the_form].elements[basename + i].checked = do_check;
        }
    }

    return true;
} // end of the 'setCheckboxesRange()' function

/**
* reference to PMA
*/


// new addon

function fillSelectFromArray(theCtrl, itemArray, defaultOpion)
{
	var i, j;
	var selectCtrl=document.getElementById(theCtrl);
	// clear selectCtrl options
	for (i = selectCtrl.options.length; i >= 0; i--)
	{
		selectCtrl.options[i] = null;
	}

	if (defaultOpion == null)
	{
		j = 0;
	}
	else
	{
		selectCtrl.options[0] = new Option(defaultOpion[0],defaultOpion[1]);
		j = 1;
	}

	if (itemArray != null)
	{
		for (i = 0; i < itemArray.length; i++)
		{
			selectCtrl.options[j] = new Option(itemArray[i][0]);
			if (itemArray[i][1] != null)
			{
				selectCtrl.options[j].value = itemArray[i][1];
			}
			j++;
		}
		//selectCtrl.options[0].selected = true;
	}
}

/**
  * copy theobj1 selected option to theobj2 <select> element
  *
  * @param   string   theobj1
  * @param   string   theobj2
  * @param   boolean   trigertext
  * @param   boolean   trigervalue
  *
  * @return  boolean
  */
function copySelectTo(theobj1,theobj2,trigertext,trigervalue)
{
	var obj1=document.getElementById(theobj1);
	var obj2=document.getElementById(theobj2);
	if(obj1.selectedIndex=="-1" || obj1.length<1)
	{
		return false;
	}
	if(trigertext)
	{
		for(var i=0;i<obj2.length;i++)
		{
			if(obj2.options[i].text==obj1.options[obj1.selectedIndex].text)
			{
				return false;
			}
		}
	}
	if(trigervalue)
	{
		for(var i=0;i<obj2.length;i++)
		{
			if(obj2.options[i].value==obj1.options[obj1.selectedIndex].value)
			{
				return false;
			}
		}
	}
	obj2.options[obj2.length]= new Option(obj1.options[obj1.selectedIndex].text,obj1.options[obj1.selectedIndex].value);
	return true;
}

// selectionobj,index
function delSelect(theobj,theindex)
{
	var obj=document.getElementById(theobj);
	if(theindex!='selected')
	{
		if(theindex<0 || theindex>=obj.length)
		{
			return false;
		}
		obj.options[theindex]=null;
		return true;
	}
	else
	{
		if(obj.selectedIndex=="-1")
		{
			return false;
		}
		obj.options[obj.selectedIndex]=null;
		return true;
	}
}
function getSelectedIndex(theobj)
{
	var obj=document.getElementById(theobj);
	if(obj.length<1)
	{
		return false;
	}
	return obj.selectedIndex;
}
// clear selectCtrl options
function clrSelect(theobj)
{
	var obj=document.getElementById(theobj);
	for (var i = obj.options.length; i >= 0; i--)
	{
		obj.options[i] = null;
	}
}

// single input add select option theobj1(select ctrl) theobj2(input ctrl)
function input_add(theobj1,theobj2,trigertext,trigervalue)
{
	var obj1=document.getElementById(theobj1);
	var obj2=document.getElementById(theobj2);
	if((obj2.value == null)||(obj2.value == "")||(obj2.value == "undefined")||(obj2.value.length == 0))
	{
		return false;
	}
	if(trigertext)
	{
		for(var i=0;i<obj1.length;i++)
		{
			if(obj1.options[i].text==obj2.value)
			{
				return false;
			}
		}
	}
	if(trigervalue)
	{
		for(var i=0;i<obj1.length;i++)
		{
			if(obj1.options[i].value==obj2.value)
			{
				return false;
			}
		}
	}
	obj1.options[obj1.length]= new Option(obj2.value,obj2.value);
}
// double input add select option theobj1(select ctrl) theobj2(input ctrl)=new option.text theobj3(input ctrl)=new option.value trigertext=boolean trigervalue=boolean
function option_add(theobj1,theobj2,theobj3,trigertext,trigervalue)
{
	var obj1=document.getElementById(theobj1);
	var obj2=document.getElementById(theobj2);
	var obj3=document.getElementById(theobj3);
	if((obj2.value == null)||(obj2.value == "")||(obj2.value == "undefined")||(obj2.value.length == 0))
	{
		obj2.focus();
		return false;
	}
	if((obj3.value == null)||(obj3.value == "")||(obj3.value == "undefined")||(obj3.value.length == 0))
	{
		obj3.focus();
		return false;
	}

	if(trigertext)
	{
		// disallow same options(text)
		for(var i=0;i<obj1.length;i++)
		{
			if(obj1.options[i].text==obj2.value)
			{
				return false;
			}
		}
	}
	
	if(trigervalue)
	{
		// disallow same options(value)

		for(var i=0;i<obj1.length;i++)
		{
			if(obj1.options[i].value==obj3.value)
			{
				return false;
			}
		}
	}

	obj1.options[obj1.length]= new Option(obj2.value,obj3.value);
}
function option_paste(theobj1,theobj2,theobj3)
{
	var obj1=document.getElementById(theobj1);
	var obj2=document.getElementById(theobj2);
	var obj3=document.getElementById(theobj3);
	if(obj1.selectedIndex=="-1")
	{
		return false;
	}
	obj2.value=obj1.options[obj1.selectedIndex].text;
	obj3.value=obj1.options[obj1.selectedIndex].value;
}
function input_paste(theobj1,theobj2)
{
	var obj1=document.getElementById(theobj1);
	var obj2=document.getElementById(theobj2);
	if(obj1.selectedIndex=="-1")
	{
		return false;
	}
	obj2.value=obj1.options[obj1.selectedIndex].value;
}
function margeselectionstring()
{
	var currentlist=document.getElementById(arguments[0]);
	var margestring='';
	var chainstr=arguments[1];
	var margetype=arguments[2];
	if(margetype=='text')
	{
		for(var i=0;i<currentlist.length;i++)
		{
			margestring+=currentlist.options[i].text+chainstr;
		}
		margestring=margestring.substring(0,margestring.length-1);
	}
	else if(margetype=='value')
	{
		for(var i=0;i<currentlist.length;i++)
		{
			margestring+=currentlist.options[i].value+chainstr;
		}
		margestring=margestring.substring(0,margestring.length-1);
	}
	return margestring;
}

function syncsel(theobj1,theobj2)
{
	var obj1=document.getElementById(theobj1);
	var obj2=document.getElementById(theobj2);
	if(obj1.selectedIndex=="-1" || obj1.length<1 || obj1.length!=obj2.length)
	{
		return false;
	}
	obj2.options[obj1.selectedIndex].selected=true;
}

function optionstohiddenarray(formobjname,selectobjname,hiddenobjname)
{
	var theformobj=document.getElementById(formobjname);
	var theselectobj=document.getElementById(selectobjname);
	if(theselectobj.length<1)
	{
		return false;
	}
	else
	{
		for(var i=0;i<theselectobj.length;i++)
		{
			var theoptions=document.createElement('input');
			theoptions.type='hidden';
			theoptions.name=hiddenobjname;
			theoptions.id=hiddenobjname;
			theoptions.value=theselectobj.options[i].value;
			theformobj.appendChild(theoptions);
		}
	}
}
function checkAll(str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  for (var i=0; i<n; i++)
  a[i].checked = window.event.srcElement.checked;
}

function checkItem(str)
{
  var e = window.event.srcElement;
  var all = eval("document.all."+ str);
  if (e.checked)
  {
    var a = document.getElementsByName(e.name);
    all.checked = true;
    for (var i=0; i<a.length; i++)
    {
      if (!a[i].checked){ all.checked = false; break;}
    }
  }
  else all.checked = false;
}

function checkNone(str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  var isempty=true;
  for (var i=0; i<n; i++)
  {
	  if (a[i].checked){ isempty = false; break;}
  }
  return isempty;
}

function showOptions()
{
	var i,start,step,len,a,args=showOptions.arguments;
	a = args[0];
	len = a.length;
	start = (args.length>=2)?args[1]:0;
	step = 2;
	for(i=start;i<len;i+=step)
	{
		document.writeln("<option value="+a[i]+">"+a[i+1]+"</option>");
	}
}

function isMaxLength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength)
	{
		obj.value=obj.value.substring(0,mlength);
	}
}

function getPos(obj)
{
    obj.focus();
    var workRange=document.selection.createRange();
    obj.select();
    var allRange=document.selection.createRange();
    workRange.setEndPoint("StartToStart",allRange);
    var len=workRange.text.length;
    workRange.collapse(false);
    workRange.select();
    return len;
}
function setCursor(obj,num)
{
	obj.focus();
    range=obj.createTextRange(); 
    range.collapse(true); 
    range.moveStart('character',num); 
    range.select();
}

//
// public functions
//


// isEmpty

function isEmpty(theobj)
{
	var obj=document.getElementById(theobj);
	return ((obj.value == null)||(obj.value == "")||(obj.value == "undefined")||(obj.value.length == 0)); 
}

// isWhitespace

function isWhitespace(theobj)
{
	var obj=document.getElementById(theobj);
	var whitespace = " \t\n\r";
	var i;
	for (i = 0; i < obj.value.length; i++)
	{ 
		var c = obj.value.charAt(i);
		if (whitespace.indexOf(c) >= 0) 
		{
			return true;
		}
	}
	return false;
}

// isOverflow
function isOverflow(theobj,lenmin,lenmax)
{
	var obj=document.getElementById(theobj);
	return ((obj.value.length < lenmin)||(obj.value.length > lenmax)); 
}

// isCharsIn

function isCharsIn(theobj, charin)
{
	var obj=document.getElementById(theobj);
	var i;
	for (i = 0; i < obj.value.length; i++)
	{ 
		var c = obj.value.charAt(i);
		if (charin.indexOf(c) == -1) return false;
	}
	return true;
}

// isCharsEx

function isCharsEx(theobj, charex)
{
	var obj=document.getElementById(theobj);
	var i,c;
	for (i = 0; i < obj.value.length; i++)
	{ 
		c = obj.value.charAt(i);
		if (charex.indexOf(c) > -1) 
		return c;
	}
	return "";
}

// confirmfield
function confirmfield(theobj1,theobj2)
{
	var obj1=document.getElementById(theobj1);
	var obj2=document.getElementById(theobj2);
	return ((obj1.value == obj2.value));
}

/* getstrlen */
function strlen(theobj)
{
	var obj=document.getElementById(theobj);
	var i;
	var len;
	len = 0;
	for (i=0;i<obj.value.length;i++)
	{
		if (obj.value.charCodeAt(i)>255) len+=2; else len++;
	}
	return len;
}

// application functions

// disable/enable field
function switchIt(theobj,state)
{
	var obj=document.getElementById(theobj);
	obj.disabled =!state;
}
// change field value

function changeIt(theobj,val)
{
	var obj=document.getElementById(theobj);
	obj.value =val;
}

// switchCheckboxState
function switchCheckboxState(theobj,state)
{
	var obj=document.getElementById(theobj);
	if(state)
	{
		obj.checked =true;
	}
	else
	{
		obj.checked =false;
	}
}

// resetRadio

function resetRadio(obj)
{
	var thisobj = document.getElementsByName(obj);
	for(i=0;i<thisobj.length;i++) thisobj[i].checked=false;
}

// switchRadioState

function switchRadioState(obj,j)
{
	var thisobj = document.getElementsByName(obj);
	for(i=0;i<thisobj.length;i++) thisobj[i].checked=false;
	thisobj[j].checked=true;
}


// checkRadioState

function checkRadioState(theobj)
{
	var obj = document.getElementsByName(theobj);
	flag=false;
	for(i=0;i<obj.length;i++) obj[i].checked?flag=true:'';
	if(!flag)
	{
		return false;
	}
	else
	{
		return true;
	}
}

// checkCheckbox

function checkCheckbox(theobj)
{
	var obj = document.getElementsByName(theobj);
	flag=false;
	obj.checked?flag=true:'';
	if(!flag)
	{
		return false;
	}
	else
	{
		return true;
	}
}


// filtratescript

function filtratescript(strUserInput)
{
	strUserInput = Replace(strUserInput, ";", "")
	strUserInput = Replace(strUserInput,"(javascript)","&##106avascript");
	strUserInput = Replace(strUserInput,"(jscript:)","&##106script:");
	strUserInput = Replace(strUserInput,"(js:)","&##106s:");
	strUserInput = Replace(strUserInput,"(value)","&##118alue");
	strUserInput = Replace(strUserInput,"(about:)","about&##58");
	strUserInput = Replace(strUserInput,"(file:)","file&##58");
	strUserInput = Replace(strUserInput,"(vbscript:)","&##118bscript:");
	strUserInput = Replace(strUserInput,"(vbs:)","&##118bs:");
	strUserInput = Replace(strUserInput,"(document.cookie)","documents&##46cookie");
	strUserInput = Replace(strUserInput,"(on(mouse|exit|error|click|key|load))","&##111n\2");
	return strUserInput;
}



