/*	
	Taff
	06/06/2005	
*/
window.onload = init;
window.onresize = init;

/*	
	Taff
	06/06/2005	
*/
function init(){
	try{
		var sLocation = window.location.href;
		if(sLocation.indexOf("/Market/") >= 0){
			turnOn(document.getElementById("imgMarket"));
		}else if(sLocation.indexOf("/Weather/") >= 0){
			turnOn(document.getElementById("imgMyFarm"));
		}else if(sLocation.indexOf("/GetQuote/") >= 0){
			turnOn(document.getElementById("imgMarket"));
		}else if(sLocation.indexOf("/Seedman/") >= 0){
			turnOn(document.getElementById("imgSeedman"));
		}else if(sLocation.indexOf("/Fertman/") >= 0){
			turnOn(document.getElementById("imgFertman"));
		}else if(sLocation.indexOf("/UsefulLinks/") >= 0){
			turnOn(document.getElementById("imgUseful"));
		}else if(sLocation.indexOf("/Help/") >= 0){
			turnOn(document.getElementById("imgHelp"));
		}else{
			if(document.getElementById("imgMyFarm")){
				turnOn(document.getElementById("imgMyFarm"));
			}
		}	
		setFillers();
		//Taff, 10/08/2005
		//attempt to run a function called doc_init in the page, ignore error if can't be found
		try{
			doc_init();
		}catch(e){
			//ignore if can't be found
		}
		
		//Hywel 23/11/2005 - need to highlight grids
		try{
			startHighlight('Report');
		}catch(e){
			//ignore if can't be found
		}		
		
	}catch(e){
		alert(e.message);
	}
}
/*	
	Taff
	06/06/2005	
*/
function turnOn(img){
	try{
		var sSrc = img.src;
		//if the image is currently off
		if(sSrc.indexOf("_over.gif") == -1){
			//turn it on
			sSrc = sSrc.replace(".gif","")
			sSrc = sSrc + "_over.gif"
			img.src = sSrc
		}
	}catch(e){
		
	}
}
/*	
	Taff
	06/06/2005	
*/
function turnOff(img){
	try{
		//turn off the current image
		var sSrc = img.src;
		sSrc = sSrc.replace("_over.gif",".gif")
		img.src = sSrc
		//make sure the correct image is on
		init();
	}catch(e){
		alert(e.message);
	}
}
/*	
	Taff
	06/06/2005	
*/
function setFillers(){
	try{
		//if the active window needs the header image extending to fill the screen
		if(document.getElementById("imgRightFill")){
			if((document.body.clientWidth-660)>0){
				document.getElementById("imgRightFill").width = document.body.clientWidth-660;
			}else{
				document.getElementById("imgRightFill").width = 0;
			}
		}
		//if the active window needs the header image extending to fill the screen
		if(document.getElementById("imgRightFillAdmin")){
			if((document.body.clientWidth-144)>0){
				document.getElementById("imgRightFillAdmin").width = document.body.clientWidth-144;
			}else{
				document.getElementById("imgRightFillAdmin").width = 0;
			}
		}
		//if the active window need the left and right fillers to go beyond the bottom of the document
		if (document.getElementById("LeftFill")) {
			if((document.body.clientHeight-5)>0){
				var i =0;
				
				try  {
					i = document.getElementById("Header").clientHeight  + document.getElementById("Main").clientHeight -5;			
				} catch(e) {
					i = document.getElementById("Header_Admin").clientHeight  + document.getElementById("Main").clientHeight -5;			
				}
										
				if (i < document.body.clientHeight) {
					i = document.body.clientHeight;
				}				
				
				if (showscroll()) {
					try  {						
						i = i + document.getElementById("Header").clientHeight;			
					} catch(e) {
						i = i + document.getElementById("Header_Admin").clientHeight;			
					}	
				}
			
				//article - special case
				try {
					if (document.getElementById("article").clientHeight)
						{
							if (document.getElementById("article").clientHeight > i)
							{ 
								i=document.getElementById("article").clientHeight;
								
								try  {						
									i = i + document.getElementById("Header").clientHeight;			
								} catch(e) {
									i = i + document.getElementById("Header_Admin").clientHeight;			
								}	
							}
						}	
					} catch(e) {
								
					}	
																								
				document.getElementById("LeftFill").style.height = i ;
				try {
					document.getElementById("RightFill").style.height = i ;
				}catch(e) {
				}				
			}else{
				document.getElementById("LeftFill").style.height = 0;
				try {	
					document.getElementById("RightFill").style.height = 0;	
				}catch(e) {
				}
			}
		}
		//if the active window needs the right hand side filling in
		if((document.body.clientWidth-795)>0){
			try {				
				document.getElementById("RightFill").style.width = document.body.clientWidth-795;	
			}catch(e) {
			}
		}else{
			try {
				//header
				try  {
					document.getElementById("Header").style.width  = document.getElementById("LeftFill").clientWidth + document.getElementById("Main").clientWidth + document.getElementById("RightFill").clientWidth;		
					document.getElementById("Header").style.width=1000;
				} catch(e) {
					document.getElementById("Header_Admin").style.width  = document.getElementById("LeftFill").clientWidth + document.getElementById("Main").clientWidth + document.getElementById("RightFill").clientWidth;		
				}
			
				document.getElementById("RightFill").style.width = 209;
			}catch(e) {				
			}			
		}
	}catch(e){
		alert(e.message);
	}
}

function changeMenuItem(cell){
	
	cell.className = "lightOrange";
}	

function showscroll(){
	var cw, iw, ow;
	//clientWidth
	if (document.documentElement&&document.documentElement.clientHeight)
		cw=document.documentElement.clientHeight;
		if (document.body&&document.body.clientHeight)
		cw=document.body.clientHeight;
		// firefox, mozilla, netscape
		if (window.innerWidth){
			iw=window.innerWidth;
			if (iw!=cw){
				return true;
				//alert('Vertical Scrollbar Does Exist');
				}else{
				return false;
				//alert('Vertical Scrollbar Does NOT Exist');
				}
			}
		else{
		// IE
		// offsetWidth
		if (document.documentElement&&document.documentElement.offsetHeight)
		ow=document.documentElement.offsetHeight;
		if (document.body&&document.body.offsetHeight)
		ow=document.body.offsetHeight;
		if (ow>cw + 4){
			return true;
		}
		else{
			return false;
		}
	}
}
