document.title = "::::: eScienceFund :::::"

//###########################################################
//# This function use to Hide All List Box Control Function #
//###########################################################
function HideAllListControl(){ 
   for (i = 0; i < window.frames.Contents.document.all.tags("SELECT").length; i++)
   {
      obj = window.frames.Contents.document.all.tags("SELECT")[i];
      if (! obj) continue;
      obj.style.visibility = "hidden";
   }
}   

//###########################################################
//# This function use to Show All List Box Control Function #
//###########################################################
function ShowAllListControl(){
   for (i = 0; i < window.frames.Contents.document.all.tags("SELECT").length; i++)
   {
      obj = window.frames.Contents.document.all.tags("SELECT")[i];
      if (! obj) continue;
      obj.style.visibility = "visible";
   }
}


//####################################################
//# This function is use to key-sort a ddropdownlist #
//####################################################

function KeySortDropDownList_onkeypress(dropdownlist,caseSensitive) {
  // check the keypressBuffer attribute is defined on the dropdownlist 
  var undefined; 
  if (dropdownlist.keypressBuffer == undefined) { 
    dropdownlist.keypressBuffer = ''; 
  } 
  // get the key that was pressed 
  var key = String.fromCharCode(window.event.keyCode); 
  dropdownlist.keypressBuffer += key;
  if (!caseSensitive) {
    // convert buffer to lowercase
    dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
  }
  // find if it is the start of any of the options 
  var optionsLength = dropdownlist.options.length; 
  for (var n=0; n < optionsLength; n++) { 
    var optionText = dropdownlist.options[n].text; 
    if (!caseSensitive) {
      optionText = optionText.toLowerCase();
    }
    if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { 
      dropdownlist.selectedIndex = n; 
      return false; // cancel the default behavior since 
                    // we have selected our own value 
    } 
  } 
  // reset initial key to be inline with default behavior 
  dropdownlist.keypressBuffer = key; 
  return true; // give default behavior 
} 


//##############################################################
//# This function use to allow user to key in 0-9 only #########
//##############################################################

function ValidateKeyPress(evt) {
  var keyValue;

  keyValue = document.all ? evt.keyCode : evt.which ;
  
  if ((keyValue >= 48 && keyValue <= 57)||
       (keyValue==8) || (keyValue==46))  {       
  return true;
  }
  else {
     //alert("Valid Value : 0 to 9");         
     //keyValue="";
     document.getElementById("hlblMessage").innerText  = "Valid Value : 0 to 9";
     
     return false;
  }
}


//##############################################################
//# This function use to Set Format Money Entry ################
//##############################################################
function setDecimal(objValue) {

      var varTEST = /^([0-9]\,{0,}\.{0,1})*$/;

      var varTESTNumOnly = /^[0-9]*$/;

      var strDecimalSplit;

      var strDecimalTemp;

      var strCommaSplit;

      var strFormatted;

      var intCount = 0;

      var intBalance = 0;

      var strArray;

      var i = window.event.keyCode;

      

      if ( (i==37) || (i==39) ) {

      }

      else

      {

            if ( objValue.value != "" ) {

                  if ( varTEST.test( objValue.value ) ) {

                        strDecimalSplit = objValue.value.split(".");

                        

                        if ( strDecimalSplit[0].length > 0 ) {

                              strCommaSplit = strDecimalSplit[0].split(",");

                              

                              if ( strCommaSplit.length > 1 ) {

                                    strFormatted = "";

                                    

                                    for ( intCount = 0; intCount < strCommaSplit.length; intCount++ ) {

                                          strFormatted += strCommaSplit[intCount];

                                    }

                                    

                                    intBalance = strFormatted.length;

                                    

                                    intCount = 0;

                                    

                                    strArray = new Array(5);

                                    

                                    while ( intBalance > 3 ) {

                                          strArray[intCount] = strFormatted.substring(strFormatted.length - 3, strFormatted.length);

                                          strFormatted = strFormatted.substring(0, strFormatted.length - 3);

                                          intBalance = strFormatted.length;

                                          intCount++;

                                    }

                                    

                                    for ( intCount = strArray.length; intCount >= 0; intCount-- ) {

                                          if ( varTESTNumOnly.test( strArray[intCount] ) ) {

                                                strFormatted += "," + strArray[intCount];

                                          }

                                    }

                                    

                                    objValue.value = strFormatted;

                              }

                              else if ( strCommaSplit.length == 1 ) {

                                    if ( ( strCommaSplit[0].length > 3 ) && ( strCommaSplit[0].length <= 4 ) ) {

                                          strFormatted = strCommaSplit[0].substring(0, 1) + "," + strCommaSplit[0].substring(1, strCommaSplit[0].length);

                                          

                                          objValue.value = strFormatted;

                                    }

                                    else

                                    {

                                          strFormatted = "";

                                    

                                          for ( intCount = 0; intCount < strCommaSplit.length; intCount++ ) {

                                                strFormatted += strCommaSplit[intCount];

                                          }

                                          

                                          intBalance = strFormatted.length;

                                          

                                          intCount = 0;

                                          

                                          strArray = new Array(5);

                                          

                                          while ( intBalance > 3 ) {

                                                strArray[intCount] = strFormatted.substring(strFormatted.length - 3, strFormatted.length);

                                                strFormatted = strFormatted.substring(0, strFormatted.length - 3);

                                                intBalance = strFormatted.length;

                                                intCount++;

                                          }

                                          

                                          for ( intCount = strArray.length; intCount >= 0; intCount-- ) {

                                                if ( varTESTNumOnly.test( strArray[intCount] ) ) {

                                                      strFormatted += "," + strArray[intCount];

                                                }

                                          }

                                          

                                          //objValue.value = strFormatted;

                                    }

                              }

                        }

                        

                        if ( strDecimalSplit.length > 1 ) {

                              objValue.value = strFormatted + "." + strDecimalSplit[1];

                        }

                        else

                              objValue.value = strFormatted;

                        

                  }

                  else {

                        strFormatted = objValue.value;

                        objValue.value = strFormatted.substring(0, strFormatted.length - 1);

                        setDecimal(objValue);

                  }

            }

      }

}


		
//############################################################
//# This function is use to expand/collapse dynamic sections #
//############################################################

NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;

if (ver4) {
    with (document) {
        write("<STYLE TYPE='text/css'>");
        if (NS4) {
            write(".parent {position:absolute; visibility:visible}");
            write(".child {position:absolute; visibility:visible}");
            write(".regular {position:absolute; visibility:visible}")
        }
        else {
            write(".child {display:none}")
        }
        write("</STYLE>");
    }
}

isExpanded = false;

function getIndex(el) {
    ind = null;
    for (i=0; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.id == el) {
            ind = i;
            break;
        }
    }
    return ind;
}

function arrange() {
    nextY = document.layers[firstInd].pageY + document.layers[firstInd].document.height;
    for (i=firstInd+1; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.visibility != "hide") {
            whichEl.pageY = nextY;
            nextY += whichEl.document.height;
        }
    }
}

function initIt(){
    if (!ver4) return;
    if (NS4) {
        for (i=0; i<document.layers.length; i++) {
            whichEl = document.layers[i];
            if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
        }
        arrange();
    }
    else {
        divColl = document.all.tags("DIV");
        for (i=0; i<divColl.length; i++) {
            whichEl = divColl(i);
            if (whichEl.className == "child") whichEl.style.display = "none";
        }
    }
}

function expandIt(el) {
    if (!ver4) return;
    if (IE4) {
        whichEl = eval(el + "Child");
        whichIm = event.srcElement;
        if (whichEl.style.display == "none") {
            whichEl.style.display = "block";
            whichIm.src = "/eScience/Image/triUp.gif";        
        }
        else {
            whichEl.style.display = "none";
            whichIm.src = "/eScience/Image/triDown.gif";
        }
    }
    else {
        whichEl = eval("document." + el + "Child");
        whichIm = eval("document." + el + "Parent.document.images['imEx']");
        if (whichEl.visibility == "hide") {
            whichEl.visibility = "show";
            whichIm.src = "/eScience/Image/triUp.gif";
        }
        else {
            whichEl.visibility = "hide";
            whichIm.src = "/eScience/Image/triDown.gif";
        }
        arrange();
    }
}

function expandAll() {
    if (!ver4) return;
    newSrc = (isExpanded) ? "/eScience/Image/triDown.gif" : "/eScience/Image/triUp.gif";

    if (NS4) {
        document.images["imEx"].src = newSrc;
        for (i=firstInd; i<document.layers.length; i++) {
            whichEl = document.layers[i];
            if (whichEl.id.indexOf("Parent") != -1) {
                whichEl.document.images["imEx"].src = newSrc;
            }
            if (whichEl.id.indexOf("Child") != -1) {
                whichEl.visibility = (isExpanded) ? "hide" : "show";
            }
        }

        arrange();
        if (isExpanded) scrollTo(0,document.layers[firstInd].pageY);
    }
    else {
        divColl = document.all.tags("DIV");
        for (i=0; i<divColl.length; i++) {
            if (divColl(i).className == "child") {
                divColl(i).style.display = (isExpanded) ? "none" : "block";
            }
        }
        imColl = document.images.item("imEx");
        for (i=0; i<imColl.length; i++) {
            imColl(i).src = newSrc;
        }
    }
    
    isExpanded = !isExpanded;
}

onload=initIt;

//##############################################
// Show/Hide functions for pointer objects     #
//##############################################
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

function showObject(obj) {
	if (ns4) obj.visibility = "show"
	else if (ie4) obj.visibility = "visible"
}

function hideObject(obj) {
	if (ns4) obj.visibility = "hide"
	else if (ie4) obj.visibility = "hidden"
}

//##############################################
//# This function is use to open Popup Windows #
//##############################################
var TimeOut = 120;    // Initial time to Close window after __ number of seconds?
var TimeRemain = 0;  // Remaining time to Close window after __ number of seconds?
var RefreshRate = 2; // Check to close window every __ number of seconds?
var popup = null;

function OpenWindow(strFullFilePath, width, height, scrollbars)
{
	var doCenter = false;
    var powidth = width;
	var poheight = height;
    
   resize = scrollbars;
    if((popup == null) || popup.closed)
    {
        attribs = '';
        if(resize) size = 'yes'; else size = 'no';
		
		for(var item in window)
		{ 
			if(item == 'screen') { doCenter = true; break; } 
		}
            
        var strURL_array = strFullFilePath.split("|") //added by leion 17052006
		for (i=0;i<strURL_array.length;i++) //added by leion 17052006
		{
			if (doCenter)
			{
				if(screen.width <= width || screen.height <= height) size = 'yes';
				WndTop  = (screen.height - poheight) / 2; //modified by leion 17052006
				WndLeft = (screen.width  - powidth)  / 2; //modified by leion 17052006
				attribs = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no,top=' + WndTop + ',left=' + WndLeft;
			} // doCenter
			else 
			{
				if(navigator.appName=='Netscape' && navigator.javaEnabled())
				{
					var toolkit = java.awt.Toolkit.getDefaultToolkit();
					var screen_size = toolkit.getScreenSize();
					if(screen_size.width <= width || screen_size.height <= height) size = 'yes';
					WndTop  = (screen_size.height - poheight) / 2; //modified by leion 17052006
					WndLeft = (screen_size.width  - powidth)  / 2; //modified by leion 17052006
					attribs = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no,top=' + WndTop + ',left=' + WndLeft;
				}
				else 
				{
					size = 'yes';
					attribs = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no';
				}
			} // doCenter
            
			popup = open(strURL_array[i], '', attribs);
			//popup = open(strFullFilePath, '', attribs);
			powidth -= 50; //added by leion 17052006
			poheight-= 50; //added by leion 17052006
		}
    } // popup is null
    
} // function PopupWindow


//###################
//# Timer Functions #
//###################

//timer functions
function ResetTimer(){
	TimeRemain = TimeOut;		
}

//timer functions
function CheckClose(){
	TimeRemain -= (RefreshRate);
	if (TimeRemain > 0)
	{
		if (popup && ChildWin.closed){
			popup = null;
		}
	else
		if (popup)
		{
			setTimeout("CheckClose();",RefreshRate * 1000);
		}
	}
else
	if (popup)
	{
		if (popup.closed)
			popup = null;
		else
		{
			popup.close();
			popup = null;
		}
	}
}		

//###################################################
//# Open Multiple Window ** added by Leion 11042006 #
//###################################################
function OpenWindowMulti(strURL1, strURL2, strURL3, width, height, scrollbars)
{
var doCenter = false;
        
   resize = scrollbars;
    if((popup == null) || popup.closed)
    {
        attribs = '';
        attribs2 = '';
        attribs3 = ''; //Added by Yvonne 17052006
        if(resize) size = 'yes'; else size = 'no';
		
		for(var item in window)
		{ 
			if(item == 'screen') { doCenter = true; break; } 
		}
            
        if (doCenter)
        {
			if(screen.width <= width || screen.height <= height) size = 'yes';
            WndTop  = (screen.height - height) / 2;
            WndLeft = (screen.width  - width)  / 2;
            attribs = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no,top=' + WndTop + ',left=' + WndLeft;
            attribs2 = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no,top=' + (WndTop + 20) + ',left=' + (WndLeft + 20);
            attribs3 = 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,status=yes,toolbar=yes,directories=no,menubar=yes,location=no,top=' + (WndTop + 20) + ',left=' + (WndLeft + 20); //Added by Yvonne 17052006
        } // doCenter
        else 
        {
			if(navigator.appName=='Netscape' && navigator.javaEnabled())
			{
				var toolkit = java.awt.Toolkit.getDefaultToolkit();
                var screen_size = toolkit.getScreenSize();
                if(screen_size.width <= width || screen_size.height <= height) size = 'yes';
                WndTop  = (screen_size.height - height) / 2;
                WndLeft = (screen_size.width  - width)  / 2;
                attribs = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no,top=' + WndTop + ',left=' + WndLeft;
                attribs2 = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no,top=' + (WndTop + 20) + ',left=' + (WndLeft + 20);
				attribs3 = 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,status=yes,toolbar=yes,directories=no,menubar=yes,location=no,top=' + (WndTop + 20) + ',left=' + (WndLeft + 20); //Added by Yvonne 17052006
            }
            else 
            {
				size = 'yes';
                attribs = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no';
                attribs2 = 'width=' + width + ',height=' + height + ',resizable=' + size + ',scrollbars=' + size + ',' + 'status=no,toolbar=no,directories=no,menubar=no,location=no';
                attribs3 = 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,status=yes,toolbar=yes,directories=no,menubar=yes,location=no,top=' + (WndTop + 20) + ',left=' + (WndLeft + 20); //Added by Yvonne 17052006
                
            }
		} // doCenter
            
        popup = open(strURL1, '', attribs);
        popup = open(strURL2, '', attribs2);
        popup = open(strURL3, '', attribs3); //Added by Yvonne 17052006
       } // popup is null
	
	
}



//################################
//# This function is set cursor  #
//################################
//Set Cursor to back
function setCaretToEnd (control) 
{
	if (control.createTextRange) 
	{
		var range = control.createTextRange();
		range.collapse(false);
		range.select();
	}
	else if (control.setSelectionRange) 
	{
		control.focus();
		var length = control.value.length;
		control.setSelectionRange(length, length);
	}
}

//Set cursor to the front
function setCaretToStart (control) {
  if (control.createTextRange) {
    var range = control.createTextRange();
    range.collapse(true);
    range.select();
  }
  else if (control.setSelectionRange) {
    control.focus();
    control.setSelectionRange(0, 0);
  }
}


//##############################################################
//# This function use to Make Confirmation on the Action Taken #
//##############################################################
function confirmPost() {
	if ( confirm('Are you sure you want to post?') )
		return false;
	else
		return true;
}

function confirmApprove() {
	if ( confirm('Are you sure you want to approve?') )
		return false;
	else
		return true;
}

function confirmReject() {
	if ( confirm('Are you sure you want to reject?') )
		return false;
	else
		return true;
}

function confirmDelete() {
	if ( confirm('Are you sure you want to delete?') )
		return false;
	else
		return true;
}

function confirmSave() {
	if ( confirm('Are you sure you want to save?') )
		return false;
	else
		return true;
}

function confirmUpdate() {
	if ( confirm('Are you sure you want to update?') )
		return false;
	else
		return true;
}

function confirmReset() {
	if ( confirm('Are you sure you want to reset?') )
		return false;
	else
		return true;
}

function confirmProcess() {
	if ( confirm('Are you sure you want to process? This may take a long time. Please do not click more than once.') )
		return false;
	else
		return true;
}


//################################################################
//# This function is to select multiple Child Check Box (chkOne) #
//# when the Parent Check Box (chkAll) is clicked in a datagrid  #
//################################################################

function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal)
{
	re = new RegExp(':' + aspCheckBoxID + '$');
	for(i = 0; i < document.forms[0].elements.length; i++)
	{
		elm = document.forms[0].elements[i];
		if (elm.type == 'checkbox')
		{
			if (elm.disabled == false)
			{
				if (re.test(elm.name))
					elm.checked = checkVal;
			}
		}
	}
	
}

//######################################################
//# This function is used to move the cursor to target #
//# textbox when the current textbox maxlength has met #
//######################################################

function setFocusInt(curr, target)
{
 	var varTEST = /^[0-9]*$/;
 	var i = window.event.keyCode;
	if ( (i==8) || (i==46) || (i==37) || (i==39) ) {
	}
	else
	{
		if ( window.document.forms[0].elements[curr].value != "" ) {
				if ( varTEST.test( window.document.forms[0].elements[curr].value ) ) {
					if ( window.document.forms[0].elements[curr].value.length == window.document.forms[0].elements[curr].maxLength ) {
						window.document.forms[0].elements[target].focus();
					}
				}
		}
	}
	return true;	
}
