var isDOM=document.getElementById?1:0; // DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
var isOpera=(navigator.appName=="Opera")?1:0;
var isOpera6=0;
var isOpera7=0;
var isOpera8=0;
var isOpera9=0;
var isMSIE=(document.all && document.all.item && !isOpera)?1:0; // IE 4+
var isGecko=(isDOM && navigator.appName=="Netscape")?1:0;
var isMSIE5=0;
var isMSIE6=0;
var isMSIE7=0;

var ua = navigator.userAgent;
var re;
re = new RegExp("Opera.([0-9]{1,})");
var rv;
	if(re.exec(ua) != null && isOpera)
	{
	rv = parseInt( RegExp.$1 );
	if(rv==6) isOpera6=1;
	if(rv==7) isOpera7=1;
	if(rv==8) isOpera8=1;
	if(rv==9) isOpera9=1;
	}
	else
	{
	re  = new RegExp("MSIE ([0-9]{1,})");
		if (re.exec(ua) != null && isMSIE)
		{
		rv = parseInt( RegExp.$1 );
		if(rv==5) isMSIE5=1;
		if(rv==6) isMSIE6=1;
		if(rv==7) isMSIE7=1;
		}
	}

var colorWidgetsNormalBackground="#ffffff";
var colorWidgetsErrorBackground="#ffcccc";
var colorTemp="";


function controllerCloseWindow()
{
self.window.close();
}


function controllerGetBounds(element)
{
var left = element.offsetLeft;
var top = element.offsetTop;
	for(var parent = element.offsetParent; parent; parent = parent.offsetParent)
	{
	left += parent.offsetLeft;
	top += parent.offsetTop;
	}
return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}


function  controllerAdjustYear(widget)
{
var str;
var cDate=new Date();
var currentYear=cDate.getFullYear();
var currentYearCentury=String(currentYear).substr(0, 2);
var currentYear2=String(currentYear).substr(2, 2);
eval('str=document.getElementById("' + widget + '").value;');
	if(str.length==2)
	{
		if(str>currentYear2)
		{
		str=(currentYearCentury-1)+str;
		}
		else
		{
		str=(currentYearCentury)+str;
		}
	eval('document.getElementById("' + widget + '").value=str;');
	}
}


function controllerCheckDate(day, month, year)
{
var newmonth;
var dt=new Date(year, month, day);
newmonth=dt.getMonth();
if(month!=newmonth) return false;
return true;
}


// checks that startdate occurs before the enddate
function controllerCheckStartEndDates(widgetstartday, widgetstartmonth, widgetstartyear, widgetendday, widgetendmonth, widgetendyear) 
{
var startday=controllerGetValue(widgetstartday);
var startmonth=controllerGetValue(widgetstartmonth)-1;
var startyear=controllerGetValue(widgetstartyear);

var endday=controllerGetValue(widgetendday);
var endmonth=controllerGetValue(widgetendmonth)-1;
var endyear=controllerGetValue(widgetendyear);

var ds=new Date(startyear, startmonth, startday);
var de=new Date(endyear, endmonth, endday);

	if(ds>de)
	{
	controllerSetAlert(widgetendday, alertCheckWidget);
	return false;
	}
return true;
}


function controllerCheckCorrectDate(widgetday, widgetmonth, widgetyear)
{
var newmonth;
var year;
var month;
var day;

day=controllerGetValue(widgetday);
month=controllerGetValue(widgetmonth);
year=controllerGetValue(widgetyear);

	if(!controllerCheckDate(day, (month-1), year))
	{
	controllerSetAlert(widgetday, alertCheckWidget);
	return false;
	}
return true;
}


function controllerCheckLimits(widget, low, high)
{
var val;
val=controllerGetValue(widget);
	if(val<low || val>high)
	{
	controllerSetAlert(widget, alertCheckWidget);
	return false;
	}
return true;
}


function controllerCheckCondition(widget1, condition, widget2)
{
var val1, val2;
val1=controllerGetValue(widget1);
val2=controllerGetValue(widget2);
var result=true;
	switch(condition)
	{
	case "<":
	if(!(val1<val2)) result=false;
	break;
	case "<=":
	if(!(val1<=val2)) result=false;
	break;
	case ">":
	if(!(val1>val2)) result=false;
	break;
	case ">=":
	if(!(val1>=val2)) result=false;
	break;
	case "=":
	if(!(val1=val2)) result=false;
	break;
	case "!=":
	if(!(val1!=val2)) result=false;
	break;
	}
	if(!result) controllerSetAlert(widget1, alertCheckWidget);
return result;
}


function controllerCheckColorType(event)
{
return controllerCheckValueType(event, /[0-9a-f]+/i);
}


function controllerCheckColor(widget)
{
return controllerCheckValue(widget, /^[0-9a-f]{6}$/);
}


function controllerCheckDigitsType(event)
{
return controllerCheckValueType(event, /[0-9]+/);
}


function controllerCheckDigits(widget)
{
return controllerCheckValue(widget, /[0-9]+/);
}


function controllerCheckDigitsNegativePercentType(event)
{
return controllerCheckValueType(event, /[\-0-9%]+/);
}


function controllerCheckDigitsNegativePercent(widget)
{
return controllerCheckValue(widget, /\-?[0-9]+%?$/);
}


function controllerCheckFloatType(event)
{
return controllerCheckValueType(event, /[0-9.]+/);
}


function controllerCheckFloat(widget)
{
return controllerCheckValue(widget, /[0-9.]+/);
}


function controllerCheckFloatNegativeType(event)
{
return controllerCheckValueType(event, /[\-0-9.]+/);
}


function controllerCheckFloatNegative(widget)
{
return controllerCheckValue(widget, /[\-0-9.]+/);
}


function controllerCheckEmail(widget)
{
return controllerCheckValue(widget, /^\w+(\.\w|\w|\-\w)*@([a-z0-9_-]+\.)+([a-z]{2,4})$/i);
}


function controllerCheckEmailType(event)
{
return controllerCheckValueType(event, /[a-z0-9_.@\-]+/i);
}


function controllerCheckWebsite(widget)
{
return controllerCheckValue(widget, /^([a-z0-9_\-:\/]+\.)+([a-z]{2,4})(\/)/i);
}


function controllerCheckWebsiteType(event)
{
return controllerCheckValueType(event, /[a-z0-9_\.\-\:\/]+/i);
}


function controllerCheckEnterType(event)
{
var charCode;
	if(isMSIE)
	{
	charCode=window.event.keyCode;
	}
	else
	{
	charCode=event.which;
	}
var frm;
	if(charCode==13)
	{
	var widget;
	if(isMSIE)
	{
	widget=window.event.srcElement;
	}
	else
	{
	widget=event.target;
	}
	frm=widget.form;
		for(var i=0; i<frm.elements.length; i++)
		{
			if(frm.elements[i].type=="submit")
			{
			frm.elements[i].click();
			}
		}
	}
}


function controllerCheckFill(widget)
{
var result;
result=controllerCheckValue(widget, /.+/);
return result;
}


function controllerCheckFillType(event)
{
return controllerCheckValueType(event, /.+/);
}


function controllerCheckSelected(widget)
{
var result;
var sel;
	if(isDOM)
	{
	eval('sel=document.getElementById("' + widget + '");');
	}
	if(sel.selectedIndex==-1 || !sel.selectedIndex)
	{
	controllerSetAlert(widget, alertCheckWidget);
	return false;
	}
return true;
}


function controllerCheckIPType(event)
{
return controllerCheckValueType(event, /[0-9\.]+/);
}


function controllerCheckIP(widget)
{
return controllerCheckValue(widget, /(([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])/);
}


function controllerCheckLatinOnly(widget)
{
var result;
result=controllerCheckValue(widget, /[a-z]+/i);
return result;
}


function controllerCheckLatinOnlyType(event)
{
return controllerCheckValueType(event, /[a-z]+/i);
}


function controllerCheckLatinDigits(widget)
{
var result;
result=controllerCheckValue(widget, /[a-z0-9_]+/);
return result;
}


function controllerCheckLatinDigitsType(event)
{
return controllerCheckValueType(event, /[a-z0-9_]+/);
}


function controllerCheckLatinDigitsSpace(widget)
{
var result;
result=controllerCheckValue(widget, /[a-z0-9_ \*]+/);
return result;
}


function controllerCheckLatinDigitsSpaceType(event)
{
return controllerCheckValueType(event, /[a-z0-9_ \*]+/);
}


function controllerCheckLatin(widget)
{
var result;
result=controllerCheckValue(widget, /[\x20-\x7F]+/i);
return result;
}


function controllerCheckLatinType(event)
{
return controllerCheckValueType(event, /[\x20-\x7F]+/i);
}


function controllerCheckLatinSpecial(widget)
{
var result;
result=controllerCheckValue(widget, /[\x00-\x7F]+/i);
return result;
}


function controllerCheckLatinSpecialType(event)
{
return controllerCheckValueType(event, /[\x00-\x7F]+/i);
}


function controllerCheckPassword(widget)
{
var result;
result=controllerCheckValue(widget, /[a-z0-9_]+/i);
return result;
}


function controllerCheckPasswordType(event)
{
return controllerCheckValueType(event, /[a-z0-9_]+/i);
}


function controllerCheckValue(widget, re)
{
var val;
val=controllerGetValue(widget);
	if(val.search(re)==-1)
	{
	controllerSetAlert(widget, alertCheckWidget);
	return false;
	}
return true;
}


function controllerGetValue(widget)
{
var val;
	if(isDOM)
	{
	eval('val=document.getElementById("' + widget + '").value;');
	}
	else if(isMSIE)
	{
	eval('val=document.all.' + widget + '.value;');
	}
return val;
}


function controllerCheckValueType(event, re)
{
var charCode;
	if(isMSIE)
	{
	charCode=window.event.keyCode;
	}
	else
	{
	charCode=event.which;
	}
if(charCode==0 || charCode==8 || charCode==9 || charCode==13) return true;
var str=String.fromCharCode(charCode);
if(str.search(re)==-1) return false;
controllerSetColorNormalBackground(event);
return true;
}


function controllerCheckIdentity(widget1, widget2)
{
var str1;
var str2;
	if(isDOM)
	{
	eval('str1=document.getElementById("' + widget1 + '").value;');
	eval('str2=document.getElementById("' + widget2 + '").value;');
	}
	else if(isMSIE)
	{
	eval('str1=document.all.' + widget1+ '.value;');
	eval('str2=document.all.' + widget2+ '.value;');
	}
	if(str1!=str2)
	{
	controllerSetAlert(widget2, alertCheckWidget);
	return false;
	}
return true;
}


function controllerGetWidgetType(widget)
{
var type="";
	if(isDOM)
	{
	eval('type=document.getElementById("' + widget + '").type;');
	}
	else if(isMSIE)
	{
	eval('type=document.all.' + widget + '.type;');
	}
return type;
}


function controllerAddOption(widgetID, optionValue, optionText)
{
var widget=document.getElementById(widgetID);
var newElem=document.createElement("OPTION");
newElem.value=optionValue;
newElem.text=optionText;
widget.options.add(newElem, widget.options.length);
/*
	for(var i=0; i<widget.options.length; i++)
	{
		if(widget.options[i].text>optionText)
		{
		widget.options.add(newElem, i);
		widget.options.selectedIndex=i;
		break;
		}
	}
	if(i==widget.options.length)
	{
	widget.options.add(newElem, i);
	widget.options.selectedIndex=i;
	}
*/
}


function controllerRemoveOption(widgetID, optionValue)
{
var widget=document.getElementById(widgetID);
	for(var i=0; i<widget.options.length; i++)
	{
		if(widget.options[i].value==optionValue)
		{
		widget.remove(i);
			if(i<widget.options.length)
			{
			widget.selectedIndex=i;
			}
		break;
		}
	}
}


function controllerSelectOptions(widgetID)
{
var widget=document.getElementById(widgetID);
var i;
	for(i=0; i<widget.options.length; i++)
	{
	widget.options[i].selected=true;
	}
}


function controllerDeselectOptions(widgetID)
{
var widget=document.getElementById(widgetID);
var i;
	for(i=0; i<widget.options.length; i++)
	{
	widget.options[i].selected=false;
	}
}


function controllerRemoveOptions(widgetID)
{
var widget=document.getElementById(widgetID);
	while(widget.options.length)
	{
	widget.remove((widget.options.length-1));
	}
}


function controllerSetAlert(obj, alertMessage)
{
alert(alertMessage);
// controllerSetColorBackground(obj, colorWidgetsErrorBackground);
controllerSetFocus(obj);
}


function controllerSetColorNormalBackground(event)
{
var widget;
	if(isMSIE)
	{
	widget=window.event.srcElement;
	}
	else
	{
	widget=event.target;
	}
// controllerSetColorBackground(widget.id, colorWidgetsNormalBackground);
}


function controllerShowHideSelects(vis)
{
var type;
var widget;
	if(isMSIE && !isMSIE7)
	{
		for(i=0; i<document.forms.length; i++)
		{
			for(j=0; j<document.forms[i].elements.length; j++)
			{
				if(document.forms[i].elements[j].id>"")
				{
				widget=document.forms[i].elements[j].id;
				type=controllerGetWidgetType(widget);
					if(type=="select-one" || type=="select-multiple")
					{
					eval('document.all.' + widget + '.style.visibility="' + vis + '";');
					}
				}
			}
		}
	}
}


function controllerSetColorBackground(widget, color)
{
var type;
type=controllerGetWidgetType(widget);
	if(isDOM)
	{
	if(type=="text" || type=="password") eval('document.getElementById("' + widget + '").style.background="' + color + '";');
	if(type=="select-one") eval('document.getElementById("' + widget + '").options[0].style.background="' + color + '";');
	}
	else if(isMSIE)
	{
	if(type=="text" || type=="password") eval('document.all.' + widget + '.style.background="' + color + '";');
	if(type=="select-one") eval('document.all.' + widget + '.options[0].style.background="' + color + '";');
	}
}


function controllerResetForm(formID)
{
	for(var i=0; i<document.getElementById(formID).elements.length; i++)
	{
		switch(document.getElementById(formID).elements[i].type)
		{
		case "text":
		case "textarea":
		case "hidden":
		document.getElementById(formID).elements[i].value="";
		break;
		case "select-one":
		document.getElementById(formID).elements[i].selectedIndex=0;
		break;
		case "checkbox":
		document.getElementById(formID).elements[i].checked=0;
		break;
		}
	}
}


function controllerSetEmail(box, srv, subject, cls, text)
{
var email=box +  '@' + srv;
var str='<a href="mailto:' + email;
if(subject) str+='?subject=' + subject;
str+='"';
	if(cls)
	{
	str+=' class="' + cls + '"';
	}
str+='>';
	if(text>"")
	{
	str+=text;
	}
	else
	{
	str+=email;
	}
str+='</a>';
document.write(str);
}


function controllerSetFocus(widget)
{
var type;
var range;
/*
type=controllerGetWidgetType(widget);
	switch(type)
	{
	case "text":
		if(isMSIE || isOpera)
		{
		// alert("Cool!");
		eval('range=document.getElementById("' + widget + '").createTextRange();');
		range.moveEnd("textedit");
		range.collapse(false);
		range.select();
		}
	break;
	}
*/
document.getElementById(widget).focus();
}


function controllerWindow(winID, winName, winURL, winWidth, winHeight, winParams)
{
var winLeft=(screen.width-winWidth)*.5;
var winTop=(screen.height-winHeight)*.5;
var winStr='width=' + winWidth + ', height=' + winHeight + ', left=' + winLeft + ', top=' + winTop;
winStr+=winParams;
	if(!winID || winID.closed)
	{
	winID=window.open(winURL, winName, winStr);
	}
	else
	{
	winID.focus();
	}
return winID;
}


function controllerObjectStartDrag(evt)
{
var elem;
var parent;
	if(evt) // Gecko, Opera
	{
	elem=evt.target;
	parent=elem.parentNode;
	}
	else
	{
	evt=window.event;
	elem=evt.srcElement;
	parent=elem.parentElement;
	}
	if(elem.id==objectDragID || parent.id==objectDragID)
	{
		if(isMSIE)
		{
		objectID=document.getElementById(objectDragID).parentElement.id;
		}
		else
		{
		objectID=document.getElementById(objectDragID).parentNode.id;
		}
	var x=parseInt(document.getElementById(objectID).style.left);
	var y=parseInt(document.getElementById(objectID).style.top);
		if(x && y)
		{
		document.getElementById(objectID).style.cursor="move";
		objectDragApproved=1;
		objectStartX=evt.clientX-x;
		objectStartY=evt.clientY-y;
		document.body.onmousedown=new Function("return false;");
		}
	}
}


function controllerObjectDrag(evt)
{
var minX=1;
var minY=1;
var scrollShiftX;
var scrollShiftY;
	if(isGecko)
	{
	scrollShiftX=window.scrollX;
	scrollShiftY=window.scrollY;
	}
	else if(!isMSIE7)
	{
	scrollShiftX=document.body.scrollLeft;
	scrollShiftY=document.body.scrollTop;
	}
	var maxX=document.body.offsetWidth+scrollShiftX-20;
	var maxY=document.body.offsetHeight+scrollShiftY-5;
	if(evt) // Gecko, Opera
	{
	;
	}
	else
	{
	evt=window.event;
	}
	if(objectDragApproved)
	{
	document.getElementById(objectID).style.cursor="move";
	var newLeft=evt.clientX-objectStartX;
		if(newLeft<=minX) newLeft=minX;
	var newRight=newLeft+parseInt(document.getElementById(objectID).style.width);
		if(newRight>=maxX) newLeft=maxX-parseInt(document.getElementById(objectID).style.width);
	var newTop=evt.clientY-objectStartY;
		if(newTop<=minY) newTop=minY;
	var newBottom=newTop+parseInt(document.getElementById(objectID).style.height);
		if(newBottom>=maxY) newTop=maxY-parseInt(document.getElementById(objectID).style.height);
	document.getElementById(objectID).style.left=newLeft+"px";
	document.getElementById(objectID).style.top=newTop+"px";
	document.getElementById(objectID).setAttribute("left", (newLeft-scrollShiftX));
	document.getElementById(objectID).setAttribute("top", (newTop-scrollShiftY));
	return false;
	}
return true;
}


function controllerObjectStopDrag()
{
objectDragApproved=0;
	if(objectID>"")
	{
	document.getElementById(objectID).style.cursor="default";
	document.body.onmousedown=null;
	}
objectID="";
}


function controllerCheckFlash()
{
var i;
var shock = false;
var flash = false;
	if(navigator.plugins.length)
	{
		for (i=0; i < navigator.plugins.length; i++)
		{
		if (navigator.plugins[i].name.indexOf("Shockwave Flash") != -1)
		shock = true;
		}
	}
	else
	{
		for(i=8;i>0;i--)
		{
		eval('try{flash=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);}catch(e){}');
			if(flash)
			{
			shock = true;
			break;
			}
		}
	}
return shock;
}


function controllerCenterPanel(panelID, panelWidth, panelHeight)
{
var windowHeight, windowWidth;
var scrollShiftY=0;
var scrollShiftX=0;
if(isGecko)
{
scrollShiftX=window.scrollX;
scrollShiftY=window.scrollY;
}
else if(document.body.scrollTop)
{
scrollShiftX=document.body.scrollLeft;
scrollShiftY=document.body.scrollTop;
}
else if(document.documentElement)
{
scrollShiftX=document.documentElement.scrollLeft;
scrollShiftY=document.documentElement.scrollTop;
}
	if(window.innerHeight)
	{
	windowWidth=window.innerWidth;
	windowHeight=window.innerHeight;
	}
	else
	{
		if (document.documentElement && document.documentElement.clientHeight)
		{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
		}
		else
		{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
		}
	}
var leftPos=scrollShiftX+(windowWidth-panelWidth)*.5+'px';
var topPos=scrollShiftY+(windowHeight-panelHeight)*.5+'px';
document.getElementById(panelID).style.left=leftPos;
document.getElementById(panelID).style.top=topPos;
}


function controllerCreateXMLHTTPObject()
{
var request = null;
	if(!request)
	try
	{
	request=new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e){}
	if(!request)
	try
	{
	request=new ActiveXObject('Microsoft.XMLHTTP');
	} catch (e){}
	if(!request)
	try
	{
	request=new XMLHttpRequest();
	} catch (e){}
return request;
}


function controllerXMLHTTPRequest(method, url, data, callback)
{
var request = controllerCreateXMLHTTPObject();
if(!request) return false;
request.onreadystatechange = function()
{
if(request.readyState == 4 && callback) callback(request);
};
request.open(method, url, true);
request.send(data);
return true;
}

/*
function controllerDisplayFlashObject(fileName)
{
var str=location.href;
	if(str.indexOf("wysiwyg")!=-1)
	{
	fileName=fileName.replace(/^\//g, "../../");
	}
str='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"';
// str+=' width="' + width + '" height="' + height + '"';
// id="' + id + '"';
str+='>';
document.write(str);
str='<param name="movie" value="' + fileName + '">';
str+='<param name="quality" value="high">';
str+='<param name="wmode" value="opaque">';
str+='<param name="menu" value="false">';
document.write(str);

str='<embed src="' + fileName + '"';
str+=' quality="high"';
// ' width="' + width + '" height="' + height + '"';
str+=' type="application/x-shockwave-flash"';
str+=' pluginspage="http://www.macromedia.com/go/getflashplayer"';
str+=' wmode="opaque"';
str+=' menu="false"';
str+='>';
document.write(str);

str='</embed>';
str+='</object>';
document.write(str);
}
*/