﻿
// Copyright MarketVelocity 2008
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, electronic, mechanical or otherwise, is prohibited
// without the prior written consent of the copyright owner.
//      Date           Dev            Comments
//		----------     ----------     --------------------------------------------------------------
//      19-Mar-08      VP             File created.
//      24-Mar-08      VP             BuilsSPageName function created to initialise Omniture variable 
//                                    in ajax call.
//      30-Apr-08      VP             Blocking page & diplaying image to show ajax progress 
//	    11-Jun-08      VP	          Scroll Issue On quote Page and large trade page  	 	 	  
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(InitializeRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);

var s_pageName = new String();
    
    function InitializeRequest(sender, args)
    {    
        document.getElementById('ModalBG').style.display = 'block';        
        document.getElementById('imgPageLoad').style.display = 'block';
        ImageLayout();       
        ModalLayout();            
    }
  
    function EndRequest(sender, args)
    {           
          BuildSPageName();                
          if(args.get_error() != undefined && ((args.get_error().httpStatusCode == '500')
               ||(args.get_error().httpStatusCode == '504')))
            { 
              args.set_errorHandled(true);          
              document.location.href ='/GenericErrorPage.aspx';  
           }
	   
           if(args.get_error()!= undefined && args.get_error().name == 'Sys.WebForms.PageRequestManagerParserErrorException')
           {
	            args.set_errorHandled(true);                         
        	    window.location.reload(true);
           }   
                           
          ctrlContainer = "";
          if(sender._postBackSettings.sourceElement)
             ctrlContainer = sender._postBackSettings.sourceElement.id.split('_');          
          if(ctrlContainer.length > 0)
          { 
            ctrlId= ctrlContainer[(ctrlContainer.length)-1];   
                              
            if(ctrlId == "drpManufacturer")
            {  
//               hidePanel = true;
//               gridTableId = "cboProductAutoSuggest_grdProduct";
//               gridDivId = "ctl00_ContentPlaceHolder_cboProductAutoSuggest_gridDiv";
//               pageBarId = "ctl00_ContentPlaceHolder_cboProductAutoSuggest_divGridPaging";
               oldResponse = ""; 
               pageIndex = 0;
               if(document.getElementById('ctl00_ContentPlaceHolder_cboProductAutosuggest'))
               ctl00_ContentPlaceHolder_cboProductAutosuggestCallServer('MfgCallBack','');  
               //alert(document.getElementById(gridTableId))         
                                     
            }
            else if(ctrlId == "drpCategory")
            {
              oldResponse = "";  
              pageIndex = 0;           
            }
          }
          
        document.getElementById('ModalBG').style.display = 'none';
        document.getElementById('imgPageLoad').style.display = 'none';       
        if(sender._postBackSettings.sourceElement.id =='ctl00_ContentPlaceHolder_btnQuote')
        document.location.href='#topofpage';        
    } 
          
    function PageLoaded()
    {
       /*Searchable drop down parameter*/
        LowerBound = 0;
        SelectedRowIndex = -1; 
        oldResponse = "";       
      /*End*/
        document.getElementById('imgPageLoad').style.display = 'none';     
        var theForm = document.forms['aspnetForm'];
        if (!theForm) 
        {
         theForm = document.aspnetForm;
        }
        theForm.style.display = 'block';

	    //Scroll Issue On quote Page and large trade page 
	    if(window.location.href.indexOf('#quoteform') != -1)
        {
		    document.location = '#quoteform';
	    }
        else if(window.location.href.indexOf('#cnt') != -1)
        {
		    document.location = '#cnt';
	    }
	    else if(window.location.href.indexOf('#DeterProduct') != -1)
        {
		    document.location = '#DeterProduct';
	    }
	    else if(window.location.href.indexOf('#eligibility') != -1)
	    {
	        document.location = '#eligibility';
	    }
	    else if(window.location.href.indexOf('#Packing_guidelines') != -1)
	    {
	        document.location = '#Packing_guidelines';
	    }			      
    }
        
    
    function BuildSPageName()
     {
        s_pageName = document.getElementById('ctl00_omniturePageName')!= null ? document.getElementById('ctl00_omniturePageName').value : ""; 
     }
     
     function ModalLayout()
     {
        var clientBounds = getClientBounds();
        var clientWidth = clientBounds.width;
        var clientHeight = clientBounds.height;        
        document.getElementById('ModalBG').style.width = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), clientWidth)+ 'px';
        document.getElementById('ModalBG').style.height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight)+ 'px';
     }
     
     function ImageLayout()
     {
        var clientBounds = getClientBounds();
        var clientWidth = clientBounds.width;
        var clientHeight = clientBounds.height;                       
        document.getElementById('imgPageLoad').style.left = clientWidth /2 + 'px';
        document.getElementById('imgPageLoad').style.top = Math.max(document.documentElement.scrollTop, document.body.scrollTop) + (clientHeight / 2)+ 'px';
     }
     function getClientBounds()
      {      
        var clientWidth;
        var clientHeight;
        switch(Sys.Browser.agent) {
            case Sys.Browser.InternetExplorer:
                clientWidth = document.documentElement.clientWidth;
                clientHeight = document.documentElement.clientHeight;
                break;
            case Sys.Browser.Safari:
                clientWidth = window.innerWidth;
                clientHeight = window.innerHeight;
                break;
            case Sys.Browser.Opera:
                clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
                clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
                break;
            default:  // Sys.Browser.Firefox, etc.
                clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
                clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
                break;
        }
        return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
    }
   

