//functions.js
//Create a boolean variable to check for a valid IE instance.
var xmlhttp = false;
//Check if we are using IE.
try {
//If the javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using IE.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a JavaScript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
//A variable used to distinguish whether to open or close the calendar.
var showCalendar = true;
function loadEditor(id) {
	if (tinyMCE.getInstanceById(id) == null)
		tinyMCE.execCommand('mceAddControl', false, id);
}
function toggleEditor(id) {
	if (tinyMCE.getInstanceById(id) == null)
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
}
function uploadform(theform){

var inst = tinyMCE.getInstanceById('content');
theform.content.value = inst.getHTML();
//Submit the form.
theform.submit();
//Then display a loading message to the user.
}
function uploadformtask(theform){
//Submit the form.
theform.submit();
//Then display a loading message to the user.
}
function doneloading(theframe,thefile){
var theloc = "showimg.php?thefile=" + thefile
theframe.processajax ("showimg",theloc);
}
//Function to set a loading status.
function setStatus (theStatus, theObj){
obj = document.getElementById(theObj);
if (obj){
obj.innerHTML = "<div class=\"bold\"><img src=\"http://www.24sevenzone.com/images/ajax-loader.gif\" />" + theStatus + "</div>";
}
}
function execute_function(option){
	switch(option){
		case 1:
			show('destinos/list.php','list_ajax', false, false, '');
			break;
		case 2:
			show('habitaciones/list.php','list_ajax', false, false, '');
			break;
		case 3:
			show('hoteles/list.php','list_ajax', false, false, '');
			break;
		case 4:
			show('tipos_hotel/list.php','list_ajax', false, false, '');
			break;
		case 5:
			show('servicios/list.php','list_ajax', false, false, '');
			break;
		case 6:
			show('tours/list.php','list_ajax', false, false, '');
			break;
		case 7:
			show('tipos_tour/list.php','list_ajax', false, false, '');
			break;
		default:
			alert('funcion no existe');
			break;
	}	
}
function show(ServerPage,id, tinymce, new_f, des_f){
	new_f = typeof(new_f) != 'undefined' ? new_f : false;
	if(tinymce){
		try {
		var elm = tinyMCE.getInstanceById('content');
		if (elm)
			tinyMCE.execCommand('mceRemoveControl', false, 'content');
		}
		catch(err){}
	}
	var objID = id;
	setStatus ("Cargando...",objID);
	var obj = document.getElementById(objID);
	processajax (ServerPage, obj, "get", "", tinymce, new_f, des_f);
}
function showActivities(thedate){
	var objID = 'buscador';
	var ServerPage = 'design/activities.php?thedate='+thedate;
	setStatus ("Cargando...",objID);
	var obj = document.getElementById(objID);
	processajax_P(ServerPage, obj, "get", "",1);
}
function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
function goLastMonth(pageServer, id, month, year)
{
// If the month is Januaru, decrement the year
if(month == 1)
{
--year;
month = 13;
}
ServerPage = pageServer+'?month='+(month-1)+'&year='+year; 
var objID = id;
var obj = document.getElementById(objID);
processajax (ServerPage, obj, "get", "");
}
function goNextMonth(pageServer, id, month, year)
{
// If the month is December, increment the year
if(month == 12)
{
++year;
month = 0;
}
ServerPage = pageServer+'?month='+(month+1)+'&year='+year;
var objID = id;
var obj = document.getElementById(objID);
processajax (ServerPage, obj, "get", "");
} 
function checkforactivity (thedate){
theObject = d("visorActividad");
theObject.style.visibility = "visible";
theObject.style.height = "";
theObject.style.width = "";
//The location we are loading the page into.
var objID = "visorActividad";
var serverPage = "design/activitiviewer.php?thedate=" + thedate;
var obj = document.getElementById(objID);
processajax (serverPage, obj, "get", "");
}
function hideactivity (){
tObject = document.getElementById("visorActividad");
tObject.style.visibility = "hidden";
tObject.style.height = "0px";
}
//Functions to submit a form.
var aok;
function getformvalues (fobj){
var str = "";
aok = true;
var val;
//Run through a list of all objects contained within the form.
for(var i = 0; i < fobj.elements.length; i++){
if(true) {
	if (fobj.elements[i].type == "checkbox"){
			if (fobj.elements[i].checked == true) {
				str += fobj.elements[i].name+"[]"+ "=" + escape(fobj.elements[i].value) + "&";
			}
	}
	else if(fobj.elements[i].type == "radio") {
		if(fobj.elements[i].checked == true){
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";	
		}
	}
	else{
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
	}
}
}
//Then return the string values.
return str;
}
function submitform (theform, serverPage, objID){
	init_variable();
	var str = getformvalues(theform);
	//If the validation is ok.
	setStatus ("Cargando...",objID);
	obj = document.getElementById(objID);
	processajax (serverPage, obj, "post", str);
}
function init_variable(){
	subnivel = false;	
}

//functions.js
