﻿
// NETSOFT USA WebForms Library script file

//****************** Custom dropdown functions *********************

function OpenCustomDropDown(exp, targetName)
{
	//var exp = document.all(expanderName)
	exp.targetCtl = document.all(targetName)
	exp.toggleExpand();
}

function SetTargetCtlValue(exp, val)
{
	if (exp.targetCtl)
		if (!exp.targetCtl.disabled && !exp.targetCtl.readOnly)
			exp.targetCtl.value = val;
}

//****************** Table checkbox toggler ************************
	
function toggleAll(selTable, column, obj)
{
	if (obj.checked)
		checkAll(selTable, column, true); 
	else
		checkAll(selTable, column, false);
}

function checkAll(selTable, column, checkValue)
{
	//var selTable = document.all("SelectInvoicesTable");
	var len = selTable.rows.length;
	for (var i = 0; i < len; i++)
	{
		if (i != 0)
		{
			var row = selTable.rows(i);
			var e = row.cells(column).firstChild;
			e.checked=checkValue;
		}	
	}
}

//******************    Pop up Window    ****************************


var oPopup;

function OpenPopup(text, width, height, left, top, className)
{
	if (!width) width = 300;
	if (!height) height = 50;
	if (!left) left = (document.body.offsetWidth / 2) - (width / 2);
	if (!top) top = (document.body.offsetHeight / 2) - (height - 2);
	if (!className) className = "PopupMessage";


	oPopup = window.createPopup();
	var oPopBody = oPopup.document.body;
	oPopup.document.createStyleSheet(document.styleSheets[0].href);
	oPopBody.className = "PopupBody";
	oPopBody.innerHTML += "<DIV class=" + className + ">" + text + "</DIV>";
	oPopup.show(left, top, width, height, document.body);
	
	return oPopup;
}

function DisplayLoadingMessage()
{
	try
	{
		var width = 120;
		var height = 20;

		if (!oPopup || !oPopup.isOpen)
			OpenPopup("Please Wait...", width, height, document.body.offsetWidth - (width + 20), 5, "LoadingMessage");
		
		if (Page_IsSubmitted || document.readyState == "interactive")
			window.setTimeout("DisplayLoadingMessage();", 10);
		else
			DisplayCompleteMessage();
	}
	catch(ex)
	{}
}

function DisplayCompleteMessage()
{
	try
	{
		var width = 100;
		var height = 30;

		var popup = OpenPopup("Completed...", width, height, document.body.offsetWidth - (width + 20), 5, "LoadingMessage");
		popup.hide();			
	}
	catch(ex)
	{}
}

//window.setTimeout("DisplayLoadingMessage();", 50);
//DisplayLoadingMessage();


//****************** WindowOpener Class ****************************

function WindowOpener(windowName, navigateUrl, windowWidth, windowHeight)
{
	this.windowName = windowName;
	this.navigateUrl = navigateUrl;
	this.windowWidth = windowWidth;
	this.windowHeight = windowHeight;
	//this.pickTarget = null;
	this.toolBar = 1;
	this.statusBar = 1;
	this.menuBar = 1;
	this.scrollBars = 1;
	this.resizable = 1;
	this.copyHistory = 1;
	this.addressBar = 1;
	this.linksBar = 1;
	this.window = null;
	this.afterOpen = null;
	this.beforeOpenFunction = null;
	this.open = WindowOpener_open;
	this.close = WindowOpener_close;
	this.notify = WindowOpener_notify;
	this.windowMode = 0;		// NewWindow = 0, ModalDialog = 1, ModelessDialog = 2
}
	
function WindowOpener_open()
{
	// call the before open function if defined
	if (this.beforeOpenFunction!=null)
		if (!this.beforeOpenFunction(this))	// passes the window opener object
			return;		// if false is returned, doesn't open the window.

	var bopen = false;
	if (this.window==null)
		bopen = true;
	else
		if (this.window.closed)
			bopen = true;
	if (bopen)
	{		
		var url = this.navigateUrl;
		
		var i = 0;
		var l = url.length;
		//window.alert(url);
		
		while (i < l)
		{	
			var origUrl = url;
			var i1 = origUrl.indexOf("@", i);
			if (i1 < 0)
				break;
			var i2 = origUrl.indexOf("@", i1 + 1);
			if (i2 < 0)
				break;
			var key = origUrl.substring(i1 + 1, i2);
			//var val = document.all(key).value.split('-')[0];
			var val = GetElemValue(key);
			i2++;
			url = origUrl.substring(0, i1) + val;
			i = url.length;		// the new i is the position starting from the end of substitution
			url += origUrl.substring(i2, l);
			l = url.length;
			//window.alert(i1 + ': '+ url);
			//i = i2 + 1 + val.length - key.length;
		}
		
		//window.alert(url);
		
		//OpenPopup("Please Wait...", 160, 30);
		
		if (this.windowWidth==0 || this.windowWidth=='' || this.windowWidth==null)
			this.windowWidth = '750px';
		if (this.windowHeight==0 || this.windowHeight=='' || this.windowHeight==null)
			this.windowHeight = '750px';
			
		//this.windowMode = 2;			// temporarily force modal dialog.
		
		if (this.windowMode == 0)		// new window
		{
			this.window = window.open(url,this.windowName,
			'left='+this.windowLeft+',top='+this.windowTop+
			',width='+this.windowWidth+',height='+this.windowHeight+
			',status='+this.statusBar+',toolbar='+this.toolBar+
			',menubar='+this.menuBar+',scrollbars='+this.scrollBars+
			',resizable='+this.resizable+',copyhistory='+this.copyHistory+
			',location='+this.addressBar+',directories='+this.linksBar);
		}
		else if (this.windowMode == 2)	// modal dialog
		{
		
			if (url.indexOf('?') >= 0)
				url = url + "&rnd=" + new Date().valueOf();
			else
				url = url + "?rnd=" + new Date().valueOf();
				
			this.window = window.showModalDialog(url,window,
			'dialogLeft:'+this.windowLeft+'; dialogTop:'+this.windowTop+
			'; dialogWidth:'+this.windowWidth+'; dialogHeight:'+this.windowHeight+
			';status:'+this.statusBar+'; toolbar:'+this.toolBar+
			'; menubar:'+this.menuBar+'; scroll:'+this.scrollBars+
			'; resizable:'+this.resizable+'; copyhistory:'+this.copyHistory+
			'; location:'+this.addressBar+'; directories:'+this.linksBar+'; unadorned:yes; center:yes;');
		}
		else if (this.windowMode == 3)	// modeless dialog
		{
			this.window = window.open(url,this.windowName,
			'left='+this.windowLeft+',top='+this.windowTop+
			',width='+this.windowWidth+',height='+this.windowHeight+
			',status='+this.statusBar+',toolbar='+this.toolBar+
			',menubar='+this.menuBar+',scroll='+this.scrollBars+
			',resizable='+this.resizable+',copyhistory='+this.copyHistory+
			',location='+this.addressBar+',directories='+this.linksBar);
		}
	}
	// call the window specific after open function if defined
	if (this.afterOpen!=null)
		this.afterOpen();
}

function WindowOpener_close()
{
	if (this.window != null)
		this.window.close();
}

function WindowOpener_notify()
{
}

				
//****************** Expandable Class ****************************
function Expandable(targetCtl, bfloating, bautoHide)
{
	this.ctl = targetCtl;
	this.expand = expandControl;
	this.expandXY = expandControlXY;
	this.isExpanded = isControlExpanded;
	this.toggleExpand = toggleExpandControl;
	this.expandForCheckBox = expandForCheckBox;
	this.controllingCheckBox = null;
	targetCtl.expandableObject = this;		// associate this to the target object
	if (bfloating == null)
		this.bfloating = false;
	else
		this.bfloating = bfloating;
	if (bautoHide == null)
		this.bautoHide = false;
	else
		this.bautoHide = bautoHide;
}

function getObjOrFirstItem(obj)
{
	return (obj.length!=null)?obj[0]:obj;
}

/*function IsContainedIn(obj, container)
{
	while (obj != null)
	{
		if (obj == container)
			return true;
		obj = obj.parentElement;
	}
	return false;
}*/

function GetContainingExpandable(obj)
{
	while (obj != null)
	{
		if (obj.expandableObject != null)
			return obj.expandableObject;
		obj = obj.parentElement;
	}
	return null;
}

function onDocumentMouseDown()
{
	if (document.currentExpandable != null)
		if (event.srcElement ==	document.currentExpandable.controllingCheckBox)
			return;
	var containingExpandable = GetContainingExpandable(event.srcElement);
	if (containingExpandable != document.currentExpandable)
		document.currentExpandable.expand(false);
}

function onDocumentMouseOut()
{
	if (event.toElement != null)
		return;
	var containingExpandable = GetContainingExpandable(event.srcElement);
	if (containingExpandable != document.currentExpandable)
		document.currentExpandable.expand(false);
}

function absEventX()
{
	var ctl = event.srcElement;
	return document.body.scrollLeft + event.clientX - ctl.offsetWidth / 2; // - event.offsetX - ctl.offsetLeft;// - 5;
	//return document.body.clientLeft + ctl.offsetLeft; //document.body.scrollLeft + event.clientX; // - event.offsetX - ctl.offsetLeft;// - 5;
	//document.body.clientLeft + ctl.offsetLeft
}

function absEventY()
{
	var ctl = event.srcElement;
	return document.body.scrollTop + event.clientY + ctl.offsetHeight;// - event.offsetY - ctl.offsetTop + ctl.offsetHeight + ctl.height-25;// - 3 + 20;
	//return document.body.clientTop + ctl.offsetTop ; //document.body.scrollTop + event.clientY + ctl.offsetHeight - 20;// - event.offsetY - ctl.offsetTop + ctl.offsetHeight + ctl.height-25;// - 3 + 20;
	//document.body.clientTop + ctl.offsetTop ; 
}

function isControlExpanded()
{
	if (this.ctl.style.display == "")
		return true;
	else
		return false;
}

function expandForCheckBox()
{
	this.expand(this.controllingCheckBox.checked, this.controllingCheckBox);
}

function expandControl(bexpand, controllingCheckBox)
{
	this.expandXY(bexpand, absEventX(), absEventY(), controllingCheckBox);
}

function toggleExpandControl(controllingCheckBox)
{
	if (this.isExpanded())
		this.expand(false, controllingCheckBox);
	else
		this.expand(true, controllingCheckBox);
}

function expandControlXY(bexpand, x, y, controllingCheckBox)
{
	if (bexpand == this.isExpanded())
		return;
	if (bexpand)
	{
		var objStyle = this.ctl.style;
		objStyle.display = "";
		if (this.bfloating)
		{
			//objStyle.posLeft = x;
			//objStyle.posTop = y;
			objStyle.left = x;
			objStyle.top = y;
			document.all[this.ctl.id + "_abspos"].value = x + "," + y;
		}
		if (this.bautoHide)
		{
			document.currentExpandable = this;
			document.onmouseup = onDocumentMouseDown;
			document.onmouseout = onDocumentMouseOut;
			this.ctl.onmouseout = onDocumentMouseOut;
		}
		if (controllingCheckBox == null)	// if called by checkbox, don't check it
			if (this.controllingCheckBox != null)
				this.controllingCheckBox.checked = true;
	}
	else
	{
		this.ctl.style.display = "none";
		if (this.bautoHide)
		{
			document.currentExpandable = null;
			document.onmouseup = null;
			document.onmouseout = null;
			this.ctl.onmouseout = null;
		}
		if (controllingCheckBox == null)	// if called by checkbox, don't check it
			if (this.controllingCheckBox != null)
				this.controllingCheckBox.checked = false;
	}
}

function NavRollOver(oTd) 
{
	if (!oTd.contains(event.fromElement)) {oTd.bgColor="#FFCC66";}
}

function NavRollOut(oTd) 
{
	if (!oTd.contains(event.toElement)) {oTd.bgColor="#FFFFFF";}
}

//*************** Date time functions ********************
function DiffDays(date1, date2)
{
	return Math.round((date2 - date1) / 864e5);
}

function RemoveChars(s, chars)
{
	var i = 0;
	if (s == null)
		return null;
	var news = "";
	for (i = 0; i < s.length; i++)
	{
		var ch = s.substring(i, i+1);
		if (chars.indexOf(ch) < 0)
			news += ch;	
	}
	return news;
}

function FormatPhone(s)
{
	if (s == null)
		return null;
		
    if (!IsOnlyDigits(s))
        return s;
		
	var sorig = s;
		
	//s = RemoveChars(s, " -()");
	
	//2012223344
	//if (s.length == 11)
	//	s = s.substr(1, 10);
		
	if (s.length >= 10)
	{
		sorig = "(" + s.substr(0, 3) + ") " + s.substr(3, 3) + "-" + s.substr(6, 4);
    	if (s.length > 10)
	        sorig = sorig + " #" + s.substr(10, s.length - 10);	
	}	
	else if (s.length == 7)
		sorig = s.substr(0, 3) + "-" + s.substr(3, 4);

	return sorig;
}

function ThouS(SS) 
{ 
  var X = "", S = String(SS), L // SS >= 0
  while (S != ""){ L = S.length-3
    X = S.substr(L, 3) + (X>"" ? ','+X : '')
    S = S.substr(0, L) }
  return X 
}

function Comma(SS) 
{ 
  var T='', S=String(SS), L=S.length-1, C, j
  for (j=0; j<=L; j++) {
    T+=C=S.charAt(j)
    if ((j < L) && ((L-j)%3 == 0) && (C != '-')) T+=',' }
  return T 
}

function FComma(SS)
{ 
  var T='', S=String(SS), L=S.length-1, C, j, P = S.indexOf('.')-1
  if (P<0) P=L
  for (j=0; j<=L; j++) {
    T+=C=S.charAt(j)
    if ((j < P) && ((P-j)%3 == 0) && (C != '-')) T+=',' }
  return T 
}

function RemoveCommas(s) 
{
  var regEx = /,/g;
  return s.replace(regEx,'');
}

function ReplacePattern(s, pattern, replace) 
{
  var regEx =  new RegExp(pattern, 'gi' );
  return s.replace(regEx, replace);
}

function FormatThousands(s)
{
	return FComma(s);
}

function FormatCurrency(s)
{
	if (s == null)
		return null;
	if (typeof(s)!="string")
		s = s.toString();
	s = RemoveChars(s, " ,");
	/*s = s.replace(" ", "");
	s = s.replace(",", "");*/
	
	//122,22.55
	if (s == "")
		return "";
	var v;
	v = parseFloat(s);
	v = Math.round(v * 100) / 100;
	return FComma(v.toFixed(2));
}

function FormatAllUpperCase(s)
{
	if (s==null)
		return null;
	return s.toUpperCase();
}

function FormatAllLowerCase(s)
{
	if (s==null)
		return null;
	return s.toLowerCase();
}

function ParseFloat(s)
{
	if (s == null)
		return 0;
	s = RemoveChars(s, " ,");
	/*s = s.replace(" ", "");
	s = s.replace(",", "");*/
	if (s == "")
		return 0;
	return parseFloat(s);
}

function ParseCurrency(s)
{
	return ParseFloat(s);
}

function ParseDate(s)
{
	s = RemoveChars(s, " ");
	//s = s.replace(" ", "");
	if (s == null || s == "")
		return null;
	return new Date(Date.parse(s));
}

function ParseDateYear(s)
{
	return ParseDate(s).getFullYear();
}

function ParseInt(s)
{
	if (s == null)
		return 0;
	s = RemoveChars(s, " ,");
	/*s = s.replace(" ", "");
	s = s.replace(",", "");*/
	if (s == "")
		return 0;
	return parseInt(s);
}

/// Validation functions

function ValidateCurrency(s)  
{
  var regEx = /(^\$\d{1,3}(,\d{3})*\.\d{2}$)|(^\(\$\d{1,3}(,\d{3})*\.\d{2}\)$)/;
  return regEx.test(s);
}

function ValidateCurrency(s)  
{
  var regEx = /(^\$\d{1,3}(,\d{3})*\.\d{2}$)|(^\(\$\d{1,3}(,\d{3})*\.\d{2}\)$)/;
  return regEx.test(s);
}

function ValidateTime (s) 
{
  // HH:MM or HH:MM:SS or HH:MM:SS.mmm
  var regEx = /^([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/;
  return regEx.test(s);
}

function ValidateState (s) 
{
  var regEx = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i; 
  return regEx.test(s);
}

function ValidateSSN(s) 
{
  var regEx = /^\d{3}\-\d{2}\-\d{4}$/;
  return regEx.test(s);
}

function ValidateEmail(s) 
{
  var regEx = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
  return regEx.test(s);
}

function ValidateUSPhone(s) 
{
  // (999) 999-9999 or (999)999-9999
  var regEx = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
  return regEx.test(s); 
}

function ValidateNumeric(s) 
{
  var regEx =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 
  return regEx.test(s);
}

function ValidateInteger(s) 
{
  var regEx = /(^-?\d\d*$)/;
  return regEx.test(s);
}

function ValidateUSZip(s) 
{
  // 99999 or 99999-9999
  var regEx  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
  //check for valid US Zipcode
  return regEx.test(s);
}

function ValidateUSDate(strValue)
{
    //Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
	var intDay = parseInt(arrayDate[1],10); 
	var intYear = parseInt(arrayDate[2],10);
    var intMonth = parseInt(arrayDate[0],10);
	
	//check for valid month
	if(intMonth > 12 || intMonth < 1) {
		return false;
	}
	
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
  
    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }
		
    //check for February
	var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
    if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
      return true; //Feb. had valid number of days
  }
  return false; //any other values, bad date
}

function ValidateRegEx(s, pattern) 
{
  var regEx = new RegExp(pattern);
  return regEx.test(s);
}


///  Element accessors

function GetElem(id)
{
	return document.getElementById(id);
}

function GetElemValue(id)
{
	
	if (typeof(ValidatorGetValue) == "function")
	{
		//window.alert(ValidatorGetValue(id));
		return ValidatorGetValue(id);
	}
	else
		return GetElem(id).value;
}

function SetElemValue(id, value)
{
	var elem = GetElem(id);
	
	if (elem != null)
		elem.value = value;
		
	if (typeof(igedit_getById) == "function")
	{
		var ctl = igedit_getById(id);
		if (ctl != null)
			ctl.setValue(value);		// set textboxes only
	}
}

/*// first parameter is the format, the rest are control names to be substituted
// format string must be something like:    "@control1@/@control2@/@control3@"
// control names are written inside @'s
//     SubstituteControlValues("@control1@/@control2@/@control3@", 
function SubstituteControlValues(format)
{
    var argv = SubstituteControlValues.arguments;
    var argc = argv.length;
    var format = argv[0];		// first param is the format
    for (var i = 1; i < argc; i++) 
    {
		argv[i]);
	}
}*/

function LTrim(str, whitespace)
{
  if (whitespace == null)
    whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...

    var j=0, i = s.length;

    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;


    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  return s;
}

function RTrim(str, whitespace)
{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  if (whitespace == null)
    whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...

    var i = s.length - 1;       // Get length of string

    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;


    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }

  return s;
}

function Trim(str, whitespace)
{
  return RTrim(LTrim(str, whitespace), whitespace);
}


// first parameter is the format
// format string must be something like:    "@control1@/@control2@/@control3@"
// control names are written inside @'s
//     SubstituteControlValues("@control1@/@control2@/@control3@")
function SubstituteControlValues(format)
{
	var regex = /@(\w)+@/;
	
	var arr = format.match(regex);
	var nullValue = true;
	while (arr != null)
    {
		var item = arr[0];
		var ctlName = Trim(item, '@');
		//window.alert(item);
		//window.alert(item + "=" + GetElemValue(ctlName));
		var val = GetElemValue(ctlName);
		if (val != null && val != "")
			nullValue = false;
		format = format.replace(new RegExp(item,"gmi"), val);
		arr = format.match(regex);
	}
	if (nullValue)
		return "";
	else
		return format;
}

function FormatMTB(format)
{
	if (format == null)
		return "";
	if (format.length == 0)
		return "";
	return SubstituteControlValues(format);
}


function findPosY(objID)
{
	//alert('finding pos');
	var obj = GetElem(objID);
	if (obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		
		return curtop;
	}
	else
		return 0;
}

function findPosX(objID)
{
	var curleft = 0;
	var obj = GetElem(objID);	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}


function IsOutOfScreenY(objID)
{
	var obj = GetElem(objID);	

    var bodyElem = document.documentElement;
	var scrollTop = parseInt(bodyElem.scrollTop, 10);
	var height = obj.offsetHeight;

    var posY = findPosY(objID);

    return (posY > (scrollTop + bodyElem.clientHeight) || posY < scrollTop);
}


function saveScroll() 
{
	//alert('saving');
	var scrollSaver = "scrollSaver";

	if (GetElem(scrollSaver))
	{
		GetElem(scrollSaver).value = document.body.scrollLeft + '&' + document.body.scrollTop;
	}
}

function doScroll(targetX, targetY)
{
	//alert('scrolling');
	window.scrollTo(targetX, targetY);	
}


function doScrollToControl(objID)
{
	doScroll(0, findPosY(objID) / (1.5));
}


function calendar(strTextBox)
{
	var woCalendar = new WindowOpener("Calendar", "DatePicker.aspx?textbox=" + strTextBox, "300px", "250px");
	woCalendar.resizable = 0;
	woCalendar.open();

	//window.open('DatePicker.aspx?textbox=' + strTextBox, 'calendar', 'width=250,height=200,resizable=no');
}



function MaskDate(str, textbox, loc, delim)
{
	str = str.replace(delim, '');
	var locs = loc.split(',');
	for (var i = 0; i <= locs.length; i++)
	{
		for (var k = 0; k <= str.length; k++)
		{ 
			if (k == locs[i])
			{	  
				if (str.substring(k, k+1) != delim)
					str = str.substring(0,k) + delim + str.substring(k, str.length)  
			}	
		} 
	} 
	textbox.value = str; 
}

var numericInput = "01234567890";
var decimalInput = "01234567890.";

function RestrictKeyboard(textbox, validCharacters)
{
	var found = false;
	for(i = 0; i < validCharacters.length; i++)
		if(window.event.keyCode == validCharacters.charCodeAt(i)) 
		{
			found = true;
			break;
		}
	if (!found)
		window.event.returnValue = false;
}





function OBButton_OnClick(buttonID)
{
    if (!Page_Controls[buttonID]) return false;

   Page_GroupToValidate = Page_Controls[buttonID][ControlGroupIndex];

    __defaultFired = false;

   if (Page_Controls[buttonID][ControlChecksForDirtyIndex] && !DisplayIsDirtyWarning())
   {
      return false;
   }
   else
   {
//	  Page_CheckDirty = false;
	  Page_IsSubmitted = true;
	  return true;	  
   }
   
/*   
   if (Page_Controls[oButton.Key][ControlCausesValidationIndex])
   {
		Page_GroupToValidate = Page_Controls[oButton.Key][ControlGroupIndex];
	
		if (typeof(Page_ClientValidate) == 'function' && !Page_ClientValidate())  
		{
			oEvent.cancel = true;
			oEvent.cancelPostBack = true;
		}
   }
*/  
}


function OBTextBox_OnChange(textboxID)
{
	SetDirty(textboxID);
}

function RestrictTextLength(textbox, limit) 
{
    if (textbox.value.length > limit)
        textbox.value = textbox.value.substring(0, limit);
}


function OBRadioButton_OnClick(radioButtonID)
{
	SetDirty(radioButtonID);
}

function OBCheckBox_OnClick(checkboxID)
{
	SetDirty(checkboxID);
	
	// Call individual checkbox onlick events
	eval('if (typeof(' + checkboxID + '_OnClick) == \'function\') ' + checkboxID + '_OnClick();');
}


function ig_UpdateDisplay(id, controlType){

var BackColor, BorderColor, ForeColor;

var isValid = true;
var tooltip = "";
var dontTouch = true; // if there is no validator attached to the control don't try to change it's appearance
					  // because it's unnecessary and also the page might be in viewonly mode	

if (typeof(Page_Validators) != "undefined")
{
	for (i = 0; i < Page_Validators.length; i++) {
		if (Page_Validators[i].enabled != false && Page_Validators[i].controltovalidate == id)
		{
			dontTouch = false;
			if (Page_Validators[i].isvalid != "undefined" && !Page_Validators[i].isvalid) 
			{
				isValid = false;
				tooltip += Page_Validators[i].errormessage;
			}
		}
	}
}

if (dontTouch) return true;

if (isValid)
{
BackColor = "white";
BorderColor = "#7F9DB9";
ForeColor = "black";
}
else
{
BackColor = "red";
BorderColor = "red";
ForeColor = "black";
}


switch(controlType)
{
    case "WebCombo":
        var oControl = igcmbo_getComboById(id); 
    break;
    case "WebTextEdit":
    case "WebNumericEdit":
    case "WebMaskEdit":
    case "WebDateTimeEdit":
    case "WebCurrencyEdit":
        var oControl = igedit_getById(id); 
    break;
    case "WebCalendar":
        var oControl = igcal_getCalendarById(id); 
    break;
    case "WebDateChooser":
        var oControl = igdrp_getComboById(id); 
        break;
    case "OBTextBox":
		var oControl = GetElem(id);
		break;
	// FORK 1.1	
	case "OBComboBox":
		var oControl = GetElem(id + '_Border');
	    break;
	default:
		//var oControl = GetElem(id);
		// We don't know what to do with this control
		// Return false so that the regular error message display takes place
		return false;
    break;
}

return true;


try
{
	if (oControl)
	{
		if (oControl.Element)
		{
			oControl.Element.style.borderWidth = "1px";
			oControl.Element.style.borderColor = BorderColor;
			oControl.Element.style.color = ForeColor;
			oControl.Element.title = tooltip;
		}
		else
		{
			if (controlType == "OBComboBox" && isValid)
			{
				oControl.style.borderStyle = "none";
			}
			else
			{	
				oControl.style.borderWidth = "1px";
				//oControl.style.borderTopStyle = "solid";
				oControl.style.borderColor = BorderColor;
				oControl.style.padding = "0px";
				oControl.style.color = ForeColor;
				oControl.title = tooltip;
			}
		}
	}
}
catch(oException)
{
}

return true;

}



function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber = true;
   var Char;

 
   for (i = 0; i < sText.length; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) < 0) 
      {
            IsNumber = false;
            break;
      }
   }
   return IsNumber;
}

function IsOnlyDigits(sText)
{
   var ValidChars = "0123456789";
   var IsOnlyDigits = true;
   var Char;
 
   for (i = 0; i < sText.length; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) < 0) 
      {
            IsOnlyDigits = false;
            break;
      }
   }
   return IsOnlyDigits;
}




/* DHTML Utility Fucntions */

function GetStyle(e, styleProp)
{
	var x = document.getElementById(e);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function ToggleElementVisibility(e)
{
    if (typeof(e) == "string" && !(e = document.getElementById(el)))
        return false;
    if (e.style.display == "" || e.style.display == "none")
        ShowElement(e);
    else
        HideElement(e);
}

function HideElement(e)
{    

            
    if (typeof(e) == "string" && !(e = document.getElementById(e)))
        return false;
    e.pDisplay = e.style.display;
    e.style.display = "none";

}

function ShowElement(e)
{   
    
    if (typeof(e) == "string" && !(e = document.getElementById(e)))
        return false;

    var tagName = e.tagName.toLowerCase();    
    switch (tagName)
    {
        case "div":
            e.style.display = "block";
            e.style.visibility = "visible";
            break;
        default:
            e.style.display = "inline";
            break;
    }
}


function SetAttributes(e, attrs, style, text) {
    if (attrs) {
        for (key in attrs) {
            if (key == 'className') {
                e.className = attrs[key];
            } else if (key == 'id') {
                e.id = attrs[key];
            } else if (key == 'onclick') {
                e.onclick = new Function(attrs[key]);
            } else if (key == 'onchange') {
                e.onchange = new Function(attrs[key]);                
            } else if (key == 'forControl') {
                e.setAttribute('for', attrs[key]);
            } else {
                e.setAttribute(key, attrs[key]);
            }
        }
    }
    if (style) {
        for (key in style) {
            e.style[key] = style[key];
        }
    }
    if (text) {
        e.appendChild(document.createTextNode(text));
    }
    return e;
    
}

function CreateElementWithName(type, name) {
  var element;
  // First try the IE way; if this fails then use the standard way
  try 
  {
    element = document.createElement('<'+type+' name="'+name+'" />');
  } 
  catch (e) 
  {
	if (!element) 
	{
        element = document.createElement(type);
        element.name = name;
    }
  }
  
  return element;
}


function RemoveAllChildren(e)
{
    if (typeof(e) == "string" && !(e = document.getElementById(e)))
        return false;

    // Clear contents
    while (e.firstChild) 
    {
        e.removeChild(e.firstChild);
    }
}


function getStyle(el,styleProp)
{
    //var x = document.getElementById(el);
    if (el.currentStyle)
	    var y = el.currentStyle[styleProp];
    else if (window.getComputedStyle)
	    var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
    return y;
}


function findAbsolutePositionXY(obj)
{
    var scTop = 0;
    var scLeft = 0;
    
    while (obj)
    {
        if (getStyle(obj, "position") != "static") break;
        scTop = scTop + obj.offsetTop;
        scLeft = scLeft + obj.offsetLeft;
        obj = obj.offsetParent;
    }
    
    return {"X": scLeft, "Y": scTop};
}


/* DHTML Utility Fucntions  */





/* Utility functions for AjaxLookupControl */

var cache = new Array();


function hideDropdown(divID, iframeID)
{
    var div = document.getElementById(divID);
    if (div != null)
        div.style.display = 'none';
        //div.style.visibility = "hidden";
    //var iframe = document.getElementById(iframeID);
    //if (iframe != null)
        //iframe.style.visibility = "hidden";
       
}


function highlightItem (divID, item)
{
    //alert('highlight');
    div = document.getElementById(divID);
    if (div == null)
        return;

        
    for (var i=0; i < div.childNodes.length; i++) {
        var iNode = div.childNodes[i];       
        var elemID = iNode.id;
        elemID = elemID.replace('item','');
        //alert(elemID);              
        var oNode = document.getElementById('itemText'+elemID);                                   
        //alert(oNode.innerHTML);
        //alert(oNode.innerHTML + ' ' + item.innerHTML);
        //alert(item.parent.innerHTML);
            if (oNode == item) {
                       
                iNode.style.background =  iNode.childNodes[0].style.background = iNode.childNodes[1].style.background = "#cccc00";                
            } else if (iNode.style.background == "#cccc00") {
                iNode.style.background = iNode.childNodes[0].style.background = iNode.childNodes[1].style.background = "";
            }
        
    }
}

function showDropDown(txtBoxID, divID, iframeID)
{
    // if any of parameters are null bail.
    if (txtBoxID == null || divID == null || txtBoxID == "" || divID == "")
        return;
    
    // if cant find any elements, bail out    
    var txtBox = document.getElementById(txtBoxID);    
    if (txtBox == null)
        return;    
    var div = document.getElementById(divID);
    if (div == null)
        return;
   
    // set the width.
    //div.style.width = txtBox.offsetWidth;
    //div.style.overflow-x ='auto';
    
    var oThis = this;

   
    /*div.onmousedown = div.onmouseup = div.onmouseover = function (oEvent) {
        oEvent = oEvent || window.event;
        oTarget = oEvent.target || oEvent.srcElement;

        if (oEvent.type == "mousedown") {
            txtBox.value = oTarget.firstChild.nodeValue;  
          
            eval(txtBoxID + 'UpdateValue(\'' + txtBox.value + '\');');      
            hideDropdown(divID, iframeID);
        } else if (oEvent.type == "mouseover") {          
            highlightItem(divID, oTarget );
        } else {
            txtBox.focus();
        }  
     }*/
}


function positionDropDown(divID, txtBoxID, iframeID)
{    
    var dropDown = document.getElementById(divID);
    if (dropDown == null)
        return;
        
   // Left
    var txtBox = document.getElementById(txtBoxID);
    var iLeft = 0;
    
    // top    
    var iTop = 0;

    dropDown.style.left = txtBox.offsetLeft + "px";    
    dropDown.style.top = (txtBox.offsetTop + 50) + "px";
    
    /*var iframe = document.getElementById(iframeID);
    iframe.style.width = dropDown.offsetWidth;
    iframe.style.height = dropDown.offsetHeight;
    iframe.style.top = dropDown.style.top;
    iframe.style.left = dropDown.style.left;
    iframe.style.zIndex = dropDown.style.zIndex - 1;
    iframe.style.display = "block";    
    iframe.style.visibility = "visible"; */
}

function bindItems(displayText,txtBoxID, divID, items, iframeID, SelectTxtMsg, NoResultTxtMsg)
{
      
   var txb = document.getElementById(txtBoxID);
   var displayTxb = document.getElementById(displayText);    

   txb.value = displayTxb.value;
   //alert(displayTxb.value + '1');   
    
   items = eval(items);
   // now items array contains an array of objects. for each item 
   // call eval again to retrieve the object. 
    showDropDown(txtBoxID, divID, iframeID);
    // bind the items here by iterating over the items array
    div = document.getElementById(divID);
    if (div == null)
    {
        txb.value = displayTxb.value;
        //alert('11');
        return; 
    }
    // clear div.
    RemoveAllChildren(div);
    //div.innerHTML = "";
    var node = null;  
    var childText = null;
    var obj = null;
    // listbox implementation
    var lst = document.createElement("select");     
    div.appendChild(lst);

    div.style.width = '400px';
    div.style.overflow = 'scroll';    
    
    lst.onchanged = function hide(oEvent)
    {
       oEvent = oEvent || window.event;
   
       if (oEvent.srcElement.value.length > 0)
       {
           txb.value = oEvent.srcElement.value;
           displayTxb.value= oEvent.srcElement.options[oEvent.srcElement.selectedIndex].text;
           hideDropdown(divID, iframeID);
       }
       txb.focus();
    };    
    
    
    displayTxb.onblur = function hideList(oEvent)
    {
        HideElement(div);
    };
 
    div.onfocus = function showList(oEvent)
    {
        ShowElement(div);
    };   
    
    /*lst.onmouseover = function highlightItem(oEvent)
    {
        oEvent = oEvent || window.event;
        alert(oEvent.srcElement.value);
    }*/

    //alert(txb.value + '2');
   
    var size = 0;       
    if (items != null)
    {
        for (var i=0; i < items.length; i++)
        {
            //node = document.createElement("div");        
            //node.id = 'item' + i;        
            var option = document.createElement("option");
            
            obj = items[i];
            option.value = obj.Value;
            option.text = obj.Name;
            //objText = obj.Name;
            //objVal = obj.Value;
            
            lst.add(option,i+1);
            
            
            //childText = document.createTextNode(objText);      
            /*childText = document.createElement("span");
            childText.id = "itemText"+i;
            childText.style.visibility = "visible";
            childText.innerHTML = objText;
            
            sValue = document.createElement("span");
            sValue.id = "itemValue"+i;
            sValue.style.visibility = "hidden";
            sValue.innerHTML = objVal;
            
            node.appendChild(childText);
            node.appendChild(sValue);*/
            
            //div.appendChild(node);               
           // childText.style.cursor = sValue.style.cursor = div.style.cursor = 'hand';
           size = i + 1;
        }
    }
    //alert(txb.value + '3');
    if (size == 0)
    {
        if (document.getElementById(displayText).value.length < 3)
        {
            var option = document.createElement("option");
            option.value = "";
            option.text = SelectTxtMsg;
            lst.add(option, 1);
            displayText
        }
        else
        {
            var option = document.createElement("option");
            option.value = "";
            option.text = NoResultTxtMsg;
            lst.add(option, 1);
        }
    }
    //alert(txb.value + '4');

    lst.size = size;
    if (lst.size > 10)
        div.style.height = '200px';
    
    //lst.style.width = 'auto';
    lst.style.border = 'none';    
    
    positionDropDown(divID, txtBoxID, iframeID); 
    ShowElement(div);
    //toggleDiv(divID);
    //alert(txb.value + '5');
    
}


function addToCache(txtBoxID,val)
{
    
    cache[txtBoxID] = val;  
}

function getFromCache(txtBoxID) 
{
    return cache[txtBoxID];
}
 
 
 
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function Trim( value ) {
	
	return LTrim(RTrim(value));
	
}
 
 
var autoSuggestControls = new Array();
 
function AutoSuggestControl(oNameTextbox, oValueTextBox, iMinLength, sMsgMinLength, sMsgNoResult) 
{
    this.cur = -1;
    this.layer = null;

    this.nameTextbox = oNameTextbox;
    this.valueTextbox = oValueTextBox;
    
    this.minLength = iMinLength;
    this.msgMinLength = sMsgMinLength;
    this.msgNoResult = sMsgNoResult;
    
    // Initialize the control
    this.init();
    
    autoSuggestControls[oNameTextbox.id] = this;
}

AutoSuggestControl.prototype.autosuggest = function (aSuggestions, bTypeAhead) 
{
    //make sure there's at least one suggestion
    if (aSuggestions.length > 0) 
    {
        if (bTypeAhead) 
        {
           this.typeAhead(aSuggestions[0]);
        }
        
        this.showSuggestions(aSuggestions);
    } 
    else 
    {
        this.hideSuggestions();
    }
};

AutoSuggestControl.prototype.createDropDown = function () 
{
    var oThis = this;

    //create the layer and assign styles
    this.layer = document.createElement("div");
    this.layer.className = "suggestions";
    this.layer.style.visibility = "hidden";
    this.layer.style.width = this.nameTextbox.offsetWidth;
    
    //when the user clicks on the a suggestion, get the text (innerHTML)
    //and place it into a textbox
    this.layer.onmousedown = 
    this.layer.onmouseup = 
    this.layer.onmouseover = function (oEvent) {
        oEvent = oEvent || window.event;
        oTarget = oEvent.target || oEvent.srcElement;

        if (oEvent.type == "mousedown") {
            if (oTarget.Selectable)
            {
                oThis.nameTextbox.value = oTarget.innerText;
                oThis.valueTextbox.value = oTarget.Value; /* non-standard attribute*/
                oThis.hideSuggestions();
            }
        } else if (oEvent.type == "mouseover") {
            oThis.highlightSuggestion(oTarget);
        } else {
            oThis.nameTextbox.focus();
        }
    };
    
    
    document.body.appendChild(this.layer);
};

AutoSuggestControl.prototype.getLeft = function ()
{

    var oNode = this.nameTextbox;
    var iLeft = 0;
    
    while(oNode != null && oNode.tagName.toUpperCase() != "BODY") {
        iLeft += oNode.offsetLeft;
        oNode = oNode.offsetParent;        
    }
    
    return iLeft;
};



AutoSuggestControl.prototype.getTop = function ()
{

    var oNode = this.nameTextbox;
    var iTop = 0;
    
    while(oNode != null && oNode.tagName.toUpperCase() != "BODY") {
        iTop += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }
    
    return iTop;
};

AutoSuggestControl.prototype.handleKeyDown = function (oEvent) 
{

    switch(oEvent.keyCode) {
        case 38: //up arrow
            this.previousSuggestion();
            break;
        case 40: //down arrow 
            this.nextSuggestion();
            break;
        case 13: //enter
            this.hideSuggestions();
            break;
    }

};

AutoSuggestControl.prototype.handleKeyUp = function (oEvent) 
{

    var iKeyCode = oEvent.keyCode;

    //for backspace (8) and delete (46), shows suggestions without typeahead
    if (iKeyCode == 8 || iKeyCode == 46) {
        this./*provider.*/requestSuggestions(this, false);
        
    //make sure not to interfere with non-character keys
    } else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode < 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
        //ignore
    } else {
        //request suggestions from the suggestion provider with typeahead
        this.requestSuggestions(this, true);
    }
};

AutoSuggestControl.prototype.hideSuggestions = function () {
    this.layer.style.visibility = "hidden";
};

AutoSuggestControl.prototype.highlightSuggestion = function (oSuggestionNode) {
    
    for (var i=0; i < this.layer.childNodes.length; i++) {
        var oNode = this.layer.childNodes[i];
        if (oNode == oSuggestionNode) {
            oNode.className = "current"
        } else if (oNode.className == "current") {
            oNode.className = "";
        }
    }
};

AutoSuggestControl.prototype.init = function () 
{

    //save a reference to this object
    var oThis = this;
    
    //assign the onkeyup event handler
    this.nameTextbox.onkeyup = function (oEvent) 
    {
    
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyUp() method with the event object
        oThis.handleKeyUp(oEvent);
    };
    
    //assign onkeydown event handler
    this.nameTextbox.onkeydown = function (oEvent) 
    {
    
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyDown() method with the event object
        oThis.handleKeyDown(oEvent);
    };
    
    //assign onblur event handler (hides suggestions)    
    this.nameTextbox.onblur = function () 
    {
        oThis.hideSuggestions();
    };
        
    //create the suggestions dropdown
    this.createDropDown();
    
    this.layer.onfocus = function ()
    {
      oThis.showSuggestions();  
    };
};

AutoSuggestControl.prototype.nextSuggestion = function () 
{
    var cSuggestionNodes = this.layer.childNodes;

    if (cSuggestionNodes.length > 0 && this.cur < cSuggestionNodes.length-1) 
    {
        var oNode = cSuggestionNodes[++this.cur];
        this.highlightSuggestion(oNode);
        this.nameTextbox.value = oNode.firstChild.nodeValue; 
        this.valueTextbox.value = oNode.firstChild.Value; 
    }
};

AutoSuggestControl.prototype.previousSuggestion = function () 
{
    var cSuggestionNodes = this.layer.childNodes;

    if (cSuggestionNodes.length > 0 && this.cur > 0) 
    {
        var oNode = cSuggestionNodes[--this.cur];
        this.highlightSuggestion(oNode);
        this.nameTextbox.value = oNode.firstChild.nodeValue;   
        this.valueTextbox.value = oNode.firstChild.Value;
    }
};

AutoSuggestControl.prototype.selectRange = function (iStart, iLength) 
{

    //use text ranges for Internet Explorer
    if (this.nameTextbox.createTextRange) 
    {
        var oRange = this.nameTextbox.createTextRange(); 
        oRange.moveStart("character", iStart); 
        oRange.moveEnd("character", iLength - this.nameTextbox.value.length);      
        oRange.select();
        
    //use setSelectionRange() for Mozilla
    } 
    else if (this.nameTextbox.setSelectionRange) 
    {
        this.nameTextbox.setSelectionRange(iStart, iLength);
    }     

    //set focus back to the textbox
    this.nameTextbox.focus();      
}; 

AutoSuggestControl.prototype.showSuggestions = function (aSuggestions) 
{
    if (aSuggestions)
    {
    
        var oDiv = null;
        this.layer.innerHTML = "";  //clear contents of the layer
        
        for (var i=0; i < aSuggestions.length; i++) 
        {
            oDiv = document.createElement("div");
            //oSpanText = document.createElement("span");
            //oSpanText.appendChild(document.createTextNode(aSuggestions[i].Name));
            //oSpanValue = document.createElement("span");
            //oSpanValue.style.display = 'none';
            //oSpanValue.appendChild(document.createTextNode(aSuggestions[i].Value));
            //oDiv.appendChild(sSpan1);
            //oDiv.appendChild(sSpan2);
            oDiv.appendChild(document.createTextNode(aSuggestions[i].Name));
            oDiv.Value = aSuggestions[i].Value; // Assign the value to an attribute on Div
            oDiv.Selectable = (aSuggestions[i].Selectable == null || aSuggestions[i].Selectable);
            this.layer.appendChild(oDiv);
        }
    }
    
    this.layer.style.left = this.getLeft() + "px";
    this.layer.style.top = (this.getTop()+this.nameTextbox.offsetHeight) + "px";
    this.layer.style.visibility = "visible";

};

AutoSuggestControl.prototype.typeAhead = function (oSuggestion) 
{

    //check for support of typeahead functionality
    if (this.nameTextbox.createTextRange || this.nameTextbox.setSelectionRange)
    {
        var iLen = this.nameTextbox.value.length; 
        this.nameTextbox.value = oSuggestion.Name; 
        this.valueTextbox.value = oSuggestion.Value;
        this.selectRange(iLen, oSuggestion.length);
    }
};


AutoSuggestControl.prototype.requestSuggestions = function(oAutoSuggestControl, bTypeAhead)
{
    var val = Trim(oAutoSuggestControl.nameTextbox.value);
    if (oAutoSuggestControl.minLength <= 0 || val.length >= oAutoSuggestControl.minLength)
    {
        if (typeof(oAutoSuggestControl.callbackFunction) == "function")
            oAutoSuggestControl.callbackFunction(oAutoSuggestControl.nameTextbox.value, 'GetList$' + (bTypeAhead ? '1' : '0') + "$" + oAutoSuggestControl.nameTextbox.id);
        else if (oAutoSuggestControl.ValueList)
        {
            // alert('Not implemented');
        }
    }
    else
    {
        var aSuggestions = new Array();
        aSuggestions[0] = new Object();
        aSuggestions[0].Name = oAutoSuggestControl.msgMinLength;
        aSuggestions[0].Value = '';
        aSuggestions[0].Selectable = false;
        oAutoSuggestControl.autosuggest(aSuggestions, false);
    }
}

AutoSuggestControl.prototype.updateList = function(argument)
{
    var aSuggestions = eval(argument);

    var bTypeAhead = this.context.split('$')[1] == '1' ? true : false;
    var autoSuggestControlID = this.context.split('$')[2];
    var oAutoSuggestControl = autoSuggestControls[autoSuggestControlID];

    //provide suggestions to the control
    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
}




/* End of Utility functions for AjaxLookupControl  */

var EventController;
EventController = {
        addEvent: function(obj, type, fn, instance, tmp) {
                if (!instance) instance = "";
                tmp || (tmp = true);
                if (typeof(obj["e" + type + instance]) == 'undefined') {
                    if( obj.attachEvent) {
                            obj["e" + type + instance] = fn;
                            obj["fn"+ type + instance] = function(){obj["e" + type + instance]( window.event );};
                            obj.attachEvent( "on" + type, obj["fn" + type + instance] );
                    } else {
                            obj.addEventListener( type, fn, tmp );
                    };
                }
        },
        removeEvent: function(obj, type, fn, instance, tmp) {
                tmp || (tmp = true);
                if( obj.detachEvent ) {
                        obj.detachEvent( "on" + type, obj["fn" + type + instance] );
                        obj["fn" + type + instance] = null;
                } else {
                        obj.removeEventListener( type, fn, tmp );
                };
        }
}


var Page_Messages = new Array();
function RegisterPageMessage(pageMessageID, fadeDuration)
{
    var elem = GetElem(pageMessageID);  
    if (!elem) return;

    if (!Page_Messages[pageMessageID])
    {
        Page_Messages[pageMessageID] = pageMessageID;
    }
    if (elem.style.display != 'none' && fadeDuration > 0)
    {
        FadeMessage(pageMessageID, fadeDuration);
    }
}

function ClearPageMessages()
{
    if (Page_Messages)
    {
        var elem;
        for (var i in Page_Messages)
        {
            elem = GetElem(Page_Messages[i]);
            if (elem)
                elem.style.display = 'none';
            //GetElem(Page_Messages[i]).innerHTML = '';
        }
    }
}

function FadeMessage(pageMessageID, fadeDuration)
{
    var elem = GetElem(pageMessageID);
    if (!elem) return;
    
    var currentHeight = elem.style.height;

    if (elem.timer)
    {
        clearTimeout(elem.timer);
    }    

    if (!elem.currentLevel)
    {
        elem.currentLevel = 100;
    }
   
    SetOpacity(pageMessageID, elem.currentLevel);
    
    if (elem.currentLevel >= 10) 
    {
        elem.currentLevel = elem.currentLevel - 5;    
        elem.timer = setTimeout("FadeMessage('" + pageMessageID + "', '" + fadeDuration + "');", fadeDuration / 5);
    }
    else
    {
        elem.style.display = 'none';
        SetOpacity(pageMessageID, 100);
    }
}

var ie_op = (document.all) ? 1 : 0;
var op = (ie_op) ? "filter" : "MozOpacity";
function SetOpacity(elemID, opacity)
{
    var st = ((ie_op) ? "alpha(opacity=" + opacity + ")" : opacity/100);
    GetElem(elemID).style[op] = st;
    //GetElem(elemID).innerHTML = GetElem(elemID).innerHTML + " " + st + " ";
}



function OBGrid_Sort(linkId, cellElement, evt) 
{
        var evtSource;
        evt = (evt)? evt : window.event;
        evtSource = (evt.srcElement)? evt.srcElement : evt.target;

        // when a hyperlink is clicked, safari returns the text node as the source element rather
        // than the hyperlink. parentNode will give us the hyperlink element.
        if (evt.target) 
        {
            if (evt.target.nodeType == 3) 
            {
                evtSource = evtSource.parentNode;
            }
        }

        if ((evtSource.getAttribute("id") != linkId) && (evt.type == "click")) {

            var linkCollection = cellElement.getElementsByTagName("a");
            for (var i = 0; i < linkCollection.length; i++) {

               var onClickAttribute = linkCollection[i].getAttribute("onclick");

               if (onClickAttribute != null) {
                linkCollection[i].onclick();
                break;
               }

               var hrefAttribute = linkCollection[i].getAttribute("href");
               this.location.href = hrefAttribute;
               break;

            }

        }

    }
    
    function OBGrid_Tooltip(td)
    {
        if (typeof(tt_Tip) == 'function')
        if (td.className.indexOf('noprint') < 0 && td.className.indexOf('notooltip') < 0)
            tt_Tip(arguments, td);
    }