﻿function getXmlHttpRequestObject() {	
	if (window.XMLHttpRequest) {		
		return new XMLHttpRequest(); //Not IE	
	} else if(window.ActiveXObject) {		
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE	
	} 
}

//Get browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();

function toggleEcommMenu(menuId) { 
    
     //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
	
	    menuDiv = $get('divSubMenu'+menuId);
	
	    if (menuDiv) {
	
		    //Setup the connection as a GET call
		    //True explicity sets the request to asyncronous (default).
		    if (menuDiv.style.display=='none') {
		        animateECommMenu(menuDiv,'open');
		        receiveReq.open("GET", "ajaxCustom.aspx?fn=ecommmenutoggle&m="+menuId+"&s=open&t="+new Date().getTime(), true);
		    } else {
		        animateECommMenu(menuDiv,'close');
		        receiveReq.open("GET", "ajaxCustom.aspx?fn=ecommmenutoggle&m="+menuId+"&s=close&t="+new Date().getTime(), true);
		    }
		    //Set the function that will be called when the XmlHttpRequest objects state changes.
		    receiveReq.onreadystatechange = toggleEcommMenuResult; 
		    //Make the actual request.
		    receiveReq.send(null);
		    
		}
	}	
    
}

//Called every time our XmlHttpRequest objects state changes.
function toggleEcommMenuResult() {
    //do nothing
}

function animateECommMenu(menu,action) {
    if (action=='open') {
        menu.style.display='';        
    } else {
        menu.style.display='none';
    }
}
    
if(typeof(Sys) !== "undefined") {
    Sys.Application.notifyScriptLoaded();
}