//shortcut for gId
function gId(idName) {
	return document.getElementById(idName);
};

//shortcut for visibility
function isVisible(obj, setTo) {
	
	if (typeof setTo=="undefined"){	
		var bln
			if (obj.style.display=='none'){
				return (obj.display=='inline')?true:false;
			}
			else{
				return (obj.style.display=='block')?true:false;
			}
		return bln
	}
	
	else{
		if (setTo){
			obj.style.display='block';
			obj.display='inline';
		}
		else{
			obj.style.display='none';
			obj.display='none';
		}
	}
	
};

//Find x position of object
function findPosX(obj)
{
var curleft = 0;
if(obj.offsetParent)
    while(1) 
    {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
        break;
        obj = obj.offsetParent;
    }
else if(obj.x)
    curleft += obj.x;
return curleft;
}

//Find y position of object
function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
    while(1)
    {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
        break;
        obj = obj.offsetParent;
    }
else if(obj.y)
    curtop += obj.y;
return curtop;
}

//Get all events
/*function allEve(e){
	var ev= (window.event)? window.event: e;
	if(!ev || !ev.type) return false;
	var ME= ev;
	
	if(ME.type.indexOf('key')!= -1){
		if(isIE || ME.type.indexOf('keypress')!= -1){
			ME.key= (ev.keyCode)? ev.keyCode: ((ev.charCode)? ev.charCode: ev.which);
		}
		else ME.key= ev.charCode;
		if(ME.key) ME.letter= String.fromCharCode(ME.key);
	}
	return ME;
}*/

//Detect if is internet explorer
function isIE()
{
    //if (navigator.userAgent.indexOf("Firefox")!=-1)
        //return false;
    if (navigator.userAgent.indexOf("MSIE")!=-1){
        return true;
    }
    else{
		return false
    }
}

// Prevents event bubble up or any usage after this is called.
// pE - event object
function StopEvent(pE)
{
   if (!pE)
     if (window.event)
	pE = window.event;
     else
	return;
   if (pE.cancelBubble != null)
      pE.cancelBubble = true;
   if (pE.stopPropagation)
      pE.stopPropagation();
   if (pE.preventDefault)
      pE.preventDefault();
   if (window.event)
      pE.returnValue = false;
   if (pE.cancel != null)
      pE.cancel = true;
}  // StopEvent

//Return selected value in listbox or blank if none selected
function getSelectedValue(lst)
{
   if (lst.selectedIndex>=0){
      return lst.options[lst.selectedIndex].value;
   }
   else{
      return ""
   }
}

//Clear items from listbox and reset selected index to -1
function clearListBox(lb){
  for (var i=lb.options.length-1; i>=0; i--){
    lb.options[i] = null;
  }
  lb.selectedIndex = -1;
}

 function setListVal(listbox, expression)
	{
		for (var i = 0; i < listbox.options.length; i++) 
		{
			if (listbox.options[i]['text'].toUpperCase().indexOf(expression.toUpperCase()) == 0)
			{
				listbox.selectedIndex = i; 
				//lstchange(listbox);
				break;
			}
		}
	}

/*
function getSelectedRowPos(grd,selRowIdx)
{
	var tr;
	var pos=0;

	//Get position of selected row
	for (i=0;i<selRowIdx;i++){
		tr=grd.children[0].children[i]
		pos=pos+ tr.clientHeight	
	}
	
	if (pos>5){
		pos=pos-5 //Show half of the above row (to show not at top of grid)
	}
	
	return pos

}*/


//110121 BS
//Pause for specified millisecs
function pausecomp(millis)
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
		while(curDate-date < millis);
} 

//110121 BS
function modalWindow(url,title,center,height,width,help,focus){

	if (typeof window.showModalDialog  == "undefined"){
		//No modal window for this OS, so use standard window
		var win= window.open(url, 'theWin', 'width=' + width + ', height=' + height + ',help=' + help + ',focus=' + focus + ', modal=yes');
		win.focus();
		return "";
    }
    else{
		//Other browser
		var val=window.showModalDialog(url,title,'center=' + center + ';dialogHeight=' + height + 'px;dialogWidth='+ width + 'px;help=' + help + 'focus:' + focus );
		return val;
    }

}
