var stdBrowser = (document.getElementById) ? true: false
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
var tooltipLeft=170;
/////////////////////////////////////////////
function valNumInput(input,e)
{
    var i = e.keyCode;
  
    switch (i) {
      case [0,8,9,12,13]:
        break;  
      default:
        autoTab(input,e);
        isNum(input);
        break;
    }
}
/////////////////////////////////////////////
function isNum(input)
{
  var s=input.value;
  var j=s.length;

  for (i=0;i<j;i++)
    {
      if (s.charAt(i)<"0"||s.charAt(i)>"9") {
        input.value = s.slice(0,i);
        return false; }
    }   
  return true;
}


/////////////////////////////////////////////////////
function autoTab(input, e) 
{
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  len=input.maxLength;

  if(input.value.length >= len && !containsElement(filter,keyCode)) {
  input.value = input.value.slice(0, len);
//  input.form[(getIndex(input)+1) % input.form.length].focus();
  var i=(getIndex(input)+1) % input.form.length;
  var j = input.form[i].readOnly;

  if (j) {
   if (document.add.elements[i+1]) {
    i++;
    }
  }

  input.form[i].focus();
}
////////////////////////////////////////////////////
function containsElement(arr, ele) 
{
  var found = false, index = 0;
  while(!found && index < arr.length)
  if(arr[index] == ele)
  found = true;
  else
  index++;
  return found;
}
///////////////////////////////////////////////////
function getIndex(input) 
{
  var index = -1, i = 0, found = false;
  while (i < input.form.length && index == -1)
  if (input.form[i] == input)index = i;
  else i++;
    return index;
  }
return true;
}

///////////////////////////////////////////
function underlineLink(elem,val,css)
{
	if (val==1) {
		elem.style.backgroundColor='#ffffd0';
		}
	else {
		elem.style.cssText=css;
	}
}
/////////////////////////////////////////////
function buttonOver(elem,val)
{
		elem.style.background='#d8f0c8'; 
		elem.style.color='#000000'; 
}
/////////////////////////////////////////////
function buttonOut(elem,val)
{
	elem.style.cssText='btn';
	if (val>0) {
		elem.style.width=val;
	}

}
////////////////////////////////////////////
function checkAll(tabnm,chknm,checkAll)
{
    // Go through all items of a check list control
    var table = document.getElementById(tabnm);
    var elem = document.frm.elements;
    for (var i = 0; i < elem.length; i++) {
		if (elem[i].type == 'checkbox') {
			if (elem[i].name.indexOf(chknm) >-1) {
				elem[i].checked=checkAll;
			}
		}
	}
}
//////////////////////////////////
function jumpToIt(sAnchor) {

//	var e=document.getElementByName(sAnchor);
//	if (e) { eval('document.all.' + sAnchor + '.scrollIntoView()') }


	var e=document.getElementById(sAnchor);
	if (e) {

		ns = (document.layers)? true:false 
		ie = (document.all)? true:false 

		if (ie) {
			if ('document.all.'+sAnchor) {
				eval('document.all.' + sAnchor + '.scrollIntoView()')
		}


		if (ns) {
			jumpToIt2(sAnchor);
			window.scrollTo(0, document.anchors[sAnchor].y)
			} 
		}
	}

}

//////////////////////////////////
function popUp(evt,tiptext)
{
	var popUpWin;
	if (stdBrowser) {
		popUpWin=document.getElementById('templateToolTip').style;
	}
	else {
		popUpWin=eval('document.templateToolTip');
	}
  
	if (document.all) {
		popUpWin.pixelTop=parseInt(evt.y)+12;
		popUpWin.pixelLeft=180;
        }
	else {
       if (stdBrowser) {
            popUpWin.top=parseInt(evt.pageY)+12 + 'px';
	    popUpWin.left='180px';
                }
       else {
	   popUpWin.top=parseInt(evt.pageY)+12;
	   popUPWin.left=180;
	    }
	}
	 popUpWin.visibility = 'visible';
	 
	 var e=document.getElementById('templateToolTip');
	 if (e) {
		e.innerText=tiptext;
		}
//	 popUpWin.innerText=tiptext;
	 window.status=tiptext;
	return true;
}
//////////////////////////////////
function popDown()
{
	var elem = document.getElementById('templateToolTip');
	if (elem) {
		elem.style.visibility = 'hidden';
		elem.innerText=''
	}	
	window.status = '';
}

////////////////////////////
function popupWindow(url,w,h,x,y)
 {

	if (document.all) {
	 x = window.screenTop + x;
	 y = window.screenLeft+ y;
	}
	else if (document.layers) {
	x = window.screenX + x;
	y = window.screenY + y;
	}

	w+=180;
	h+=150;

  var win = window.open(url,
    "_blank",
    "location=no,directories=no,resizable=yes,toolbar=no,menubar=no,status=no,scrollbars=yes,width="+w+"+,height="+h+",screenX="+x+",screenY="+y+",top="+y+",left="+x);
	if (window.focus) {
		win.focus();
		}
}

////////////////////////////
function popupWindowFull(url,w,h,x,y)
 {

	if (document.all) {
	 x = window.screenTop + x;
	 y = window.screenLeft+ y;
	}
	else if (document.layers) {
	x = window.screenX + x;
	y = window.screenY + y;
	}
	w+=110;
	h+=120;

  var win = window.open(url,
    "_blank",
    "location=no,directories=no,resizable=yes,toolbar=yes,menubar=yes,status=yes,scrollbars=yes,width="+w+"+,height="+h+",screenX="+x+",screenY="+y+",top="+y+",left="+x);
	if (window.focus) {
		win.focus();
		}
}


/////////////////////////////////////////////
function inputFocus(elem)
{
//	elem.style.background='#ffffdd'; 
	elem.select();
//	elem.style.borderWidth='1px';
//	elem.style.borderStyle='solid';
//	elem.style.borderColor='#808080';
}

/////////////////////////////////////////////
function inputBlur(elem)
{
//	elem.style.background='#ffffff';
//	elem.style.borderWidth='1px';
//	elem.style.borderStyle='solid';
//	elem.style.borderColor='#808080';
}


/////////////////////////////////////////////
function inputFocusBlue(elem)
{
	elem.style.background='#ddeeff'; 
	elem.style.borderWidth='1px';
	elem.style.borderStyle='solid';
	elem.style.borderColor='#606060';
	elem.select();
}


////////////////////
function clrSelect(elem,val) {
	var e=document.getElementById(elem);

	if (e) {
		e.selectedIndex=val;
	}
}
//////////////////////////////////////////////////////////
function clrInput(elem) {

	var e=document.getElementById(elem);

	if (e) {
		e.value='';
		e.focus();
	}
}		


//////////////////////////////////
function jumpToIt2(sAnchor) {

	var e=document.getElementByName(sAnchor);
	if (e) {

		eval('document.all.' + sAnchor + '.scrollIntoView()')
		}


}



