function recalc(frm) {
	for (var i=0; i < frm.cake.length; i++) {
		if (frm.cake[i].checked) var cake_val = frm.cake[i].value;
	}
	for (var i=0; i < frm.size.length; i++) {
		if (frm.size[i].checked) var size_val = frm.size[i].value;
	}	
	for (var i=0; i < frm.delivery.length; i++) {
		if (frm.delivery[i].checked) var delivery_val = frm.delivery[i].value;
	}
	var final_val = ((cake_val * size_val) + (cake_val * delivery_val));
	document.getElementById('cotm_price').innerHTML = "Annual Price<b>$" + final_val + "</b>";
}

function updateingredients(frm) {
	
	var ingstring = "";
	var cake = document.getElementById("cake");
	var filling = document.getElementById("filling");
	var frosting = document.getElementById("frosting");
	
	tmpindex = cake.options[cake.selectedIndex];
	if (tmpindex != null) {
		tmp = cake.options[cake.selectedIndex].value;
		if (tmp != "") {
			ingstring += "<p><b>CAKE</b> (";
			ingstring += cake.options[cake.selectedIndex].text;
			ingstring += "): ";
			ingstring += tmp;
			ingstring += "</p>";
		}
	}
	tmpindex = filling.options[filling.selectedIndex];
	if (tmpindex != null) {
		tmp = filling.options[filling.selectedIndex].value;
		if (tmp != "") {
			ingstring += "<p><b>FILLING</b> (";
			ingstring += filling.options[filling.selectedIndex].text;
			ingstring += "): ";
			ingstring += tmp;
			ingstring += "</p>";
		}	
	}
	tmpindex = frosting.options[frosting.selectedIndex];
	if (tmpindex != null) {	
		tmp = frosting.options[frosting.selectedIndex].value;
		if (tmp != "") {
			ingstring += "<p><b>FROSTING</b> (";
			ingstring += frosting.options[frosting.selectedIndex].text;
			ingstring += "): ";
			ingstring += tmp;
		}
	}
	document.getElementById("ingredientlist").innerHTML = ingstring;
}

var limit = 500;
var long_limit = 1800;

function check() {
	if(document.f.comments.value.length > limit) {
		alert('Too much data!');
		document.f.comments.focus();
		return false; 
	} else
	return true; 
}
 
function update_counter() {
	var old = document.f.counter.value;
	document.f.counter.value=document.f.comments.value.length;
	if(document.f.counter.value > limit && old <= limit) {
		alert('Too much data in the text box!');
		if(document.styleSheets) {
		 	document.f.counter.style.fontWeight = 'bold';
		   	document.f.counter.style.color = '#ff0000'; 
		}
	} else if (document.f.counter.value <= limit && old > limit && document.styleSheets ) {
	   document.f.counter.style.fontWeight = 'normal';
	   document.f.counter.style.color = '#000000'; 
	} 
}

 
function update_counter_long() {
	var old = document.f.counter.value;
	document.f.counter.value=document.f.comments.value.length;
	if(document.f.counter.value > long_limit && old <= long_limit) {
		alert('Too much data in the text box!');
		if(document.styleSheets) {
		 	document.f.counter.style.fontWeight = 'bold';
		   	document.f.counter.style.color = '#ff0000'; 
		}
	} else if (document.f.counter.value <= long_limit && old > long_limit && document.styleSheets ) {
	   document.f.counter.style.fontWeight = 'normal';
	   document.f.counter.style.color = '#000000'; 
	} 
}

function share_warning(checkval) {
	if(checkval) {
		document.getElementById("share_warning").innerHTML = "When you share this item, it will be reviewed by Lunchtaker. If it meets <a href='/article.php?id=6&Sharing+lunch+foods+on+Lunchtaker.com' target='_blank'>our criteria</a> and is accepted into the library, you will no longer be able to edit the item.";
	} else {
		document.getElementById("share_warning").innerHTML = "";	
	}
}

function neworexisting(p) {
	radios = document.getElementsByName('add_type');
	if (p) {
		radios[1].checked = true;
	} else {
		radios[0].checked = true;			
	}
}

function clearratings() {
	var i=1, m="";
	for (i=1;i<=5;i++) {
		m = i + "star";
		document.getElementById(m).src = "img/0star.gif";
	}
}

function rate(rating) {
	clearratings();
	document.getElementById("1star").src = "img/1star.gif";
	if (rating > 1) document.getElementById("2star").src = "img/1star.gif";
	if (rating > 2) document.getElementById("3star").src = "img/1star.gif";
	if (rating > 3) document.getElementById("4star").src = "img/1star.gif";
	if (rating > 4) document.getElementById("5star").src = "img/1star.gif";
}

function rate_return(rating) {	
	var fl = Math.floor(rating);
	var cl = Math.ceil(rating);
	var fraction = false;
	if (fl != cl) fraction = true;
	clearratings();
	document.getElementById("1star").src = "img/1star.gif";
	if (rating > 1) {
		document.getElementById("2star").src = "img/1star.gif";
		if (rating < 2) document.getElementById("2star").src = "img/star_half.gif"
	}
	if (rating > 2) {
		document.getElementById("3star").src = "img/1star.gif";
		if (rating < 3) document.getElementById("3star").src = "img/star_half.gif"
	}
	if (rating > 3) {
		document.getElementById("4star").src = "img/1star.gif";
		if (rating < 4) document.getElementById("4star").src = "img/star_half.gif"
	} 
	if (rating > 4) {
		document.getElementById("5star").src = "img/1star.gif";
		if (rating < 5) document.getElementById("5star").src = "img/star_half.gif"
	}
}
function paginate(num) {
	document.forms["galleryForm"].pageno.value = num;
	$('form').submit();
}
function switch_az(frm, val) {
	frm.letter.value = val;
	frm.submit();	
}