﻿/**********************************************************************
/// <summary>
// Name of File     : CommonFunctions.cs
// Author           : Deepinder Pal Singh - PCC Technology Group
// Class Definition : Chronological Development
// Version: 1.0
// Create date      : 10th Sept, 2006
// 
// Modification log:
// Date(mm/dd/yyyy) 	Author: 	        Change Request #	    Description
// 09/10/2006           Deepinder Pal Singh                         Created File
// 10/24/2006           Deepinder Pal Singh                         Added CheckValueExists(), Trim() functions
/// </summary>
************************************************************************/  
    //function to prompt message to save changes while navigating site
    var needToConfirm = false;
    var hasAdminRights=false;
    var pageName="";
    var isDirtyAddress=false;
    
 //to calculate GHBDC/HEDCO Amount and Total Loan Amount
function CalculateGHBDCHEDCOAmount()
{ 
            var ctrlGHBDCHEDCOAmount= getClientId('divLoanInfo','txtGHBDCHEDCOAmount','INPUT');  
            ctrlGHBDCHEDCOAmount=getId(ctrlGHBDCHEDCOAmount);
       
            var ctrlPLJAmount= getClientId('divLoanInfo','txtPJLAmount','INPUT');  
            ctrlPLJAmount=getId(ctrlPLJAmount);
      
            var ctrlSJLAmount= getClientId('divLoanInfo','txtSJLAmount','INPUT');  
            ctrlSJLAmount=getId(ctrlSJLAmount);
      
            var ctrlTJLAmount= getClientId('divLoanInfo','txtTJLAmount','INPUT');  
            ctrlTJLAmount=getId(ctrlTJLAmount);
            
            var ctrlComputedLeverege= getClientId('divLoanInfo','txtComputedLeverege','INPUT');  
            ctrlComputedLeverege=getId(ctrlComputedLeverege);
             
            var ctrlTotalLoanAmount= getClientId('divLoanInfo','txtTotalLoanAmount','INPUT');  
            ctrlTotalLoanAmount=getId(ctrlTotalLoanAmount);   
            ctrlTotalLoanAmount.value=0;
            if(ctrlPLJAmount.value !='')        
            {
                   if(!isCurrency(ctrlPLJAmount.value,2))
                   {  
                   }
                  else
                  {
                         var totalAmount='';
                         ctrlGHBDCHEDCOAmount.value=formatDouble(ctrlPLJAmount.value);                                          
                         if(ctrlTotalLoanAmount.value=='' || ctrlTotalLoanAmount.value=='0')
                         {
                            totalAmount=parseFloat(ctrlTotalLoanAmount.value); 
                         }
                         else
                         {
                         totalAmount=formatDouble(ctrlTotalLoanAmount.value);
                         }                         
                         ctrlTotalLoanAmount.value= parseFloat(totalAmount) + formatDouble(ctrlPLJAmount.value);               
                         
                  }               
            }      
           else
           {
                 ctrlGHBDCHEDCOAmount.value="";
           }
         
         if(ctrlSJLAmount.value !='')        
         {
                   if(!isCurrency(ctrlSJLAmount.value,2))
                   {     
                   }
                  else
                  { 
                         var totalAmount='';
                         if(ctrlTotalLoanAmount.value=='' || ctrlTotalLoanAmount.value=='0')
                         {
                            totalAmount=parseFloat(ctrlTotalLoanAmount.value); 
                         }
                         else
                         {
                         totalAmount=formatDouble(ctrlTotalLoanAmount.value);
                         }
                         ctrlTotalLoanAmount.value= parseFloat(totalAmount) + formatDouble(ctrlSJLAmount.value);                        
                         
                  }               
          }      
          
          if(ctrlTJLAmount.value !='')        
          {
                   if(!isCurrency(ctrlTJLAmount.value,2))
                   {                          
                   }
                  else
                  {       
                         var totalAmount='';
                         if(ctrlTotalLoanAmount.value=='' || ctrlTotalLoanAmount.value=='0')
                         {
                            totalAmount=parseFloat(ctrlTotalLoanAmount.value); 
                         }
                         else
                         {
                         totalAmount=formatDouble(ctrlTotalLoanAmount.value);
                         }           
                         ctrlTotalLoanAmount.value= parseFloat(totalAmount) + formatDouble(ctrlTJLAmount.value);                        
                        
                  }               
          }   
          
       if(ctrlGHBDCHEDCOAmount.value=='' || ctrlGHBDCHEDCOAmount.value==0)
       {
                ctrlComputedLeverege.value='';
       }
       else
       {
                     if(ValidateLoanInfo() && ctrlPLJAmount.value !='' && ctrlSJLAmount.value !='' && ctrlTJLAmount.value !='')
                     {                            
                          ctrlComputedLeverege.value=RoundNumber((formatDouble(ctrlPLJAmount.value)+ formatDouble(ctrlSJLAmount.value)+ formatDouble(ctrlTJLAmount.value))/formatDouble(ctrlGHBDCHEDCOAmount.value)) + ' : 1';
                     }  
                     else
                     {
                        ctrlComputedLeverege.value=' : 1';
                     }    
       } 
       if(ctrlTotalLoanAmount.value=="0")
            ctrlTotalLoanAmount.value="";         
       
       formatCurrency('txtPJLAmount');
       formatCurrency('txtSJLAmount');
       formatCurrency('txtTJLAmount');  
       formatCurrency('txtTotalLoanAmount');            
       formatCurrency('txtGHBDCHEDCOAmount');            
}


 function formatDouble(source)
    {            
         var NewNum='';
         for(var i=0;i<=source.length;i++)
         {
                var a= source.substring(i,i+1);
                if(source.substring(i,i+1)!=',')
                    NewNum=NewNum+ source.substring(i,i+1);                 
         }                  
         return parseFloat(NewNum);
    } 
    
    
    function setDirty()    
     { 
            needToConfirm=true; 
     }     
     
     function ShowDirtyConfirm()
     {
          var msg="Are you sure you want to navigate away from this page? \n\n You will lose all the changes made since your last save.\n\n Press OK to continue, or Cancel to stay on the current page." 
                    if(confirm(msg))
                    {  
                           return true;
                    }
                    else
                    {
                           return false; 
                    }
     }
    function ShowDirtyConfirmOnEdit()
    {
        var msg="Please Save the unsaved data on the form before proceeding. \n\nIf you choose to click OK now then all the unsaved data will be lost." 
        if(confirm(msg))
        {  
            return true;
        }
        else
        {
            return false; 
        }
    }
    function saveChanges()
    {    
     
      if(parent.document.getElementById("checkUpdation").value=="true")
      {
        var answer=confirm("There has been a change. Do you want to save this record?");        
        if(answer)
        {          
         
           return true;
        }
        else
        {           
           parent.document.getElementById("checkUpdation").value="false"; 
           return false;
        }                   
      } 
      else
      {
           return false;
      }    
     }
    
    //function to provide navigation to different pages using iframe in main.aspx
    function openWindow(url) 
    {       
//      var allowSave=saveChanges();     
//      if (allowSave)
//      {      
//        return;
//      }
      document.getElementById('contentPage').setAttribute('src',url);
    } 
    //function to make tabs active or deactive 
    function makeActive(tab)
	{
//	    var allowSave=saveChanges();     
//          if (allowSave)
//          {      
//            return;
//          }
	    switch (tab)
        {
        
            case "ClientSession": 
//                this.document.getElementById('dvClientSession').style.display = 'block';
//                this.document.getElementById('dvLoan').style.display = 'none';
//                this.document.getElementById('dvDocumentPrinting').style.display = 'none';
//                this.document.getElementById('dvSecurity').style.display = 'none';
//                this.document.getElementById('dvAccounting').style.display = 'none';
                this.document.getElementById('img1').setAttribute('src','../Images/client_session_activetab.gif');                
                this.document.getElementById('img2').setAttribute('src','../Images/loan_info_tab.gif');   
                this.document.getElementById('img3').setAttribute('src','../Images/doc_printing_tab.gif'); 
                this.document.getElementById('img4').setAttribute('src','../Images/security_tab.gif');   
                this.document.getElementById('img5').setAttribute('src','../Images/accounting_tab.gif'); 
                this.document.getElementById('img6').setAttribute('src','../Images/logout_tab.gif');   
                openWindow('../LoanClients/ClientGeneralDetail.aspx'); 
                break;
            case "LoanInfo":         
//                this.document.getElementById('dvClientSession').style.display = 'none';
//                this.document.getElementById('dvLoan').style.display = 'block';
//                this.document.getElementById('dvDocumentPrinting').style.display = 'none';
//                this.document.getElementById('dvSecurity').style.display = 'none';
//                this.document.getElementById('dvAccounting').style.display = 'none';
                this.document.getElementById('img1').setAttribute('src','../Images/client_session_tab.gif');                
                this.document.getElementById('img2').setAttribute('src','../Images/loan_info_activetab.gif');   
                this.document.getElementById('img3').setAttribute('src','../Images/doc_printing_tab.gif'); 
                this.document.getElementById('img4').setAttribute('src','../Images/security_tab.gif');   
                this.document.getElementById('img5').setAttribute('src','../Images/accounting_tab.gif'); 
                this.document.getElementById('img6').setAttribute('src','../Images/logout_tab.gif');  
                openWindow('../Admin/AdminHome.aspx'); 
                break;	 
            case "DocumentPrinting":                 
//                this.document.getElementById('dvDocumentPrinting').style.display = 'block';                
//                this.document.getElementById('dvClientSession').style.display = 'none';
//                this.document.getElementById('dvLoan').style.display = 'none';
//                this.document.getElementById('dvSecurity').style.display = 'none';
//                this.document.getElementById('dvAccounting').style.display = 'none';
                this.document.getElementById('img1').setAttribute('src','../Images/client_session_tab.gif');                
                this.document.getElementById('img2').setAttribute('src','../Images/loan_info_tab.gif');   
                this.document.getElementById('img3').setAttribute('src','../Images/doc_printing_activetab.gif'); 
                this.document.getElementById('img4').setAttribute('src','../Images/security_tab.gif');   
                this.document.getElementById('img5').setAttribute('src','../Images/accounting_tab.gif'); 
                this.document.getElementById('img6').setAttribute('src','../Images/logout_tab.gif'); 
                openWindow('../Admin/Documents.aspx'); 
                break;
            case "Security":
//                this.document.getElementById('dvDocumentPrinting').style.display = 'none';
//                this.document.getElementById('dvClientSession').style.display = 'none';
//                this.document.getElementById('dvLoan').style.display = 'none';
//                this.document.getElementById('dvSecurity').style.display = 'block';
//                this.document.getElementById('dvAccounting').style.display = 'none';
                this.document.getElementById('img1').setAttribute('src','../Images/client_session_tab.gif');                
                this.document.getElementById('img2').setAttribute('src','../Images/loan_info_tab.gif');   
                this.document.getElementById('img3').setAttribute('src','../Images/doc_printing_tab.gif'); 
                this.document.getElementById('img4').setAttribute('src','../Images/security_activetab.gif');   
                this.document.getElementById('img5').setAttribute('src','../Images/accounting_tab.gif'); 
                this.document.getElementById('img6').setAttribute('src','../Images/logout_tab.gif');   
                break;
            case "Accounting":
//                this.document.getElementById('dvDocumentPrinting').style.display = 'none';
//                this.document.getElementById('dvClientSession').style.display = 'none';
//                this.document.getElementById('dvLoan').style.display = 'none';
//                this.document.getElementById('dvSecurity').style.display = 'none';
//                this.document.getElementById('dvAccounting').style.display = 'none';                
                this.document.getElementById('img1').setAttribute('src','../Images/client_session_tab.gif');                
                this.document.getElementById('img2').setAttribute('src','../Images/loan_info_tab.gif');   
                this.document.getElementById('img3').setAttribute('src','../Images/doc_printing_tab.gif'); 
                this.document.getElementById('img4').setAttribute('src','../Images/security_tab.gif');   
                this.document.getElementById('img5').setAttribute('src','../Images/accounting_activetab.gif'); 
                this.document.getElementById('img6').setAttribute('src','../Images/logout_tab.gif'); 
                openWindow('../Admin/QuickBooks.aspx');   
                break;                
            case "logout":                
                parent.location = "../Default.aspx";
                break;                          
        }
	}   
	function makeActiveNew(tab)
	{
	    switch (tab)
	    {
	        case "ClientSession":
////	            this.document.getElementById('dvDocumentPrinting').style.display = 'none';
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';                
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info_active.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif');  
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif'); 
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif'); 
                //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');        
	            break;
	        case "BusinessPlan":
////	            this.document.getElementById('dvDocumentPrinting').style.display = 'none';
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';                
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan_active.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif'); 
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif'); 
                this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');      
	            break;
	        case "DocumentPrinting":                 	            
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'none';
////                this.document.getElementById('divManageLoan').style.display = 'block';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan_active.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif'); 
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif'); 
                //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');         
                break;
          case "LoanInfo":         
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'block';
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'none';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry_active.gif'); 
                this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif'); 
                this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');            
                break;	 
          case "Reports":
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif');  
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_activetab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif'); 
                //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');             
                break;
          case "Mailing":
////                this.document.getElementById('dvDocumentPrinting').style.display = 'block';                
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'none';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif');  
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_activetab.gif');     
                //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');          
                break;
           case "Security":
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';                
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_activetab.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif'); 
                //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');              
                break;
            case "LoanRequest":
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';                
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application_active.gif');     
                break;
            case "ManageLoans":
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';                
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan_active.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage-_loans_activetab.gif');     
                //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');         
                break;
            case "LoanInquiry":
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';                
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry_active.gif'); 
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');     
                break;
            case "ManageLoanApp":
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';                
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app_active.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');     
                break;
            case "MyAccount":
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';                
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';
                this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app_active.gif');   
                //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');     
                //Updated By:Amrit singh      Reason:To Add new tab    Dated:20 Oct. 2007
                this.document.getElementById('imgMyAccount').setAttribute('src','../Images/my_account_activetab.gif');
                break;
                
                 case "Lookup":
////                this.document.getElementById('dvDocumentPrinting').style.display = 'none';                
////                this.document.getElementById('dvClientSession').style.display = 'none';
////                this.document.getElementById('dvLoan').style.display = 'none';
////                this.document.getElementById('dvSecurity').style.display = 'none';
////                this.document.getElementById('dvAccounting').style.display = 'block';
                    this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                
                    //this.document.getElementById('imgBusinessPlan').setAttribute('src','../Images/business_plan.gif');   
                    this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                    //this.document.getElementById('imgManageLoanApp').setAttribute('src','../Images/manage_loan_app_active.gif');   
                    //this.document.getElementById('imgManageLoan').setAttribute('src','../Images/manage_loan.gif'); 
                    //this.document.getElementById('imgScanning').setAttribute('src','../Images/scanning.gif'); 
                    //this.document.getElementById('imgdocuments').setAttribute('src','../Images/documents.gif'); 
                    this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                    this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                    this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                    this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                    //this.document.getElementById('imgLoanRequest').setAttribute('src','../Images/loan_application.gif');     
                    //Updated By:Amrit singh      Reason:To Add new tab    Dated:20 Oct. 2007
                    this.document.getElementById('imgMyAccount').setAttribute('src','../Images/my_account_tab.gif');
                    
                    this.document.getElementById('imgLookup').setAttribute('src','../Images/manage_lookups_activetab.gif');
                
                break;
                
                case "Dashboard":
                    this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                                
                    this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                    this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                    this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                    this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                    this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                    this.document.getElementById('imgMyAccount').setAttribute('src','../Images/my_account_tab.gif');                
                    this.document.getElementById('imgLookup').setAttribute('src','../Images/manage_lookups_tab.gif');
                    this.document.getElementById('imgDashboard').setAttribute('src','../Images/Dashboard_activetab.gif');
                break;
                
                
                case "Assignment":
                    this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                                
                    this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                    this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                    this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                    this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                    this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                    this.document.getElementById('imgMyAccount').setAttribute('src','../Images/my_account_tab.gif');                
                    this.document.getElementById('imgLookup').setAttribute('src','../Images/manage_lookups_tab.gif');
                    imgInquiryAssignment=getClientId('tbAssignment','imgInquiryAssignment','IMG');
                    imgInquiryAssignment=getId(imgInquiryAssignment);
                    imgInquiryAssignment.setAttribute('src','../Images/assignment_active_tab.gif');         
                break;
                
                case "ManageAssignment":
                    this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                                
                    this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                    this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                    this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                    this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                    this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                    this.document.getElementById('imgMyAccount').setAttribute('src','../Images/my_account_tab.gif');                
                    this.document.getElementById('imgLookup').setAttribute('src','../Images/manage_lookups_tab.gif');
                    imgManageAssignment=getClientId('tbAssignment','imgManageAssignment','IMG');
                    imgManageAssignment=getId(imgManageAssignment);
                    imgManageAssignment.setAttribute('src','../Images/manage_assignment_activetab.gif'); 
                break;
                case "News":
                    this.document.getElementById('imgClientInfo').setAttribute('src','../Images/client_info.gif');                                
                    this.document.getElementById('imgLoanApp').setAttribute('src','../Images/loan_inquiry.gif'); 
                    this.document.getElementById('imgSecurity').setAttribute('src','../Images/security_tab.gif'); 
                    this.document.getElementById('imgLogout').setAttribute('src','../Images/logout_tab.gif');            
                    this.document.getElementById('imgReports').setAttribute('src','../Images/reports_tab.gif'); 
                    this.document.getElementById('imgMassMailing').setAttribute('src','../Images/mass_mailing_tab.gif');     
                    this.document.getElementById('imgMyAccount').setAttribute('src','../Images/my_account_tab.gif');                
                    this.document.getElementById('imgLookup').setAttribute('src','../Images/manage_lookups_tab.gif');                    
                    this.document.getElementById('imgNews').setAttribute('src','../Images/news_activetab.gif');                    
                break;
	    }
	}
	//function to make active default tab
	function MakeTab(redUrl)
	{	    	
	    this.document.getElementById('tbMenu').style.display = 'block';
        this.document.getElementById('img1').setAttribute('src','../images/residential_active_tab.gif');                
        this.document.getElementById('img2').setAttribute('src','../images/business_tab.gif');   
        this.document.getElementById('img3').setAttribute('src','../images/admin_tab.gif');  
        //Menu Code
        this.document.getElementById('dvAdmin').style.display = 'none';
        this.document.getElementById('dvResid').style.display = 'block';
        this.document.getElementById('dvSB').style.display = 'none';
        //Left panel Code
        //this.document.getElementById('tbAdmin').style.display = 'none';
        //this.document.getElementById('tbResid').style.display = 'block';
        //openWindow('../Admin/Adminhome.aspx');
        
        openWindow(redUrl);
	}
    //Redirect User from Quick Search  
    function NavigateSearch(pId)
    {       
        var projId = document.getElementById("LeftPanelAdmin_txt");  
        var c = igcmbo_getComboById("LeftPanelAdminxWebPanel2xwcQuickSearch");   
        if(pId == 0)
        {                      
            if(projId.value != "")
            {                
                makeActive("residential");
                var sURL = "../Projects/MaintainProject.aspx?pId="+pId;                                                         
		        //window.opener.document.location.href = sURL;  
		        parent.location = "..\\AppStructure\\Main.aspx?redirect="+ sURL;              
                //openWindow('../Projects/MaintainProject.aspx?pId='+pId); 
                return true;
            }
            else
            {    
                alert("Matching project could not be found");
                return false;
            }
        }
        else
        {
            projId.value = pId;
            makeActive("residential");
            var sURL1 = "../Projects/MaintainProject.aspx?pId="+pId;                                                         
		        //window.opener.document.location.href = sURL;  
		    parent.location = "..\\AppStructure\\Main.aspx?redirect="+ sURL1;                                                        
		    //window.opener.document.location.href = sURL; 
            //openWindow('../Projects/MaintainProject.aspx?pId='+pId);  
        }
    }     
        
    //Used to Redirect from MyTask LeftAdmin Panel
    function NavigateTask(projUrl)
    {       
         var allowSave=saveChanges();     
         if (allowSave)
         {      
            return;
         }
         var g = igcmbo_getComboById("LeftPanelAdminxWebPanel2xwcQuickSearch");       
         g.setDisplayValue("" , true);       
             
         if(projUrl == "")
         {             
            return false;           
         }
         else
         {  
            makeActive("residential");                     
            openWindow(projUrl);                                     
            return false;
         }    
    }
    
    //Used to redirect User from Adminhome middle section
     function NavigateEntity(tableName, itemName)
     {           
        var cell = igtbl_getCellById(itemName);
        var column = igtbl_getColumnById(itemName);
        if(column.Key == "EntityName") 
        {    
           var row = igtbl_getRowById(itemName);            
           var cell = row.getCell(3);         
           var taskUrl;
           taskUrl = cell.getValue();
           taskUrl = taskUrl.replace("~","%20");                                          
           taskUrl = taskUrl.replace("/","$"); 
           taskUrl = taskUrl.replace("/","$"); 
           //taskUrl = taskUrl.replace("?","@"); 
           //window.location = taskUrl;           
           parent.location = "..\\AppStructure\\Main.aspx?redirect="+ taskUrl;                    
        }  
    }  
      
    //function to navigate from maintianprogram page
    function NavigateLocation(tableName, itemName)
    {           
        var cell = igtbl_getCellById(itemName);
        var column = igtbl_getColumnById(itemName);
        if(column.Key == "locn_nm") 
        {                
           var row = igtbl_getRowById(itemName);            
           var cell = row.getCell(3);         
           var taskUrl;
           taskUrl = cell.getValue();   
           //window.open(taskUrl,taskUrl,null,null);                                              
           window.open(taskUrl,'welcome','width=300,height=200,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes');                 
        }  
    } 
   //Method to format date according to your requirement. 
  function addZero(vNumber){ 
  return ((vNumber < 10) ? "0" : "") + vNumber 
  }        
  function formatDate(vDate, vFormat){ 
    var vDay                      = addZero(vDate.getDate()); 
    var vMonth            = addZero(vDate.getMonth()+1); 
    var vYearLong         = addZero(vDate.getFullYear()); 
    var vYearShort        = addZero(vDate.getFullYear().toString().substring(3,4)); 
    var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
    var vHour             = addZero(vDate.getHours()); 
    var vMinute           = addZero(vDate.getMinutes()); 
    var vSecond           = addZero(vDate.getSeconds()); 
    var vDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
    vDateString           = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 
    return vDateString 
  }
  //function to get selected value of WebCombo on MaintainProgram Page
  function GetMasterProgram(webCombo,g,h)
  {    
       var mpId = document.getElementById("txtMastPrg");    
       var wbComb = igcmbo_getComboById(webCombo);        
       var combIndex = wbComb.getSelectedIndex();       
       if(combIndex != -1)
       {         
         var gridComb = wbComb.getGrid();         
         var gridRow = gridComb.Rows.getRow(combIndex);            
         var cellValue = gridRow.getCell(0).getValue();    
         mpId.value = cellValue;     
        }               
   }
   //This method will check a value exists in drop down list or not
   //If exists return true else return false
   function CheckValueExists(ddl, value)
    {                    
        for(i = 0; i < ddl.length; i++)
        {
            if(ddl[i].innerHTML.toUpperCase() == value.toUpperCase())
            {                
                return true;
            }
        }          
        return false;
    }        
   //Trim the string provided and return it
   function Trim(TRIM_VALUE)
    {
        if(TRIM_VALUE.length < 1)
        {
            return"";
        }
        //Right trim the value
        TRIM_VALUE = RTrim(TRIM_VALUE);        
        //Left trim the value
        TRIM_VALUE = LTrim(TRIM_VALUE);
        
        if(TRIM_VALUE=="")
        {
            return "";
        }
        else
        {
            return TRIM_VALUE;
        }
    }
    
    function ValidatePhoneNo(phoneNumber) 
{
        var regPhone = /^(\()?(\d{3})([\)-\. ])?(\d{3})([-\. ])?(\d{4})$/;
        if (phoneNumber.match(regPhone))
        {
                return true;
        }
        else
        {
                return false;
        }
}
   
    function ValidatePhone(Value)
    { 
         var w_space = String.fromCharCode(32);
         var v_length = Value.length;
         var iTemp = v_length -1;
         var is_space=false;
         if(Trim(Value).length > 0)
         {    
             while(iTemp > -1)
             {
                if(Value.charAt(iTemp) == w_space)
                {
                    is_space=true;                
                }
                iTemp=iTemp-1;
            }
            if(is_space==true || Trim(Value).length < 10)
            {
                return false;
            }   
        }
        return true;
    }    
    
    
    function ValidateSSN(Value)
    {     

         var w_space = String.fromCharCode(32);
         var v_length = Value.length;
         var iTemp = v_length -1;
         var is_space=false;       
         if(Trim(Value).length > 0)
         {    
             while(iTemp > -1)
             {
                if(Value.charAt(iTemp) == w_space)
                {
                    is_space=true;                
                }
                iTemp=iTemp-1;
            }
            if(is_space==true || Trim(Value).length < 9)
            {
                return false;
            }   
        }
        return true;
    }    
    
     function ValidateTin(Value)
    {     

         var w_space = String.fromCharCode(32);
         var v_length = Value.length;
         var iTemp = v_length -1;
         var is_space=false;
         if(v_length < 9 && v_length!=0)
         {
            return false;
         }
         if(Trim(Value).length > 0)
         {    
             while(iTemp > -1)
             {                
                if(Value.charAt(iTemp) == w_space && Value.charAt(iTemp)=="-")
                {
                    is_space=true;                
                }
                iTemp=iTemp-1;
            }
            if(is_space==true)
            {
                return false;
            }   
        }
        return true;
    }    
    
    //Right Trim the string provided and return it
    function RTrim(VALUE)
    {
        var w_space = String.fromCharCode(32);
        var v_length = VALUE.length;
        var strTemp = "";
        
        if(v_length < 0)
        {
            return"";
        }
        var iTemp = v_length -1;
        
        while(iTemp > -1)
        {
            if(VALUE.charAt(iTemp) == w_space){}
            else
            {
                strTemp = VALUE.substring(0,iTemp +1);
                break;
            }
            iTemp = iTemp-1;
        } //End While

        return strTemp;
    } //End Function
    
    //Left Trim the string provided and return it
    function LTrim(VALUE)
    {
        var w_space = String.fromCharCode(32);
        if(v_length < 1)
        {
            return"";
        }
        var v_length = VALUE.length;
        var strTemp = "";
        var iTemp = 0;

        while(iTemp < v_length)
        {
            if(VALUE.charAt(iTemp) == w_space){}
            else
            {
                strTemp = VALUE.substring(iTemp,v_length);
                break;
            }
            iTemp = iTemp + 1;
        } //End While

        return strTemp;
    } //End Function
 
 //Function to check whether field contains white space or not
 function hasWhiteSpace(s) 
 {     
   reWhiteSpace = new RegExp(/^\s+$/);
   // Check for white space
   if (s.match(/^s+$/) || s == "") 
   {
      return false;
   }
   else
   {
    return true;
   }
} 
//Function to validate Special Characters including space.
function SpecialCharacter(val)
{
    var xChars = "!0#$%^&*()+=[]\\\';,./{}|\":<>? ";
    for (var i = 0; i < val.length; i++) 
    {
  	    if (xChars.indexOf(val.charAt(i)) != -1) 
  	    {  
  	        return false;     
  	    }    
    }
    return true;
}  

function validatePasswordCharacter(val)
{
    var xChars = "\'\"\\";
    for (var i = 0; i < val.length; i++) 
    {
  	    if (xChars.indexOf(val.charAt(i)) != -1) 
  	    {  
  	        return false;     
  	    }    
    }
    return true;
} 

function ValidateAddress(val)
{
    var xChars="!&'<>";
    for (var i = 0; i < val.length; i++) 
    {
  	    if (xChars.indexOf(val.charAt(i)) != -1) 
  	    {  
  	        return false;     
  	    }    
    }
    return true;
}

 //Function to validate Special Characters 
function SpecialCharacterWithSpace(val)
{
    var xChars = "!@#$%^&*()+=[]\\\';,./{}|\":<>?";
    for (var i = 0; i < val.length; i++) 
    {
  	    if (xChars.indexOf(val.charAt(i)) != -1) 
  	    {  
  	        return false;     
  	    }    
    }
    return true;
}  

//Function to check white space in user name & password.
function CheckSpace(val)
{
   if(!val=='')
    {
        var xChars = " ";
        for (var i = 0; i < val.length; i++) 
        {
  	        if (xChars.indexOf(val.charAt(i)) != -1) 
  	        {  
  	            return false;     
  	        }    
        }
    }
    return true;
}   

    
//Function to validate Special Characters white space and numbers.
function SpecialCharacterWithNumberSpace(val)
{
   if(!val=='')
    {
        var xChars = "!@#$%^&*()+=[]\\\';,./{}|\":<>?1234567890 ";
        for (var i = 0; i < val.length; i++) 
        {
  	        if (xChars.indexOf(val.charAt(i)) != -1) 
  	        {  
  	            return false;     
  	        }    
        }
    }
    return true;
}



//Function to validate names including white space .
//This function accepts white space, "_" and "-".
function ValidateNameWithSpace(val)
{
   if(!val=='')
    {
        var xChars = "!@#$%^&*()+=[]\\\';,/{}|\":<>?1234567890";
        for (var i = 0; i < val.length; i++) 
        {
  	        if (xChars.indexOf(val.charAt(i)) != -1) 
  	        {  
  	            return false;     
  	        }    
        }
    }
    return true;
} 

function ValidateFullName(val)
{
   if(!val=='')
    {
        var xChars = "!@#$%^&*()+=[]\\\';/{}|\":<>?1234567890";
        for (var i = 0; i < val.length; i++) 
        {
  	        if (xChars.indexOf(val.charAt(i)) != -1) 
  	        {  
  	            return false;     
  	        }    
        }
    }
    return true;
} 
 
//Check browser is IE or Netscape or Mozilla    
var bIsNS= (document.getElementById && !document.all) ? 1 : 0;
var bIsIE = document.all ? 1 : 0;
        
 function getId(ctrlId)
 {
    return document.getElementById(ctrlId);
 }
 
 function getElementsByTag(control,tagName)
 {
    return control.getElementsByTagName(tagName);
 }
 function getClientId(containerId,controlId, tagName)
 {

    var returnId=null;
    var ctlContainer = getId(containerId);
    if(null != ctlContainer)
    {
        var elements = getElementsByTag(ctlContainer,tagName)
        if(elements.length>0)
        {
            for(i=0;i<elements.length;i++)
            {
                if (elements[i].id.length > 0)
                {
                    tmp = elements[i].id.split('_');
			        id = tmp[tmp.length-1];			
			        if(id==controlId)
			            returnId = elements[i].id;
			    }
            }
        }        
    }
  return returnId;  
 }
 function isNumeric(ctrl)
 { 
        var flg=0;
        var val=Trim(ctrl.value);
   
	  if (val == "")  { return true; }
	 
	  for (i=0; i<val.length; i++)
	  {
	    if (val.charAt(i) < "0") {flg=1;}
	    if (val.charAt(i) > "9") {flg=1;}
	  }
	  if(flg==1)
	  {
	
	  //  alert('Please enter Numeric value');
	 //   ctrl.value=""; 
	 //   ctrl.focus();
	    return false;
	  }
	  else
	  {
	    return true;
	  }
}

 function isNumericVal(value)
 { 
        var flg=0;
        var val=value;
   
	  if (val == "")  { return true; }
	 
	  for (i=0; i<val.length; i++)
	  {
	    if (val.charAt(i) < "0") {flg=1;}
	    if (val.charAt(i) > "9") {flg=1;}
	  }
	  if(flg==1)
	  {
	
	  //  alert('Please enter Numeric value');
	 //   ctrl.value=""; 
	 //   ctrl.focus();
	    return false;
	  }
	  else
	  {
	    return true;
	  }
}


function isNumericText(ctrl)
    { 
       
        var flg=0;
        var val=ctrl.value;
   
	  if (val == "")  { return true; }
	 
	  for (i=0; i<val.length; i++)
	  {
	   // if(i == 3 || i == 8)
	    {	    
	        if (val.charAt(i) < "0" && val.charAt(i) != '-') {flg=1;}
	        if (val.charAt(i) > "9" && val.charAt(i) != '-') {flg=1;}
	    }
//	    else
//	    {
//	        if (val.charAt(i) < "0") {flg=1;}
//	        if (val.charAt(i) > "9") {flg=1;}
//	    }	    
	  }
	  //alert(flg)
	  if(flg==1)
	  {
	    alert('Please enter Numeric value');
	    ctrl.value=""; 
	    ctrl.focus();
	    return false;
	  }
	  else
	  {
	    return true;
	  }
    }
function formatPhoneNumber(ctrl)
{
    var val=ctrl.value;
    //alert(val + " before return");
    val = getNumericString(val);
   // alert("Numeric" + val);
    if(val == "")
    {
        return "";
    }
    if(val.length >= 10)
    {       
        val = insertAt(val,3,'-')
        val = insertAt(val,7,'-')
        ctrl.value = val;
    }
     
}
function getNumericString(val)
{
    var strNumString
    //alert ("val in getNmeric" + val);
    if(val == ""){return "";}
    
     for (i=0; i<val.length; i++)
      {
       // alert("in loop for" + val.charAt(i) + " val length " + val.length)
        if (val.charAt(i) >= "0" && val.charAt(i) <= "9") 
        {
           // alert(strNumString + "getting int values");
            if(strNumString == null)
            {
                //alert("for first time");
                strNumString = val.charAt(i);
            }
            else
            {
                strNumString = strNumString + val.charAt(i);
            }
        }
        
      }
	 //alert("returning " + strNumString)
	  return strNumString;
}
function insertAt(OrgString , placeToInsert , strToInsert)
{
    return OrgString.substr(0,Number(placeToInsert)) + strToInsert + OrgString.substr(Number(placeToInsert)) 
}
function CheckNumeric(x)
{
    var code=event.keyCode;
    //alert(code);
    if (code>=48 && code<=57)
    return true;
    else
    return false;
}
function validateDropDownCtrl(ctrl)
{
    //ctrl parameter is the combination of the Control ID and Message to Display.
    ctrlInfo = ctrl.split(':');
    var control = document.getElementById(ctrlInfo[0]);
    
    if(control.selectedIndex <= 0)
    {
        alert(ctrlInfo[1])
        return false;
    }
   
    return true;
}
function isValidEmail(email, required) 
{

    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email=="") {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

//To Check Date format
function isDate(dateStr) 
{

if(dateStr=='')
     return true;
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?

    if (matchArray == null) {
        //alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
        return false;
    }

    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[5];

    if(year < 1753 || year > 9999)//check year range
    {
        return false;
    }
    if (month < 1 || month > 12) { // check month range
        //alert("Month must be between 1 and 12.");
        return false;
    }

    if (day < 1 || day > 31) {
        //alert("Day must be between 1 and 31.");
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        //alert("Month "+month+" doesn't have 31 days!")
        return false;
    }

    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            //alert("February " + year + " doesn't have " + day + " days!");
            return false;
        }
    }
    return true; // date is valid
    
     
   
}
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

function ValidateControls(controls)
{
    var controlArray = controls.split(";")
    var alertString = "";
    var emptyField = "";
    for (count = 0 ; count < controlArray.length ; count++)
    {       
       emptyField =  verifyField(controlArray[count] + "\r")
       //if(LTrim(RTrim(emptyField)) != "")
      
       if(LTrim(RTrim(emptyField)) != "")
        alertString = alertString + emptyField + "\r";
        
    }

    if(LTrim(RTrim(alertString)) != "")
    {
        alert("Please Enter Following Information \r" + alertString);
        return false;
    }
    else 
    {
        return true;
    }
}
function verifyField(control)
{
    controlInfo = control.split(":")
    ctrl = document.getElementById(controlInfo[0])
    if((LTrim(RTrim(ctrl.value)).indexOf('Req')!= -1)|| (controlInfo[2].indexOf('Both')!=-1))
    {  
        if(LTrim(RTrim(ctrl.value)) == "")     
        return controlInfo[1];
        
    }
    if((controlInfo[2].indexOf('Spec')!= -1) || (controlInfo[2].indexOf('Both')!=-1))
    {
         
        if(!CheckSpecialChars(controlInfo[0]))
        {
            return controlInfo[1] +" - Special Char Not Allowed";
        }
        return "";
    }
   else
   {
        return "";
   }
    
}
function CheckEmailId(EmailId)
{
   
        if(!isValidEmail(document.getElementById(EmailId).value, false))
        {
            alert("Wrong Email Id");
            document.getElementById(EmailId).focus();
            return false;
        }
        return true;
}
function CheckSpecialChars(CtrlId)
{
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

    for (var i = 0; i < document.getElementById(CtrlId).value.length; i++) 
    {
  	    if (iChars.indexOf(document.getElementById(CtrlId).value.charAt(i)) != -1) 
  	    {  	        
  	       // alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
  	        return false;
  	    }
  	    
    }
    return true;

}
function SavePassWord(txtPassword)
{
    var txthidden = document.getElementById("hdnPassWord");
    txthidden.value = RTrim(LTrim(txtPassword.value)) ;   
   
}


function CallNewWindowWithFocus(sUrl,sName)
{            
    NewWindow(sUrl,sName, (screen.availHeight-325)/2, (screen.availWidth-screen.width)/2, 425, screen.width);
}
function NewWindow(sURL, sName, lTop, lLeft, lHeight, lWidth, bIncludeOrnaments, bScrollResize, bResizeable)
{
        var sOrnaments;
        var sScrollResize;
        var sFeatures;
    	
        if (bIncludeOrnaments)
            sOrnaments="yes";
        else
            sOrnaments="no";
    		
        if (bScrollResize)
            sScrollResize="yes";
        else
            sScrollResize="no";
    		
        var sFeatures="top="+lTop;
        sFeatures=sFeatures+",left="+lLeft;
        sFeatures=sFeatures+",height="+lHeight;
        sFeatures=sFeatures+",width="+lWidth;
        //sFeatures=sFeatures+",toolbar="+sOrnaments;
        sFeatures=sFeatures+",menubar="+sOrnaments;
        //sFeatures=sFeatures+",location="+sOrnaments;
        //sFeatures=sFeatures+",directories="+sOrnaments;
        //sFeatures=sFeatures+",status="+sOrnaments;
        sFeatures=sFeatures+",scrollbars="+sScrollResize;
        //sFeatures=sFeatures+",resizable="+bResizeable;
    	sFeatures=sFeatures+",resizable=1";
        window.open(sURL,sName,'resizable=1,scrollbars=1,menubar=1')
}
    function validateField(ctrl)
    {
////         var ctrlvalue = ctrl.value;
////         //alert(ctrlvalue)
////         var matches = ctrlvalue.match(new RegExp("[a-zA-Z]"));
////         if((matches ? matches.length : 0) == 0)
////         {
////            ctrl.value = "";
////         }   

//        eventSrcID=(event.srcElement)?event.srcElement.id:'undefined';
//        eventtype=event.type;
//        //alert(String.fromCharCode(event.keyCode))
//        alert(event.keyCode);
//        status=eventSrcID+' has received a '+eventtype+' event.';

    }
function ResetForm(formname,skipFocus)//autoFocus == 1 then sets focus else skips focus
{
   
    //if(formname==null)
     formname = "form1";
     
    a = document.forms[formname].length;
  
    for(i=0;i<a;i++)
    {
        if(document.forms[formname].elements[i])
        {
            switch(document.forms[formname].elements[i].type)
            {
                case "checkbox":
                try{
                   document.forms[formname].elements[i].checked = false;
                }catch(ex){break;}
                  break;       
            
                case "text":            
                 
                 try{
                    document.forms[formname].elements[i].value="";
                    if(skipFocus != 1)
                        document.forms[formname].elements[i].focus();
                 }catch(ex){break;}
                                                       
                 break;
                            
                case "select-one":                    
                 try{
                                        
                    if(document.forms[formname].elements[i].id.toLowerCase().indexOf("_drppnl_")>0 && document.forms[formname].elements[i].id.indexOf("_504")>0)
                    {
                        //dt=new Date();
                        //document.forms[formname].elements[i].selectedIndex=dt.getMonth();                       
                    }
                    else if(document.forms[formname].elements[i].id.toLowerCase().indexOf("_drppnl_")>0 && document.forms[formname].elements[i].id.indexOf("_506")>0)
                    {
//                        cmbo=document.forms[formname].elements[i];
//                        len=cmbo.options.length;  
//                                              
//                        dt=new Date();                       
//                        for(j=0; j<len; j++)
//                        {
//                            if(cmbo.options[j].text==dt.getYear())
//                            {                                
//                                cmbo.selectedIndex=j;
//                            }
//                        }  
                       
                    }
                    else
                        document.forms[formname].elements[i].selectedIndex = 0;
                        
                 }catch(ex){break;}
                 break;
                 
                 case "select-multiple":
                 try{
                    document.forms[formname].elements[i].selectedIndex = -1;
                 }catch(ex){break;}
                 break;
                 
                 case "password":
                 try{
                    document.forms[formname].elements[i].value="";                    
                 }catch(ex){break;}                                                       
                 break; 
                 case "radio":
                 try
                 {
                    document.forms[formname].elements[i].checked="";
                 }               
                 catch(ex){break;}
                 break;
                 case "textarea":
                 try{
                    document.forms[formname].elements[i].value="";                    
                 }catch(ex){break;}                                                       
                 break; 
            }
        }        
    }
    return false;
}

function vChangeCheckbox()
{
    try
    {
        for(i=0;i<document.forms[0].length ; i++)
        {
            if(document.forms[0].elements[i].type=='checkbox')
            {
                document.forms[0].elements[i].disabled=false;
            }
        }
    }
    catch(ex)
    {
        alert(ex);
    }
}

function ClearContainer(contId,skipFocus)//autoFocus == 1 then sets focus else skips focus
{   
    //if(formname==null)
    //formname = "form1";
     
    a = getId(contId);
    var inputs=getElementsByTag(a,'INPUT');
    clear(inputs);
    var selects=getElementsByTag(a,'SELECT');
    clear(selects);
    var spans = getElementsByTag(a,'SPAN');
    clear(spans);
	var textareas = getElementsByTag(a,'TEXTAREA');
	clear(textareas);    
    
    return false;
}

function clear(elements)
{
    for (var i=0; i<elements.length; i++) 
	{	    
		if (elements[i].id.length > 0)
		{
		    tmp = elements[i].id.split('_');
			id = tmp[tmp.length-1];
			switch(elements[i].type)
			{
			    case 'checkbox':
			        try{
				    elements[i].checked=false;	
				    }catch(ex){break;}
				    break;
			    case 'radio':
			        try{
			        elements[i].checked="";
			        }catch(ex){break;}
			        break;
			    case 'text':
			        try{
			        elements[i].value="";
			        }catch(ex){break;}
			        break;
			    case 'textarea':
			        try{
			        elements[i].value="";
			        }catch(ex){break;}
			        break;
			    case "select-one":
			        try{                                     
                    if(elements[i].id.toLowerCase().indexOf("_drppnl_")>0 && elements[i].id.indexOf("_504")>0)
                    {
                                            
                    }
                    else if(elements[i].id.toLowerCase().indexOf("_drppnl_")>0 && elements[i].id.indexOf("_506")>0)
                    {
 
                       
                    }
                    else
                        elements[i].selectedIndex = 0;
                    }catch(ex){break;}
                    break;
               case "select-multiple":  
                    try{             
                    elements[i].selectedIndex = -1;
                    }catch(ex){break;}
                    break;
               case "password":
                    try{
                    elements[i].value="";
                    }catch(ex){break;}
                    break;
                
			}
	    }
	}
	
	
	function isemail(eml)
    {
    	
    var str = Trim(eml.value);
    var str1 = eml.value.length;
    if(str == "")
     {
      alert("\nThe email field is blank .\n\nPlease enter your email id.");
      eml.focus();
      return false;
     }
    if (str.indexOf("@")== -1 || str.indexOf(".")== -1)
    {
    alert("Please enter the correct E-mail ID");
    eml.focus();
    return false;
    }
    if((str.substring(0,1) == "@" || str.substring(0,1)== ".") || str.substring(0,1)=="-" || str.substring(0,1)=="_")
     {
      alert("The Email ID can not begin with @ or . or - or _ ");
      eml.focus();
      return false;
     }
    if ((str.substring(str1-1,str1)=="@" || str.substring(str1-1,str1)=="."))
    {
      alert("The Email ID can not end with @ or . ");
      eml.focus();
      return false;
    }
    var index1 = str.indexOf("@");
    var index2 = str.indexOf(".");
    var index3=str.indexOf("-");
    var index4=str.indexOf("_");
     
    if(str.substring(index1+1,index1+2) ==".")
    {
    alert(". can not come immidately after @");
    eml.focus();
    return false;
    }
    if ( ( index3==index1+1) || ( index4==index1+1))
    {
    alert("please enter the correct Email ID as no two special chars can come in sequence");
    eml.focus();
    return false;
    }
    for (var i = 0; i < str.length; i++) 
     {
      var ch = str.substring(i, i + 1);
      if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_') && ch !='-' && ch !='@' && ch !='.')
      {
       alert("\nThe Email field  accepts letters,numbers & underscore.\n\nPlease re-enter your Email id Name.");
      // eml.select();
       eml.focus();
       return false;
      }
     }
    return true;
    }			    
}

function isCurrency(val,dp)
{    
	var nNum = 0;				
	var nDecimal = 0;			
	var txtLen;				
	var xTxt;					
	var decPos;				
	var nNumCount = 0;		
	var i;					
	var x;	
	xTxt = Trim(val);
	txtLen = xTxt.length
	var pos = xTxt.indexOf('.')+1;
	var xChars = "`~-!_#$%^&*()+=[]\\\';/{}|\":<>''@? abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZ"; 

 if(xTxt!='')
 {
    for (var i = 0; i < val.length; i++) 
    {        
  	    if (xChars.indexOf(val.charAt(i)) != -1) 
  	    {  
  	        return false;     
  	    }    
  }    
  
  if(txtLen==1 && xTxt==".")
  {
    return false;
  }  
	for(i = 0; i < txtLen; i++)
	{
	   x = xTxt.substr(i, 1);
	   if(parseInt(x)==0)
	   {
	        nNumCount=nNumCount+1; 
	   } 
	   if(x == "." )
			nDecimal = nDecimal + 1; 	
		else if(parseInt(x) >= 0 || parseInt(x) <= 9)
			nNum = nNum + 1; 		
	} 
	if(nDecimal > 1)
	{		
		return false;
	} 
	else if(parseInt((xTxt * 1))==0)
	{
	    return false;
	} 
}
	return true;
}   

function CheckDecimal(x, dp)
{
	var code=event.keyCode;
	//debugger;
	if ((code>=48 && code<=57) || (code == 8) || (code == 46))
	{
	    var pos = x.value.indexOf('.');
		if (code == 46)
		{
		    if (pos > -1) return false;
		}
	    else
	    {
             if (pos > -1)
             {
                if ((dp>0) && ((x.value.length - pos) > dp))
                    return false;
             }      
        }

		return true;
	}	
	else
		return false;
}

function fnLoading(divButtonId,divLoadingId)
{
    /*getId(divButtonId).style.display='none';
    getId(divLoadingId).style.display='block';*/
    if(divLoadingId == "divProgress")
        getId(divLoadingId).innerHTML='<b><span class="formtex">Please wait.....</span><b>';
   
}

//Round off number to 2 places
function RoundNumber(rnum) 
{		
	var rlength = 2; // The number of decimal places to round to
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newNumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newNumber = newNumber+5000;
	} else {
		var newNumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	return newNumber;
}

function OnKeyPressIntMaxLen(source,len) 
{		
	if(len > 0)
	{
	    if (source.value.length >= len) {
		    event.keyCode = 0;
		    return;
	    }
	}

	var code = event.keyCode;

	//var idx = source.value.indexOf(".");

	if ((code < 48) || (code > 57)) 
			event.keyCode = 0;
}

function OnKeyPressInt(source) 
{		
	if (source.value.length >= 8) {
		event.keyCode = 0;
		return;
	}

	var code = event.keyCode;

	//var idx = source.value.indexOf(".");

	if ((code < 48) || (code > 57)) 
			event.keyCode = 0;
}


function OnKeyPressBorrowerCode(source) 
{		
	if (source.value.length >= 10) {
		event.keyCode = 0;
		return;
	}

	var code = event.keyCode;

	//var idx = source.value.indexOf(".");

	if ((code < 48) || (code > 57)) 
			event.keyCode = 0;
}

function OnKeyPressTrackingNo(source) 
{	
	var code = event.keyCode;

	//var idx = source.value.indexOf(".");

	if ((code < 48) || (code > 57)) 
			event.keyCode = 0;
}


function onKeyPressTextArea()
{
   var code = event.keyCode;
   if ((code == 92) || (code ==39) || (code==34)) 
			event.keyCode = 0;
}

function OnKeyPressMoney(source) 
{
	if (source.value.length >= 11) {
		event.keyCode = 0;
		return;
	}
	
	var code = event.keyCode;
	
	var idx = source.value.indexOf(".");

	if ((code < 48) || (code > 57)) {
		if ((code == 45) && (source.value.length > 0))
			event.keyCode = 0;
		if (((idx >= 0) || (code != 46)) && (code != 45))
			event.keyCode = 0;
	} else {
		if ((idx >= 0) && (source.value.length > (idx + 2)))
			event.keyCode = 0;
	}
}	
	
	
	
function StringReplace(string, charToFind, charToReplace)
{
debugger;
     if(null == string)
        return;        
 
        var i=0;
        var anotherString=null;
    for(i=0;i<string.length;i++)
    {     
         if(string.substr(i,1)==charToFind) 
            {    
                anotherString=anotherString+ charToReplace;
            }
        else
            {
                anotherString=anotherString+string.substring(i,1);     
            }
    }
    alert(anotherString);
    return anotherString;
}


function getQueryVariable(variable) 
{ 
    var query = window.location.search.substring(1); 
    var vars = query.split("&"); 
    for (var i=0;i<vars.length;i++) 
    { 
        var pair = vars[i].split("="); 
        if (pair[0] == variable) 
        { 
            return pair[1]; 
        } 
    } 
}

   

function beforeEvent(owner, tabItem, evnt)
{
    if(! confirm('sure?'))        //debugger;        
    {
        evnt.cancel=true;
    }
    
}
function checkTextAreaMaxLength(len, textBox)
{
    
  
        var maxLength = parseInt(len);
        
        if(!checkSpecialKeys())
        {
         if(textBox.value.length > maxLength-1)
         {
              event.returnValue = false;
         }
         }
   
}
function checkSpecialKeys()
{
    if(event.keyCode !=8 && event.keyCode!=46 && event.keyCode!=37 && event.keyCode!=38 && event.keyCode!=39 && event.keyCode!=40)
        return false;
    else
        return true;
}

//Parse number to currency format
function ParseElement(thisOne)
{
    var wd;
    wd="w";
    var tempNum;
       var number=getId(thisOne);
        if(number.value=='')
        { 
        tempNum=0;   
        }
        else
        {
            tempNum=String(number.value);
        }
        for (i=0;i<tempNum.length;i++)
        {
            if (tempNum.charAt(i)=='.')
            {
                wd="d";
                break;
            }
        }
        if (wd=="w")
        {        
            tempNum=tempNum+".00";
            number.value= tempNum;
        }        
        else
        {
            if (tempNum.charAt(tempNum.length-2)=='.')
            {
                 tempNum=tempNum+"0";
                number.value= tempNum;
            }
            else
            {
                tempNum=Math.round(tempNum*100)/100;
                number.value= tempNum;
            }
        }     
}


function FormatAmountToCurrency(sourceName) 
	{   	
	    var num=sourceName;
        num = num.toString().replace(/\$|\,/g,'');
        var finalNum='';
        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));
        finalNum= (((sign)?'':'-') + num + '.' + cents);
        if(finalNum=="0.00")
            finalNum="";
        return finalNum;
}
