﻿// JScript File

    				// thanks to GOOD OLE MICROSOFT, I can provide you the following working
    				// example of a DROP DOWN LIST that allows you to type more than the
    				// FIRST LETTER of what you are looking for in a drop down.
    				// I hopw that you find this to be useful. I have been looking for this
    				// code for almost a year now. 
    				// Again, do not vote for me as this code is from Microsoft.
    				// Respectfully, Jason Buck jbuck@esubinc.com
    				// Happy Programming.
    				// The CODE WAS FOUND at the following location
    				// http://msdn.microsoft.com/msdnmag/issues/01/05/web/figures.asp
    // Auto-select listbox
    // mike pope, Visual Basic UE
    // This script and the listbox on this page illustrates one 
    // way to create an "auto-complete" listbox, where the
    var toFind = ""; // Variable that acts as keyboard buffer
    var timeoutID = "";// Process id for timer (used when stopping 
    // the timeout)
    timeoutInterval = 250;// Milliseconds. Shorten to cause keyboard 
    // buffer to be cleared faster
    var timeoutCtr = 0;// Initialization of timer count down
    var timeoutCtrLimit = 3 ; // Number of times to allow timer to count 
    // down
    var oControl = "";// Maintains a global reference to the 
    // control that the user is working with.
    function listbox_onkeypress(){
    // This function is called when the user presses a key while focus is in 
    // the listbox. It maintains the keyboard buffer.
    // Each time the user presses a key, the timer is restarted. 
    // First, stop the previous timer; this function will restart it.
    window.clearInterval(timeoutID)
    // Which control raised the event? We'll need to know which control to 
    // set the selection in.
    oControl = window.event.srcElement;
    var keycode = window.event.keyCode;
    if(keycode >= 32 ){
    // What character did the user type?
    var c = String.fromCharCode(keycode);
    c = c.toUpperCase(); 
    // Convert it to uppercase so that comparisons don't fail
    toFind += c ; // Add to the keyboard buffer
    find();// Search the listbox
    timeoutID = window.setInterval("idle()", timeoutInterval); 
    // Restart the timer
    }
    }
    function listbox_onblur(){
    // This function is called when the user leaves the listbox.
    window.clearInterval(timeoutID);
    resetToFind();
    }
    function idle(){
    // This function is called if the timeout expires. If this is the 
    // third (by default) time that the idle function has been called, 
    // it stops the timer and clears the keyboard buffer
    timeoutCtr += 1
    if(timeoutCtr > timeoutCtrLimit){
    resetToFind();
    timeoutCtr = 0;
    window.clearInterval(timeoutID);
    }
    }
    function resetToFind(){
    toFind = ""
    }
    function find(){
    // Walk through the select list looking for a match
    var allOptions = document.all.item(oControl.id);
    //alert('Hello');
    //alert(allOptions.name);

    for (i=0; i < allOptions.length; i++){
    // Gets the next item from the listbox
    nextOptionText = allOptions(i).text.toUpperCase();
    // By default, the values in the listbox and as entered by the 
    // user are strings. This causes a string comparison to be made, 
    // which is not correct for numbers (1 < 11 < 2).
    // The following lines coerce numbers into an (internal) number 
    // format so that the subsequent comparison is done as a 
    // number (1 < 2 < 11).
    if(!isNaN(nextOptionText) && !isNaN(toFind) ){
    nextOptionText *= 1;// coerce into number
    toFind *= 1;
    }
    // Does the next item match exactly what the user typed?
    if(toFind == nextOptionText){
    // OK, we can stop at this option. Set focus here
    oControl.selectedIndex = i;
    window.event.returnValue = false;
    break;
    }
    // If the string does not match exactly, find which two entries 
    // it should be between.
    if(i < allOptions.length-1){
    // If we are not yet at the last listbox item, see if the 
    // search string comes between the current entry and the next 
    // one. If so, place the selection there.
    lookAheadOptionText = allOptions(i+1).text.toUpperCase() ;
    if( (toFind > nextOptionText) && 
    (toFind < lookAheadOptionText) ){
    oControl.selectedIndex = i+1;
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    break;
    } // if
    } // if
    else{
    // If we are at the end of the entries and the search string 
    // is still higher than the entries, select the last entry
    if(toFind > nextOptionText){
    oControl.selectedIndex = allOptions.length-1 // stick it 
    // at the end
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    break;
    } // if
    } // else
    } // for
    } // function



    function formatCurrency(num) 
    {
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
            num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
            num = num.substring(0,num.length-(4*i+3))+','+
            num.substring(num.length-(4*i+3));
        return (((sign)?'':'-')  + num + '.' + cents);
        return false;
    }
//  End -->


function commaSplit(srcNumber) {
var txtNumber = '' + srcNumber;
if (isNaN(txtNumber) || txtNumber == "") {
alert("Oops!  That does not appear to be a valid number.  Please try again.");
fieldName.select();
fieldName.focus();
}
else {
var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
var arrNumber = txtNumber.split('.');
arrNumber[0] += '.';
do {
arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2');
} while (rxSplit.test(arrNumber[0]));
if (arrNumber.length > 1) {
return arrNumber.join('');
}
else {
return arrNumber[0].split('.')[0];
      }
   }
}
//  End -->


<!-- Begin
function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  one = txtFeeWIP.value;
  two = txtExpenseWIP.value; 
  txtTotalWIP.value = (one * 1) + (two * 1);
}
function stopCalc(){
  clearInterval(interval);
}
//  End -->
function 

openChild (file,window) { 
childWindow=open(file,window,'resizable=1,width=410,height=438,toolbar=No,menubar=No,top=250,left=400,status=no,scrollbars=1'); 
if (childWindow.opener == null) childWindow.opener = self; 
}

/*=======Script For All Page=======*/
function NumberOnly()
{
	if((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 46)
	{
		event.keyCode = 0;
	}	
}
function NumberOnlyWithPercent()
{
	if((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 46 && event.keyCode != 37)
	{
		event.keyCode = 0;
	}	
}
function formatnumber(num,decimals)
{
	var txtdecimal = "";
	txt = num+"";
	splittxt = txt.split(".");
	
	for (i=0; i<decimals; i++) {txtdecimal += "0";}
	if (!splittxt[1]) 
	{
		returnnum=splittxt[0]+"."+txtdecimal
	}
	else
	{
		returnnum=splittxt[0]+"."+splittxt[1].slice(0,decimals)
	}
	return returnnum;
}
function validateEmail(elementName) {
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var ele = document.getElementById(elementName);
  var re = new RegExp(filter);
  if (ele.value.match(re)) {
    return true;
  } else {
    return false;
  }
}
function CalculateAge(_birthdate){
    //_ birthdate format dd/mm/yyyy
    var now = new Date();
    var birthdate = _birthdate.split('/');
    var born = new Date(birthdate[2], birthdate[1]*1-1, birthdate[0]);
    var result;
    
    result = Math.floor((now.getTime() - born.getTime()) / (365 * 24 * 60 * 60 * 1000));
    
    return result;
}
function Tips()
{
    window.open("Tips.aspx","_blank","fullscreen=no,resizable=no,scrollbars=yes,width=500,height=500");
}

function EmptyChar()
{	
		event.keyCode = 0;
}