/* 
  ------------------------------------------------
  PVII Equal CSS Columns scripts -Version 2
  Copyright (c) 2005 Project Seven Development
  www.projectseven.com
  Version: 2.1.0
  ------------------------------------------------
*/

// by Paul@YellowPencil.com and Scott@YellowPencil.com
// feel free to delete all comments except for the above credit

function AllowOnly(Expression)
{
//alert(Expression);
 
 
 Expression = Replace(Expression, '0..9', '0123456789');
 Expression = Replace(Expression, '|', '');

 var ch = String.fromCharCode(window.event.keyCode);

 ch = ch.toLowerCase();
 Expression = Expression.toLowerCase();
 var a = Expression.indexOf(ch);
 if (a == -1)
  window.event.keyCode = 0;
}
function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Find);
		if (a == -1)
			break
		else
			temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}

var maxHeight = 0;

function setTall() {

	//alert(" inside settall");
	if (document.getElementById) {
		// the divs array contains references to each column's div element.  
		// Replace 'center' 'right' and 'left' with your own.  
		// Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
		var divs = new Array(document.getElementById('paddingcolumn'),document.getElementById('leftcontentcolumn'),document.getElementById('rightcontentcolumn'));
		
		// Let's determine the maximum height out of all columns specified
		for (var i = 0; i < divs.length; i++) {
		//  alert("The Intially height is :" + divs[i].offsetHeight );
		   if(divs[i])
			if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
		}
		
		// Let's set all columns to that maximum height
		for (var i = 0; i < divs.length; i++) {
			//alert("setting"+ i);
			
		if(i<2)
		{
		 if(divs[i])
			divs[i].style.height = maxHeight + 'px';
			// Now, if the browser's in standards-compliant mode, the height property
			// sets the height excluding padding, so we figure the padding out by subtracting the
			// old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
			
			//alert("i is less than 2");
			 if(divs[i])
			 {
				if (divs[i].offsetHeight > maxHeight) 
				{			
					divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
					
				}
			}
		}
		
		
		
		else
		{
			divs[i].style.height = 0;
			divs[i].style.height = maxHeight + 'px';
		}
		}//end for
		
		
		
	}
	
	r1h=0;
	r2h=0;
	r3h=0;
	var code=0;
	
	
	 
		if (document.getElementById('rightbottom') && document.getElementById('rightdownimage') )
		{
			var r1=document.getElementById('righttop');
			r1h=r1.offsetHeight;
		//	alert(" top He"+r1h);
			if (document.getElementById('rightbottom') && (document.getElementById('rightdownimage')))
			{
				code=1;
				var r2=document.getElementById('rightbottom');
				r2h=r2.offsetHeight;
			}
			var r3=document.getElementById('rightdownimage');
			r3h=r3.offsetHeight;	
			//alert(" Image He"+r3h);
			//alert("Max Height "+maxHeight);
			rheight= r1h + r2h + r3h;
			//alert("Right Height "+rheight);
			diff=maxHeight - rheight;
			//alert("Diff is "+diff);
			if (code)
			{
				//alert("has right Bottom");
				nh= diff+ r2h;
				//alert(nh);
				r2.style.height = nh + 'px';
			}
			else
			{
				nh= diff+ r1h;
			//	alert(nh);
				r1.style.height = nh + 'px';
			}
		}
	 
	
}
function setPress()
{
	//alert("In down "+maxHeight);//rightoplinktext3
	var r1=document.getElementById('righttop');
	var r2=document.getElementById('rightbottombody');
	var r3=document.getElementById('pressrightwrapper');
	var r4=document.getElementById('contentline');	
	var r4h=r4.offsetHeight;	
	
	r1h=r1.offsetHeight;
	r2h=r2.offsetHeight;
	r3h=r3.offsetHeight;
	total=r1h+ r2h +r3h;
	//alert("Total "+total);
	var diff=maxHeight -total;
	//alert("Diff "+diff);
	var nh=diff+r3h;
	//alert("new "+nh);
	r3.style.height = nh + 'px';	
}
function setRecipes()
{
	//alert("In down "+maxHeight);//rightoplinktext3
	var r1=document.getElementById('righttoptitle');
	var r2=document.getElementById('righttopbody');
	var r3=document.getElementById('recipesrightwrapper');
	
	var nh=0;
	r1h=r1.offsetHeight;
	r2h=r2.offsetHeight;
	r3h=r1.offsetHeight;
	total=r1h+ r2h +r3h;
	var diff=maxHeight -total;
	nh=diff+r3h;
	r3.style.height = nh + 'px';
}
function setViewcart()
{
	var r1=document.getElementById('righttoptitle');
	var r11=document.getElementById('rightoplinktext3');
	var r2=document.getElementById('rightdownimage');
	var r3=document.getElementById('viewcartwrapper');
	
	var nh=0;
	r1h=r1.offsetHeight;
	r11h=r11.offsetHeight;
	r2h=r2.offsetHeight;
	r3h=r1.offsetHeight;
	total=r1h+ r11h+ r2h +r3h;
	var diff=maxHeight -total;
	nh=diff+r3h;
	r3.style.height = nh + 'px';
	
	
}
function setDown()
{
	//alert("In down "+maxHeight);//rightoplinktext3
	var r1=document.getElementById('righttoptitle');
	var r2=document.getElementById('rightoplinktext3');
	var r3=document.getElementById('righttopbodytext3');
	var r4=document.getElementById('rightdownimage');
		r1h=r1.offsetHeight;
		if (!r2)
		r2h=0;
		else
		r2h=r2.offsetHeight;
		
		r3h=r3.offsetHeight;
		r4h=r4.offsetHeight;
		total=r1h+r2h+r3h+r4h;
		//alert("Total "+total);
		diff=maxHeight -total;
		//alert("Diff "+diff);
		//alert("Int "+r3h);
		var nh=diff+r3h;
		r3.style.height = nh + 'px';	
		//alert(nh);
		r3h=r3.offsetHeight;
		//alert("Fin "+r3h);
}
window.onload = function() {
	//alert("window on load");
	setTall();
	if (document.getElementById('rightcol2'))
	{
		 setDown();
	}
	if (document.getElementById('pressrightwrapper'))
	{
		 setPress();
		 setTall();
	}
	if (document.getElementById('recipesrightwrapper'))
	{
		 setRecipes();
	}
	if (document.getElementById('viewcartwrapper'))
	{
		 setViewcart();
		 setFooter();
	}
	
	//setTall();
}

window.onresize = function() {

	//setTall();
}
var windowHeight = 0;
function getWindowHeight() {
			
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
}
function setFooter(){

	var fh=document.getElementById('footer').offsetHeight;
	var total=maxHeight+fh;
	var d1=document.getElementById('paddingcolumn')
	var d2=document.getElementById('leftcontentcolumn')
	var d3=document.getElementById('viewcartwrapper')
	d1h=d1.offsetHeight;
	d2h=d2.offsetHeight;
	d3h=d3.offsetHeight;
	getWindowHeight();
	var diff=windowHeight-total;
	//alert(windowHeight);
	//alert(total);
	//alert("Diff "+diff)
	if ( windowHeight > (total+78))
	{
		if (diff > 0)
		{
			//alert("set footer");
			var nh1=diff+d1h-78;
			var nh2=diff+d2h-78;
			var nh3=diff+d3h-78;
			d1.style.height = nh1 + 'px';
			d2.style.height = nh2 + 'px';
			d3.style.height = nh3 + 'px';
		}
	}
	else
	{
		//alert("Not set");
	}
}


