
/*
  function checkInput(oTxt,iType) // Allows only specified type of values to be entered.
  function checkDateFormat(oTxt) // Allows values to be entered in date format.
  function RollOver(oRow) // Changes the row style when mouse is over
  function RollOut(oRow) // Changes the row style when mouse is moved out
  function Select(oRow) // Changes the row style when mouse is clicked
  function MoveToNext(oRow) // Changes the style when arrow keys are pressed
  function trim(sVlaue); trims the given string  and returns trimmed sting
  function startsWith(sValue,sStartString) // checks the given string with the start string
  function endsWith(sValue,sEndString) // checks the given string with the end string
*/

var objPrevClass="";
var TYPE_NUMERIC=2,TYPE_FLOAT=3,TYPE_DATE=4;

if( document.captureEvents )
{
    if( Event.KEYUP )
    {
        //NS 4, NS 6+, Mozilla 0.9+
        document.captureEvents( Event.KEYUP );
    }
}
/**
  Allows values of type specified in parameter to be entered.
  @param objTxt -- TextField object
  @param iType -- Field type -- Default - 'string'
  values: string=1,numeric=2,float=3,date=4
**/
function checkInput(objTxt,iType)
{
    var evt,keycode;
    if(window.event)
        evt = window.event;
    else
        evt = window.Event;

    keycode = evt.keyCode;

    if( keycode!=37 && keycode!=39 && keycode!=8 && keycode!=46 && keycode!=36&& keycode!=35)
    {               // left arrow,right arrow, backspace, delete , Home , End
        if(iType==2)//Numeric
        {
           objTxt.value = objTxt.value.replace(/([^\-0-9])/g,"");
           //oTxt.value = oTxt.value.replace(/([^/\d])/g,"");

           if(objTxt.value.lastIndexOf("-") > 0)
                objTxt.value=objTxt.value.substring(0,objTxt.value.lastIndexOf("-"));
        }
        else if(iType==3)//Float
        {
            objTxt.value = objTxt.value.replace(/([^.\-0-9])/g,"");

            if(objTxt.value.lastIndexOf("-")>0)
                objTxt.value=objTxt.value.substring(0,objTxt.value.lastIndexOf("-"));
            if(objTxt.value.indexOf(".")!=objTxt.value.lastIndexOf("."))
                objTxt.value=objTxt.value.substring(0,objTxt.value.lastIndexOf("."));
        }
        else if(iType==4)//date
        {
            checkDateFormat(objTxt);
        }
    }
}
/**
   Checks for date format
   @param oTxt -- TextField Object
**/
function checkDateFormat(objTxt)
{
    for(var i=0;i < objTxt.value.length;i++)
    {
        if(i==2 || i==5)
        {
            if(objTxt.value.charAt(i)!="/")
            objTxt.value = objTxt.value.substring(0,i);
        }
        else if((objTxt.value.lastIndexOf("/"))!=(objTxt.value.indexOf("/")) &&(objTxt.value.lastIndexOf("/")!=-1))
        {
            if((objTxt.value.lastIndexOf("/") - objTxt.value.indexOf("/") )!=3 )
                objTxt.value = objTxt.value.substring(0,objTxt.value.lastIndexOf("/"))
        }
        else if(objTxt.value.indexOf("/") != -1)
        {
            if(objTxt.value.indexOf("/") < 2)
                objTxt.value = objTxt.value.replace(/([^0-9])/g,"");
        }
        if(objTxt.value.charAt(3)=="/"|| objTxt.value.charAt(4)=="/")
        {
             objTxt.value = objTxt.value.substring(0,objTxt.value.indexOf("/")+1);
        }
        objTxt.value = objTxt.value.replace(/([^\/0-9])/g,"");

        //oTxt.value = oTxt.value.replace(/^(\d{3}\/d{2}\/d{4})$/);
     }
}
/**
   Changes the row color when mouse is moved over the row
   @param oRow -- Current Row Object
**/
function RollOver(objRow)
{
    if(objRow.className!="sSelectedRow")
    {
        objRow.setAttribute("RowClassName",objRow.className);
        objRow.className = "sHighlightedRow";
    }
}
    /**
     Changes the row color when mouse is moved out
     @param oRow -- Current Row Object
    **/
function RollOut(objRow)
{
    if(objRow.className!="sSelectedRow")
    {
        objRow.className = objRow.getAttribute("RowClassName");
        objRow.setAttribute("RowClassName",null);
    }
}

/**
   Changes the row color when mouse click event is fired on Row
   @param oRow -- Current Row Object
**/
function Select(objRow)
{
    //oRow = oRow.parentNode;
    var objTable = objRow.parentNode;

    for(var i=1;i < objTable.childNodes.length;i++)
    {
        if(objTable.childNodes[i] && objTable.childNodes[i].className=="sSelectedRow")
        {
            objTable.childNodes[i].className = objPrevClass;
            break;
        }
    }
    objPrevClass = objRow.getAttribute("RowClassName");
    objRow.setAttribute("RowClassName",null);
    objRow.className = "sSelectedRow";

    if(window.addEventListener)
    {            // Mozilla, Netscape, Firefox
        alert("adding listener...  "+objTable);
	    document.getElementById(objTable.parentNode.id).addEventListener('keyup', MoveToNext, false);
    }
    /*
        oTable.addEventListener("onKeyUp",MoveToNext,false);
     */
}
/**
    Moves to next row when key arrows are pressed.
   @param oRow -- Current Row Object
**/
function MoveToNext(objRow)
{
    //if(oRow.className=='selectedRow')
     //   oRow.className = 'highlightedRow';
    var evt,objTable;
    if(window.event)                     // IE
    {
        evt = window.event;
        objTable = objRow.parentNode;
    }
    else                                // Netscape, Mozilla
    {
        evt = window.Event;
        alert("src...."+objRow);
        objTable = objRow.srcElement;
    }
    var keycode = evt.keyCode;

    for(var i=1;i < objTable.childNodes.length;i++)
    {
        if(objTable.childNodes[i].className == "sSelectedRow")
        {
            if(keycode==40 && objTable.childNodes[i+1])        //downarrow
            {
                objTable.childNodes[i].className = objPrevClass;
                objPrevClass = objTable.childNodes[i+1].className;
                objTable.childNodes[i+1].className = "sSelectedRow";
                break;
            }
            else if(keycode==38 && objTable.childNodes[i-2])  //up arrow
            {
                objTable.childNodes[i].className = objPrevClass;
                objPrevClass = objTable.childNodes[i-1].className;
                objTable.childNodes[i-1].className = "sSelectedRow";
                break;
            }
        }

    }
    /*oPrevClass = oRow.getAttribute("RowClassName");
    oRow.setAttribute("RowClassName",null);
    oRow.className = "selectedRow";*/
}

    function trim(s)
    {
        return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
    }

/*function trim(sVlaue)
{
  var sNewValue="";
  var iStartIndex=-1,iEndIndex;
  for(var index=0;index<sVlaue.length;index++)
  {
    if(iStartIndex==-1 && sVlaue.charAt(index)!=' ')
       iStartIndex=index;
    else
     {
        if(sVlaue.charAt(index)==' ')
          iEndIndex=index;
        else if(sVlaue.charAt(index)!=' ')
          iEndIndex=-1;
     }
  }
  if(iEndIndex!=-1)
     return sVlaue.substring(iStartIndex,iEndIndex);
 else
    return sVlaue.substring(iStartIndex,sVlaue.length);

} */

function startsWith(sValue,sStartString)
{
    sValue=sValue.substring(0,sStartString.length)
    if(sValue==sStartString)
      return true;
   else
     return false;
}
function endsWith(sValue,sEndString)
{
    sValue=sValue.substring(sValue.length-sEndString.length,sValue.length)
    if(sValue==sEndString)
      return true;
   else
     return false;
}
function getBrowserType()
{
    var browser_version= "0";//parseInt(navigator.appVersion);
    var browser_type = navigator.appName;
    var iType;

   // alert("browser_version "+browser_version+",navigator.appName.. "+browser_type )

    if(navigator.userAgent .indexOf("MSIE 6.0")!=-1)
    {
    	iType = 10 + browser_version;
    }
    else if(navigator.userAgent .indexOf("Netscape/8.0.3.3")!=-1)
    {
    	iType = 20 + browser_version;
    }
    else if(navigator.userAgent .indexOf("Firefox/1.0.7")!=-1)
    {
    	iType = 30 + browser_version;
    }

    else if (browser_type == "Microsoft Internet Explorer" )
    {
        iType = 10 + browser_version;
    }

    else if (browser_type == "Netscape")
    {
        iType = 20 + browser_version;
    }
    else if (browser_type == "Mozilla")
    {
        iType = 30 + browser_version;
    }
    //alert("browser type  "+iType);
  return iType;
}

