// JavaScript Document
var cookie_price = .5;

function fadepic()
{
	if (curpos<100)
	{
		curpos+=10;
		if (tempobj.filters)
			tempobj.filters.alpha.opacity=curpos;
		else if (tempobj.style.MozOpacity)
			tempobj.style.MozOpacity=curpos/100;
	}
	else
	{
		clearInterval(dropslide);
		nextcanvas=(curcanvas=="canvas0")? "canvas0" : "canvas1";
		tempobj= document.getElementById(nextcanvas);
		tempobj.innerHTML='<img src="'+fadeimages[nextimageindex]+'">';
		nextimageindex=(nextimageindex<fadeimages.length-1)? nextimageindex+1 : 0;
		setTimeout("rotateimage()",pause);
	}
}

function rotateimage()
{
	resetit(curcanvas);
	var crossobj=tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas);
	crossobj.style.zIndex++;
	var temp='setInterval("fadepic()",50)';
	dropslide=eval(temp);
	curcanvas=(curcanvas=="canvas0")? "canvas1" : "canvas0";
	curimageindex=(curimageindex<fadeimages.length-1)? curimageindex+1 : 0;
}

function resetit(what)
{
	curpos=10;
	var crossobj= document.getElementById(what);
	if (crossobj.filters)
		crossobj.filters.alpha.opacity=curpos;
	else if (crossobj.style.MozOpacity)
		crossobj.style.MozOpacity=curpos/100;
}

function startit()
{
	var crossobj=document.getElementById(curcanvas);
	crossobj.innerHTML='<img src="'+fadeimages[curimageindex]+'">';
	rotateimage();
}

function PopVal()
{
	window.open('valpop.htm', 'Valentines', 'toolbar=no,location=no,width=510,height=660');
}

function PopEaster()
{
	window.open('easterpop.htm', 'Easter', 'toolbar=no,location=no,width=510,height=660');
}

function PopHoliday()
{
	window.open('holidaypop.htm', 'Holiday', 'scrollbars=yes,resizable=yes,toolbar=no,location=no,width=550,height=680');
}

function windowSize() 
{
	if( typeof( window.innerWidth ) == 'number' ) 
	{
    	//Non-IE
    	myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
    	//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
    	//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
}

function iecompattest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function snowIE_NS6() 
{  // IE and NS6 main animation function
	//doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
	//doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
	for (i = 0; i < no; ++ i) 
	{  // iterate for every dot
		yp[i] += sty[i];
		if (yp[i] > doc_height-50) 
		{
			xp[i] = Math.random()*(doc_width-am[i]-30);
			yp[i] = 0;
			stx[i] = 0.02 + Math.random()/10;
			sty[i] = 0.7 + Math.random();
		}
		dx[i] += stx[i];
		document.getElementById("dot"+i).style.top=yp[i]+"px";
		document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
	}
	snowtimer=setTimeout("snowIE_NS6()", 10);
}
	
function hidesnow()
{
	if (window.snowtimer) clearTimeout(snowtimer)
	for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden"
}
			
function snow()
{
	/******************************************
	* Snow Effect Script- By Altan d.o.o. (http://www.altan.hr/snow/index.html)
	* Visit Dynamic Drive DHTML code library (http://www.dynamicdrive.com/) for full source code
	* Last updated Nov 9th, 05' by DD. This notice must stay intact for use
	******************************************/
	  
	//Configure below to change URL path to the snow image
	var snowsrc="images/snow3.gif"
	// Configure whether snow should disappear after x seconds (0=never):
	var hidesnowtime = 0;
	///////////Stop Config//////////////////////////////////
	
	var i; 
	  
	windowSize();
	doc_width = myWidth;
	doc_height = myHeight;
		
	dx = new Array();
	xp = new Array();
	yp = new Array();
	am = new Array();
	stx = new Array();
	sty = new Array();
	for (i = 0; i < no; ++ i) 
	{  
		dx[i] = 0;                        // set coordinate variables
		xp[i] = Math.random()*(doc_width-50);  // set position variables
		yp[i] = Math.random()*doc_height;
		am[i] = Math.random()*20;         // set amplitude variables
		stx[i] = 0.02 + Math.random()/10; // set step variables
		sty[i] = 0.7 + Math.random();     // set step variables
		if (ie4up||ns6up) 
		{
			if (i == 0) 
			{
				document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><a href=\"http://dynamicdrive.com\"><img src='"+snowsrc+"' border=\"0\"><\/a><\/div>");
			} 
			else 
			{
				document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snowsrc+"' border=\"0\"><\/div>");
			}
		}
	}

	if (ie4up||ns6up)
	{
		snowIE_NS6();
		if (hidesnowtime>0)
			setTimeout("hidesnow()", hidesnowtime*1000)
	}
}

function CalPop(sInputName)
{
	window.open('Cal.asp?N=' + escape(sInputName) + '&DT=' + escape(window.eval(sInputName).value), 'CalPop', 'toolbar=no,location=no,width=220,height=220');
}

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

function dispTotalPrice(form)
{
	var cake;
	var can1;
	var can2;
	var can3;
	var cookie;
	var petit;
	
	cake = parseFloat(lblPrice.innerText.substr(1));
	can1 = parseFloat(form.cantotal1.value);
	can2 = parseFloat(form.cantotal2.value);
	can3 = parseFloat(form.cantotal3.value);
	cookie = parseFloat(cookietotal.innerText.substr(1));
	petit = parseFloat(petittotal.innerText.substr(1));

	total = isNaN(cake)?0:cake;
	total = total + (isNaN(can1)?0:can1);
	total = total + (isNaN(can2)?0:can2);
	total = total + (isNaN(can3)?0:can3);
	total = total + (isNaN(cookie)?0:cookie);
	total = total + (isNaN(petit)?0:petit);
	total = formatCurrency(total);
	form.totalprice.value = total;
}

function dispCake(form)
{
	var price;
	var oFlavor;
	
	oFlavor = eval("form.cakeflavor");
	
	switch (form.cakesize.value)
	{
		case "1" :
			price = 27;
			lblServes.innerText = "12 - 15";
			break;
		case "2" :
			price = 30;
			lblServes.innerText = "15 - 18";
			break;
		case "3" :
			price = 30;
			lblServes.innerText = "15 - 18";
			break;
		case "4" :
			price = 32;
			lblServes.innerText = "20";
			break;
		case "5" :
			price = 55;
			lblServes.innerText = "25";
			break;
		case "6" :
			price = 35;
			lblServes.innerText = "30 - 35";
			break;
		case "7" :
			price = 50;
			lblServes.innerText = "40";
			break;
		case "8" :
			price = 80;
			lblServes.innerText = "50";
			break;
		case "9" :
			price = 25;
			lblServes.innerText = "10 - 12";
			break;
		case "10" :
			price = 55;
			lblServes.innerText = "16 - 20";
			break;
		case "11" :
			price = 35;
			lblServes.innerText = "18 - 20";
			break;
		default :
			price = 0;
			lblServes.innerText = "";
	}
	if (oFlavor.value == 4)
	{
		price = price + 5;
		if (form.cakesize.value == "8")
			price = price + 5;
	}
	lblPrice.innerText = formatCurrency(price);
	dispTotalPrice(form);
}

function dispCanPrice(form, can)
{
	var total;
	var price;
	var oCanSize;
	var oDipped;
	var oQty;
	var oTotal;
	var oPrice;
	
	oCanSize = eval("form.cansize" + can);
	oDipped = eval("form.dipped" + can);
	oQty = eval("form.canqty" + can);
	oTotal = eval("form.cantotal" + can);
	oPrice = eval("canprice" + can);
	switch (oCanSize.value)
	{
		case "1" :
			price = 1.75;
			break;
		case "2" :
			price = 2;
			break;
		default :
			price = 0;
	}
	if (oDipped.checked)
		price = price + .25;
	oPrice.innerText = formatCurrency(price);
	if (oQty.value != "")
	{
		total = price * oQty.value;
		oTotal.value = total;
		dispTotalPrice(form);
	}
}

function dispCookie(form)
{
	if (form.cookieqty.value != "")
	{
		total = cookie_price * form.cookieqty.value;
		cookietotal.innerText = formatCurrency(total);
		dispTotalPrice(form);
	}
}
function dispPetit(form)
{
	var price;
	if (form.petitqty.value != "")
	{
		total = form.petitqty.value * 1.25;
		petittotal.innerText = formatCurrency(total);
		dispTotalPrice(form);
	}
}
