// define getElementsByClassName for old ie
document.getElementsByClassName = function(class_name) {
    var docList = this.all || this.getElementsByTagName('*');
    var matchArray = new Array();

    /*Create a regular expression object for class*/
    var re = new RegExp("(?:^|\\s)"+class_name+"(?:\\s|$)");
    for (var i = 0; i < docList.length; i++) {
        if (re.test(docList[i].className) ) {
            matchArray[matchArray.length] = docList[i];
        }
    }

	return matchArray;
}//eof annonymous function


var active;
active = "images/2_main_menu_on.gif";

function rollon(id) {
	mysrc = id.src;
	mysrc = mysrc.substr(0, mysrc.length - 4);
	id.src = mysrc + "_on.gif";
}

function rolloff(id) {
	mysrc = id.src;
	mysrc = mysrc.substr(0, mysrc.length - 7);
	id.src = mysrc + ".gif";
}

function verticalCenter() {
	var winH = 0;
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winH = window.innerHeight-16;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winH = document.body.offsetHeight-20;
		}
	}
}

function rollon2(id) {
	//roll on only if not already rolled on (check suffix)
	mysrc = id.src;
		
	thelen = mysrc.length;
	if (thelen > 7) {
		laststr = mysrc.substr(thelen-7, 7);
		if (laststr == "_on.gif")
			return; //already on
	}
	
	mysrc = mysrc.substr(0, mysrc.length - 4);
	id.src = mysrc + "_on.gif";
}

function rolloff2(id) {
	//roll off only if not active (check active)
	mysrc = id.src;
	
	if (active == mysrc) {
		//window.alert(active + "==" + mysrc);
		return;
	}
	thelen = mysrc.length;
	laststr = mysrc.substr(thelen - 7, 7);
	if (laststr == "_on.gif") {
		mysrc = mysrc.substr(0, mysrc.length - 7);
		id.src = mysrc + ".gif";
	}
}

function makeActive(id) {
	active = id.src;
	for (i = 1; i <= 5; i++) {
		theimg = document.getElementById('img' + i);
		rolloff2(theimg);
	}
	rollon2(id);
}

function closePop(id) {
	if (id == '') {
		thepopup = document.getElementById("popup");
	} else {
		thepopup = document.getElementById(id);
	}
	if (thepopup) {
		// thepopup.style.visibility = "hidden";
		thepopup.style.display = "none";
	}
}

function openPop(id) {
	if (id == '') {
		thepopup = document.getElementById("popup");
	} else {
		thepopup = document.getElementById(id);
	}
	if (thepopup) {
		// thepopup.style.visibility = "visible";
		thepopup.style.display = "block";
	}
}

function closePopAll() {
	//popup_ xmas, shrimp, iso, ichigo, trivia, mussels
	thearr = new Array("xmas", "shrimp", "iso", "ichigo", "trivia", "mussels", "teriyaki", "happy", "tako",
				"corn");
	for (i = 0; i < thearr.length; i++) {
		closePop("popup_" + thearr[i]);
	}
	classel = document.getElementsByClassName("popup_general");
	if (classel) {
		for (j = 0; j < classel.length; j++) {
			// classel[j].style.visibility = "hidden";
			classel[j].style.display = "none";
		}
	}
}

//AJAX FUNCTIONS
var xmlHttp;

function fetchItem(itemid) {
	document.getElementById("poptable_holder").innerHTML="Retrieving...";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return
	} 
	var url="fetchitem.php";
	url=url+"?id="+itemid
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function fetchBranch(bid) {
	document.getElementById("poptable_holder").innerHTML="Retrieving...";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return
	} 
	var url="fetchbranch.php";
	url=url+"?id="+bid
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("poptable_holder").innerHTML=xmlHttp.responseText;
		document.getElementById("popup").style.visibility = "visible";
	} 
} 

function GetXmlHttpObject() { 
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}
