﻿
// JScript File
    document.onkeydown = mykeyhandler;
//	document.oncontextmenu = nocontextmenu;    

//	Restrict Right Click
	function nocontextmenu() {
	try {
		event.cancelBubble = true, event.returnValue = false;
		return false;
	} 
	catch(e) { alert(e + '\nID: nocontextmenu\n' + 'Code: ' + (e.number & 0xFFFF) + '\n' + e.description); }
	}
	
//	Restrict Keystrokes
	function mykeyhandler() {	
	//try {
		//BACKSPACE
		if ((window.event) && (window.event.keyCode == 0x8) && (window.event.srcElement.tagName != 'TEXTAREA') && (window.event.srcElement.tagName != 'INPUT'))
			window.event.keyCode = 0x13;
		else {
			if(window.event.srcElement.contentEditable == 'false')	
			window.event.keyCode = 0x13;	 
		}	
		//F5
		if ((window.event) && (window.event.keyCode == 0x74))
			 window.event.keyCode = 0x13;
		//F6
		if ((window.event) && (window.event.keyCode == 0x75))
			 window.event.keyCode = 0x13;
		//PAUSE
		if ((window.event) && (window.event.keyCode == 0x13)) {
			event.cancelBubble = true, event.returnValue = false;
			return false;
		}
		//CTRL + Other Key Strokes
		if (window.event.ctrlKey == true) {
			if (window.event && (
				(window.event.keyCode == 78) || 
				(window.event.keyCode == 80) || 
				(window.event.keyCode == 37) || 
				(window.event.keyCode == 39) || 
				(window.event.keyCode == 87) || 
				(window.event.keyCode == 79) || 
				(window.event.keyCode == 73) || 
				(window.event.keyCode == 72) || 
				(window.event.keyCode == 76) || 
				(window.event.keyCode == 11) || 
				(window.event.keyCode == 82)
			)) {
				window.event.cancelBubble = true, window.event.returnValue = false;
				window.event.keyCode = 0x13;
				return false;
			}
		}
		//ALT + Other Key Strokes
		if (window.event.altKey == true) {
			if (window.event && (
				(window.event.keyCode == 37) || 
				(window.event.keyCode == 39)    
			)) {
				window.event.cancelBubble = true, window.event.returnValue = false;
				return false;
			}
		}		
	//}
	//catch(e) { alert(e + '\nID: mykeyhandler\n' + 'Code: ' + (e.number & 0xFFFF) + '\n' + e.description); }
	}


    //Confirmation Popup
	function fnConfirm(sMsg) {
		return confirm(sMsg);
	}
	
    
	function fnConfirmUndo() {

		var sMsg = 'Undo Transaction? \n\n'
		
		sMsg += 'Please Note: '
		
		sMsg += 'Transactions linked to multiple transactions will be reversed. See help for more information.'
		
		return confirm(sMsg);
	}
	
	

    //Validation Functions
    function NumericValidator(sender, args) {
        if(isNaN(args.Value) == true)
            args.IsValid = false;
        else
            args.IsValid = true;    
        return;
    }

    function RequiredDropDownListValidator(sender, args) {
        if(args.Value == 0) {
            //alert(sender.style.className);
            args.IsValid = false;
        }    
        else
            args.IsValid = true;
        return;

    }




    function switchMenu() {   
       var el = event.srcElement;
       if (el.className=="ContextMenuItem") {
          el.className="highlightItem";
       } else if (el.className=="highlightItem") {
          el.className="ContextMenuItem";
       }
    }
    
    function displayMenu(iCustomerID) {
       document.all.hdnCustomerID.value = iCustomerID;
       var whichDiv = event.srcElement;
       document.all.menu1.style.leftPos+=10;
       document.all.menu1.style.posLeft=event.clientX;
       document.all.menu1.style.posTop=event.clientY;
       document.all.menu1.style.display="block";
       document.all.menu1.setCapture();
    }

    function clickCustomerMenu() {
       var iCustomerID = document.all.hdnCustomerID.value;
       document.all.menu1.releaseCapture();
       document.all.menu1.style.display="none";
       var el = event.srcElement;
       if (el.id=="mnuEdit") {
          location.href='Customers.aspx?act=edit&id='+iCustomerID;
       } else if (el.id=="mnuNewInvoice") {
          location.href='Invoices.aspx?act=new&custid='+iCustomerID;
       } else if (el.id=="mnuNewOrder") {
          location.href='Orders.aspx?act=new&custid='+iCustomerID;
       } else if (el.id=="mnuDelete") {
          if (confirm('Are you sure you want to delete this Customer?')) 
            location.href='Customers.aspx?act=delete&id='+iCustomerID;
       } else if (el.id=="mnuViewCustomer") {
          location.href='Customers.aspx?id='+iCustomerID;
       }
    }        

    // -------------------------------------------------------------------------
    //Invoices Context Menu
    
    function displayInvMenu(iInvoiceID, iCustomerID) {
       document.all.hdnInvoiceID.value = iInvoiceID;
       document.all.hdnCustomerID.value = iCustomerID;
       var whichDiv = event.srcElement;
       document.all.divInvoicesMenu.style.leftPos+=10;
       document.all.divInvoicesMenu.style.posLeft=event.clientX;
       document.all.divInvoicesMenu.style.posTop=event.clientY;
       document.all.divInvoicesMenu.style.display="block";
       document.all.divInvoicesMenu.setCapture();
    }
    
    function clickInvoiceMenu() {
       var iInvoiceID = document.all.hdnInvoiceID.value;
       var iCustomerID = document.all.hdnCustomerID.value;
       document.all.divInvoicesMenu.releaseCapture();
       document.all.divInvoicesMenu.style.display="none";
       var el = event.srcElement;
       if (el.id=="mnuInvEdit") {
          location.href='Invoices.aspx?act=edit&id='+iInvoiceID+'&custid='+iCustomerID;
          
       } else if (el.id=="mnuInvHistory") {
          location.href='Invoices.aspx?act=history&id='+iInvoiceID+'&custid='+iCustomerID;
          
       } else if (el.id=="mnuInvPaymnet") {
          location.href='Payments.aspx?act=invoice&id='+iInvoiceID+'&custid='+iCustomerID;
          
       } else if (el.id=="mnuInvDelete") {
          if (confirm('Are you sure you want to delete this Invoice?')) 
            location.href='Invoices.aspx?act=delete&id='+iInvoiceID+'&custid='+iCustomerID;
            
       } else if (el.id=="mnuInvView") {
          location.href='Invoices.aspx?id='+iInvoiceID+'&custid='+iCustomerID;
       }
       
    } 
    // -------------------------------------------------------------------------
    //Orders Context Menu
    
    function displayOrdMenu(iOrderID, iCustomerID) {
       document.all.hdnOrderID.value = iOrderID;
       document.all.hdnCustomerID.value = iCustomerID;
       var whichDiv = event.srcElement;
       document.all.divOrdersMenu.style.leftPos+=10;
       document.all.divOrdersMenu.style.posLeft=event.clientX;
       document.all.divOrdersMenu.style.posTop=event.clientY;
       document.all.divOrdersMenu.style.display="block";
       document.all.divOrdersMenu.setCapture();
    }
    
    function clickOrderMenu() {
       var iOrderID = document.all.hdnOrderID.value;
       var iCustomerID = document.all.hdnCustomerID.value;
       document.all.divOrdersMenu.releaseCapture();
       document.all.divOrdersMenu.style.display="none";
       var el = event.srcElement;
       if (el.id=="mnuOrdEdit") {
          location.href='Orders.aspx?act=edit&id='+iOrderID+'&custid='+iCustomerID;
          
       } else if (el.id=="mnuOrdHistory") {
          location.href='Orders.aspx?act=history&id='+iOrderID+'&custid='+iCustomerID;

       } else if (el.id=="mnuOrdInvoice") {
            location.href='Orders.aspx?act=invoice&id='+iOrderID+'&custid='+iCustomerID;
          
       } else if (el.id=="mnuOrdDelete") {
          if (confirm('Are you sure you want to delete this Order?')) 
            location.href='Orders.aspx?act=delete&id='+iOrderID+'&custid='+iCustomerID;
            
       } else if (el.id=="mnuOrdView") {
          location.href='Orders.aspx?id='+iOrderID+'&custid='+iCustomerID;
       }
       
    } 
    // -------------------------------------------------------------------------    
    //Deal Context Menu
    
    function displayDealMenu(iDealID) {
       document.all.hdnDealID.value = iDealID;
       var whichDiv = event.srcElement;
       document.all.divDealsMenu.style.leftPos+=10;
       document.all.divDealsMenu.style.posLeft=event.clientX;
       document.all.divDealsMenu.style.posTop=event.clientY;
       document.all.divDealsMenu.style.display="block";
       document.all.divDealsMenu.setCapture();
    }
    
    function clickDealMenu() {
       var iDealID = document.all.hdnDealID.value;
       document.all.divDealsMenu.releaseCapture();
       document.all.divDealsMenu.style.display="none";
       var el = event.srcElement;
       if (el.id=="mnuDealEdit") {
          location.href='Deals.aspx?act=edit&id='+iDealID;
          
       } else if (el.id=="mnuDealHistory") {
          location.href='Deals.aspx?act=history&id='+iDealID;

       } else if (el.id=="mnuDealPaymnet") {
            location.href='Payments.aspx?act=deal&id='+iDealID;
          
       } else if (el.id=="mnuDealDelete") {
          if (confirm('Are you sure you want to delete this Order?')) 
            location.href='Deals.aspx?act=delete&id='+iDealID;

       } else if (el.id=="mnuDealCancel") {
            location.href='Deals.aspx?act=extend&id='+iDealID;

       } else if (el.id=="mnuDealExtend") {
            location.href='Deals.aspx?act=cancel&id='+iDealID;
            
       } else if (el.id=="mnuDealView") {
          location.href='Deals.aspx?id='+iDealID;
       }
       
    }    
    // -------------------------------------------------------------------------    
    //Foreign Account Context Menu
    
    function displayForeignAccountMenu(iForeignAccountID) {
       document.all.hdnForeignAccountID.value = iForeignAccountID;
       var whichDiv = event.srcElement;
       document.all.divForeignAccountMenu.style.leftPos+=10;
       document.all.divForeignAccountMenu.style.posLeft=event.clientX;
       document.all.divForeignAccountMenu.style.posTop=event.clientY;
       document.all.divForeignAccountMenu.style.display="block";
       document.all.divForeignAccountMenu.setCapture();
    }
    
    function clickForeignAccountMenu() {
       var iForeignAccountID = document.all.hdnForeignAccountID.value;
       document.all.divForeignAccountMenu.releaseCapture();
       document.all.divForeignAccountMenu.style.display="none";
       var el = event.srcElement;
       if (el.id=="mnuForeignAccountEdit") {
          location.href='ForeignAccounts.aspx?act=edit&id='+iForeignAccountID;
          
       } else if (el.id=="mnuForeignAccountHistory") {
          location.href='ForeignAccounts.aspx?act=history&id='+iForeignAccountID;

       } else if (el.id=="mnuForeignAccountTransaction") {
            location.href='Payments.aspx?act=deal&id='+iForeignAccountID;
          
       } else if (el.id=="mnuForeignAccountDelete") {
          if (confirm('Are you sure you want to delete this Foreign Account?')) 
            location.href='ForeignAccounts.aspx?act=delete&id='+iForeignAccountID;
            
       } else if (el.id=="mnuForeignAccountView") {
          location.href='ForeignAccounts.aspx?id='+iForeignAccountID;
       }
       
    }          
    // -------------------------------------------------------------------------    
    //Stop Context Menu
    
    function displayStopMenu(iStopID) {
       document.all.hdnStopID.value = iStopID;
       var whichDiv = event.srcElement;
       document.all.divStopMenu.style.leftPos+=10;
       document.all.divStopMenu.style.posLeft=event.clientX;
       document.all.divStopMenu.style.posTop=event.clientY;
       document.all.divStopMenu.style.display="block";
       document.all.divStopMenu.setCapture();
    }
    
    function clickStopMenu() {
       var iStopID = document.all.hdnStopID.value;
       document.all.divStopMenu.releaseCapture();
       document.all.divStopMenu.style.display="none";
       var el = event.srcElement;
       if (el.id=="mnuStopEdit") {
          location.href='Stops.aspx?act=edit&id='+iStopID;
          
       } else if (el.id=="mnuStopDelete") {
          if (confirm('Are you sure you want to delete this Stop?')) 
            location.href='Stops.aspx?act=delete&id='+iStopID;
            
       } else if (el.id=="mnuStopView") {
          location.href='Stops.aspx?id='+iStopID;
       }
    }      

    //Manages Spot; Forward and Costing rates
    function fnDealerExtendDealCancelCostingRate(oThis, i) {
    
        var sObj = oThis.id;
        var sServerTag;
        var sThis;

        if ((sObj.substr(sObj.length - 27, 27)) == 'txtExtendDealCancelSpotRate') {
            sServerTag = sObj.substr(0, sObj.length - 27);
            sThis = 'txtExtendDealCancelSpotRate';

        }
        if ((sObj.substr(sObj.length - 31, 31)) == 'txtExtendDealCancelContractRate') {
            sServerTag = sObj.substr(0, sObj.length - 31);
            sThis = 'txtExtendDealCancelContractRate';
        }           
        var oSpotRate = document.getElementById(sServerTag+'txtExtendDealCancelSpotRate');
        var oForwardPoints = document.getElementById(sServerTag+'txtExtendDealCancelForwardPoints');
        var oContractRate = document.getElementById(sServerTag+'txtExtendDealCancelContractRate');

        var oNewSpotRate = document.getElementById(sServerTag+'txtExtendDealPaymentSpotRate');
        var oNewForwardPoints = document.getElementById(sServerTag+'txtExtendDealPaymentForwardPoints');
        var oNewContractRate = document.getElementById(sServerTag+'txtExtendDealPaymentContractRate');

        var iSpotRate = new Number(oSpotRate.value);
        var iForwardPoints = new Number(oForwardPoints.value);
        var iContractRate = new Number(oContractRate.value);
        
        var iNewContractRate = new Number(oNewContractRate.value);

        oForwardPoints.value = fnReplaceNull(customround((Number(iContractRate) - Number(iSpotRate)),4));
        
        oNewForwardPoints.value = fnReplaceNull(customround((Number(iNewContractRate) - Number(iSpotRate)),4));
        oNewSpotRate.value = fnReplaceNull(customround(Number(iSpotRate),4)); 
        
    }
    
    //Manages Spot; Forward and Costing rates
    function fnDealerExtendDealPaymentCostingRate(oThis, i) {
    
        var sObj = oThis.id;
        var sServerTag;
        var sThis;

        if ((sObj.substr(sObj.length - 28, 28)) == 'txtExtendDealPaymentSpotRate') {
            sServerTag = sObj.substr(0, sObj.length - 28);
            sThis = 'txtExtendDealPaymentSpotRate';

        }
        if ((sObj.substr(sObj.length - 32, 32)) == 'txtExtendDealPaymentContractRate') {
            sServerTag = sObj.substr(0, sObj.length - 32);       
            sThis = 'txtExtendDealPaymentContractRate';
        }           
        var oSpotRate = document.getElementById(sServerTag+'txtExtendDealPaymentSpotRate');
        var oForwardPoints = document.getElementById(sServerTag+'txtExtendDealPaymentForwardPoints');
        var oContractRate = document.getElementById(sServerTag+'txtExtendDealPaymentContractRate');

        var iSpotRate = new Number(oSpotRate.value);
        var iForwardPoints = new Number(oForwardPoints.value);
        var iContractRate = new Number(oContractRate.value);

        oForwardPoints.value = fnReplaceNull(customround((Number(iContractRate) - Number(iSpotRate)),4));
    }
    
    //Manages Spot; Forward and Costing rates
    function fnDealerCancelCostingRate(oThis, i) {
    
        var sObj = oThis.id;
        var sServerTag;
        var sThis;
     
        if ((sObj.substr(sObj.length - 21, 21)) == 'txtCancelDealSpotRate') {
            sServerTag = sObj.substr(0, sObj.length - 21);       
            sThis = 'txtCancelDealSpotRate';

        }
        if ((sObj.substr(sObj.length - 25, 25)) == 'txtCancelDealContractRate') {
            sServerTag = sObj.substr(0, sObj.length - 25);       
            sThis = 'txtCancelDealContractRate';
        }           

        var oSpotRate = document.getElementById(sServerTag+'txtCancelDealSpotRate');
        var oForwardPoints = document.getElementById(sServerTag+'txtCancelDealForwardPoints');
        var oContractRate = document.getElementById(sServerTag+'txtCancelDealContractRate');
        
        var iSpotRate = new Number(oSpotRate.value);
        var iForwardPoints = new Number(oForwardPoints.value);
        var iContractRate = new Number(oContractRate.value);

        oForwardPoints.value = fnReplaceNull(customround((Number(iContractRate) - Number(iSpotRate)),4));

    }
    
    //Manages Spot; Forward and Costing rates
    function fnCostingRate(oThis, i) {
    
        var sObj = oThis.id;
        var sServerTag;
        var sThis;
     
        if ((sObj.substr(sObj.length - 11, 11)) == 'txtSpotRate') {
            sServerTag = sObj.substr(0, sObj.length - 11);       
            sThis = 'txtSpotRate';

        }
        if ((sObj.substr(sObj.length - 16, 16)) == 'txtForwardPoints') {
            sServerTag = sObj.substr(0, sObj.length - 16);       
            sThis = 'txtForwardPoints';
        }
        if ((sObj.substr(sObj.length - 15, 15)) == 'txtContractRate') {
            sServerTag = sObj.substr(0, sObj.length - 15);       
            sThis = 'txtContractRate';
        }           

        var oSpotRate = document.getElementById(sServerTag+'txtSpotRate');
        var oForwardPoints = document.getElementById(sServerTag+'txtForwardPoints');
        var oContractRate = document.getElementById(sServerTag+'txtContractRate');
        
        var iSpotRate = new Number(oSpotRate.value);
        var iForwardPoints = new Number(oForwardPoints.value);
        var iContractRate = new Number(oContractRate.value);

        //[*Spot || Fwd] [Spot > 0] [ Fwd > 0] : Costing = Spot + Fwd
        if(((sThis == 'txtSpotRate') || (sThis == 'txtForwardPoints')) && (oSpotRate.value.length != 0) && (oForwardPoints.value.length != 0))
	        oContractRate.value =  fnReplaceNull(customround((Number(iForwardPoints) + Number(iSpotRate)),4));
        //[*Spot] [Fwd = 0] : Costing = ""
        if((sThis == 'txtSpotRate') && (oForwardPoints.value.length == 0))
	        oContractRate.value = '';
        //[*Fwd] [Fwd = 0] [Spot > 0] : Costing = ""
        if((sThis == 'txtForwardPoints') && (oForwardPoints.value.length == 0) && (oSpotRate.value.length != 0))
	        oContractRate.value = '';
        //[*Fwd] [Spot = 0] [Costing > 0] : Spot = Costing - Fwd
        if((sThis == 'txtForwardPoints') && (oSpotRate.value.length == 0) && (oContractRate.value.length != 0))
	        oSpotRate.value =  fnReplaceNull(customround((Number(iContractRate) - Number(iForwardPoints)),4));
        //[*Costing] [Fwd > 0] : Spot = Costing - Fwd
        if((sThis == 'txtContractRate') && (oForwardPoints.value.length != 0))
	        oSpotRate.value =  fnReplaceNull(customround((Number(iContractRate) - Number(iForwardPoints)),4));
        //[*Costing] [Costing > 0] [Fwd = 0] [Spot > 0] : Spot = ""
        if((sThis == 'txtContractRate') && (oContractRate.value.length != 0) && (oForwardPoints.value.length == 0) && (oSpotRate.value.length != 0))
	        oSpotRate.value = "";

    }
    
    
    //Manages Spot; Forward and Costing rates
    function fnSpotCostingRate(oThis, i) {
    
        var sObj = oThis.id;
        var sServerTag;
        var sThis;
     
        if ((sObj.substr(sObj.length - 15, 15)) == 'txtSpotSpotRate') {
            sServerTag = sObj.substr(0, sObj.length - 15);
            sThis = 'txtSpotSpotRate';

        }
        if ((sObj.substr(sObj.length - 20, 20)) == 'txtSpotForwardPoints') {
            sServerTag = sObj.substr(0, sObj.length - 20);
            sThis = 'txtSpotForwardPoints';
        }
        if ((sObj.substr(sObj.length - 19, 19)) == 'txtSpotContractRate') {
            sServerTag = sObj.substr(0, sObj.length - 19);
            sThis = 'txtSpotContractRate';
        }           

        var oSpotRate = document.getElementById(sServerTag+'txtSpotSpotRate');
        var oForwardPoints = document.getElementById(sServerTag+'txtSpotForwardPoints');
        var oContractRate = document.getElementById(sServerTag+'txtSpotContractRate');
        
        var iSpotRate = new Number(oSpotRate.value);
        var iForwardPoints = new Number(oForwardPoints.value);
        var iContractRate = new Number(oContractRate.value);

        //[*Spot || Fwd] [Spot > 0] [ Fwd > 0] : Costing = Spot + Fwd
        if(((sThis == 'txtSpotSpotRate') || (sThis == 'txtSpotForwardPoints')) && (oSpotRate.value.length != 0) && (oForwardPoints.value.length != 0))
	        oContractRate.value =  fnReplaceNull(customround((Number(iForwardPoints) + Number(iSpotRate)),4));
        //[*Spot] [Fwd = 0] : Costing = ""
        if((sThis == 'txtSpotSpotRate') && (oForwardPoints.value.length == 0))
	        oContractRate.value = '';
        //[*Fwd] [Fwd = 0] [Spot > 0] : Costing = ""
        if((sThis == 'txtSpotForwardPoints') && (oForwardPoints.value.length == 0) && (oSpotRate.value.length != 0))
	        oContractRate.value = '';
        //[*Fwd] [Spot = 0] [Costing > 0] : Spot = Costing - Fwd
        if((sThis == 'txtSpotForwardPoints') && (oSpotRate.value.length == 0) && (oContractRate.value.length != 0))
	        oSpotRate.value =  fnReplaceNull(customround((Number(iContractRate) - Number(iForwardPoints)),4));
        //[*Costing] [Fwd > 0] : Spot = Costing - Fwd
        if((sThis == 'txtSpotContractRate') && (oForwardPoints.value.length != 0))
	        oSpotRate.value =  fnReplaceNull(customround((Number(iContractRate) - Number(iForwardPoints)),4));
        //[*Costing] [Costing > 0] [Fwd = 0] [Spot > 0] : Spot = ""
        if((sThis == 'txtSpotContractRate') && (oContractRate.value.length != 0) && (oForwardPoints.value.length == 0) && (oSpotRate.value.length != 0))
	        oSpotRate.value = "";

    }    
    
    //Manages Spot; Forward and Costing rates
    function fnInvoiceCostingRate(oThis, i) {
    
        var sObj = oThis.id;
        var sServerTag;
        var sThis;
     
        if ((sObj.substr(sObj.length - 18, 18)) == 'txtCostingSpotRate') {
            sServerTag = sObj.substr(0, sObj.length - 18);       
            sThis = 'txtCostingSpotRate';
        }           
        if ((sObj.substr(sObj.length - 16, 16)) == 'txtForwardPoints') {
            sServerTag = sObj.substr(0, sObj.length - 16);       
            sThis = 'txtForwardPoints';
        }
        if ((sObj.substr(sObj.length - 14, 14)) == 'txtCostingRate') {
            sServerTag = sObj.substr(0, sObj.length - 14);       
            sThis = 'txtCostingRate';
        }

        var oSpotRate = document.getElementById(sServerTag+'txtCostingSpotRate');
        var oForwardPoints = document.getElementById(sServerTag+'txtForwardPoints');
        var oContractRate = document.getElementById(sServerTag+'txtCostingRate');
        
        var iSpotRate = new Number(oSpotRate.value);
        var iForwardPoints = new Number(oForwardPoints.value);
        var iContractRate = new Number(oContractRate.value);

        //[*Spot || Fwd] [Spot > 0] [ Fwd > 0] : Costing = Spot + Fwd
        if(((sThis == 'txtCostingSpotRate') || (sThis == 'txtForwardPoints')) && (oSpotRate.value.length != 0) && (oForwardPoints.value.length != 0))
	        oContractRate.value = fnReplaceNull(customround((Number(iForwardPoints) + Number(iSpotRate)),4));
        //[*Spot] [Fwd = 0] : Costing = ""
        if((sThis == 'txtCostingSpotRate') && (oForwardPoints.value.length == 0))
	        oContractRate.value = '';
        //[*Fwd] [Fwd = 0] [Spot > 0] : Costing = ""
        if((sThis == 'txtForwardPoints') && (oForwardPoints.value.length == 0) && (oSpotRate.value.length != 0))
	        oContractRate.value = '';
        //[*Fwd] [Spot = 0] [Costing > 0] : Spot = Costing - Fwd
        if((sThis == 'txtForwardPoints') && (oSpotRate.value.length == 0) && (oContractRate.value.length != 0))
	        oSpotRate.value =  fnReplaceNull(customround((Number(iContractRate) - Number(iForwardPoints)),4));
        //[*Costing] [Fwd > 0] : Spot = Costing - Fwd
        if((sThis == 'txtCostingRate') && (oForwardPoints.value.length != 0))
	        oSpotRate.value =  fnReplaceNull(customround((Number(iContractRate) - Number(iForwardPoints)),4));
        //[*Costing] [Costing > 0] [Fwd = 0] [Spot > 0] : Spot = ""
        if((sThis == 'txtCostingRate') && (oContractRate.value.length != 0) && (oForwardPoints.value.length == 0) && (oSpotRate.value.length != 0))
	        oSpotRate.value = "";

    }    
    
	
	function fnReplaceNull(sValue) {
	
	    if(isNaN(sValue))
	        return '';
	    else
	        return sValue;    
	
	}
	
//	Round variable
	function customround(number,X) {
	try {
	    X = (!X ? 2 : X);
	    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
	}
	catch(e) { alert(e + '\nID: customround\n' + 'Code: ' + (e.number & 0xFFFF) + '\n' + e.description); }
	}	
	
	
    function CheckLength(Obj, iSize){
        LenString = Obj.value.length;
        if (LenString > iSize){
            Obj.value = Obj.value.substring(0,iSize);
        }
    }


//Results Window Scroll Size Control
function xsizeViewport(myObj) {

    myObject = document.getElementById(myObj);

    myObject.style.height = (document.body.clientHeight - 250);

}
function xonResizeHandler() {
    sizeViewport('tblResultsList');
}
function xonLoadHandler() {
    sizeViewport('tblResultsList');
}

function sizeViewport2(myObj) {

    myObject = document.getElementById(myObj);

    myObject.style.height = (document.body.clientHeight - 270);

}
function onResizeHandler2() {
    sizeViewport2('tblResultsList');
}
function onLoadHandler2() {
    sizeViewport2('tblResultsList');
}

function sizeViewport3(myObj) {

    myObject = document.getElementById(myObj);

    myObject.style.height = (document.body.clientHeight - 300);

}
function onResizeHandler3() {
    sizeViewport3('tblResultsList');
}
function onLoadHandler3() {
    sizeViewport3('tblResultsList');
}

function sizeViewport4(myObj) {

    myObject = document.getElementById(myObj);

    myObject.style.height = (document.body.clientHeight - 330);

}
function onResizeHandler4() {
    sizeViewport4('tblResultsList');
}
function onLoadHandler4() {
    sizeViewport4('tblResultsList');
}


function sizeViewport5(myObj) {

    myObject = document.getElementById(myObj);

    myObject.style.height = (document.body.clientHeight - 350);

}
function onResizeHandler5() {
    sizeViewport5('tblResultsList');
}
function onLoadHandler5() {
    sizeViewport5('tblResultsList');
}


function sizeViewport6(myObj) {

    myObject = document.getElementById(myObj);

    myObject.style.height = (document.body.clientHeight - 240);

}
function onResizeHandler6() {
    sizeViewport6('tblResultsList');
}
function onLoadHandler6() {
    sizeViewport6('tblResultsList');
}
//



function sizeViewport(myObj, size) {

    myObject = document.getElementById(myObj);

    if((document.body.clientHeight - size) <= 0)
        myObject.style.height = 200
    else
        myObject.style.height = (document.body.clientHeight - size);

}
//Customer
function onResizeHandlerCustomerList() {
    sizeViewport('tblResultsCustomerList', 180);
}
function onLoadHandlerCustomerList() {
    sizeViewport('tblResultsCustomerList', 180);
}
//Invoice
function onResizeHandlerInvoiceList() {
    sizeViewport('tblResultsInvoiceList', 180);
}
function onLoadHandlerInvoiceList() {
    sizeViewport('tblResultsInvoiceList', 180);
}
//Deal
function onResizeHandlerDealList() {
    sizeViewport('tblResultsDealList', 180);
}
function onLoadHandlerDealList() {
    sizeViewport('tblResultsDealList', 180);
}
//Dealer Client Deal
function onResizeHandlerDealerClientDealList() {
    sizeViewport('tblResultsDealList', 230);
}
function onLoadHandlerDealerClientDealList() {
    sizeViewport('tblResultsDealList', 230);
}
//FA
function onLoadHandlerFAList() {
    sizeViewport('tblResultsFAList', 180);
}
function onResizeHandlerFAList() {
    sizeViewport('tblResultsFAList', 180);
}
//FA
function onLoadHandlerStopList() {
    sizeViewport('tblResultsStopList', 180);
}
function onResizeHandlerStopList() {
    sizeViewport('tblResultsStopList', 180);
}
//Customer Invoices
function onResizeHandlerCustomerInvoiceList() {
    sizeViewport('tblResultsCustomerInvoiceList', 220);
}
function onLoadHandlerCustomerInvoiceList() {
    sizeViewport('tblResultsCustomerInvoiceList', 220);
}
//Customer Orders
function onResizeHandlerCustomerOrderList() {
    sizeViewport('tblResultsCustomerOrderList', 220);
}
function onLoadHandlerCustomerOrderList() {
    sizeViewport('tblResultsCustomerOrderList', 220);
}
// History
function onResizeHandlerHistoryList() {
    sizeViewport('tblResultsHistoryList', 240);
}
function onLoadHandlerHistoryList() {
    sizeViewport('tblResultsHistoryList', 240);
}
//Order Invoicing
function onResizeHandlerOrderInvoiceyList() {
    sizeViewport('tblResultsOrderInvoiceyList', 220);
}
function onLoadHandlerOrderInvoiceyList() {
    sizeViewport('tblResultsOrderInvoiceyList', 220);
}
//Deal Payments
function onResizeHandlerDealPaymentList() {
    sizeViewport('tblResultsDealPaymentList', 300);
}
function onLoadHandlerDealPaymentList() {
    sizeViewport('tblResultsDealPaymentList', 300);
}
//Invoice Payments
function onResizeHandlerInvoicePaymentList() {
    sizeViewport('tblResultsInvoicePaymentList', 290);
}
function onLoadHandlerInvoicePaymentList() {
    sizeViewport('tblResultsInvoicePaymentList', 290);
}
//FA Invoice Payments
function onResizeHandlerFAInvoicePaymentList() {
    sizeViewport('tblResultsFAInvoicePaymentList', 290);
}
function onLoadHandlerFAInvoicePaymentList() {
    sizeViewport('tblResultsFAInvoicePaymentList', 290);
}
//FA Deal Payments
function onResizeHandlerFADealPaymentList() {
    sizeViewport('tblResultsFADealPaymentList', 290);
}
function onLoadHandlerFADealPaymentList() {
    sizeViewport('tblResultsFADealPaymentList', 290);
}
//FA Payments
function onResizeHandlerFAPaymentList() {
    sizeViewport('tblResultsFAPaymentList', 290);
}
function onLoadHandlerFAPaymentList() {
    sizeViewport('tblResultsFAPaymentList', 290);
}
//Bank
function onResizeHandlerBankList() {
    sizeViewport('tblResultsBankList', 160);
}
function onLoadHandlerBankList() {
    sizeViewport('tblResultsBankList', 160);
}
//ZAR Bank
function onResizeHandlerZARBankList() {
    sizeViewport('tblResultsZARBankList', 180);
}
function onLoadHandlerZARBankList() {
    sizeViewport('tblResultsZARBankList', 180);
}
//ZAR Bank Edit
function onResizeHandlerZARBankListEdit() {
    sizeViewport('tblResultsBankListEdit', 180);
}
function onLoadHandlerZARBankListEdit() {
    sizeViewport('tblResultsBankListEdit', 180);
}
//Dealer ZAR Bank Edit
function onResizeHandlerDealerZARBankListEdit() {
    sizeViewport('tblResultsDealerBankListEdit', 200);
}
function onLoadHandlerDealerZARBankListEdit() {
    sizeViewport('tblResultsDealerBankListEdit', 200);
}
//Payment Terms
function onResizeHandlerPaymentTermsList() {
    sizeViewport('tblResultsPaymentTermsList', 160);
}
function onLoadHandlerPaymentTermsList() {
    sizeViewport('tblResultsPaymentTermsList', 160);
}
//Freighter
function onResizeHandlerFreighterList() {
    sizeViewport('tblResultsFreighterList', 160);
}
function onLoadHandlerFreighterList() {
    sizeViewport('tblResultsFreighterList', 160);
}
//Order List
function onResizeHandlerOrderList() {
    sizeViewport('tblResultsOrderList', 150);
}
function onLoadHandlerOrderList() {
    sizeViewport('tblResultsOrderList', 150);
}
//Home
function onResizeHandlerHome() {
    sizeViewport('tblResultsHome', 160);
}
function onLoadHandlerHome() {
    sizeViewport('tblResultsHome', 160);
}
// Profile Currency
function onResizeHandlerProfileCurrencyList() {
    sizeViewport('tblResultsProfileCurrencyList', 290);
}
function onLoadHandlerProfileCurrencyList() {
    sizeViewport('tblResultsProfileCurrencyList', 290);
}
//Admin
function onResizeHandlerAdminList() {
    sizeViewport('tblResultsAdminList', 290);
}
function onLoadHandlerAdminList() {
    sizeViewport('tblResultsAdminList', 290);
}
function onResizeHandlerAdminInvoiceList() {
    sizeViewport('tblResultsAdminInvoiceList', 290);
}
function onLoadHandlerAdminInvoiceList() {
    sizeViewport('tblResultsAdminInvoiceList', 290);
}
function onResizeHandlerAdminCreateInvoice() {
    sizeViewport('tblResultsAdminCreateInvoice', 290);
}
function onLoadHandlerAdminCreateInvoice() {
    sizeViewport('tblResultsAdminCreateInvoice', 290);
}
function onLoadHandlerAdminCreateInvoice() {
    sizeViewport('tblResultsAdminCreateInvoice', 290);
}
function onResizeHandlerStandardList() {
    sizeViewport('tblResultsReport', 200);
}
function onLoadHandlerStandardList() {
    sizeViewport('tblResultsReport', 200);
}
// Dealer Dashboard
function onResizeHandlerDealerDashboardList() {
    sizeViewport('tblResultsDealerDashboardList', 150);
}
function onLoadHandlerDealerDashboardList() {
    sizeViewport('tblResultsDealerDashboardList', 150);
}
// Dealer Deal History
function onResizeHandlerDealerDealHistory() {
    sizeViewport('tblResultsDealerDealHistory', 190);
}
function onLoadHandlerDealerDealHistory() {
    sizeViewport('tblResultsDealerDealHistory', 190);
}
// Dealer List
function onResizeHandlerDealerList() {
    sizeViewport('tblResultsDealerList', 180);
}
function onLoadHandlerDealerList() {
    sizeViewport('tblResultsDealerList', 180);
}
//Dealer Early Pay Deals
function onResizeHandlerEarlyPayDealList() {
    sizeViewport('tblResultsEarlyPayDealList', 625);
}
function onLoadHandlerEarlyPayDealList() {
    sizeViewport('tblResultsEarlyPayDealList', 625);
}
//Dealer Early Pay Invoices
function onResizeHandlerEarlyPayInvoiceList() {
    sizeViewport('tblResultsEarlyPayInvoiceList', 625);
}
function onLoadHandlerEarlyPayInvoiceList() {
    sizeViewport('tblResultsEarlyPayInvoiceList', 625);
}

function onLoadHandlerDealerDealList() {
    sizeViewport('tblResultsDealerDealList', 220);
}
function onResizeHandlerDealerDealList() {
    sizeViewport('tblResultsDealerDealList', 220);
}

function fnDisplayHomeReport(sReport) {

    /*
    document.all.trReport01.style.display = 'none';
    document.all.trReport02.style.display = 'none';
    document.all.trReport03.style.display = 'none';
    document.all.trReport04.style.display = 'none';
    document.all.trReport05.style.display = 'none';
    document.all(sReport).style.display = 'block';
    */    
    
    if(document.all(sReport).style.display == 'block')
        document.all(sReport).style.display = 'none';
    else
        document.all(sReport).style.display = 'block';    

}




