function keyCheck(eventObj, obj)
{
	var keyCode

	// Check For Browser Type
	if (document.all){ 
		keyCode=eventObj.keyCode
	}
	else{
		keyCode=eventObj.which
	}

	var str=obj.value

	if(keyCode==46){ 
		if (str.indexOf(".")>0){
			return false
		}
	}

	if((keyCode<48 || keyCode >58)   &&   (keyCode != 46)){ // Allow only integers and decimal points
		return false
	}

	return true
}



function OMPrintWin(url){
	var winWidth = 580;
	var winHeight = 480;
	var posLeft = (screen.availWidth - winWidth) / 2;
	var posTop = (screen.availHeight - winHeight) / 2;
	var winInfo = 'width=' + winWidth + ',height=' + winHeight + ',left=' + posLeft + ',top=' + posTop + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';
	var winlaunch = window.open(url, 'popupwindow', winInfo);
	winlaunch.moveTo(posLeft,posTop);
        winlaunch.print();
        winlaunch.close();
}

function OMFormatFloatRound(aVal, aDec){
    var bValue = aVal;
    var i=0;
    var bPeso=1;
    for (i=0; i<aDec; i++)
      bPeso = bPeso * 10;
    bValue = Math.round(bValue *bPeso);
    bValue = bValue / bPeso;
    return(bValue);
}

function OMRound(aVal){
  return(Math.round(aVal));
}

function OMTrim(str){
  var bStr="";
  var i=0;
  var j=0;
  if (str=="") return("");

  for (i=0; i< str.length && str.charAt(i) == " "; i++);
  for (j=str.length-1; j>=0 && str.charAt(i) == " "; j++);
   
  bStr = str.substring(i,j+1);
  return(bStr);
}

function OMParseNumberToStr(str){
  var bStr="";
  if (str == "")  bStr="null";
  if (str == "0") bStr= "zero"; 
  if (str == "1") bStr= "uno"; 
  if (str == "2") bStr= "due"; 
  if (str == "3") bStr= "tre"; 
  if (str == "4") bStr= "quattro"; 
  if (str == "5") bStr= "cinque"; 
  if (str == "6") bStr= "sex"; 
  if (str == "7") bStr= "sette"; 
  if (str == "8") bStr= "otto";   
  if (str == "9") bStr= "nove"; 
  if (str == "10") bStr= "dieci"; 
  return(bStr);
}

function OMParseInt(str){
  var bStr="";
  var i=0;
  if (str=="") return("0");

  for (i=0; i< str.length; i++)
  {
    if (str.charAt(i) == "-" || 
        str.charAt(i) == "0" || 
        str.charAt(i) == "1" ||
        str.charAt(i) == "2" || 
        str.charAt(i) == "3" ||
        str.charAt(i) == "4" || 
        str.charAt(i) == "5" ||
        str.charAt(i) == "6" || 
        str.charAt(i) == "7" ||
        str.charAt(i) == "8" || 
        str.charAt(i) == "9")
      bStr += str.charAt(i);
  }  
  return(bStr);
}

function OMParseNumber(str){
  var bStr="";
  var i=0;
  if (str=="") return("0");

  for (i=0; i< str.length; i++)
  {
    if (str.charAt(i) == "0" || 
        str.charAt(i) == "1" ||
        str.charAt(i) == "2" || 
        str.charAt(i) == "3" ||
        str.charAt(i) == "4" || 
        str.charAt(i) == "5" ||
        str.charAt(i) == "6" || 
        str.charAt(i) == "7" ||
        str.charAt(i) == "8" || 
        str.charAt(i) == "9")
      bStr += str.charAt(i);
  }  
  return(bStr);
}

function OMParseFloat(str){
  var bStr="";
  var i=0;
  if (str=="") return("0");

  for (i=0; i< str.length; i++)
  {
    if (str.charAt(i) == "0" || 
        str.charAt(i) == "1" ||
        str.charAt(i) == "2" || 
        str.charAt(i) == "3" ||
        str.charAt(i) == "4" || 
        str.charAt(i) == "5" ||
        str.charAt(i) == "6" || 
        str.charAt(i) == "7" ||
        str.charAt(i) == "8" || 
        str.charAt(i) == "9" )
      bStr += str.charAt(i);
    if (str.charAt(i) == ',' ||
        str.charAt(i) == '.')
      bStr += '.';
  }  
  return(bStr);
}

function OMParseStrURL(str){
  var bStr="";
  var bHex="";
  var i=0;
  if (str=="") return("");

  for (i=0; i< str.length; i++)
  {
    if (str.charAt(i) == "+")
    {
      bStr += " ";
      continue;
    }
    if (str.charAt(i) == "%")
    {
      if (i< str.length) i++;
      if (i< str.length) i++;
      if (str.charAt(i-1) == "2" && str.charAt(i) == "E")
      {
        bStr += ".";
        continue;
      } 
      bStr += "%"+str.charAt(i-1)+str.charAt(i);
      continue;
    }
    bStr += str.CharAt(i);
  }  
  return(bStr);
}

function OMStringToInt(bstr)
{
  var bsum=0;
  var bnum=0;
  var bmult=1;
  var i=0;

  for (i=bstr.length-1; i>=0; i--)
  { 
    if (bstr.charAt(i) == "0") bnum =0;
    if (bstr.charAt(i) == "1") bnum =1;
    if (bstr.charAt(i) == "2") bnum =2;
    if (bstr.charAt(i) == "3") bnum =3;
    if (bstr.charAt(i) == "4") bnum =4;
    if (bstr.charAt(i) == "5") bnum =5;
    if (bstr.charAt(i) == "6") bnum =6;
    if (bstr.charAt(i) == "7") bnum =7;
    if (bstr.charAt(i) == "8") bnum =8;
    if (bstr.charAt(i) == "9") bnum =9;
    bsum = bsum + bmult * bnum;
    bmult = bmult *10;
  }
  return(bsum);
}


function OMParseDate(bstr) {
  var bStr="";
  var str="";
  var i=0;
  var bSep=0;
  var bOk =0;
  var bDay="";
  var bMonth="";
  var bYear="";
  var bToday="";
  var bData= 0;
  var bRes1=0.0;
  var bRes2=0.0;
  var bDiv1=0.0;
  var bDiv2=0.0;
  var nDay=0;
  var nMonth=0;
  var nYear=0;
  var today = new Date();  
  month = today.getMonth();
  date = today.getDate();
  year = today.getYear() + "";
  Year = "20"+ year.substring(year.length-2,year.length);
  Month = month + 1;
  bToday = date+"/"+Month+"/"+Year;


  if (bstr=="") return("");

  for (i=0; i< bstr.length; i++)
  {
    if (bstr.charAt(i) == "0" || 
        bstr.charAt(i) == "1" ||
        bstr.charAt(i) == "2" || 
        bstr.charAt(i) == "3" ||
        bstr.charAt(i) == "4" || 
        bstr.charAt(i) == "5" ||
        bstr.charAt(i) == "6" || 
        bstr.charAt(i) == "7" ||
        bstr.charAt(i) == "8" || 
        bstr.charAt(i) == "9"  )
      str += bstr.charAt(i);
    if (bstr.charAt(i) == '.' ||
        bstr.charAt(i) == '/')
      str += '/';
  }

  for (i=0; i< str.length; i++)
  {
    if (str.charAt(i) == "/")
      bSep = 1;
  }  
  if (bSep == 0)
  {
    if (str.length <= 2)
    {
      for (i=0; i< str.length; i++)
         bDay += str.charAt(i);
      bMonth = Month; 
      bYear = Year;
    } else  if (str.length <= 4)
    {
      for (i=0; i< 2; i++)
         bDay += str.charAt(i);
      for (i=2; i< str.length; i++)
         bMonth += str.charAt(i);
      bYear = Year;
    } else  if (str.length <= 8)
    {
      for (i=0; i< 2; i++)
         bDay += str.charAt(i);
      for (i=2; i< 4; i++)
         bMonth += str.charAt(i);
      for (i=4; i< str.length; i++)
         bYear += str.charAt(i);
    }
  } 
  if (bSep == 1)
  {
    for (i=0; i< str.length && str.charAt(i) != "/"; i++)
     bDay += str.charAt(i);
    for (i++; i< str.length && str.charAt(i) != "/"; i++)
      bMonth += str.charAt(i);
    for (i++; i< str.length && str.charAt(i) != "/"; i++)
      bYear += str.charAt(i);
    if (bDay == "") bDay = date;
    if (bMonth == "") bMonth = Month;
    if (bYear == "") bYear = Year;
  }
  
  nDay = OMStringToInt(bDay);
  nMonth = OMStringToInt(bMonth);
  nYear = OMStringToInt(bYear.substr(0,4));
 
  if (nDay <= 0) nDay = 1;
  if (nMonth > 12) nMonth = 12;
  if (nMonth < 1) nMonth = 1;
  if (nYear > 70 && nYear <= 99)
     nYear += 1900;
  if (nYear >= 0 && nYear <= 70)
     nYear += 2000;
  if (nYear < 1800) nYear = 1800;
  if (nMonth == 11 || nMonth == 4 || nMonth == 6 || nMonth == 9)
  {
    if (nDay > 30) nDay = 30;
  } else if (nMonth == 2) 
  { 
    bRes1 = nYear % 4;
    bRes2 = nYear % 100;
    if (bRes1 == 0 || bRes2 ==0)
    {
      if (nDay > 29) nDay = 29;
    } else
    {
      if (nDay > 28) nDay = 28;
    }  
    
  } else 
  {
    if (nDay > 31) nDay = 31;
  }
  bDay = nDay.toString();
  bMonth = nMonth.toString();
  bYear = nYear.toString();

  if (nDay < 10 && bDay.charAt(0) != "0")  
    bStr = "0";
  bStr += bDay+"/";
  if (nMonth < 10 && bMonth.charAt(0) != "0")
    bStr += "0";
  bStr += bMonth+"/"+bYear;
  return(bStr);
}

function OMParseTime(bstr) {
  var i=0;
  var str = "";
  var bSep = 0;
  var bHours = "";
  var bMinutes = "";
  var bSeconds = "";
  var nHours = 0;
  var nMinutes = 0;
  var nSeconds = 0;
  var hours = "";
  var minutes = "";
  var seconds = "";

  var bData = new Date();
  hours = bData.getHours();
  minutes = bData.getMinutes();
  seconds = bData.getSeconds();


  for (i=0; i< bstr.length; i++)
  {
    if (bstr.charAt(i) == "0" || 
        bstr.charAt(i) == "1" ||
        bstr.charAt(i) == "2" || 
        bstr.charAt(i) == "3" ||
        bstr.charAt(i) == "4" || 
        bstr.charAt(i) == "5" ||
        bstr.charAt(i) == "6" || 
        bstr.charAt(i) == "7" ||
        bstr.charAt(i) == "8" || 
        bstr.charAt(i) == "9" ||
        bstr.charAt(i) == ':' )
      str += bstr.charAt(i);
    if (bstr.charAt(i) == '.' ||
        bstr.charAt(i) == '/')
      str += ':';
  }

  for (i=0; i< str.length; i++)
  {
    if (str.charAt(i) == ":")
      bSep = 1;
  }  
  if (bSep == 1)
  {
    for (i=0; i< str.length && str.charAt(i) != ":"; i++)
      bHours += str.charAt(i);
    for (i++; i< str.length && str.charAt(i) != ":"; i++)
      bMinutes += str.charAt(i);
    for (i++; i< str.length && str.charAt(i) != ":"; i++)
      bSeconds += str.charAt(i);
    if (bHours == "") bHours = hours;
    if (bMinutes == "") bMinutes = minutes;
    if (bSeconds == "") bSeconds = seconds;
  }
  
  nHours = bHours;
  nMinutes = bMinutes;
  nSeconds = bSeconds;
  if (nHours > 23) nHours = 23;
  if (nMinutes > 59) nMinutes = 59;
  if (nSeconds > 59) nSeconds = 59;

  str = String(nHours)+":"+String(nMinutes)+":"+String(nSeconds);
  
  if (str == String("::")) str = "0:0:0";
  return(str);
}


function omWindowOpen(aPage)
{
newwindow = window.open(aPage,"","")
newwindow.creator=self
}

function OMWindowOpenSmall(url){
	var winWidth = 800;
	var winHeight = 600;
	var posLeft = (screen.availWidth - winWidth) / 2;
	var posTop = (screen.availHeight - winHeight) / 2;
	var winInfo = 'width=' + winWidth + ',height=' + winHeight + ',left=' + posLeft + ',top=' + posTop + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';
	var winlaunch = window.open(url, 'popupwindow', winInfo);
	winlaunch.moveTo(posLeft,posTop);
}

function OMWindowOpenSmallScroll(url, winWidth, winHeight){
	//var winWidth = 600;
	//var winHeight = 250;
	var posLeft = (screen.availWidth - winWidth) / 2;
	var posTop = (screen.availHeight - winHeight) / 2;
	var winInfo = 'width=' + winWidth + ',height=' + winHeight + ',left=' + posLeft + ',top=' + posTop + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';
	var winlaunch = window.open(url, 'popupwindow', winInfo);
      winlaunch.creator = self;
	winlaunch.moveTo(posLeft,posTop);
}

function OMWindowOpenSmallScrollNo(url, winWidth, winHeight){
	//var winWidth = 600;
	//var winHeight = 250;
	var posLeft = (screen.availWidth - winWidth) / 2;
	var posTop = (screen.availHeight - winHeight) / 2;
	var winInfo = 'width=' + winWidth + ',height=' + winHeight + ',left=' + posLeft + ',top=' + posTop + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no';
	var winlaunch = window.open(url, 'popupwindow', winInfo);
      winlaunch.creator = self;
	winlaunch.moveTo(posLeft,posTop);
}

function OMCancelString(str,strC) {
   var idx=0;
   var strN = "";

   if (str == "null" || str=="undefined")
   { 
      return(strN);
   }
   if (str == strC)
   { 
      return(strN);
   }

   idx = str.search(strC);
   if (idx < 0) 
   { 
      return(str);
   }
  
   strN = str.slice(0,idx-1);
   strN += str.slice(idx+strC.length, str.length);

   return(strN);  
}

function OMFormShow(object) {
  if (document.getElementById) {
    document.getElementById(object).style.visibility = 'visible';
  }
  else if (document.layers && document.layers[object]) {
    document.layers[object].visibility = 'visible';
  }
  else if (document.all) {
    document.all[object].style.visibility = 'visible';
  }
}

function OMFormHide(object) {
  if (document.getElementById) {
    document.getElementById(object).style.visibility = 'hidden';
  }
  else if (document.layers && document.layers[object]) {
    document.layers[object].visibility = 'hidden';
  }
  else if (document.all) {
    document.all[object].style.visibility = 'hidden';
  }
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

