var selRow;

function saveAndClose(){
	abortSaveTest=true;
	document.mainForm.action+='&close=yes';
	document.mainForm.submit();	
}

function saveAndNew(){
	abortSaveTest=true;
	document.mainForm.action+='&saveNew=yes';
	document.mainForm.submit();	
}

function disableRightClick(){
	if (window.Event)	document.captureEvents(Event.MOUSEUP);
	  
	function nocontextmenu() {
	  event.cancelBubble = true, event.returnValue = false;
	  return false;
	} 
	
	function norightclick(e) {
	  if (window.Event) {
		if (e.which == 2 || e.which == 3) return false;
	  }
	  else if (event.button == 2 || event.button == 3) {
		event.cancelBubble = true, event.returnValue = false;
		return false;
	  }
	}
	if (document.layers)	document.captureEvents(Event.MOUSEDOWN);
	document.oncontextmenu = nocontextmenu;
	document.onmousedown = norightclick;
	document.onmouseup = norightclick;
}

function disableSelection(){
	document.onselectstart = new Function ("return false");
}

function enableSelection(obj){ 
	document.onselectstart = new Function ("return true");
	if (obj) obj.select();
}

function trcc(theRow, cellColor)
{
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined' || theRow.cells[1].bgColor=='#316ac5') {
        return false;
    }

    var row_cells_cnt           = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
	        theRow.cells[c].bgColor = cellColor;
    }
    return true;
}
function selTR(whatTR)
{
		if (typeof(selRow) != 'undefined') {
			var row_cells_cnt           = selRow.cells.length;
			for (var c = 0; c < row_cells_cnt; c++) {
					selRow.cells[c].bgColor = '#FFFFFF';
					selRow.cells[c].style.color = '#000000';
			}
		}
		var row_cells_cnt           = whatTR.cells.length;
		for (var c = 0; c < row_cells_cnt; c++) {
				whatTR.cells[c].bgColor = '#316AC5';
				whatTR.cells[c].style.color = '#FFFFFF';			
		}
	
		selRow=whatTR;
}
/* function selTR(theLink)
{
    if (typeof(selRow) != 'undefined') {
	    var row_cells_cnt           = selRow.cells.length;
    	for (var c = 0; c < row_cells_cnt; c++) {
	    	    selRow.cells[c].bgColor = '#FFFFFF';
    	}
    }
    if (typeof(theLink.style) == 'undefined') {
        return false;
    }
	eventNode=event.srcElement;
	while (eventNode.tagName!='TR'){
		eventNode=eventNode.parentNode;
	}
    var row_cells_cnt           = eventNode.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
	        eventNode.cells[c].bgColor = '#BACDF5';
    }
	selRow=eventNode;
} */

function hlcoloff(thePos,theColor){
	for (var i=0;i<dataTable.rows.length-1;i++){
		dataTable.rows[i].cells[thePos].bgColor=theColor;
	}
}

function checkAll(frm)
{
	for (var i=0;i<frm.elements.length;i++)
	{
		var e = frm.elements[i];
		if (e.name != 'selectAll')
		  e.checked = !e.checked;
	}
}

function DeleteRecord()
{
	return confirm("Têm a certeza que deseja apagar este Registo?")
}

function NDeleteRecord(url)
{
	var result
	result=confirm("Têm a certeza que deseja apagar este Registo?");
	if (result){
		window.location.href=url;
		return false;
	} else {
		return false;
	}
}

<!--Selects a checkbox by clicking on the correspondent row. Place onclick="sChk(this);" on <TR>//-->
function sChk(src){
 if(event.srcElement.tagName!='A' && event.srcElement.tagName!='INPUT'){
	var obj=src.all.tags('INPUT')[0];
	obj.checked=!obj.checked;
	}
}
function hlon(theCell,thePos){
	dataTable.rows[0].cells[thePos+1].background="img/bckgray.gif";
	for (var i=0;i<dataTable.rows.length-1;i++){
		i++;
		if (dataTable.rows[i].cells[thePos+1].bgColor!='#bacdf5')
			dataTable.rows[i].cells[thePos+1].bgColor='#f7f7f7'
		else
			dataTable.rows[i].cells[thePos+1].bgColor='#cbdef6';
	}	
}
function hloff(theCell,thePos,theColor){
	dataTable.rows[0].cells[thePos+1].background="img/bckblue.gif";
	for (var i=0;i<dataTable.rows.length-1;i++){
		i++;
		if (dataTable.rows[i].cells[thePos+1].bgColor!='#cbdef6')
			dataTable.rows[i].cells[thePos+1].bgColor=theColor;
		else
			dataTable.rows[i].cells[thePos+1].bgColor='#bacdf5';
	}	
}
function colon(theCell,thePos){
	dataTable.rows[0].cells[thePos+1].bgColor="#cceeff";
	for (var i=1;i<dataTable.rows.length;i++){
		dataTable.rows[i].cells[thePos+1].bgColor='#eeeeee';
	}	
}
function coloff(theCell,thePos,theColor){
	dataTable.rows[0].cells[thePos+1].bgColor=theColor;
	for (var i=1;i<dataTable.rows.length;i++){
		dataTable.rows[i].cells[thePos+1].bgColor="#ffffff";
	}	
}
function rowonoff(theRow,ison)
{
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }

    var row_cells_cnt           = theRow.cells.length;
	if (ison)
		theRow.cells[0].bgColor = "#BACDF5";
	else
		theRow.cells[0].bgColor = "#a9bce4";
    for (var c = 1; c < row_cells_cnt; c++) {
		if (ison)
	        theRow.cells[c].bgColor = "#eeeeee";
		else
			theRow.cells[c].bgColor = "#ffffff";
    }
    return true;
}

<!-- HighLight ON Caption Cell //-->
function mClk(src){  if(event.srcElement.tagName=='TD'){  src.children.tags('A')[0].click(); }} 
function popup(url,name,w,h) {  
	var wLeft = (screen.width-w)/2;
	var wTop = ((screen.height-h)/2)-30;
	popupWin = window.open(url,name, 'top='+wTop+',left='+wLeft+',width='+w+',height='+h+',scrollbars=1,resizable=1,status=1'); 
	popupWin.focus();
}
function popupWithoutScroll(url,name,w,h) {  
	var wLeft = (screen.width-w)/2;
	var wTop = ((screen.height-h)/2)-30;
	popupWin = window.open(url,name, 'top='+wTop+',left='+wLeft+',width='+w+',height='+h+',scrollbars=0,resizable=1,status=1'); 
	popupWin.focus();
}
function popupfixed(url,name,w,h) {  
	var wLeft = (screen.width-w)/2;
	var wTop = ((screen.height-h)/2)-30;
	popupWin = window.open(url,name, 'top='+wTop+',left='+wLeft+',width='+w+',height='+h+',scrollbars=0,resizable=0,status=1'); 
	popupWin.focus();
}
function popuptlbr(url,name,w,h) {  
	var wLeft = (screen.width-w)/2;
	var wTop = (screen.height-h)/2;
	popupWin = window.open(url,name, 'top='+wTop+',left='+wLeft+',width='+w+',height='+h+',toolbar=1,scrollbars=1,resizable=1,status=1');
	popupWin.focus();	
}
function popupNothing(url,name,w,h) {  
	var wLeft = (screen.width-w)/2;
	var wTop = ((screen.height-h)/2)-30;
	popupWin = window.open(url,name, 'top='+wTop+',left='+wLeft+',width='+w+',height='+h+',scrollbars=0,resizable=0,status=0'); 
	popupWin.focus();
}
function initTlbr(){
	var TDs = document.getElementsByTagName('TD');
	for (aux=0;aux<TDs.length;aux++){
		if (TDs[aux].id == 'tlbrBtn'){
			TDs[aux].onmouseover = function () {
				this.background='/img/tlbr_hover.gif';			
			}
			TDs[aux].onmouseout = function () {
				this.background='';
				this.style.color='#000000';
			}
			TDs[aux].onmousedown = function () {
				this.background='/img/tlbr_select.gif';
				this.style.color='#ffffff';
			}
			TDs[aux].onmouseup = function () {
				this.background='/img/tlbr_hover.gif';
				this.style.color='#000000';
			}
		}
	}
}

function deleteRecord(recType,recId){
	if (recId!='undefined'){
		if ( confirm("Têm a certeza que deseja apagar este Registo?") ){
			popup('/admin/delete_record.asp?what='+recType+'&id='+recId,'apagarinst','400','120');
			return true;
		}
	}
}
function resizeIFrame(frName) {
	var frObj = document.getElementById(frName);
	if ( frObj ) frObj.height=document.body.offsetHeight-frObj.offsetTop;
}

function loadFrame(frameName,frameLocation,saveCookie){
		var frm = eval(frameName);
		if ( frm ) {
				if ( frameLocation ) {
					frm.location = frameLocation;
					if (saveCookie) {
						setCookie('sctr_'+frameName,frameLocation);
					}
				}
		}
}

function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;
  var objColl = (strTag == '*' && document.all && !window.opera) ? document.all : objContElm.getElementsByTagName(strTag);
  var arr = new Array();
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
  var arrClass = strClass.split(delim);
  for (var i = 0, j = objColl.length; i < j; i++) {
    var arrObjClass = objColl[i].className.split(' ');
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]);
          break comparisonLoop;
        }
      }
    }
  }
  return arr;
}

Array.prototype.push = function(value) {
  this[this.length] = value;
}

function addCurrency(S) {
	S = String(S);
	if (S){
		var RgX = /^(.*\s)?([-+\u00A3\u20AC]?\d+)(\d{3}\b)/
		return S == (S=S.replace(RgX, "$1$2.$3")) ? S+' €' : addCurrency(S);
	} else {
		return S;
	}
}

function removeCurrency(S) {
	S = String(S);
	S = S.replace(' €','').replace('.','');
	return S;
}

function popupDate(field){
	resultDialog = window.showModalDialog( '/ext/sctr-app/inc/calendar.asp','','dialogWidth:127px;dialogHeight:180px;dialogLeft:'+(event.screenX-60)+';dialogTop:'+(event.screenY-90)+';center:0;scroll:0;resizable:0;status:0;help:0;' );
	if ( resultDialog ) field.value=resultDialog;
}	

