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) {
			//alert(xhr[xhri].responseText)
		    document.getElementById(divID).innerHTML=xhr[xhri].responseText
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	xhr[xhri].send(null);
}

function vote(cid, ctid, hasVoted) {

	if (hasVoted=="0"){
		var xhri = xhrRequest('html');	
		xhr[xhri].open('GET', '../forum/vote.aspx?cid='+cid +'&ctid='+ctid, true);
		xhr[xhri].onreadystatechange = function() {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				//alert(xhr[xhri].responseText)
				//document.getElementById(divID).innerHTML=xhr[xhri].responseText
				xi[xhri] = 1;
				xhr[xhri] = null;
				alert("Thank you!");
				window.location.reload();
			}
		};
		xhr[xhri].send(null);
	}else{
		alert("One vote per day only!");
	}
}




function gotoURL(URL) { 
	window.location.hash = URL;
}


// show portfolio by portfolioID
function changeMenuImage(CategoryID){
     fcn('../files/getmenuimage.aspx?CategoryID='+CategoryID,'menuImageHolder');
}

function changeSpecialImage(PageID){
     fcn('../files/getpageimage.aspx?PageID='+PageID,'menuImageHolder');
}

function writeMenuContent(CategoryID){
	
   //document.getElementById('contentWrapper').style.height = "200px";
   if (navigator.appName.indexOf("Netscape") != -1) {
		document.getElementById('contentWrapper').style.minHeight = "200px";
   } else{
		document.getElementById('contentWrapper').style.height = "600px";
   }
     fcn('../files/getmenucontent.aspx?CategoryID='+CategoryID,'contentWrapper');
     JSFX_FloatTopDiv();
}

function getLeadershipCrews(CategoryID){
    fcn('../files/getleadershipcontent.aspx?CategoryID='+CategoryID,'leadershipContent');
    JSFX_FloatTopDiv();
}

function getFranchisingContent(PageID,DefaultPageID){
    writeFranchisingDiv();
    fcn('../files/getfranchisingcategory.aspx?PageID='+PageID,'franchisingCategory');
    
    if(parseInt(DefaultPageID) > 0){
      fcn('../files/getfranchisingsubcontent.aspx?PageID='+DefaultPageID,'franchisingContent');
    }else{
      fcn('../files/getfranchisingsubcontent.aspx?PageID='+PageID,'franchisingContent');
    }
}

function getFrancisingSubContent(PageID){
    fcn('../files/getfranchisingsubcontent.aspx?PageID='+PageID,'franchisingContent');
}

function getFAQContent(PageID){
    writeFranchisingDiv();
    fcn('../files/getfaq.aspx?PageID='+PageID,'contentWrapper');
}

function writeFranchisingDiv(){
    fcn('../files/getfranchisingdivs.aspx','contentWrapper');
}

/*function getTVC(sHeader,sDate,sBody,sVideoID,sWidth,sHeight){
	var sCopy = "";
	sCopy = "<p><b>";
	if (sHeader != "") {
		sCopy = sCopy + sHeader;
	} else {
		sCopy = sCopy + "Oops! Sorry, this video has been removed";	
	}
	sCopy = sCopy + "</b>";
	if (sDate != "") {
		sCopy = sCopy + " - <i>" + sDate + "</i>";
	}
	if (sBody != "") {
		sCopy = sCopy + "<br/>" + sBody;
	}
	sCopy = sCopy + "</p>";*/
	
function loadYouTubeValidator() {
	/*var image = new Image();
	var isValid = new Boolean();
	image.src = "http://www.youtube.com/favicon.ico";
	
	isValid = false;
	if (image.height > 0) {
		isValid = true;
	}
	return isValid;*/
	
/*	var xhri = xhrRequest('html');	
	var bResult = true;
	alert("Inside1 " + bResult);
		
	xhr[xhri].open('GET', '"http://www.youtube.com/js/account.js', true);
	alert("Inside2 " + bResult);
		
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			if(typeof addVideosToQuicklist == 'function') {
				bResult = true;
			} else {
				bResult = false;
			}
		} else {
			bResult = false;
		}
		xi[xhri] = 1;
		xhr[xhri] = null;
	};
	return bResult;
	
	var xhri = xhrRequest('html');	
	var bResult = false;
	alert("Inside " + bResult);
	
	xhr[xhri].open('GET', '"../files/youtubecheck.asp', true);
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			var ytResult = xhr[xhri].responseText;
			
			if (ytResult == "true") {
				bResult = true;
			}
		} else {
			bResult = false;
		}
		xi[xhri] = 1;
		xhr[xhri] = null;
	};
	return bResult;*/
}


	
function getTVC(pageID, isFeatured, isNewTV, isPreview){
	var xhri = xhrRequest('html');
	var sWidth = 425;
	var sHeight = 344;
	var isYouTubeSupported = 1;
	
	//alert("Function called " + has_you_tube());
	if (has_you_tube() == false) {
		isYouTubeSupported = 0;
	}
	
	//alert("YouTube? " + isYouTubeSupported);
	
	if (isFeatured == 1) {
		xhr[xhri].open('GET', '../files/getfeaturedtvcinfo.aspx?PageID='+pageID+'&YT='+isYouTubeSupported+'&PREVIEW='+isPreview + '&IsNewTV='+isNewTV, true);
	} else {
		xhr[xhri].open('GET', '../files/gettvcinfo.aspx?PageID='+pageID+'&YT='+isYouTubeSupported+'&PREVIEW='+isPreview, true);
	}
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			var arrTVCs = xhr[xhri].responseText.split("$|$");
			var i = 0;
			
			for(i=0;i<arrTVCs.length-1;i++){
				var tvcArr = arrTVCs[i].split("||");
				var sHeader = tvcArr[0];
				var sDate = tvcArr[1];
				var sBody = tvcArr[2];
				var sVideoID = tvcArr[3];
				var sCopy = "";

				sCopy = "<p><b>";
				if (sHeader != "") {
					sCopy = sCopy + sHeader;
				} else {
					sCopy = sCopy + "Oops! Sorry, this video has been removed";	
				}
				sCopy = sCopy + "</b>";
				if (sDate != "") {
					sCopy = sCopy + " - <i>" + sDate + "</i>";
				}
				if (sBody != "") {
					sCopy = sCopy + "<br/>" + sBody;
				}
				sCopy = sCopy + "</p>";
				document.getElementById('tvcHeading').innerHTML = sHeader;
				document.getElementById('tvcHeader').innerHTML = sCopy;
				document.getElementById('tvcHolder').innerHTML = "";
				fcn('../files/gettvc.aspx?m='+sVideoID+'&w='+sWidth+'&h='+sHeight,'tvcHolder');
			}
			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?storestate='+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 >= 1; j--){
				selectbox.options[j]=null;
			}
			ClearRestInfo();
			
			if (st != 1) {
				selectbox.options[0].text = "Please select a location";
			} else {
				selectbox.options[0].text = "";
			}
			
			var arrRests = xhr[xhri].responseText.split("$|$");
			var i = 0;
			var textLength = 0;
			var tempLength = 0;
			
			for(i=0;i<arrRests.length-1;i++){
				var restArr = arrRests[i].split("||");
				var optn = document.createElement("OPTION");
				optn.text = restArr[1];										// Address
				optn.value = restArr[0];									// Store ID (SID)
				selectbox.options.add(optn);
				
				tempLength = optn.text.length;
				if (tempLength > textLength) {
					textLength = tempLength;
				}
			}
			//selectbox.setAttribute('width', textLength); 
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	xhr[xhri].send(null);
}

function ClearRestInfo() {
	document.getElementById('ABO').value = "";
	document.getElementById('RMM').value = "";
	document.getElementById('RVP').value = "";
	document.getElementById('Franchisee').value = "";
	document.getElementById('DMA').value = "";
	document.getElementById('StoreAddress').value = "";
	document.getElementById('StoreCity').value = "";
	document.getElementById('StoreZip').value = "";
}

function GetRestDL(sid) {
	var xhri = xhrRequest('html');	
	xhr[xhri].open('GET', '../files/geteclubrest.aspx?sid='+sid, true);
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			ClearRestInfo();
			
			var restArr = xhr[xhri].responseText.split("||");
			document.getElementById('ABO').value = restArr[1];
			document.getElementById('RMM').value = restArr[2];
			document.getElementById('RVP').value = restArr[3];
			document.getElementById('Franchisee').value = restArr[4];
			document.getElementById('DMA').value = restArr[5];
			document.getElementById('StoreAddress').value = restArr[6];
			document.getElementById('StoreCity').value = restArr[7];
			document.getElementById('StoreZip').value = restArr[8];
			document.getElementById('StoreState').value = restArr[9];
			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 = "blueLineNo";
		obj.innerHTML = "";
	}else{
		wlObj.className = "blueLine";
		obj.className = "viewMap";
		obj.innerHTML = '<iframe name="MapFrame" id="MapFrame" src="../files/locations-map.aspx?ID=' + rid + '" style="width:423px; height:380px; border:0px;" allowTransparency="true" frameborder="0" scrolling="no"></iframe>';
	}

}


//window.onload = loadMulti();

