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 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 showMothersDay(){
	document.getElementById("fullCover").innerHTML="";
    fcn('../files/mothersday.asp','fullCover');
	showDiv('fullCover');
}

function showMothersDayComp(){
	document.getElementById("flashDiv").innerHTML="";
    fcn('../files/mothersdaycomp.asp','flashDiv');
	showDivComp();
}

function showFathersDay(){
	document.getElementById("flashDiv").innerHTML="";
    fcn('../files/fathersday_2009.asp','flashDiv');
	showDivComp();
}

function showFathersDayCodes(){
	document.getElementById("flashDiv").innerHTML="";
    fcn('../files/fathersdayCodes_2009.asp','flashDiv');
	showDivComp();
}

function showGiftCard(){
	if(window.location.href.indexOf('home.asp') >0){
		document.getElementById("promotionDiv").innerHTML="<img src='../assets/homeImg.jpg'>";
	}
	document.getElementById("flashDiv").innerHTML="";
    fcn('../files/giftcard.asp','flashDiv');
	showDivComp();
}

function showGiftCardC1(){
	if(window.location.href.indexOf('home_2008c1.asp') >0){
		document.getElementById("promotionDiv").innerHTML="<img src='../assets/2008C1Promotion.jpg'>";
	}
	document.getElementById("flashDiv").innerHTML="";
    fcn('../files/giftcard.asp','flashDiv');
	showDivComp();
}

function hideGiftCardC1() {
	if(window.location.href.indexOf('home_2008c1.asp') >0){
		var so = new SWFObject("../assets/2008C1Preloader.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 showMothersDayDiv() {
	if(window.location.href.indexOf('home.asp') >0){
		showCampainImg();
	}
	Dialog.alert({url: "mothersdaydiv_2008.asp", options: {method: 'get'}}, 
				{className: "alphacube", width:350, okLabel: " "});
	
}	

function showFathersDayDiv() {
	//if(window.location.href.indexOf('home.asp') >0){
		//showCampainImg();
	//}
	Dialog.alert({url: "fathersdaydiv_2009.asp", options: {method: 'get'}}, 
				{className: "alphacube", width:350, okLabel: " "});
	
}	

function showGiftCardDiv() {
	if(window.location.href.indexOf('home.asp') >0){
		showCampainImg();
	}
	Dialog.alert({url: "giftcarddiv_2008.asp", options: {method: 'get'}}, 
				{className: "alphacube", width:350, okLabel: " "});
	
}	


function showCampainImg() {
	document.getElementById("cDiv").innerHTML="<img src='../assets/2009C3Still.jpg'>";
	//document.getElementById("cDiv").innerHTML= "";
}

function showCampainSwf() {
	document.getElementById("cDiv").innerHTML="";
    fcn('../files/swf-2009C3.asp','cDiv');
	//var so = new SWFObject('../assets/2008C2Preloader.swf', "cDiv", "604", "409", "8");
	//so.addParam("wmode", "transparent");
	//so.write("cDiv");
}			
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GetRestsDL(st, selectbox) {
	var xhri = xhrRequest('html');	
	xhr[xhri].open('GET', '../files/includes/getrests.asp?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);
}
