var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE

function xhrRequest(type) {
	if (!type) {
		type = 'html';
	}

	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length; 
	
	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {

		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}

	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;

	// SET UP THE REQUEST
	if (window.ActiveXObject) {
		try {
			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) {
		xhr[xhrsend] = new XMLHttpRequest();
		if (xhr[xhrsend].overrideMimeType) {
			xhr[xhrsend].overrideMimeType('text/' + type);
		}
	}
	return (xhrsend);
}

function fcn(url, divID) {
	var xhri = xhrRequest('html');	
	xhr[xhri].open('GET', url, true);
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
		    document.getElementById(divID).innerHTML=xhr[xhri].responseText
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	xhr[xhri].send(null);
}

function GetRestsDL(st, selectbox) {
	var xhri = xhrRequest('html');	
	xhr[xhri].open('GET', '../files/geteclubrests.aspx?state='+st, true);
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			//clear the dropdown list first 
			for (var j = (selectbox.options.length-1); j >= 0; j--){
         		selectbox.options[j]=null;
     		}
			var arrRests = xhr[xhri].responseText.split("$|$");
			var i = 0
			for(i=0;i<arrRests.length-1;i++){
				var restArr = arrRests[i].split("||");
				var optn = document.createElement("OPTION");
				optn.text = restArr[1];
				optn.value = restArr[0];
				selectbox.options.add(optn);
			}
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	xhr[xhri].send(null);
}



function gotoURL(URL) { 
	window.location.hash = URL;
}

function hideDiv(src) {
	document.getElementById("coverDiv").style.display = 'none';
	document.getElementById(src).style.display = 'none';
}	

function hideDivComp() {
	if(window.location.href.indexOf('home.asp') >0){
		var so = new SWFObject("../assets/C6Preloader.swf", "prom", "604", "409", "8");
		so.addParam("wmode", "transparent");
		so.write("promotionDiv");
	}
	document.getElementById("flashDiv").style.display = 'none';
	document.getElementById("closeDiv").style.display = 'none';
	document.getElementById("coverBgDiv").style.display = 'none';
}	

function showDiv(src) {
	document.getElementById("coverDiv").style.display = 'block';
	document.getElementById(src).style.display = 'block';
}	

function showDivComp() {
	document.getElementById("flashDiv").style.display = 'block';
	document.getElementById("closeDiv").style.display = 'block';
	document.getElementById("coverBgDiv").style.display = 'block';
}	



function getTVC(mName,width,height){
    fcn('../files/gettvc.aspx?m='+mName+'&w='+width+'&h='+height,'tvcHolder');
}

/*
function ShowMap(rid){
    //fcn('../files/locations-getmap.aspx?RestaurantID='+rid,'div1');
	var obj = document.getElementById("div"+rid); // find the div for private dining div
	var wlObj = document.getElementById("wldiv"+rid); // find the white line div
	if (obj.className == "viewMap"){
		obj.className = "viewMapNo";
		wlObj.className = "whitelineNo";
	}else{
		wlObj.className = "whiteline";
		obj.className = "viewMap";
		var xhri = xhrRequest('html');	
		xhr[xhri].open('GET', "../files/locations-getmapinfo.aspx?RestaurantID="+rid, true);
		xhr[xhri].onreadystatechange = function() {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				obj.innerHTML = "";
				var arrInfo = xhr[xhri].responseText.split("$|$");
				if (GBrowserIsCompatible()) {
					var map = new GMap2(obj);
					map.addControl(new GSmallMapControl());
					//map.addControl(new GMapTypeControl());
					//map.setCenter(new GLatLng(arrInfo[0], arrInfo[1]), 13);
					map.setCenter(new GLatLng(arrInfo[0], arrInfo[1]), 11, G_SATELLITE_MAP);
					var infoTabs = [  
					new GInfoWindowTab("Physical", arrInfo[2])
					];	
					marker = new GMarker(map.getCenter());
					GEvent.addListener(marker, "click", function() {  
						marker.openInfoWindowTabsHtml(infoTabs);
					});
					map.addOverlay(marker);
					marker.openInfoWindowTabsHtml(infoTabs);
				  }			
				
				xi[xhri] = 1;
				xhr[xhri] = null;
			}
		};
		xhr[xhri].send(null);
	}
}
*/


function ShowMap(rid){
	var obj = document.getElementById("div"+rid); // find the div for private dining div
	var wlObj = document.getElementById("wldiv"+rid); // find the white line div
	if (obj.className == "viewMap"){
		obj.className = "viewMapNo";
		wlObj.className = "whitelineNo";
	}else{
		wlObj.className = "whiteline";
		obj.className = "viewMap";
		obj.innerHTML = '<iframe name="MapFrame" id="MapFrame" src="../files/locations-map.aspx?RestaurantID=' + rid + '" style="width:520px; height:420px; border:0px" allowtransparency="true" frameborder="0" scrolling="no"></iframe>';
	}

}

function ShowDining(rid){
	var obj = document.getElementById("div"+rid); // find the div for private dining div
	var wlObj = document.getElementById("wldiv"+rid); // find the white line div
	if (obj.className == "privDine"){
		obj.className = "privDineNo";
		wlObj.className = "whitelineNo";
	} else {
		obj.className = "privDine";
		wlObj.className = "whiteline";
		obj.innerHTML = '<iframe name="PrivateDiningFrame" id="PrivateDiningFrame" src="../files/locations-privatedininginfo.aspx?RestaurantID=' + rid + '" style="width:580px; height:300px; border:0px" allowtransparency="true" frameborder="0" scrolling="no"></iframe>';
	}
}

function ShowDiningOld(rid){
    //fcn('../files/locations-getmap.aspx?RestaurantID='+rid,'div1');
	var obj = document.getElementById("div"+rid); // find the div for private dining div
	var wlObj = document.getElementById("wldiv"+rid); // find the white line div
	if (obj.className == "privDine"){
		obj.className = "privDineNo";
		wlObj.className = "whitelineNo";
	}else{
		obj.className = "privDine";
		wlObj.className = "whiteline";
		var xhri = xhrRequest('html');	
		xhr[xhri].open('GET', "../files/locations-privatedininginfo.aspx?RestaurantID="+rid, true);
		xhr[xhri].onreadystatechange = function() {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var arrInfo = xhr[xhri].responseText.split("$|$");
				obj.innerHTML = arrInfo[0];
				xi[xhri] = 1;
				xhr[xhri] = null;
				//window.addEvent('domready', startSlide('gallery'+rid, arrInfo[1]));
				/*
				var myShow = new Slideshow('gallery2');
				myShow.type = "push";
				myShow.navigation = "arrows+"
				myShow.duration = [2000, 4000];
				myShow.hu = "../uploaded/image/large/";
				myShow.width = "400";
				myShow.height = "300";
				myShow.images = "'br-test-green1.jpg','br-test-green2.jpg','TEDDYtest.jpg','br test.jpg'";
				
				*/
				//window.addEvent('domready',function(){
				//var imgNames = "br-test-green1.jpg,br-test-green2.jpg"
				//alert(imgNamesArr.toString());
					var slideObj = {};
					slideObj.duration = [2000,4000];
					slideObj.navigation = 'arrows';
					slideObj.width = 245;
					slideObj.height = 200;
					slideObj.hu = '../uploaded/image/large/';
					slideObj.type = 'fade'; //fade, pan, zoom, combo, push or wipe
					slideObj.images = arrInfo[1].split(",");
					slideObj.captions = arrInfo[2].split(",");
					myShow = new Slideshow('gallery'+rid,slideObj);
					//myShow.play();
				//});
				
				/*
				
				var myShow = new Slideshow('gallery'+rid, { type: 'push', duration: [2000, 4000], width: 400, height:300, hu: '../uploaded/image/large/', images: ['br-test-green1.jpg','br-test-green2.jpg','TEDDYtest.jpg','br test.jpg']});	*/
				
			}
		};
		xhr[xhri].send(null);
	}
}

function emailRest(rid){
	var xhri = xhrRequest('html');	
	xhr[xhri].open('POST', "../files/emailus.aspx", true);
	xhr[xhri].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			/*var arrInfo = xhr[xhri].responseText.split("$|$");
			obj.innerHTML = arrInfo[0];
			xi[xhri] = 1;
			*/
			alert(xhr[xhri].responseText);
			//xhr[xhri] = null;
		}
		xhr[xhri].send("RestaurantID="+rid);
	}
}


function ShowDiningTestOld(rid){
    //fcn('../files/locations-getmap.aspx?RestaurantID='+rid,'div1');
	var obj = document.getElementById("div"+rid); // find the div for private dining div
	var wlObj = document.getElementById("wldiv"+rid); // find the white line div
	if (obj.className == "privDine"){
		obj.className = "privDineNo";
		wlObj.className = "whitelineNo";
	}else{
		obj.className = "privDine";
		wlObj.className = "whiteline";
		var xhri = xhrRequest('html');	
		xhr[xhri].open('GET', "../files/locations-privatedininginfo-test.aspx?RestaurantID="+rid, true);
		xhr[xhri].onreadystatechange = function() {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var arrInfo = xhr[xhri].responseText.split("$|$");
				obj.innerHTML = arrInfo[0];
				xi[xhri] = 1;
				xhr[xhri] = null;
				//window.addEvent('domready', startSlide('gallery'+rid, arrInfo[1]));
				/*
				var myShow = new Slideshow('gallery2');
				myShow.type = "push";
				myShow.navigation = "arrows+"
				myShow.duration = [2000, 4000];
				myShow.hu = "../uploaded/image/large/";
				myShow.width = "400";
				myShow.height = "300";
				myShow.images = "'br-test-green1.jpg','br-test-green2.jpg','TEDDYtest.jpg','br test.jpg'";
				
				*/
				//window.addEvent('domready',function(){
				//var imgNames = "br-test-green1.jpg,br-test-green2.jpg"
				//alert(imgNamesArr.toString());
					var slideObj = {};
					slideObj.duration = [2000,2000];
					slideObj.navigation = 'arrows';
					slideObj.width = 245;
					slideObj.height = 200;
					slideObj.hu = '../uploaded/image/large/';
					slideObj.type = 'fade'; //fade, pan, zoom, combo, push or wipe
					slideObj.images = arrInfo[1].split(",");
					slideObj.captions = arrInfo[2].split(",");
					myShow = new Slideshow('gallery'+rid,slideObj);
					//myShow.play();
				//});
				
				/*
				
				var myShow = new Slideshow('gallery'+rid, { type: 'push', duration: [2000, 4000], width: 400, height:300, hu: '../uploaded/image/large/', images: ['br-test-green1.jpg','br-test-green2.jpg','TEDDYtest.jpg','br test.jpg']});	*/
				
			}
		};
		xhr[xhri].send(null);
	}
}

/*
function startSlide(rid){
	var xhri = xhrRequest('html');	
	xhr[xhri].open('GET', "../files/locations-privatedininginfo-test.aspx?RestaurantID="+rid, true);
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			var arrInfo = xhr[xhri].responseText.split("$|$");
			obj.innerHTML = arrInfo[0];
			xi[xhri] = 1;
			xhr[xhri] = null;
				var slideobj = {};
				slideobj.duration = [2000,2000];
				slideobj.navigation = 'arrows';
				slideobj.width = 245;
				slideobj.height = 200;
				slideobj.hu = '../uploaded/image/large/';
				slideobj.type = 'fade'; //fade, pan, zoom, combo, push or wipe
				slideobj.images = arrinfo[1].split(",");
				slideobj.captions = arrinfo[2].split(",");
				myshow = new slideshow('gallery'+rid,slideobj);
		}
	};
    xhr[xhri].send(null);
	
	//var myShow = new Slideshow('gallery2', { type: 'push', navigation: 'arrows+', duration: [2000, 4000], width: 400, height:300, hu: '../uploaded/image/large/', images: [imgNames]});	
}

function startGallery(gdiv) {
	var myGallery = new gallery($(gdiv), {
	timed: true,
	showArrows: true,
	showCarousel: false
	});
}


function ShowMap() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("div1"));
	var physical = "<b>St Cuthbert's College</b><br> 122 Market Road, <br>Epsom, <br>Auckland, <br>New Zealand";
	var postal = "<b>St Cuthbert's College</b><br>PO Box 26 020, <br>Epsom, <br>Auckland 1344, <br>New Zealand ";
	map.addControl(new GSmallMapControl());
	//map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(-36.886771, 174.778849), 13);
	var infoTabs = [  
	new GInfoWindowTab("Physical", physical),  
	new GInfoWindowTab("Postal", postal)
	];	
	marker = new GMarker(map.getCenter());
	GEvent.addListener(marker, "click", function() {  
		marker.openInfoWindowTabsHtml(infoTabs);
	});
	map.addOverlay(marker);
	marker.openInfoWindowTabsHtml(infoTabs);
  }
}

*/


