// stores the reference to the XMLHttpRequest object

var xmlHttp = createXmlHttpRequestObject();

var EventUrl = "../../Util/Php/pisoE.php";

var ProvUrl = "../../Util/Php/pisoP.php";

var EventsMenu = "../../Util/Php/eventMenu.php";

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject(){
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// this should work for all browsers except IE6 and older
	try{
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	}
	catch(e){
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		// try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
			try{
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e) {}
		}
	}
	// return the created object or display an error message
	if (!xmlHttp)
	alert("Error creating the XMLHttpRequest object.");
	else
	return xmlHttp;
}


function showhLogo(boxLetter,stepNo){
	document.getElementById(boxLetter).src = "/Images/Web/" + boxLetter + stepNo + ".gif";
}


function loadEventMenu(){
// test if user has browser that supports native XSLT functionality
	if(window.XMLHttpRequest){
		// load the grid
		loadEventMenus();
		return;
	}
	// test if user has Internet Explorer with proper XSLT support
	if (window.ActiveXObject){
		// load the grid
		loadEventMenus();
		// exit the function
		return;
	}
	// if browser functionality testing failed, alert the user
	alert("Your browser doesn't support the necessary functionality.");
}

// makes asynchronous request to load a new page of the grid
function loadEventMenus(){
	// disable edit mode when loading new page
	editableId = false;
	// continue only if the XMLHttpRequest object isn't busy
	if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)){
		var query = EventsMenu + "?act=lem";
		xmlHttp.open("GET", query, true);
		xmlHttp.onreadystatechange = handleEventMenusLoad;
		xmlHttp.send(null);
	}
}


// handle receiving the server response with a new page of products
function handleEventMenusLoad(){
	// when readyState is 4, we read the server response
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 ){
		// read the response
		response = xmlHttp.responseText;
		// server error?
		if (response.indexOf("ERRNO") >= 0 || response.indexOf("error") >= 0 || response.length == 0){
			// display error message
			alert(response.length == 0 ? "Server error." : response);
			// exit function
			return;
		}
		// the server response in XML format
		xmlResponse = xmlHttp.responseText;
		// browser with native functionality?
		if (window.XMLHttpRequest || window.ActiveXObject){
			// display the page of products
			var gridDiv = document.getElementById("menuEventos");
			gridDiv.innerHTML=xmlHttp.responseText;
		}
	}
}

// eveything starts here
function loadEvent(){
// test if user has browser that supports native XSLT functionality
	if(window.XMLHttpRequest){
		// load the grid
		loadEvents(1);
		return;
	}
	// test if user has Internet Explorer with proper XSLT support
	if (window.ActiveXObject){
		// load the grid
		loadEvents(1);
		// exit the function
		return;
	}
	// if browser functionality testing failed, alert the user
	alert("Your browser doesn't support the necessary functionality.");
}

// makes asynchronous request to load a new page of the grid
function loadEvents(pageNo){
	var sec = document.getElementById('lstSeccion').value;
	var periodo = document.getElementById('lstMes').value;
	// disable edit mode when loading new page
	editableId = false;
	// continue only if the XMLHttpRequest object isn't busy
	if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)){
		var query = EventUrl + "?act=le&sec=" + sec + "&per=" + periodo + "&pg=" + pageNo;
		xmlHttp.open("GET", query, true);
		xmlHttp.onreadystatechange = handleGridPageLoad;
		xmlHttp.send(null);
	}
}


function loadProv(){
// test if user has browser that supports native XSLT functionality
	if(window.XMLHttpRequest){
		// load the grid
		loadProvs(1);
		return;
	}
	// test if user has Internet Explorer with proper XSLT support
	if (window.ActiveXObject){
		// load the grid
		loadProvs(1);
		// exit the function
		return;
	}
	// if browser functionality testing failed, alert the user
	alert("Your browser doesn't support the necessary functionality.");
}

// makes asynchronous request to load a new page of the grid
function loadProvs(pageNo){
	var sec = document.getElementById('lstSeccion').value;
	// disable edit mode when loading new page
	editableId = false;
	// continue only if the XMLHttpRequest object isn't busy
	if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)){
		var query = ProvUrl + "?act=lp&sec=" + sec + "&pg=" + pageNo;
		xmlHttp.open("GET", query, true);
		xmlHttp.onreadystatechange = handleGridPageLoad;
		xmlHttp.send(null);
	}
}


// handle receiving the server response with a new page of products
function handleGridPageLoad(seccions,seccionh){
	// when readyState is 4, we read the server response
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200 ){
		// read the response
		document.getElementById("Loading").style.display = "none";
		document.getElementById("Loading").style.visibility = "hidden";
		document.getElementById("ListBox").style.display = "inline";
		document.getElementById("ListBox").style.visibility = "visible";
		document.getElementById("lstSeccion").disabled = "";
		document.getElementById("lstMes").disabled = "";
		response = xmlHttp.responseText;
		// server error?
		if (response.indexOf("ERRNO") >= 0 || response.indexOf("error") >= 0 || response.length == 0){
			// display error message
			alert(response.length == 0 ? "Server serror." : response);
			// exit function
			return;
		}
		// the server response in XML format
		xmlResponse = xmlHttp.responseText;
		// browser with native functionality?
		if (window.XMLHttpRequest || window.ActiveXObject){
			// display the page of products
			var gridDiv = document.getElementById("ListBox");
			gridDiv.innerHTML=xmlHttp.responseText;
		}
		HeightMenuProductos();
	}
	else{
		document.getElementById("ListBox").style.display = "none";
		document.getElementById("ListBox").style.visibility = "hidden";
		document.getElementById("Loading").style.display = "inline";
		document.getElementById("Loading").style.visibility = "visible";
		document.getElementById("lstSeccion").disabled = "disabled";
		document.getElementById("lstMes").disabled = "disabled";
	}
}

function goBack(){
	window.history.back()
}

function OPNW(Page){
	window.open(Page)
}

function HeightMenuProductos(){
	 if (document.getElementById('Cont').offsetHeight > ((document.getElementById('MenuSecciones').offsetHeight))- 180){
		document.getElementById('MenuSecciones').style.height = document.getElementById('Cont').offsetHeight + 200 + "px";
	 } else {
	 	document.getElementById('MenuSecciones').style.height = "auto";
	 }
}

function showSubMenu(seccions,seccionh){
	show = document.getElementById(seccions);
	hide = document.getElementById(seccionh);
		show.style.visibility = "visible";
		show.style.height = "auto";
		hide.style.visibility = "hidden";
		hide.style.height = "0px";
	HeightMenuProductos();
}

function btnloadE(listName,seccionValue){
	document.getElementById(listName).value=seccionValue;
	loadEvents(1);
}

function btnloadP(listName,seccionValue){
	document.getElementById(listName).value=seccionValue;
	loadProvs(1);
}

function bookmark()
	{window.external.AddFavorite("http://www.pisodeexhibicion.com/","www.pisodeexhibicion.com")
}