﻿    
    var oGlobal=new Object();
    var oModal=new Object();
    var oFW=window.top;
    
//************************************************************************************************************		
//** B E F O R E   P A G E   L O A D      		
//************************************************************************************************************	
    
    function captureEvents(){
        cancelBubble=true;
        //event.returnValue=false;
        return false;
    }
        
    document.onmousedown = captureEvents;
    document.onselectstart = captureEvents;
    
    oGlobal.cancel_events=' onmousedown="event.cancelBubble=true;event.returnValue=true;" onselectstart="event.cancelBubble=true;event.returnValue=true;" ';
    
     
    // document.onselect = captureEvents;
    // document.ondblclick = captureEvents;
     

//************************************************************************************************************		
//** L O G O F F		
//************************************************************************************************************	
    
    function PerformLogoff() {
    
        PageMethods.callbackLogoff(callbackLogOff);        
    }
    
    function callbackLogOff(stCallbackData) {
    
        var xmlDoc=xmlLoad(stCallbackData);
    }
    
//************************************************************************************************************		
//** X M L   L O A D E R   F U N C T I O N S     		
//************************************************************************************************************	
    
    oGlobal.filters=new Array();
    
    oGlobal.default_error_packet = "<RETURNPACKET>" + 
                                        "<FUNCTION>DEFAULT ERROR PACKET</FUNCTION>" + 
                                        "<STATUS>ERROR</STATUS>" + 
                                        "<TOTALROWS>0</TOTALROWS>" + 
                                        "<TAG></TAG>" + 
                                        "<DATA><COLUMNS><COLUMN></COLUMN></COLUMNS></DATA>" + 
                                        "</RETURNPACKET>"
    
    function xmlLoad(xml_string) { 

        xml_string=unescape(xml_string);
        
        if(document.implementation.createDocument) {    
        
                // ** Firefox 
                var xmlParser = new DOMParser(); 

                var xmlDoc = xmlParser.parseFromString(xml_string, 'text/xml');
            
                var oElement = xmlDoc.evaluate('//STATUS', xmlDoc, null, XPathResult.ANY_TYPE, null);
       
                switch(oElement.iterateNext().textContent.toUpperCase()) {
                
                    case "REDIRECT":
                        window.top.oModal.returnValue='';
                        closeAllPopupWindows();
                        window.top.location.href=xmlDoc.evaluate('//REDIRECTURL', xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;   
                        return;
                        break;

                    case "ERROR":
                        window.top.oModal.returnValue='';
                        closeAllPopupWindows();

                        if(oGlobal.root) {
                            // ** ROOT default page
                            window.top.location.href=oGlobal.root+"/Content/Error/Default.aspx?ERR="+xmlDoc.evaluate('//ERRORMSG', xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
                        }
                        else {
                            // ** ALL Content pages
                            window.top.location.href="../../Content/Error/Default.aspx?ERR="+xmlDoc.evaluate('//ERRORMSG', xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
                        }
                        xmlDoc = xmlParser.parseFromString(oGlobal.default_error_packet, 'text/xml');
                        break;
                }
        } 
        else { 
                
                // ** Internet Explorer
                var xmlDoc = new ActiveXObject('Microsoft.XMLDOM'); 
        
                xmlDoc.async = false; 
  
                var loadResult = xmlDoc.loadXML(xml_string); 
  
                if (!loadResult){
		            alert('XML Load Error!\nXML failed to load.\nCode:' + xmlDoc.parseError.errorCode + ", " + xmlDoc.parseError.reason);
		            return oGlobal.default_error_packet;
		        }
      
                switch(xmlDoc.selectSingleNode('//STATUS').text) {
                
                    case "REDIRECT":
                        window.top.oModal.returnValue='';
                        closeAllPopupWindows();
                        window.top.location.href=xmlDoc.selectSingleNode('//REDIRECTURL').text;     
                        return;
		                break;
                    
                    case "ERROR":
                        window.top.oModal.returnValue='';
                        closeAllPopupWindows();
                        
                        if(oGlobal.root) {
                            // ** ROOT default page
                            window.top.location.href=oGlobal.root+"/Content/Error/Default.aspx?ERR="+xmlDoc.selectSingleNode('//ERRORMSG').text;
                        }
                        else {
                            // ** ALL Content pages
                            window.top.location.href="../../Content/Error/Default.aspx?ERR="+xmlDoc.selectSingleNode('//ERRORMSG').text;
                        }
                        xmlDoc.loadXML(oGlobal.default_error_packet);
                        break;
                }
        } 
        
        if(document.getElementById('xmlData')) {
            
            document.getElementById('xmlData').value=xml_string;
        }
        
        return xmlDoc;
    } 
    
    function getSingleNodeText(el, xmlDoc) {
        
        var strReturn="";
        
        if(document.implementation.createDocument) {    
        
            if(xmlDoc.evaluate(el, xmlDoc, null, XPathResult.ANY_TYPE, null)) {
        
                return xmlDoc.evaluate(el, xmlDoc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;
            }
        }
        else {
        
            if(xmlDoc.selectSingleNode(el)) {
	            
	            return xmlDoc.selectSingleNode(el).text;     
	        }
        }
        
        strReturn="";
    }
    
    function getSingleNodeAttribute(el, attrib, xmlDoc, xmlRow) {
        
        var strReturn="";
        
        try {
        
            if(document.implementation.createDocument) {    
                
                if(xmlRow) {
                    return xmlDoc.evaluate('@'+attrib, xmlRow, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent;
                }
                else {
                    return xmlDoc.evaluate(el+((el=='')?'':'/')+'@'+attrib, xmlDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent;
                }    
            }
            else {
                
                if(el=='') {
                    return xmlDoc.getAttribute(attrib);     
                }
                else {
                    return xmlDoc.selectSingleNode(el).getAttribute(attrib);     
                }
            }
        }
        catch(e){}
	    
        return strReturn; 
    }
    
    function setInnerHTML(strPassID, strValue) {
        
        if(!document.getElementById(strPassID)) return;
        
        var el=document.getElementById(strPassID);
        
        if(document.implementation.createDocument) {   
            
            // On other browsers may need to use create code
            //el.textContent=strValue;
            el.innerHTML=strValue;
        }
        else {
            el.innerHTML=strValue;
        }
    }
    
    function setInnerText(strPassID, strValue) {
        
        var el=document.getElementById(strPassID);
        
        if(document.implementation.createDocument) {   
            
            el.textContent=strValue;
        }
        else {
            el.innerText=strValue;
        }
    }
    
    function getInnerText(strPassID) {
        
        var el=document.getElementById(strPassID);
        
        if(document.implementation.createDocument) {   
            
            return el.textContent;
        }
        else {
            return el.innerText;
        }
    }
      
    function getObjectInnerText(el) {
   
        if(document.implementation.createDocument) {   
            
            return el.textContent;
        }
        else {
            return el.innerText;
        }
    }

//************************************************************************************************************		
//** W I N D O W   F U N C T I O N S     		
//************************************************************************************************************	
    
    oGlobal.action_post_evaluate='';
    oGlobal.init_process=true;
    oGlobal.store_ref='';
        
    function actionGrid(s_type, s_value) {
		
  		if(s_value=='') {
  		    alert('No criteria passed, action was not performed');
  		    return;
  		}
  		
  		oGlobal.store_ref=s_value;
  	
	    switch(s_type) {
		    
		    case "ADD_DELIVERY_ADDRESS":
		        openIframeWindow(s_type, '../DeliveryAddressAdd/Default.aspx');    
		        break;
		        
		    case "AMEND_DELIVERY_ADDRESS":
		        openIframeWindow(s_type, '../DeliveryAddressAmend/Default.aspx?DELID='+s_value);    
		        break;
		    
		    case "BATCH":
		        openIframeWindow('BATCH_DETAILS', '../ViewProductDetails/Default.aspx?PRODUCT_CODE='+s_value.split('|')[0]+'&FREESTOCK='+s_value.split('|')[1]);
			    break;
		    
		    case "CUSTOMERSTATS":
		        window.top.location.href=oGlobal.root+'/Content/StatsProdCollByCust/Default.aspx?CUST_ID='+s_value;    
		        break;    
		    
		    case "DELETE_DELIVERY_ADDRESS":    
		        if(confirm('Are you sure you want to delete delivery address '+s_value+'?'))
		        {
		            PageMethods.callbackDeleteDeliveryAddress(s_value, createReport, callbackError); 
		        }
		        break;
		    
		    case "DELREF":
			    openIframeWindow(s_type, '../ViewDeliveryDetails/Default.aspx?DEL_REF='+s_value);
			    break;
		    
		    case "INVOICE":
		        openIframeWindow(s_type, '../ViewInvoiceDetails/Default.aspx');
			    break;
			
			case "ORDER":
			
			    //KW 25/02/2008 Close and return to parent if the following occurs:
			    //              1.  User opens order details and clicks product details link
			    //              2.  User clicks link to same order from product details
			    //              Previously this ended up in an error or a blank screen
			    if (parent.oGlobal.work_order_ref != s_value) {
			        openIframeWindow(s_type, '../ViewOrderDetails/Default.aspx?ORDER_REF='+s_value);
			    }
			    else {
			        //Call the closeIframeWindow method on the parent to close the current Order iframe
			       parent.closeIframeWindow();
			       
			       //Reload the product
			       //parent.productTab();
			    }
			
			    break;
			    
			case "PLACEORDER":
			    // ** Adds an order line
			    oGlobal.action_post_evaluate='actionGrid("PLACEORDER", "'+s_value+'");';

			    if(checkCustomerGlobal()==true) {
			        oGlobal.action_post_evaluate='';
			        openIframeWindow('ORDERLINEADD', '../OrderEntryLine/Default.aspx?ITEM_ID='+s_value+'&ORDER_TYPE=N&LINE_NO=*&RELOAD=N');
		        }
		        break;    
		        
		    case "REQUESTSAMPLE":
		        oGlobal.action_post_evaluate='actionGrid("REQUESTSAMPLE", "'+s_value+'");';
			    if(checkCustomerGlobal()==true) {
			        oGlobal.action_post_evaluate='';
		            openIframeWindow('ORDERLINEADD', '../OrderEntryLine/Default.aspx?ITEM_ID='+s_value+'&ORDER_TYPE=Y&LINE_NO=*&RELOAD=N');
		        }
		        break;
		    
		    case "ORDERCONFIRM":
		   	    openIframeWindow(s_type, '../OrderEntryConfirm/Default.aspx?DEL_ID='+s_value);
		        break;
		            
			case "ORDERLINEADD":
			    var arrOrder=s_value.split('|');
			    
			    var s_load_location='N';
	 
			    if(arrOrder[2]) {
			        // ** Loaded from framework
			        s_load_location='Y';
			    }
			    
			    openIframeWindow(s_type, '../OrderEntryLine/Default.aspx?ITEM_ID='+arrOrder[0]+'&ORDER_TYPE='+arrOrder[1]+'&LINE_NO=*&RELOAD=Y&FRMWRK='+s_load_location);
		        break;
			    
			case "ORDERLINEAMEND":
			    // ** BASKET PROCESS
			    var arrOrder=s_value.split('|');
			    openIframeWindow(s_type, '../OrderEntryLine/Default.aspx?ITEM_ID=*&ORDER_TYPE='+arrOrder[1]+'&LINE_NO='+arrOrder[0]+'&RELOAD=Y');
			    break;
			
			case "ORDERLINEDELETE":
			    // ** BASKET PROCESS
			    if(confirm(oML.PromptOrderDeleteLine.replace(/%1/,s_value))) {
			        oGlobal.delete_line=true;
			        PageMethods.callbackDeleteLineFromBasket(s_value, s_value, reloadBasket, callbackError); 
			    }
			    break;
			
			case "ORDERLINEDELETESILENT":
			    // ** CALLED WHEN CANCELLING THE ADDITION OF A LINE ALLOCATED ACROSS BATCHES
			    //    THIS IS NEEDED BECAUSE LINE IS ALWAYS ADDED BEFORE USER SEES DIALOG
			    oGlobal.delete_line=true;
			    PageMethods.callbackDeleteLineFromBasket(s_value, s_value, reloadBasket,callbackError);
			    break;
			
			case "ORDERPRODUCTSEARCH":    
			    openIframeWindow(s_type, '../OrderEntryProductSearch/Default.aspx?ORDER_TYPE='+s_value);
			    break;
			
			case "ORDERDELIVERYADDRESS":
			    openIframeWindow(s_type, '../OrderEntryDeliveryAddress/Default.aspx');
			    break;
			    
			case "PRODUCT":
			    //KW 25/02/2008 Close and return to parent if the following occurs:
			    //              1.  User opens product details and clicks order details link
			    //              2.  User clicks link to same product from order details
			    //              Previously this ended up in an error or a blank screen
			    if (parent.oGlobal.product_code != s_value) {
			        openIframeWindow(s_type, '../ViewProductDetails/Default.aspx?PRODUCT_CODE='+s_value);
			    }
			    else {
			        //Call the closeIframeWindow method on the parent to close the current Order iframe
			       parent.closeIframeWindow();
			       
			       //Reload the product
			       parent.productTab();
			    }
			    break;
			
			case "PARCEL":
			    PageMethods.callbackCountParcelEntries(s_value, s_value, callbackParcel, callbackError);    
			    break;
			    
			case 'PARCELURL':
			    openIframeWindow(s_type, s_value);
			    break;
			    
			case 'RESERVEACTION':
			    var arrWork=s_value.split('|');
	            
	            oGlobal.orginal_value=s_value;
			    oGlobal.reserve_order_no=arrWork[0];
			    oGlobal.reserve_order_line_no=arrWork[1];
			    oGlobal.reserve_product_code=arrWork[2];
			    oGlobal.reserve_action=arrWork[3];
			    oGlobal.reserve_qty=arrWork[4];
			    oGlobal.reserve_qty_suffix=arrWork[5];
			    oGlobal.reserve_ordref=arrWork[6];
			    oGlobal.reserve_grid_line_no=arrWork[7];
	
			    openIframeWindow(s_type, '../ReserveAction/Default.aspx');
			    break;
			    
            case "STATS_COLLECTION":
                openIframeWindow(s_type, '../ViewStatsDetails/Default.aspx?COLLECTION_CODE='+escape(s_value));
                break;

            case "CHANGE_PASSWORD":
                // ** NOT CALLED FROM GRID - USED FOR CONVENIENCE
                if(window.location.href.toUpperCase().indexOf('/CONTENT/') > -1) {
                    openIframeWindow(s_type, '../ChangePassword/Default.aspx');
                }
                else {
                    openIframeWindow(s_type, 'Content/ChangePassword/Default.aspx');
                }
                break;
                
            case "VIEWCOLLECTION":
                // ** Called from Product View to load framework collection page
                //window.top.location.href='../CollectionEnquiry/Default.aspx?REF='+s_value;    
                window.open('../CollectionEnquiry/Default.aspx?REF='+s_value, '','menubar=no,scrollbars=no,height=700px,width=800px');  
                break;
	    }
    }
    
    function callbackParcel(stCallbackData) {
    
        var xmlDoc = xmlLoad(stCallbackData);
    
        var oWork=new Object();
      
        oWork.totalRows=parseInt(getSingleNodeText('//TOTALROWS', xmlDoc),10);
        oWork.tag=getSingleNodeText('//TAG', xmlDoc);
        oWork.url=getSingleNodeText('//URL', xmlDoc);
     
        if(oWork.totalRows > 1) {
            openIframeWindow('PARCEL', '../ViewTrackingDetails/Default.aspx?REF='+escape(oWork.tag));
        }
        else {
            openIframeWindow('PARCELURL', oWork.url);
        }
    }
    
    function openIframeWindow(s_window, s_path) {
        
        if(s_window=='') {
            alert('Open Window');
            return;
        }
        
        s_size='';
        
        document.getElementById('ifrPlaceHolder').innerHTML='';
        document.getElementById('ifrPlaceHolder').innerHTML='<center><iframe id="ifrModal" name="ifrModal" src="" allowtransparency="true" class="modal" style="height:0px;width:0px;" scrolling="no" frameborder="0"></iframe></center>';
                
        oWin=document.getElementById('ifrModal');
        oModal.window=s_window;
        oModal.open=true;
        oModal.returnValue='';
        
        maintainFilters(false);
        
        switch(s_window) {
            
            case 'ADD_DELIVERY_ADDRESS':
                oWin.style.height='450px';
                oWin.style.width='490px';
                s_size='?WIDTH=490&HEIGHT=400';
                break;
            
            case 'AMEND_DELIVERY_ADDRESS':
                oWin.style.height='450px';
                oWin.style.width='490px';
                s_size='&WIDTH=490&HEIGHT=400';
                break;
                
            case 'BATCH_DETAILS':
                oWin.style.height='575px';
                oWin.style.width='675px';
                s_size='&WIDTH=675&HEIGHT=575';
                s_path=s_path+'&TAB=BATCH';
                break;
                
            case 'CHANGE_PASSWORD':
                oWin.style.height='285px';
                oWin.style.width='400px';
                s_size='?WIDTH=400&HEIGHT=235';
                break;
                
            case 'CUSTOMER_PRODUCT':
                // ** Modification required for changing customer via Product window
                oModal.window='CUSTOMER'; 
                oFW.oGlobal.store_customer_reference=oFW.oGlobal.customer_reference;
                oFW.oGlobal.selected_customer_reference='';
                
                s_path=s_path+"?CUST_STATS=N"
                
                oWin.style.height='500px';
                oWin.style.width='650px';
                s_size='&WIDTH=650';
                break;    
            
            case 'CUSTOMER':
                oGlobal.store_customer_reference=oGlobal.customer_reference;
                oGlobal.selected_customer_reference='';
                
                s_path=s_path+"?CUST_STATS=N"
                
                oWin.style.height='500px';
                oWin.style.width='650px';
                s_size='&WIDTH=650';
                break;
                
            case 'CUSTOMER_STATS':
                // ** Special call of the customer window that returns 
                // ** a customer reference  
                s_path=s_path+"?CUST_STATS=Y"
                
                oWin.style.height='500px';
                oWin.style.width='650px';
                s_size='&WIDTH=650';
                break;
                
            case 'DELIVERY_ADDRESS':
                oWin.style.height='550px';
                oWin.style.width='675px';
                s_size='?WIDTH=675&HEIGHT=500';
                break;
                
            case 'DELREF':
                oWin.style.height='550px';
                oWin.style.width='500px';
                s_size='&WIDTH=500&HEIGHT=250';
                break;
            
            case 'INVOICE':
                // ** IE7 - Does not allow the status/address bar to be hidden, new security feature
                //if(document.implementation.createDocument) {  
                    window.open(unescape(s_path),s_window,'location=no,toolbar=no,directories=no,resizable=yes,scrollbars=no'); 
                //}
                //else {
                //    var arguments=new Object();
                //    window.showModelessDialog(unescape(s_path),arguments,'maximize=yes;center=yes;scroll=no;status=no;resizable=yes;help=no;dialogHeight=575px;dialogWidth=650px;')
                //}
                return; 
                break;
                
            case 'ORDER':
                oWin.style.height='550px';
                oWin.style.width='675px';
                s_size='&WIDTH=675';
                break;
                
            case 'ORDERCONFIRM':
                oModal.window='ORDERCONFIRM';
                oWin.style.height='575px';
                oWin.style.width='675px';
                s_size='&WIDTH=675&HEIGHT=500';
                break;
            
            case 'ORDERLINEADD':
                oWin.style.height='550px';
                oWin.style.width='675px';
                s_size='&WIDTH=675&HEIGHT=500';
                break;
            
            case 'ORDERLINEAMEND':
                oWin.style.height='550px';
                oWin.style.width='675px';
                s_size='&WIDTH=675&HEIGHT=500';
                break;
            
            case 'ORDERPRODUCTSEARCH':
                oWin.style.height='550px';
                oWin.style.width='675px';
                s_size='&WIDTH=675&HEIGHT=500';
                break;
            
            case 'ORDERDELIVERYADDRESS':
                oModal.window='ORDERDELIVERYADDRESS';
                oWin.style.height='575px';
                oWin.style.width='675px';
                s_size='?WIDTH=675&HEIGHT=500';
                break;
            
            case 'PARCEL':
                oWin.style.height='550px';
                oWin.style.width='575px';
                s_size='&WIDTH=575&HEIGHT=250';
                break;
            
            case 'PATTERN_BOOK_SEARCH':
                // ** Special search from the Pattern Book Sales Analysis to return a valid Product Code
                oWin.style.height='550px';
                oWin.style.width='675px';
                s_size='?WIDTH=675&HEIGHT=500';
                break;
                
            case 'PRODUCT':
                oWin.style.height='575px';
                oWin.style.width='675px';
                s_size='&WIDTH=675&HEIGHT=575';
                break;
            
            case 'PARCELURL':
                window.open(unescape(s_path),s_window,'toolbar=yes,directories=no,resizable=yes'); 
                return;    
                break;
                
            case 'RESERVEACTION':
                oWin.style.height='550px';
                oWin.style.width='675px';
                s_size='?WIDTH=675&HEIGHT=500';
                break;
            
            case "STATS_COLLECTION":
                oWin.style.height='550px';
                oWin.style.width='675px';
                s_size='&WIDTH=675&HEIGHT=500';
                break;
        }
        
        if(window.name=='') {
            oLock=document.getElementById('divLock');
            showLayer(oLock, true);
        }
        else {
            hideLayer(document.getElementById('tblMain'));
        }
        
        var pnode = oWin.parentNode;
        var parentIsIFRAME = false;
        
        if(oWin.ownerDocument.location.href.indexOf('OrderEntryDeliveryAddress') > -1) parentIsIFRAME = true;
        if(oWin.ownerDocument.location.href.indexOf('OrderEntryConfirm') > -1) parentIsIFRAME = true;
        if(oWin.ownerDocument.location.href.indexOf('ViewDeliveryDetails') > -1) parentIsIFRAME = true;
        if(oWin.ownerDocument.location.href.indexOf('ViewInvoiceDetails') > -1) parentIsIFRAME = true;
        if(oWin.ownerDocument.location.href.indexOf('ViewOrderDetails') > -1) parentIsIFRAME = true;
        if(oWin.ownerDocument.location.href.indexOf('ViewProductDetails') > -1) parentIsIFRAME = true;
        if(oWin.ownerDocument.location.href.indexOf('ViewStatsDetails') > -1) parentIsIFRAME = true;
        if(oWin.ownerDocument.location.href.indexOf('ViewTrackingDetails') > -1) parentIsIFRAME = true;
        
        if(parentIsIFRAME==false){
            oWin.style.top=(document.body.clientHeight-parseInt(oWin.style.height,10))/2;
        
            if(parseInt(oWin.style.top,10) < 11) oWin.style.top = '11px';
       
            oWin.style.left=(document.body.clientWidth-parseInt(oWin.style.width,10))/2;        
       
            if(parseInt(oWin.style.left,10) < 50) oWin.style.left = '50px';
       }
       else{
           oWin.style.top=0;
           oWin.style.left=0;
       }
       
        oWin.src=s_path+s_size;
        showLayer(oWin);
    }
    
    function closeIframeWindow() {
        
        try {
            if(window.name=='') {
                hideLayer(document.getElementById('divLock'), true);
            }
            
            // ** CLEAR IFRAME
            hideLayer(document.getElementById('ifrModal'));
            
            oModal.open=false;
            maintainFilters(true);
            
            switch(oModal.window) {
                
                case 'ADD_DELIVERY_ADDRESS':
                
                    // ** If a new address has been added refresh the list
                    if(oModal.returnValue!='') {
                    
                        oGrid.inp01=oModal.returnValue;
                        oGrid.inp02='';
                        oGrid.inp03='';
                        
                        createReport(oGrid.reportType, oGrid.reportTitle);
                    }
                    break;
                    
                case 'AMEND_DELIVERY_ADDRESS':
                
                    // ** If an address has been amended refresh the list
                    if(oModal.returnValue!='') {
                    
                        oGrid.inp01='';
                        oGrid.inp02='';
                        oGrid.inp03='';
                        
                        createReport(oGrid.reportType, oGrid.reportTitle);
                    }
                    break;
                    
                case 'CUSTOMER':
                   
                    if(oFW.oGlobal.selected_customer_reference!='') {
                 
                        if(oFW.oGlobal.store_customer_reference!=oFW.oGlobal.selected_customer_reference) {
                            // ** RELOAD - Main window to refresh the customer details
                            if(oFW.document.getElementById('tdCustomerDetails')) {
                                oGlobal.work=oFW.oGlobal.customer_reference+'&nbsp;-&nbsp;'+oFW.oGlobal.customer_name;
                                oFW.setInnerHTML('tdCustomerDetails', oGlobal.work);
                            }
                            else {
                                oFW.location.reload(true);
                            }
                        }
                    }
                    
                    // ** If a function was required to run once the customer has changed
                    
                    if(oGlobal.cust_post_evaluate) {
                        eval(oGlobal.cust_post_evaluate);
                    }
                    else if(oGlobal.action_post_evaluate){
                        eval(oGlobal.action_post_evaluate);
                    }
                    break;
                
                case 'CUSTOMER_STATS':
                    // ** Call Return Function on Product Collection - By Customer
                    selectCustomerCollection(oModal.returnValue);    
                    break;
                    
                case 'ORDERLINEADD':
                    // ** Check response and process
                    if(oModal.returnValue=='RELOAD') reloadPageLocally();
                    oGlobal.report_processing=false;
                    break;
                    
                case 'ORDERLINEAMEND':
                    // ** Check response and process
                    if(oModal.returnValue=='RELOAD') reloadPageLocally();
                    break;
                    
                case 'ORDERPRODUCTSEARCH':
                    // ** If the search returns a product code, load the order line window
                    if(oModal.returnValue!='') {
                        //actionGrid('ORDERLINEADD', oModal.returnValue);
                        
                        var arrWork=oModal.returnValue.split('|');
                        document.getElementById('inpproductcode').value=arrWork[0];
                        oGlobal.work_product_code=document.getElementById('inpproductcode').value;
                        getOrderLineDetails();
                        return;
                    } 
                    oGlobal.report_processing=false;
                    break;
                
                case 'ORDERDELIVERYADDRESS':
                    if(oModal.returnValue=='RELOAD') window.top.location.reload(true);
                    break;
                    
                case 'ORDERCONFIRM':
                    if(oModal.returnValue=='RELOAD') window.top.location.reload(true);
                    break;
                    
                case 'PATTERN_BOOK_SEARCH':
                    // ** Special search from the Pattern Book Sales Analysis to return a valid Product Code
                    selectPatternBookCode(oModal.returnValue);
                    break;

                case 'RESERVEACTION':
                    if(oModal.returnValue!='') {
                    
                        // ** REMOVE the line from the grid.
                        var arrReturn=oModal.returnValue.split("|");
                        
                        switch(arrReturn[0]) {
                        
                            case "CONFIRM":
                                alert(oML.PromptOrderLineReleased);
                                break;
                                
                            case "AMEND":
                                alert(oML.PromptOrderLineAmended);
                                break;
                                
                            case "CANCEL":
                                alert(oML.PromptOrderLineCancelled);
                                break;
                        }
                        
                        if(arrReturn[0]=='AMEND') {
                            
                            gridUpdateCellValue(2, arrReturn[1]+'&nbsp;'+oGlobal.reserve_qty_suffix);
                            gridUpdateCellValue(5, arrReturn[2]);
         
                            var arrWork=new Array();
                            
                            arrWork[arrWork.length]=oGlobal.reserve_order_no;
                            arrWork[arrWork.length]=oGlobal.reserve_order_line_no;
                            arrWork[arrWork.length]=oGlobal.reserve_product_code;
                            arrWork[arrWork.length]=oGlobal.reserve_action;
                            arrWork[arrWork.length]=arrReturn[1];
                            arrWork[arrWork.length]=oGlobal.reserve_qty_suffix;
                            arrWork[arrWork.length]=arrReturn[2];
                            arrWork[arrWork.length]=oGlobal.reserve_grid_line_no;
         
                            var oTable=document.getElementById('tblGrid'); 
                            var strID=oTable.getAttribute('selectedrow');
       
                            if(strID!='') {
                         
                                var oSelected=document.getElementById(strID);
                                oSelected.childNodes[7].childNodes[0].childNodes[0].href="JavaScript: actionGrid('RESERVEACTION','"+arrWork.join("|")+"')";
                            }                                                                                            
                            
                        }
                        else {
                            oGrid.result_count_01=oGrid.result_count_01-1;
	   	                    oGrid.result_count_02=oGrid.result_count_02-1;
                            
                            oGrid.work=oGrid.resultsText;
                            oGrid.work=oGrid.work.replace(/%1/,oGrid.result_count_01);
	   	                    oGrid.work=oGrid.work.replace(/%2/,oGrid.result_count_02);
                            
                            setInnerHTML('tdActionResults', oGrid.work);
                            
                            document.getElementById('tblGrid').deleteRow(document.getElementById('trGrid'+oGlobal.reserve_grid_line_no).rowIndex);
                            gridClearSelected();
                        }
                    }
                    break;
                    

            }
          
            if(window.name!='') {
                showLayer(document.getElementById('tblMain'));
            }
         
            oModal.window='';
        }
        catch(e){
        }
    }
    
    function closeAllPopupWindows() {
    
        try{
            if(window.name!='') {
		
		        if(window.top.ifrModal.src!='') {
        
                    window.top.closeIframeWindow();
                }    
            }
        }
        catch(e) {}
    }
    
//************************************************************************************************************		
//** G E N E R A L   F U N C T I O N S     		
//************************************************************************************************************	
    
    oGlobal.print_ind=0;
    
    function printGrid(sPlaceholder, sReport) {
        
        document.getElementById(sPlaceholder).innerHTML='';
        
        var arrReport=sReport.split('|');
        
        var arrHTML=new Array();
        
        arrHTML[arrHTML.length]='<link title="printCSS" rel="stylesheet" type="text/css" href="../../css/printReport.css" />';
        arrHTML[arrHTML.length]='<center>';
        arrHTML[arrHTML.length]='<img src="../../img/header.jpg">';
        
        for(var i=0;i<arrReport.length;i++) {
            var val = document.getElementById(arrReport[i]).innerHTML;
            val = val.replace(/<\/tbody>/g,'');
            val = val.replace(/<tfoot>/g,'');
            val = val.replace(/<\/tfoot>/g,'<\/tbody>');
            arrHTML[arrHTML.length]=val;
        }

        if(document.getElementById('divActionResults')) {
            arrHTML[arrHTML.length]=document.getElementById('divActionResults').innerHTML;
        }
        
        arrHTML[arrHTML.length]='</center>';
        
        oGlobal.print_ind++;
        oGlobal.print_window='ifrPrint'+oGlobal.print_ind
        
        document.getElementById(sPlaceholder).innerHTML='<iframe id="'+oGlobal.print_window+'" name="'+oGlobal.print_window+'" style="height:0px;width:0px;" frameborder="0"></iframe>';
        
        var oWin=eval(oGlobal.print_window)
                 
        oWin.document.open();
        oWin.document.write(arrHTML.join(''));
        oWin.document.close();
        oWin.focus();

        window.setTimeout('printReport('+oGlobal.print_window+');',500);
    }
    
    function printReport(sID) {

        var oWin=eval(sID)
 
        oWin.focus();
        oWin.print();
    }
    
    oGlobal.copy_ind=0;
    
    function copyGrid(sPlaceholder, sReport , sReportTitle) {
        
        document.getElementById(sPlaceholder).innerHTML='';
        
        var arrReport=sReport.split('|');
        
        var arrHTML=new Array();
        
        //Setup the header for the copy and paste window
        arrHTML[arrHTML.length]='<HTML>';
        arrHTML[arrHTML.length]='<HEAD>';
        arrHTML[arrHTML.length]='<TITLE><WebTex> - Copy Report</TITLE>'
        
        //KW 03/04/2008 Use relative address for stylesheet
        arrHTML[arrHTML.length]='<link title="printCSS" rel="stylesheet" type="text/css" href="../../css/report.css" />';
        arrHTML[arrHTML.length]='<style>.grid_header_truncate {padding-right:0px !important;}</style>';
        arrHTML[arrHTML.length]='<style>TABLE {width:75% !important;}</style>';
        
        //KW 15/01/2008 Force column C1 to padd 10px if required
        arrHTML[arrHTML.length]='<style>#C1 {_padding-left:10px !important;}</style>';
        
        //Add the following row to make copying from here easier to see!!!
        //arrHTML[arrHTML.length]='<style>TD {background-color: rgb(253, 253, 190) !important;}</style>';
        arrHTML[arrHTML.length]='<script type="text/javascript" language="JavaScript">function mouseOverEvent(obj){return;}</script>';
        arrHTML[arrHTML.length]='<script type="text/javascript" language="JavaScript">function mouseOutEvent(obj){return;}</script>';
        arrHTML[arrHTML.length]='<script type="text/javascript" language="JavaScript">function mouseClickEvent(obj){return;}</script>';
        arrHTML[arrHTML.length]='<script type="text/javascript" language="JavaScript">function sortReport(obj){return;}</script>';
        arrHTML[arrHTML.length]='<script type="text/javascript" language="JavaScript">function actionGrid(obj, obj2){return;}</script>';
        arrHTML[arrHTML.length]='</HEAD>'
        arrHTML[arrHTML.length]='<BODY>'
        arrHTML[arrHTML.length]='<center>';
        arrHTML[arrHTML.length]='<img src="../../img/header.jpg">';
        arrHTML[arrHTML.length]='<BR><span class="report_header">'+sReportTitle+'</span>';
        
        //Copy the report to an array.
        
        for(var i=0;i<arrReport.length;i++) {
                        
            arrHTML[arrHTML.length]=document.getElementById(arrReport[i]).innerHTML;
        }

        arrHTML[arrHTML.length]='</center>';
        arrHTML[arrHTML.length]='</BODY>'
        arrHTML[arrHTML.length]='</HTML>'
        
        //Launch the copy window
        copyReport(arrHTML);
        
    }
    
    function copyReport(arrReport) {
    
        //Replace any DIVs and As  (globally and case insensitive)
        for(var i=0;i<arrReport.length;i++) {
            arrReport[i] = arrReport[i].replace(/<div/ig,'<d1v');
            arrReport[i] = arrReport[i].replace(/<\/div>/ig,'</d1v>');
            arrReport[i] = arrReport[i].replace(/<a/ig,'<a1');
            arrReport[i] = arrReport[i].replace(/<\/a>/ig,'</a1>');
        }

        if (parseInt(navigator.appVersion.charAt(0))>=4){
            var isNN=(navigator.appName=="Netscape")?1:0;
            var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
        }
        
        var optNN='scrollbars=yes';
        var optIE='scrollbars=yes,resizable=yes,top=50,left=50,width='+(window.screen.availWidth-100)+',height='+(window.screen.availHeight-100);
        var copy = '';
        
        if (isNN) copy = window.open('about:blank');
        if (isIE) copy = window.open('about:blank','',optIE);
        
        copy.document.writeln(arrReport.join(''));
        copy.document.close();
        
    }
    
    function maintainFilters(bVisible) {
        
        window.clearTimeout(filterTimer);  
        
        if(document.all) {
            
            if(bVisible) {
                
                // ** Stops the re-show until modal has been closed 
                if(oModal.open) return;
                
                for(var i=0;i<oGlobal.filters.length;i++) {
                    showLayer(oGlobal.filters[i],true);
                }
            }
            else {
            
                for(var i=0;i<oGlobal.filters.length;i++) {
                    hideLayer(oGlobal.filters[i],true);
                }
            }
        }
    }
    
    function buildBullet(s_type) {
        
        var arrHTML=new Array();
        
        arrHTML[arrHTML.length]='<td style="padding:0 3 0 3;" valign="middle">';
        arrHTML[arrHTML.length]='<table cellpadding="0" cellspacing="0" border="0">';
        arrHTML[arrHTML.length]='<tr>';
        arrHTML[arrHTML.length]='<td class="bullet"><img src="../../img/bullet.gif" class="'+s_type+'" border=0 /></td>';
        arrHTML[arrHTML.length]='</tr>';
        arrHTML[arrHTML.length]='</table>';
        arrHTML[arrHTML.length]='</td>';
        
        return arrHTML.join('');
    } 
    
    function selectQuestion(el, event) {
        
        oUL=document.getElementById('reportCriteria');
        
        for(var i=0;i<oUL.childNodes.length;i++) {
        
            if(oUL.childNodes[i].tagName=="LI") {
                
                oUL.childNodes[i].style.backgroundImage='none';            
            }
        }
     
        window.setTimeout("document.getElementById('"+el.id+"').style.backgroundImage='url(../../img/arrow-right.gif)';",0);
        
        event.cancelBubble=true;
    }
    
    function processClick(el) {
        
        try {
	 
	        if(window.addEventListener){ 
	            var Event = document.createEvent('MouseEvents');
	            Event.initEvent('click', false, false);
	            document.getElementById(el).dispatchEvent(Event);
		    }
	        else {
	        
	            document.getElementById(el).click();
	        }
	    }
	    catch(e){}
	}
    
    function setAttachEvents(element, event_name, func) {

        if(window.addEventListener){ 
            element.addEventListener(event_name, eval(func), false);
        }
        else {
		    event_name='on'+event_name;
		    element.attachEvent(event_name, eval(func));
		}
    }
    
    function cancelEvent() {
		    
	    try {
		    event.cancelBubble=true;
		    event.returnValue=false;
		}
		catch(e){}
	}
	
	function buildCustomerHeader(xmlDoc) {
        
        oGlobal.customer_allow_change=((getSingleNodeAttribute('//SELECTEDCUSTOMER', 'ALLOWEDTOCHANGE', xmlDoc).toUpperCase()=='TRUE')?true:false);
        oGlobal.customer_reference=getSingleNodeAttribute('//SELECTEDCUSTOMER', 'CUSTREF', xmlDoc);
        oGlobal.customer_name=getSingleNodeAttribute('//SELECTEDCUSTOMER', 'CUSTNAME', xmlDoc);
        oGlobal.customer_type=getSingleNodeAttribute('//SELECTEDCUSTOMER', 'CUSTTYPE', xmlDoc);
            
        if(oGlobal.customer_reference=='') {
            oGlobal.work='&nbsp;';
        }
        else {
            oGlobal.work=oGlobal.customer_reference+'&nbsp;-&nbsp;'+oGlobal.customer_name;
        }
                
        setInnerHTML('tdCustomerDetails', oGlobal.work);
        
        if(!oGlobal.customer_allow_change) {
            hideLayer(document.getElementById('tdCustomerChange'));
        }
        
        oGlobal.work='';
    }
	
    function toggleCriteria(arg1, arg2) {
			
		var oToggle=document.getElementById("spn"+arg1+"Expander");
		var oCriteria=document.getElementById(arg2+"Criteria");
		var oInput=document.getElementById("input"+arg1); 
		
		hideLayer(oInput);
		
		if(oCriteria.style.display=='none') {
		
			showLayer(oCriteria);
			oToggle.style.backgroundImage='url(../../img/mnu_minus.gif)';
		}
		else {
			hideLayer(oCriteria);
			oToggle.style.backgroundImage='url(../../img/mnu_plus.gif)';
			
			if(document.getElementById('divCriteria')) {
			
			    // ** Mkae sure the input placeholder is closed 
			    hideLayer(document.getElementById('divCriteria'));
			}
    	}
	}
	
	function showLayer(obj, blnVisibility) {
	    if(obj) {
	        
	        //KW 18/02/2008 Make sure lock div fills the screen so who background is shaded, including non-scrolled areas
	        if(obj.id=='divLock') {
	        
	            obj.style.height = obj.offsetParent.scrollHeight;
	            
	        }
	        
	        if(!blnVisibility) {
	    	    
	    	    obj.style.display='block';
	    	}
	    	else {
	    	    obj.style.visibility='visible';
	    	}
		}
	}
	
	function hideLayer(obj, blnVisibility) {
	    
	    if(obj) {

	        if(!blnVisibility) {
	    	    
	    	    obj.style.display='none';
	    	}
	    	else {
	    	    obj.style.visibility='hidden';
	    	}
		}
    }

    function trim(sValue) {
        
        return sValue.replace(/ /g,'');

    }
    
    function GetQueryString() {
    
        // Splits the querystring into its ID and VALUE pairs
        // Returns an object that can reference the value using the ID
        
        var args=new Object();
        var query=location.search.substr(1);
        var pairs=query.split('&');
       
        for(var i=0;i<pairs.length;i++) {
        
            var pos=pairs[i].indexOf('=');
            if(pos == -1) continue;
            var argname=pairs[i].substr(0,pos);
            var value=pairs[i].substr(pos+1);
            
            try {
                args[argname]=decodeURIComponent(value);
            }
            catch(e){
                args[argname]=unescape(value);
            }
        }
        
        return args;
    }
    
    function alignLastUpdated(xmlDoc) {
        
        var oWork=new Object();
        var oA=getAnchorPosition('siteLogout');
        
        oWork.last_updated=document.getElementById('divLastUpdated');
        oWork.last_updated.innerHTML=oML.LabelLastUpdated+"&nbsp;"+getSingleNodeAttribute('//DATA/STATSLASTUPDATED', 'LastUpdated', xmlDoc);
        
        if(document.implementation.createDocument) { 
        
            oWork.last_updated.style.left=oA.x-parseInt(oWork.last_updated.clientWidth,10)-20+'px';
            oWork.last_updated.style.top=oA.y+70+'px';
        }
        else {
            
            var intWork=parseInt((document.body.clientWidth-document.getElementById('tblMain').clientWidth)/2,10)+20;
   
            oWork.last_updated.style.left=oA.x-parseInt(oWork.last_updated.clientWidth,10)-intWork+'px';
            oWork.last_updated.style.top=oA.y+70+'px';
        }
    }
    
    function checkWebProduct(xmlRow) {
        oGlobal.web_product='';
        
       oGlobal.web_product=xmlRow.childNodes[xmlRow.childNodes.length-1].attributes['value'].value;
          
    }
    
//************************************************************************************************************		
//** C U S T O M E R   C H E C K S 
//************************************************************************************************************	
    
    function checkCustomerGlobal(s_type, s_value) {
        
        if(oFW.oGlobal.customer_type=='C') {
            
            // ** OK - Allow Through
            return true;
        }
        else {

            if(oFW.oGlobal.customer_reference=='') {
                
                if(oGlobal.init_process) {
            
                    oGlobal.init_process=false;
             
                    if(oFW.oGlobal.customer_allow_change) {
                        
                        if(document.getElementById('aChangeCustomer')) {
                        
                            processClick('aChangeCustomer'); 
                        }
                        else {
                            
                            openIframeWindow('CUSTOMER_PRODUCT','../ChangeCustomer/Default.aspx');
                        }
                    }
                }
                else {
                    
                    oGlobal.init_process=true;
                }
                
                return false;
            }
            else {
            
                // ** Load the Basket
                return true;
            }
        }
    }
    
//************************************************************************************************************		
//** G E N E R I C   T A B L E   M O U S E   E V E N T S     		
//************************************************************************************************************	
    
    function gridClearSelected() {
    
        var objTable=document.getElementById('tblGrid'); 
        
        objTable.setAttribute('selectedrow', '');
    }
    
    function gridUpdateCellValue(sCell, sValue) {
    
        var objTable=document.getElementById('tblGrid'); 
        var strID=objTable.getAttribute('selectedrow');
        
        if(strID!='') {
            
            var objSelected=document.getElementById(strID);
            
            objSelected.childNodes[sCell].innerHTML=sValue;
            objSelected.childNodes[sCell].style.color='red';
            
            if(document.implementation.createDocument) {   
            
                objSelected.childNodes[sCell].title=oML.ValueUpdatedTooltip + ' '+objSelected.childNodes[sCell].textContent;
            }
            else {
                objSelected.childNodes[sCell].title=oML.ValueUpdatedTooltip + ' '+objSelected.childNodes[sCell].innerText;
            }
        }
    }
    
    function mouseClickEvent(obj) {
    	
	    var objTable=document.getElementById('tblGrid'); 
        var strID=objTable.getAttribute('selectedrow');
	
	    if(strID!='') {
		
		    var objSelected=document.getElementById(strID);
			
		    for(var i=0;i<objSelected.childNodes.length;i++) {
		
			    if(objSelected.childNodes[i].tagName=="TD") {
					
				    objSelected.childNodes[i].style.backgroundColor='#FFFFFF';
			    }
		    }
			
			objSelected.setAttribute('selected', '');
	    }
		
	    var intChildren=obj.childNodes.length;
		
	    for(var i=0;i<intChildren;i++) {
		
		    if(obj.childNodes[i].tagName=="TD") {
				
			    obj.childNodes[i].style.backgroundColor='#FDFDBE';
		    }
	    }
		
		objTable.setAttribute('selectedrow', obj.id);
		obj.setAttribute('selected', '1');
    }
    
    function mouseOverEvent(obj) {

		var selected='';
    	
    	if(document.implementation.createDocument) {  
    	    
    	    selected=obj.getAttribute('selected');
    	}
    	else {
    	    selected=obj.selected;
    	}
    	
	    if(selected=='1') return;
	
        var intChildren=obj.childNodes.length;
		
        for(var i=0;i<intChildren;i++) {
		
            if(obj.childNodes[i].tagName=="TD") {
				
	            obj.childNodes[i].style.backgroundColor='#D0D0D0';
            }
        }
	}

    function mouseOutEvent(obj) {
    
        var selected='';
    	
    	if(document.implementation.createDocument) {  
    	    
    	    selected=obj.getAttribute('selected');
    	}
    	else {
    	    selected=obj.selected;
    	}
    	
    	if(selected=='1') return;
	
        var intChildren=obj.childNodes.length;
		
        for(var i=0;i<intChildren;i++) {
		
            if(obj.childNodes[i].tagName=="TD") {
				
	            obj.childNodes[i].style.backgroundColor='#FFFFFF';
            }
        }
    }
    
    function showHideDisclaimer()
	{
	    var disclaimer = document.getElementById('divColourDisclaimer');
	    (disclaimer.style.visibility=='visible')?disclaimer.style.visibility='hidden':disclaimer.style.visibility='visible';
	}

//************************************************************************************************************		
//** D I S P L A Y   I M A G E    		
//************************************************************************************************************	

    // Set the horizontal and vertical position for the popup

    PositionX = 100;
    PositionY = 100;

    // Set these value approximately 20 pixels greater than the
    // size of the largest image to be used (needed for Netscape)

    defaultWidth  = 500;
    defaultHeight = 500;

    // Set autoclose true to have the window close automatically
    // Set autoclose false to allow multiple popup windows

    if (parseInt(navigator.appVersion.charAt(0))>=4){
        var isNN=(navigator.appName=="Netscape")?1:0;
        var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
    }
        
    var optNN='scrollbars=no,resizable=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
    var optIE='scrollbars=no,resizable=no,width=100,height=100,left='+PositionX+',top='+PositionY;
    var AutoClose = true;
    
    function popImage(imageURL,imageTitle){
        
        //KW 25/02/2008 Added fix so that images display correctly in IE7
        //              1.  Div added to output to centre the image, this is because min width in IE7 is 250px
        //              2.  Window Height in IE7 includes title bar and status bar, added offset to height to allow 
        //                  for this
        
        if (isNN){imgWin=window.open('about:blank','',optNN);}
        if (isIE){imgWin=window.open('about:blank','',optIE);}
       
        with (imgWin.document){
            writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
            writeln('<sc'+'ript>');
            writeln('var isNN,isIE;');
            writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
            writeln('isNN=(navigator.appName=="Netscape")?1:0;');
            writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
            writeln('function reSizeToImage(){');
            writeln('if (isIE){');
            writeln('width=(document.images[0].width);');
            writeln('height=(document.images[0].height);');
            writeln('window.resizeTo(width,height);');
            writeln('var offHeight;');
            writeln('offHeight = (document.images[0].height - document.body.offsetHeight);');
            writeln('window.resizeTo(width, height + offHeight);');
            writeln('}');
            writeln('if (isNN){');
            writeln('window.innerWidth=document.images["ProductImg"].width;');
            writeln('window.innerHeight=document.images["ProductImg"].height;}}');
            writeln('function doTitle(){document.title="'+imageTitle+'";}');
            writeln('</sc'+'ript>');
            if (!AutoClose) writeln('</head><body bgcolor=fffff scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
            else writeln('</head><body bgcolor=ffffff scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
            writeln('<div align="center"><img name="ProductImg" src="'+imageURL+'" style="display:block"></div></body></html>');
            close();
        }
    }

//************************************************************************************************************		
//** A N C H O R   F U N C T I O N S (mainly for use in calendar functions)     		
//************************************************************************************************************	

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
 		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
 		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);		
		}
 	else if (use_css) {
 		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
 		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}
	 
// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
