﻿function toggleLrgImg(id,show) {
	var width = document.getElementById(id).width + 5 + "px";		
	document.getElementById("lrg"+id).style.display = "none";
	if(show) {
		document.getElementById("lrg"+id).style.display = "block";
		// if browser is not IE
		if(!Browser()) {
			document.getElementById("lrg"+id).style.marginLeft = width;
		}
	}
}

function ajaxload(url, containerid, condition) {
	try { // Browser object detection
		
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
		new ActiveXObject("Microsoft.XMLHTTP");		
	}
	catch (e){alert(e.description)} // browser doesn't support ajax. handle however you want
	xmlhttp.onreadystatechange = function(){statuschanged(containerid,condition)}; // every time ready status changes, statuschanged() function executes
	xmlhttp.open("GET", url, true); // Usage: open(HTTP method, url, and asynchronous = true or false)
	xmlhttp.send(null); // send the request.
}

function statuschanged(containerid, condition){
	if((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { // readyState codes: 0=Uninitialised 1=Loading 2=Loaded 3=Interactive 4=Completed; status code: 200=OK
		if(xmlhttp.responseText != "") {
			if(condition == "h") { // populating a hidden field
				document.getElementById(containerid).value = xmlhttp.responseText; // xmlhttp.responseText object contains the text of 'url'		
			}
			else if(condition == "a") { // if condition is append
				document.getElementById(containerid).innerHTML += xmlhttp.responseText; // xmlhttp.responseText object contains the text of 'url'		
			}
			else {
				document.getElementById(containerid).innerHTML = xmlhttp.responseText; // xmlhttp.responseText object contains the text of 'url'		
			}			
		}
	}
	else { // else, readyState is not yet Completed and status is not yet OK, so here we display loading text
		document.getElementById(containerid).innerHTML = "Loading...";		
	}
}

function changeTab(id) {
    var tabs = new Array("specials","breakfast","lunch","other");
    for(var i=0; i<tabs.length; i++) {
        document.getElementById(tabs[i] + "Content").style.display = "none";
        if(tabs[i] != id) {
            document.getElementById(tabs[i]).style.backgroundImage = "url('/App_Themes/Default/Images/" + tabs[i] + ".gif')";
        }
    }
    document.getElementById(id + "Content").style.display = "block";
    document.getElementById(id).getElementsByTagName("a")[0].style.background = "none";
    document.getElementById(id).style.backgroundImage = "url('/App_Themes/Default/Images/" + id + "-ov.gif')";
}

function writeEmail(name, domain, ext) {
    at = "@";
    dot = ".";    
    var email = name + at + domain + dot + ext;
    document.write('<a href="mailto:' + email + '" title="' + email + '">' + email + '<\/a>');
}

function capitalizeFirstLetter(str) {
    var newStr = "";
    str = str.split(" ");
    for(var i=0; i<str.length; i++) {
        newStr += str[i].substring(0,1).toUpperCase() + str[i].substring(1,str[i].length) + " ";
    }
    return newStr;
}