// JavaScript Document
// Navigation Code

function requestPage(url) {
	var oXmlHttp = zXmlHttp.createRequest();
    oXmlHttp.open("get", url, true);
    oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				displayPage(oXmlHttp.responseText);
			} else {
				 displayPage("Ha ocurrido un Error: " + oXmlHttp.statusText); //statusText is not always accurate
			}
		}
	};
	oXmlHttp.send(null);
}

function displayPage(sText) {
	var divPage = document.getElementById("divPage");
    divPage.innerHTML = sText;
}

function requestNav(url) {
	var oXmlHttp = zXmlHttp.createRequest();
    oXmlHttp.open("get", url, true);
    oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				displayNav(oXmlHttp.responseText);
			} else {
				 displayNav("Ha ocurrido un Error: " + oXmlHttp.statusText); //statusText is not always accurate
			}
		}
	};
	oXmlHttp.send(null);
}

function displayNav(sText) {
	var divNav = document.getElementById("divNav");
    divNav.innerHTML = sText;
}
// END NAVIGATION

// MENU AREA
userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function findElement(n,ly) {
	if (browserVers < 4)		return document[n];
	var curDoc = ly ? ly.document : document;
	var elem = curDoc[n];
	if (!elem) {
		for (var i=0;i<curDoc.layers.length;i++) {
			elem = findElement(n,curDoc.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (document.layers) {
				img = findElement(changeImages.arguments[i],0);
			}
			else {
				img = document.images[changeImages.arguments[i]];
			}
			if (img) {
				img.src = changeImages.arguments[i+1];
			}
		}
	}
}

var preloadFlag = false;
function preloadImages(url) {
	if (document.images) {
		inicioOver = newImage(url+"inicioOver.png");
		corpOver = newImage(url+"corpOver.png");
		afiliatesOver = newImage(url+"afiliatesOver.png");
		contactsOver = newImage(url+"contactsOver.png");
		mivipOver = newImage(url+"mivipOver.png");
		helpOver = newImage(url+"helpOver.png");
		logoutOver = newImage(url+"logoutOver.png");
		historialOver = newImage(url+"historialOver.png");
		reservationsOver = newImage(url+"reservationsOver.png");
		findClientOver = newImage(url+"findMemberOver.png");
		configOver = newImage(url+"configOver.png");
		statsOver = newImage(url+"statsOver.png");
		preloadFlag = true;
	}
}

function submenu(menu) {
	sub_m=document.getElementById('submenu');
	switch (menu) {
		case ('ho'):
			sub_m.innerHTML='';
			break;
		
		case ('corp'):
			sub_m.innerHTML='<div id="corpSubMenu" class="corpM"><table height="33" border="0" cellpadding="0" cellspacing="0" align="left"><tr><td height="33"><div id="quienes" onclick="requestPage(\'quienes.php#who\');">&raquo;&nbsp;Quienes Somos?&nbsp;</div></td><td height="33"><div id="corp" onclick="requestPage(\'quienes.php#corpInfo\');">&nbsp;&raquo;&nbsp;Informacion Corporativa</div></td></tr></table></div>';
			break;
			
		case ('af'):
			sub_m.innerHTML='<div id="afSubMenu" class="aflM"><table height="33" border="0" cellpadding="0" cellspacing="0" align="left"><tr><td height="33"><div id="afwhat" onclick="requestPage(\'afiliates.php#what\');">&raquo;&nbsp;Que es un Afiliado?&nbsp;</div></td><td height="33"><div id="afwhy" onclick="requestPage(\'afiliates.php#why\');">&raquo;&nbsp;Para que ser un Afiliado?&nbsp;</div></td><td height="33"><div id="afhow" onclick="requestPage(\'afiliates.php#how\');">&nbsp;&raquo;&nbsp;Como convertirse en Afiliado?&nbsp;</div></td><td height="33"><div id="afwho" onclick="requestPage(\'afiliates.php#who\');">&nbsp;&raquo;&nbsp;Nuestros Afiliados</div></td></tr></table></div>';
			break;
			
		case ('contacts'):
			sub_m.innerHTML='';
			break;
		
		case ('reg'):
			sub_m.innerHTML='<div id="regSubMenu" class="regM"><table height="33" border="0" cellpadding="0" cellspacing="0" align="left"><tr><td height="33"><div id="regUser" onclick="requestPage(\'nvipUser.php\');">&raquo;&nbsp;nocheVIP&nbsp;</div></td><td height="33"><div id="regComp" onclick="requestPage(\'nvipAdmin.php\');">&nbsp;&raquo;&nbsp;nocheVIP Empresarial&nbsp;</div></td><td height="33"><div id="regComp" onclick="requestPage(\'reg.php\');">&nbsp;&raquo;&nbsp;Registrate&nbsp;</div></td></tr></table></div>';
			break;

		case ('help'):
			sub_m.innerHTML='';
			break;
		
		case ('vip'):
			sub_m.innerHTML='<div id="vipSubMenu" class="vipM"><table height="33" border="0" cellpadding="0" cellspacing="0" align="left"><tr><td height="33"><div id="regUser" onclick="requestPage(\'resTicket.php\');">&raquo;&nbsp;Reservar Entrada&nbsp;</div></td><td height="33"><div id="regComp" onclick="requestPage(\'resTable.php\');">&nbsp;&raquo;&nbsp;Reservar Mesa&nbsp;</div></td></table></div>';
			break;
			
		case ('resMenu'):
			sub_m.innerHTML='';
			break;
		
		case ('config'):
			sub_m.innerHTML='<div id="confSubMenu" class="confM"><table height="33" border="0" cellpadding="0" cellspacing="0" align="left"><tr><td height="33"><div id="sysconf" onclick="requestPage(\'config.php\');">&raquo;&nbsp;Sistema&nbsp;</div></td><td height="33"><div id="addTable" onclick="requestPage(\'table.php\');">&raquo;&nbsp;Agregar Mesas&nbsp;</div></td><td height="33"><div id="modTable" onclick="requestPage(\'modTable.php\');">&raquo;&nbsp;Modificar Mesas&nbsp;</div></td></tr></table></div>';
			break;
		
		case ('stats'):
			sub_m.innerHTML='';
			break;
			
		case ('client'):
			sub_m.innerHTML='';
			break;
		
		case ('logout'):
			sub_m.innerHTML='';
			break;
	}
}

//END MENU AREA

// SENDFORM UNTESTED USED IN LOGIN
// CHANGE TO FUNCTION LOGIN
function doLogin(userNav,goTo) {
	var handle = document.getElementById("handle");
	var passwd = document.getElementById("passwd");

	showStatus("Espere un momento...");
	handle.disabled = true;
	passwd.disabled = true;

	var oForm = document.forms[0];
	var sBody = getRequestBody(oForm);

	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200 && oXmlHttp.responseText == '') {
				var nav = zXmlHttp.createRequest();
				nav.open("get", userNav, true);
				nav.onreadystatechange = function () {
					if (nav.readyState == 4) {
						if (nav.status == 200) {
							var dashboard = zXmlHttp.createRequest();
							dashboard.open("get", goTo, true);
							dashboard.onreadystatechange = function () {
								if (dashboard.readyState == 4) {
									if (dashboard.status == 200) {
										displayPage(dashboard.responseText);
										displayNav(nav.responseText);
									} else {
										showStatus("Ha ocurrido un Error: " + dashboard.statusText); //statusText is not always accurate
									}
								}
							};
							dashboard.send(null);
						} else {
							showStatus("Ha ocurrido un Error: " + nav.statusText); //statusText is not always accurate
						}
					}
				};
				nav.send(null);
			} else {
				displayPage(oXmlHttp.responseText);
				showStatus(oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);        
}

function doLogOut(url) {
	var splitUrl = url.split('&');
	var menu = splitUrl[1].split('=');
	var homePage = splitUrl[2].split('=');
	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", url, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				var nav = zXmlHttp.createRequest();
				nav.open("get", menu[1], true);
				nav.onreadystatechange = function () {
					if (nav.readyState == 4) {
						if (nav.status == 200) {
							var page = zXmlHttp.createRequest();
							page.open("get", homePage[1], true);
							page.onreadystatechange = function () {
								if (page.readyState == 4) {
									if (page.status == 200) {
										displayPage(page.responseText);
										displayNav(nav.responseText);
									} else {
										displayPage("Ha ocurrido un Error: " + page.statusText); //statusText is not always accurate
									}
								}
							};
							page.send(null);
						} else {
							displayPage("Ha ocurrido un Error: " + nav.statusText); //statusText is not always accurate
						}
					}
				};
				nav.send(null);
			} else {
				displayPage("Ha ocurrido un Error: " + oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(null);        
}

function getRequestBody(oForm) {
	var aParams = new Array();
	
	for (var i=0 ; i < oForm.elements.length; i++) {
		var sParam = encodeURIComponent(oForm.elements[i].name);
		sParam += "=";
		sParam += encodeURIComponent(oForm.elements[i].value);
		aParams.push(sParam);
	} 
	
	return aParams.join("&");        
}

function showStatus(sMessage) {
	var divStatus = document.getElementById("divStatus");
	divStatus.innerHTML = sMessage;            
}

// LOGIN VALIDATION
function showhide(layer_ref,err,type) {
	var legend = '&nbsp;';
	if (err == true) {
		state = '1px solid #FF0000';
		legend = '(R) - Campo Requerido<br />(N) - Campo Num&eacute;rico<br />(EQ) - Campos deben Coincidir<br />(F) - Formato Incorrecto';
		switch (type) {
			case('r'):
				req = '(R)';
				break;
				
			case('rn'):
				req = '(R)(N)';
				break;
				
			case('req'):
				req = '(R)(EQ)';
				break;
				
			case('rf'):
				req ='(R)(F)';
				break;
			
			case('ok'):
				req = '';
				break;
		}
	
	} else {
		state = '1px solid #999999';
		req = '';
	}
		
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = state");
	}
	
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = state;
	}
	
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.border = state;
		hzb = document.getElementById(layer_ref+"R");
		hzb.innerHTML = req;
		showStatus(legend);
	}
}

function showhideL(layer_ref,err,type) {
	var legend = '&nbsp;';
	if (err == true) {
		state = '1px solid #FF0000';
		switch (type) {
			case('r'):
				req = '(R)';
				legend = '(R) - Campo Requerido';
				break;
				
			case('ok'):
				req = '';
				legend = '&nbsp;';
				break;
		}
	
	} else {
		state = '1px solid #999999';
		req = '';
		legend = '&nbsp;';
	}
		
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval("document.all." + layer_ref + ".style.display = state");
	}
	
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = state;
	}
	
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.border = state;
		hzb = document.getElementById(layer_ref+"R");
		hzb.innerHTML = req;
		showStatus(legend);
	}
}

var haveerrors = 0;
function showDiv(divId, showHideDiv, errors) {
	if (!haveerrors && errors) haveerrors = errors;
}

function validateLogin(f,Nav,goTo) {
	haveerrors = 0;
	(f.handle.value.length < 1)
	? showDiv("handle", showhideL("handle",true,"r"), true)   // no semi-colon after this line!
	: showDiv("handle", showhideL("handle",false,"ok"), false); // true = errors, false = no errors
	
	(f.passwd.value.length < 1)
	? showDiv("passwd", showhideL("passwd",true,"r"), true) 
	: showDiv("passwd", showhideL("passwd",false,"ok"), false);
	
	if (!haveerrors) {
		doLogin(Nav,goTo); return false;	
	}
}

// END LOGIN AREA

// REGISTRATION VALIDATION
var errs = 0;
function showDivs(divId, showHideDiv, errors) {
	if (!errs && errors) errs = errors;
}
function validateReg(f,goTo) {
	errs = 0;
	(f.handle.value.length < 1)
	? showDivs("handle", showhide("handle",true,"r"), true)   // no semi-colon after this line!
	: showDivs("handle", showhide("handle",false,"ok"), false); // true = errors, false = no errors
	
	(f.passwd.value.length < 1 || f.passwd.value != f.passwdCheck.value)
	? showDivs("passwd", showhide("passwd",true,"req"), true) 
	: showDivs("passwd", showhide("passwd",false,"ok"), false);
	
	(f.passwdCheck.value.length < 1 || f.passwd.value != f.passwdCheck.value)
	? showDivs("passwdCheck", showhide("passwdCheck",true,"req"), true) 
	: showDivs("passwdCheck", showhide("passwdCheck",false,"ok"), false);
	
	(f.email.value.search("@") == -1 || f.email.value.search("[.*]") == -1)
	? showDivs("email", showhide("email",true,"rf"), true) 
	: showDivs("email", showhide("email",false,"ok"), false);
	
	(f.name.value.length < 1)
	? showDivs("name", showhide("name",true,"r"), true)
	: showDivs("name", showhide("name",false,"ok"), false);
	
	(f.lastname.value.length < 1)
	? showDivs("lastname", showhide("lastname",true,"r"), true)
	: showDivs("lastname", showhide("lastname",false,"ok"), false);
	
	(f.idUser.value.length < 1 || f.idUser.value.search("[a-zA-Z]") != -1)
	? showDivs("idUser", showhide("idUser",true,"rn"), true)
	: showDivs("idUser", showhide("idUser",false,"ok"), false);

	(f.phone.value.length < 1 || f.phone.value.search("[a-zA-Z]") != -1)
	? showDivs("phone", showhide("phone",true,"rn"), true)
	: showDivs("phone", showhide("phone",false,"ok"), false);
	
	(f.address.value.length < 1)
	? showDivs("address", showhide("address",true,"r"), true)
	: showDivs("address", showhide("address",false,"ok"), false);
	
	(f.profession.value.length < 1)
	? showDivs("profession", showhide("profession",true,"r"), true)
	: showDivs("profession", showhide("profession",false,"ok"), false);
	
	if (!errs) {
		sendForm(goTo); return false;
	}
}
// POST FORM
function sendForm(goTo) {
	var oForm = document.forms[0];
	var sBody = getRequestBody(oForm);
			
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200 && oXmlHttp.responseText == '') {
				var gotoPage = zXmlHttp.createRequest();
				gotoPage.open("get", goTo, true);
				gotoPage.onreadystatechange = function () {
					if (gotoPage.readyState == 4) {
						if (gotoPage.status == 200) {
							displayPage(gotoPage.responseText);
							switch (goTo) {
								case('config.php'):
									showStatus("Configuraci&oacute;n Guardada.");
									break;
								case('adminReservation.php'):
									showStatus("Mesa Reservada.");
									break;
								case('table.php'):
									showStatus("Mesa Agregada");
									break;
							}
						} else {
							showStatus("Ha ocurrido un Error: " + gotoPage.statusText);
						}
					}
				};
				gotoPage.send(null);
			} else {
				displayPage(oXmlHttp.responseText);
				showStatus(oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);        
}
// TABLE RESERVATIONS

function loadMenu(id,menu) {
	id.checked;
	m = document.getElementById("view");
	m.innerHTML = menu;

	var t = document.getElementById("total");
	t.rows[0].cells[1].innerHTML = id.value+'<input type="hidden" value="'+id.value+'" name="table" />';
}

function doMath(oForm,goTo) {
	
	var total = parseInt(oForm.resCost.value);
	if (oForm.food) {
		if (oForm.food.selectedIndex > 0 && oForm.qtyFood.value != '') {
			var selInd = oForm.food.selectedIndex;
			var foodVal = oForm.food.options[selInd].text;
			foodVal = foodVal+"Value";
			var foodValue = document.getElementById(foodVal).value;
			var foodCost = oForm.qtyFood.value*foodValue;
			if (foodCost == 0) {
				foodCost = 'No Seleccion&oacute; Comida con su Reservaci&oacute;n';
			} else {
				total += parseInt(foodCost);
			}
		} else {
			foodCost = 'No Seleccion&oacute; Comida con su Reservaci&oacute;n';
		}
	} else {
		var foodCost = 0;
	}
	
	if (oForm.drinks) {
		if (oForm.drinks.selectedIndex > 0 && oForm.qtyDrinks.value != '') {
			var selInd = oForm.drinks.selectedIndex;
			var drinksVal = oForm.drinks.options[selInd].text;
			drinksVal = drinksVal+"Value";
			var drinksValue = document.getElementById(drinksVal).value;
			var drinksCost = oForm.qtyDrinks.value*drinksValue;
			if (drinksCost == 0) {
				drinksCost = 'No Seleccion&oacute; Bebidas con su Reservaci&oacute;n';
			} else {
				total += parseInt(drinksCost); 
			}
		} else {
				drinksCost = 'No Seleccion&oacute; Bebidas con su Reservaci&oacute;n';
		}
	} else {
		var drinksCost = 0;
	}
	
	var t = document.getElementById('total');
	t.rows[1].cells[1].innerHTML = oForm.resCost.value;
	t.rows[2].cells[1].innerHTML = foodCost;
	t.rows[3].cells[1].innerHTML = drinksCost;
	t.rows[4].cells[1].innerHTML = total+'<input type="hidden" name="totSub" value="'+total+'" />';
	
	var send = document.getElementById('accept').rows[0].cells;
	send[0].innerHTML = '<input type="submit" name="submitRes" value="Reservar" onClick="sendForm(\''+goTo+'\'); return false;" class="submitYes" />';
}

function doTicketMath() {
	var oForm = document.forms[0];
	var res = document.getElementById('submitRes');
	
	var t = document.getElementById("total");
	var availTicket = parseInt(t.rows[0].cells[1].innerHTML);
	var qtySelected = document.getElementById("qtyTicket");
	var selInd = qtySelected.selectedIndex;
	var qtySelected;
	
	if (selInd == 0) {
		qtySelected	= 0;
	} else {
		qtySelected = parseInt(qtySelected.options[selInd].value);		
	}
	
	if (availTicket >= qtySelected) {
		var resCost = parseInt(oForm.resCost.value);
		
		var qtyTicket = parseInt(oForm.qtyTicket.value);
		var ticketCost = parseInt(oForm.ticketCost.value);
		var total = qtyTicket * resCost;
		total += qtyTicket * ticketCost;
		
		if (!parseInt(qtyTicket)) {
			qtyTicket = 0;
			total = 0;
		}
		
		if (total === 0) {
			res.disabled = true;
			changeStyle('submitRes','submitNo');
			
			var t = document.getElementById('total');
			t.rows[1].cells[1].innerHTML = qtyTicket;
			t.rows[4].cells[1].innerHTML = total;
		} else {
			res.disabled = false;
			changeStyle('submitRes','submitYes');
			
			var t = document.getElementById('total');
			t.rows[1].cells[1].innerHTML = qtyTicket;
			t.rows[4].cells[1].innerHTML = total+'<input type="hidden" id="totSub" name="totSub" value="'+total+'" />';
		}	
	} else {
		res.disabled = true;
		changeStyle('submitRes','submitNo');
	}
	
}

function confirmRes(f) {
	var temp = window.confirm('Esta seguro que desea hacer la Reservaci&oacute;n?');
	if (temp) {
		return f.submit;
	} else {
		return false;
	}
}

function changeStyle(id,style) {
	var d = document.getElementById(id);
	d.className = style;
}

function validateTime() {
	var oForm = document.forms[0];
	if (oForm.resTimeSelect.selectedIndex > 0) {
		var res = document.getElementById('continue')
		res.disabled = false;
		changeStyle('continue','submitYes');
	} else {
		var res = document.getElementById('continue')
		res.disabled = true;
		changeStyle('continue','submitNo');
	}
}
// VALIDATIONS FOR BILL
function IsNumeric(sText,id) {
    var ValidChars = "0123456789";
    var IsNumber=true;
    var Char;
    var string;
    var llevo=0;

	for (i = 0; i < sText.length && IsNumber == true; i++) {
       Char = sText.charAt(i);
       if (ValidChars.indexOf(Char) == -1) {
         a=document.getElementById(id);
         string=sText;
         str=string.substr(0,i-llevo);
         a.value=str;
         llevo+=1;
       }
    }
}

function changeResDiv(id) {
	var oForm = document.forms[0];
	var sBody = getRequestBody(oForm);
			
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				var d = document.getElementById(id);
				d.innerHTML = oXmlHttp.responseText;
			} else {
				displayPage(oXmlHttp.statusText);
			}
		}            
	};
	oXmlHttp.send(sBody);   
}

// ADMIN AREA FUNCTIONS GETS USER INFO
function getOneLike(php) {
	var sId = document.getElementById("searchString").value;
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", php +"?queryId="+ sId, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				displayMembers(oXmlHttp.responseText);
				var divDisplayMember = document.getElementById("divMemberInfo");
				if(divDisplayMember.innerHTML != '<img src="http://localhost/images/placeHolder.png" id="viewPic" name="viewPic" width="300" height="300" border="0"  />'){
					displayMemberInfo('<img src="http://localhost/images/placeHolder.png" id="viewPic" name="viewPic" width="300" height="300" border="0"  />');	
				}
			} else {
				displayMembers("Ha occurido un error: " + oXmlHttp.statusText); //statusText is not always accurate
			}
		}
	};
	oXmlHttp.send(null);
}

function getAllUserInfo(php,searchString) {
	var sId = searchString;
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", php +"?Id="+ sId, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				displayMemberInfo(oXmlHttp.responseText);
			} else {
				displayMemberInfo("Ha occurido un error: " + oXmlHttp.statusText); //statusText is not always accurate
			}
		}
	};
	oXmlHttp.send(null);
}

function showUserDetail (php, searchString) {
	var sId = searchString;
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", php +"?Id="+ sId, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				displayMemberInfo(oXmlHttp.responseText);
			} else {
				displayMemberInfo("Ha occurido un error: " + oXmlHttp.statusText); //statusText is not always accurate
			}
		}
	};
	oXmlHttp.send(null);
}

function changeMonth(php) {
	var t = document.getElementById("statDateSelect");
	var selInd = t.selectedIndex;
	var sId = t.options[selInd].value;
	var txt = document.getElementById("txt");
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", php +"?date="+ sId, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				txt.innerHTML = oXmlHttp.responseText;
			} else {
				txt.innerHTML = "Ha occurido un error: " + oXmlHttp.statusText; //statusText is not always accurate
			}
		}
	};
	oXmlHttp.send(null);
}

function displayMembers(sText) {
	var divGetOneMemberLike = document.getElementById("divGetOneMemberLike");
	divGetOneMemberLike.innerHTML = sText;
}

function displayMemberInfo(sText) {
		var divDisplayMember = document.getElementById("divMemberInfo");
		divDisplayMember.innerHTML = sText;
}

function timeOuts(php) {
	setTimeout("getOneLike(\'"+php+"\')",300);
}

var goBack = '';
function showResDetail (php, searchString, div) {
	var sId = searchString;
	var display = document.getElementById(div);
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", php +"?Id="+ sId + "&goBack=" + div, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				goBack = display.innerHTML;
				display.innerHTML = (oXmlHttp.responseText);
			} else {
				display.innerHTML = (oXmlHttp.responseText);
			}
		}
	};
	oXmlHttp.send(null);
}
function showLast(div) {
	var lastDiv = document.getElementById(div);
	lastDiv.innerHTML = goBack;
}
function showTableDetail (php, searchString) {
	var sId = searchString;
	var display = document.getElementById("divModTable");
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", php +"?Id="+ sId, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				display.innerHTML = (oXmlHttp.responseText);
			} else {
				display.innerHTML = (oXmlHttp.responseText);
			}
		}
	};
	oXmlHttp.send(null);
}

function removeTable (php, searchString) {
	var sId = searchString;
	var display = document.getElementById("divModTable");
	var table = document.getElementById(searchString);
	var oXmlHttp = zXmlHttp.createRequest();
	
	oXmlHttp.open("get", php +"?rId="+ sId, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				display.innerHTML = (oXmlHttp.responseText);
				table.innerHTML = '';
			} else {
				display.innerHTML = (oXmlHttp.responseText);
			}
		}
	};
	oXmlHttp.send(null);
}

function adminChangeTableDiv(sText) {
	var divAdminResTable = document.getElementById("tdAdminTableRes");
	divAdminResTable.innerHTML = (sText);
}

function adminGetDashBoardRes(php) {
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", php, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				adminChangeTableDiv(oXmlHttp.responseText);
			} else {
				adminChangeTableDiv("Ha occurido un error: " + oXmlHttp.statusText); //statusText is not always accurate
			}
		}
	};
	oXmlHttp.send(null);
}

function changeStatus(php,id,val) {
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", php+"?enabled="+id+"&val="+val, true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
				requestPage('adminDashBoard.php');
			} else {
				adminChangeTableDiv("Ha occurido un error: " + oXmlHttp.statusText); //statusText is not always accurate
			}
		}
	};
	oXmlHttp.send(null);
}
var oldbg = '';
function keepBg(id) {
	
	var bg = document.getElementById(id);

	if (bg.id != oldbg) {
		if (bg.style.backgroundColor != '#CCCCFF') {
			if (oldbg != '') {
				var toWhite = document.getElementById(oldbg);
				toWhite.style.backgroundColor='';
			}
			bg.style.backgroundColor = '#CCCCFF';
			oldbg = bg.id;
		}
	}
}

// ADD TABLE VALIDATION
var haveerrors = 0;
function showDiv(divId, showHideDiv, errors) {
	if (!haveerrors && errors) haveerrors = errors;
}

function validateTable(f,goTo) {
	haveerrors = 0;
	(f.idTable.value.length < 1)
	? showDiv("idTable", showhideL("idTable",true,"r"), true)   // no semi-colon after this line!
	: showDiv("idTable", showhideL("idTable",false,"ok"), false); // true = errors, false = no errors
	
	(f.size.value.length < 1)
	? showDiv("size", showhideL("size",true,"r"), true) 
	: showDiv("size", showhideL("size",false,"ok"), false);
	
	(f.picture.value.length < 1)
	? showDiv("picture", showhideL("picture",true,"r"), true) 
	: showDiv("picture", showhideL("picture",false,"ok"), false);
	
	(f.description.value.length < 1)
	? showDiv("description", showhideL("description",true,"r"), true) 
	: showDiv("description", showhideL("description",false,"ok"), false);
	
	if (!haveerrors) {
		sendForm(goTo); return false;	
	}
}