var Browser = navigator.userAgent.toLowerCase();
var IE = (Browser.indexOf('msie') != -1) ? true:false;


function MyAutoTab(current,to){
    if (current.getAttribute && current.value.length==current.getAttribute("maxlength")) {
        to.focus();
        //This next line highlightes the entire field.
        to.select(); 
    }
}


var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function MyAutoTab2(input,len, 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];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
    input.form[(getIndex(input)+1) % input.form.length].select();
  }

  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 OpenNewWindowWH(url,wd,ht,scrbar){
	//url and scrbar must be in single quotes where called.
	window.open(url,"","height=" + ht + ",width=" + wd + ",scrollbars=" + scrbar + ",resizable=yes");
}

function IsEmpty(strVal){ ///AS BOOLEAN
	var NewStr = (strVal).replace(/\s*/,"");
	var retVal = (NewStr.length == 0)? true:false;
	
	return retVal;
}

function OpenImageWindow(image, imgwidth, imgheight){
	var mybar='scrollbars=yes,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,top=20,left=20';
    mybar += ',width=';
    mybar += imgwidth;
    mybar += ',height=';
    mybar += imgheight;
    var newWin=open(image,'',mybar);
}

function OpenImageInWindowWH(url,wd,ht){
	//url and scrbar must be in single quotes where called.
	//window.open(url,"","height=" + ht + ",width=" + wd + ",scrollbars=" + scrbar + ",resizable=no");
	window.open(url,"","height=" + ht + ",width=" + wd + ",scrollbars=no,resizable=no,top=10,left=20");
}



function HiLightLeftNavLink(tdObj){
	if(IE){
		//tdObj.style.backgroundColor= "#8DABD8";
		tdObj.className = "clsHiLightLeftNavLink";
		tdObj.style.cursor = "hand";
		//tdObj.style.width = "100";
	}else{
		//tdObj.bgColor= "#6666FF";
		tdObj.className = "clsHiLightLeftNavLink";
		tdObj.style.cursor = "pointer";
	}
}

function HiLightLeftNavLink_sub(tdObj){
	if(IE){
		//tdObj.style.backgroundColor= "#8DABD8";
		tdObj.className = "clsHiLightLeftNavLink_sub";
		tdObj.style.cursor = "hand";
		//tdObj.style.width = "100";
	}else{
		//tdObj.bgColor= "#6666FF";
		tdObj.className = "clsHiLightLeftNavLink_sub";
		tdObj.style.cursor = "pointer";
	}
}

function DeHiLightLeftNavLink(tdObj){
	if(IE){
		//tdObj.style.backgroundColor= "#000066";
		tdObj.className = "clsLeftNavLink";
		tdObj.style.cursor = "auto";
	}else{
		//tdObj.bgColor= "#00066";
		tdObj.className = "clsLeftNavLink";
		tdObj.style.cursor = "auto";
	}
}

function DeHiLightLeftNavLink_sub(tdObj){
	if(IE){
		//tdObj.style.backgroundColor= "#000066";
		tdObj.className = "clsLeftNavLink_sub";
		tdObj.style.cursor = "auto";
	}else{
		//tdObj.bgColor= "#00066";
		tdObj.className = "clsLeftNavLink_sub";
		tdObj.style.cursor = "auto";
	}
}

function ShowLeftSubMenu(smnuId,obj,mnuId){
	var top=0;
	var left=0;
	var Menu = document.getElementById(mnuId);
	var sMenu = document.getElementById(smnuId);

	top=Menu.offsetTop;
	left=Menu.offsetLeft;

	sMenu.style.left = left+130;
	sMenu.style.top = top+56;
	sMenu.style.visibility = "visible";	
}

function HideLeftSubMenu(smnuId,evt,obj){
	var top=obj.offsetTop;
	var left=obj.offsetLeft;
	var width=obj.offsetWidth;
	var height=obj.offsetHeight;
	var X=evt.clientX;
	var Y=evt.clientY;
	
	var objParent=obj.offsetParent;
	var scrolltop=objParent.scrollTop;
	
	var Menu = document.getElementById(smnuId);
	
	
	if(IE){
		if(!Menu.contains(event.toElement)){
			Menu.style.visibility = "hidden";
		}
	}else{
		//The scrolltop value adjusts for scrolling up or down on the page.
		if(Y+1+scrolltop>top+height){
			Menu.style.visibility = "hidden";
		}
		if(Y+scrolltop<top){
			Menu.style.visibility = "hidden";
		}
		if(X+1>left+width){
			Menu.style.visibility = "hidden";
		}
	}
}

function HideSubMenuFromLeftLink(smnuId,evt,obj,MHeight){
	var objParent=obj.offsetParent
	var ParentTop=objParent.offsetTop;
	
	//var scrolltop=objParent.scrollTop;
	
	var top=obj.offsetTop;
	var left=obj.offsetLeft;
	var width=obj.offsetWidth;
	var X=evt.clientX;
	var Y=evt.clientY;
	
	var Menu = document.getElementById(smnuId);
	
	if(IE){
		if(!Menu.contains(event.toElement)){
			Menu.style.visibility = "hidden";
		}
	}else{
		//This IF hides sub-menu if your on the parent and go above the parent.
		//The X check is done here to make sure that the mouse is within the parent menu.
		if((Y<ParentTop+top+MHeight)&&(X<left+width)){
			Menu.style.visibility = "hidden";
		}
		//This IF hides sub-menu if your on the parent and go below the parent.
		//The X check is done here to make sure that the mouse is within the parent menu.
		if((Y+1>ParentTop+top+MHeight)&&(X<left+width)){
			Menu.style.visibility = "hidden";
		}
	}
}
