var datatype = null;

function GetXmlHttpObject(handler) { 
	var objXmlHttp=null;

	if (window.ActiveXObject)   // ActiveX version
	{
		try
		{ 
			objXmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			objXmlHttp.onreadystatechange=handler;
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled");
			return;
		} 
	} 
	else if (window.XMLHttpRequest)     // Object of the current windows
	{ 
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
}

function updatePrice(selectedvalue) {
	
	var url		=	"/tabcontent/updateprice.php";
	var info	=	"sd="+selectedvalue;
	xmlHttp		=	GetXmlHttpObject(updatePriceResponse);
	xmlHttp.open("POST", url , true);

	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", info.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.send(info);
}

function getRoomAvailability(roomtypeid, hotelid, packageid) {
	
	var url		=	"/tabcontent/getroomavailability.php";
	var info	=	"rid="+roomtypeid+"&hid="+hotelid+"&pid="+packageid;
	xmlHttp		=	GetXmlHttpObject(getRoomAvailabilityResponse);
	xmlHttp.open("POST", url , true);

	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", info.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.send(info);
}

function getRoomAvailabilityResponse() {
   var output = '';
   if(xmlHttp.readyState == 4) {
      if(xmlHttp.status == 200) {
         output = xmlHttp.responseText;
		 document.getElementById('ajax-content').innerHTML = output;
      }
   }
}

function updatePriceResponse() {
   var output = '';
   if(xmlHttp.readyState == 4) {
      if(xmlHttp.status == 200) {
         output = xmlHttp.responseText;
		 document.getElementById('pricechange').innerHTML = output;
       }
   } else {
      //document.getElementById('ajax-container').innerHTML = "<img src='/img/ajax-loader.gif' width='80' height='53' />";
   }
}


function displayOptionalExtras(selectedvalue) {
	
	var url		=	"/tabcontent/displayextras.php";
	var info	=	"sd="+selectedvalue;
	xmlHttp		=	GetXmlHttpObject(displayResponse);
	xmlHttp.open("POST", url , true);

	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", info.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.send(info);
}

function displayResponse() {
   var output = '';
   if(xmlHttp.readyState == 4) {
      if(xmlHttp.status == 200) {
         output = xmlHttp.responseText;
		 document.getElementById('ajax-container').innerHTML = output;
		 if (document.getElementById('debugger')) {
			 var f = document.getElementById('debugger');
			 f.src = f.src;
		 }
       } else {
         document.getElementById('ajax-container').innerHTML = errorMessage+"\n"+output;
       }
   } else {
      document.getElementById('ajax-container').innerHTML = "<img src='/img/ajax-loader.gif' width='80' height='53' />";
   }
}

function callTabContent(url, pageElement, callMessage, errorMessage) {

	document.getElementById(pageElement).innerHTML = callMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responseTabContent(pageElement, errorMessage);};
     req.open("GET",url,true);
     req.send(null);
}

function responseTabContent(pageElement, errorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(pageElement).innerHTML = output;
		 document.getElementById('preloader').innerHTML = "";
       } else {
         document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
       }
   } else {
      document.getElementById('preloader').innerHTML = "<img src='/img/ajax-loader.gif' width='80' height='53' />";
   }
}

function makeActive(tab, script) { 
	var aObj	=	document.getElementById("tabmenu").getElementsByTagName('a');
	var i		=	aObj.length;
	var tabs	=	[];
	
	while(i--) { 
		if (aObj[i].id.indexOf('tab')==0) {
			tabs.push(aObj[i]);
		}
	}
	//alert(tabs.length);
	
	for (i=1; i<=tabs.length; i++) {
		document.getElementById("tab"+i).className = ""; 
	}
	
	document.getElementById("tab"+tab).className = "active"; 
	callTabContent('/tabcontent/'+script+'.php?content= '+tab, 'tabbed-content', '', 'error loading...'); 
} 

function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        'carouselfeed.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
		var brokenstring = Array();
        // split on the pipe to separate image path and url path
		var longstring   = jQuery(this).text();
		var brokenstring = longstring.split("|");
		
		carousel.add(first + i, mycarousel_getItemHTML(brokenstring[0], brokenstring[1]));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(filepath, url)
{
    return '<a href="/events/' + url + '"><img src="' + filepath + '" width="140" height="90" alt="" /></a>';
};

function logout() {
    var blnConfirm = window.confirm('Are you sure you want to logout of your account?');

    if (blnConfirm) {
		window.location.href = '/logout';
	}

    return blnConfirm;
}

function changeState() {
	if (document.getElementById("agree").checked) {
		document.getElementById("payfull").disabled = false;
		document.getElementById("payfull").style.color = "#fff";
		document.getElementById("payfull").style.cursor = "pointer";
		document.getElementById("paydeposit").disabled = false;
		document.getElementById("paydeposit").style.color = "#fff";
		document.getElementById("paydeposit").style.cursor = "pointer";
	} else {
		document.getElementById("payfull").disabled = true;
		document.getElementById("payfull").style.color = "#ccc";
		document.getElementById("payfull").style.cursor = "text";
		document.getElementById("paydeposit").disabled = true;
		document.getElementById("paydeposit").style.color = "#ccc";
		document.getElementById("paydeposit").style.cursor = "text";
	}
}

function toggleLayer( whichLayer ){  var elem, vis;  if( document.getElementById ) // this is the way the standards work    
	elem = document.getElementById( whichLayer );  else if( document.all ) // this is the way old msie versions work      
	elem = document.all[whichLayer];  else if( document.layers ) // this is the way nn4 works    
	elem = document.layers[whichLayer];  vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',5000);
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};





