// JavaScript Document

var myWidth  = 0;
var myHeight = 0;
var scrOfX   = 0;
var scrOfY   = 0;
var elList   = document.getElementsByTagName("TR");

function setRow(Row) 
{
	resetGrid()
	
	pos           = Row.id.indexOf('-');
	nn            = Row.id.substring(1, pos-1);
	Row.id        = nn + '-Y';
	Row.className = 'tr_slct';
}

function resetGrid()
{
	for (i = 0; i < elList.length; i++)
	{
		if (elList[i].id != '')
		{
			stat = elList[i].id.substring(elList[i].id.length-1);
				
			if (stat == 'Y')
			{	
				pos = elList[i].id.indexOf('-');
				nnc = elList[i].id.substring(1, pos-1);
				elList[i].id = nnc + '-N'
				if (nnc % 2 == 0) elList[i].className = "tr_dark"
				if (nnc % 2 != 0) elList[i].className = "tr_light"
				break;
			}
		}
	}
}

function setBGC (Row,BGC)
{
	if (Row.id.substring(Row.id.length-1) == 'N') Row.className = BGC
}

function getWinSize(W)
{
	if (W == 'Current') win = window
	if (W == 'Parent' ) win = parent
	if (W == 'Top'    ) win = top
	if (W == 'Opener' ) win = opener
	
	//Non-IE
	if (typeof(win.innerWidth ) == 'number') 
	{
		myWidth  = win.innerWidth;
		myHeight = win.innerHeight;
		return;
	} 
  
	//IE 6+ in 'standards compliant mode'
	if (win.document.documentElement && (win.document.documentElement.clientWidth || win.document.documentElement.clientHeight)) 
	{
		myWidth  = win.document.documentElement.clientWidth;
		myHeight = win.document.documentElement.clientHeight;
		return;
	}
	
	//IE 4 compatible
	if (win.document.body && (win.document.body.clientWidth || win.document.body.clientHeight)) 
	{
		myWidth  = win.document.body.clientWidth;
		myHeight = win.document.body.clientHeight;
		return;
	}
}

function getOffset(WND,OBJ,ELM) 
{
	scrOfX = 0;
	scrOfY = 0;
	var win
	var objList
		
	if (OBJ == '')
	{
		if (WND == 'Current') win = window
		if (WND == 'Parent' ) win = window.parent
		if (WND == 'Top'    ) win = window.top
		if (WND == 'Opener' ) win = window.opener
		if (WND == 'OpTop'  ) win = window.opener.top
	}
	else
	{
		if (WND == 'Current') objList = window.document.getElementsByTagName(OBJ);
		if (WND == 'Parent' ) objList = window.parent.document.getElementsByTagName(OBJ);
		if (WND == 'Top'    ) objList = window.top.document.getElementsByTagName(OBJ);
		if (WND == 'Opener' ) objList = window.opener.document.getElementsByTagName(OBJ);
		if (WND == 'OpTop'  ) objList = window.opener.top.document.getElementsByTagName(OBJ);
		
		for (i = 0; i < objList.length; i++)
		{if (objList[i].id == ELM) win = objList[i];}
	}
	
	//IE-6 Netscape-7 standards compliant mode
	if (win.scrollLeft || win.scrollTop)
	{
		scrOfY = win.scrollTop;
		scrOfX = win.scrollLeft;
		return;
	}
	
	//Netscape compliant
	if (OBJ == '' && typeof(win.pageYOffset ) == 'number') 
	{
		scrOfY = win.pageYOffset;
		scrOfX = win.pageXOffset;
		return;
	} 
  
	//DOM compliant
	if (OBJ == '' && win.document.body && ( win.document.body.scrollLeft || win.document.body.scrollTop)) 
	{
		scrOfY = win.document.body.scrollTop;
		scrOfX = win.document.body.scrollLeft;
		return;
	} 
  
	//IE6 standards compliant mode
	if (OBJ == '' && win.document.documentElement && (win.document.documentElement.scrollLeft || win.document.documentElement.scrollTop))
	{
		scrOfY = win.document.documentElement.scrollTop;
		scrOfX = win.document.documentElement.scrollLeft;
		return;
	}
	
	//IE6 standards compliant mode
	
	if (win.documentElement && (win.documentElement.scrollLeft || win.documentElement.scrollTop))
	{
		scrOfY = win.documentElement.scrollTop;
		scrOfX = win.documentElement.scrollLeft;
		return;
	}
}

function DynaWin(text,P) 
{
	var content
	
	getWinSize(P);
	
	WW = 400; WX = (myWidth  - WW)/2;
	WH = 300; WY = (myHeight - WH)/2;
	
	disp = window.open("","pop","height=" + WH + ",width=" + WW + ",left=" + WX + ",top=" + WY);
	content  = '<HTML><TITLE>Error Screen</TITLE></HEAD><BODY BGCOLOR="#ffeeee" onBlur="self.close()">';
	content += '<H3 ALIGN="CENTER">PLEASE CORRECT ERRORS</H3><TABLE ALIGN="CENTER"><TR><TD><FONT COLOR="BLUE">';
	content += text+'</FONT></TD></TR></TABLE>';
	//content += '<H3 ALIGN="CENTER"><A HREF="#" onClick="self.close()">Click here to Close this Window</A></H3>';
	content += '<P ALIGN="CENTER"><input type="button" name="close" value="Close Window" onClick="self.close()"></P>';
	content += '</BODY></HTML>';
	
	disp.document.write(content);
	disp.document.close();
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function date(x)
{
	var anum=/((^\d{2})(\/)(\d{2})(\/)(\d{4}$))|((^\d{4})(\/)(\d{2})(\/)(\d{2}$))/
	
	if (anum.test(x)) return true
	else              return false
}

function number(a,x)
{
	var str = ""
	
	if (a==1) str = "0123456789"
	if (a==2) str = "0123456789, "
	if (a==3) str = "0123456789/"
	
	for (var i=0; i<x.length; i++)
	{
		if (str.indexOf(x.charAt(i)) == -1)
		return false;
	}
	
	return true;
	
	//var anum=/(^\d+$)|(^\d+\.\d+$)/
	//if (anum.test(x)) return true
	//else              return false
}



function keySort(dropdownlist,caseSensitive) {
  // check the keypressBuffer attribute is defined on the dropdownlist 
  var undefined; 
  if (dropdownlist.keypressBuffer == undefined) { 
    dropdownlist.keypressBuffer = ''; 
  } 
  // get the key that was pressed 
  var key = String.fromCharCode(window.event.keyCode); 
  dropdownlist.keypressBuffer += key;
  if (!caseSensitive) {
    // convert buffer to lowercase
    dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
  }
  // find if it is the start of any of the options 
  var optionsLength = dropdownlist.options.length; 
  for (var n=0; n < optionsLength; n++) { 
    var optionText = dropdownlist.options[n].text; 
    if (!caseSensitive) {
      optionText = optionText.toLowerCase();
    }
    if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { 
      dropdownlist.selectedIndex = n; 
      return false; // cancel the default behavior since 
                    // we have selected our own value 
    } 
  } 
  // reset initial key to be inline with default behavior 
  dropdownlist.keypressBuffer = key; 
  return true; // give default behavior 
} 
/*
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
*/
