// JavaScript Document

// EDIT THESE VALUES IF REQUIRED
var alertText = 'Are you sure you wish to perform this action' + "\n"; //DEFAULT TEXT DISPLAYED ON CONFIRM BUTTONS/LINKS WHEN NO ALT/TITLE
var newWindowLink = false; //OPEN EXTERNAL LINKS BY DEFAULT IN A NEW WINDOW (TRUE/FALSE)?


var woms = new Array(); //CREATE ARRAY OF FUNCTIONS TO LAUNCH ONLOAD

//ONLOAD MANAGER
function womOn(){
  window.onload = womGo;
}

function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}

function womAdd(func){
  woms[woms.length] = func;
}

function custlightwindow ()
{
	$(".custlightwindow").fancybox({ 'scrolling'		: 'no',
								     'width'         		: 640, 	
									 'height'        		: 400,
									 'padding'		: 10

	});
}

function CreateBookmarkLink() {

	title = document.title;
	url = window.location.href;
	
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");
	} else if(window.external) {
		window.external.AddFavorite( url, title); 
	} else if(window.opera && window.print) {
		return true;
	}
	
}

function objToggle(obj) { 

	var obj = document.getElementById(obj);

	if(obj.style.display == "block") { 
		obj.style.display = "none";
	} else { 
		obj.style.display = "block";
	}

}

function expandMenu() {
	
	var control=document.getElementById('nav');
	var listElements=control.getElementsByTagName("li");
	
	for(var i=0; i<listElements.length; i++) {
		//EXPAND MENU
		listElements[i].onmouseover=function() {
				var uls=this.getElementsByTagName("ul");
				for(var n=0; n<uls.length; n++) {
					if(n==0) {
						uls[n].style.display="block";
					}
					
				}
			}
		//CLOSE MENU	
		listElements[i].onmouseout=function() {
			var uls=this.getElementsByTagName("ul");
				for(var n=0; n<uls.length; n++) {
					if(n==0) {
						uls[n].style.display="none";
					}
					
				}
		}
	}
}

/*
* homepage
*/

/*
if(!document.getElementById('keyword')) return false;
	
	var keyword = document.getElementById('keyword');
	
	keyword.onfocus = function()
	{
		if(document.getElementById('keyword').value == 'Keyword / Item code')
		{
				document.getElementById('keyword').value = '';
		}
	}
*/


function searchform() 
{
	if(!document.getElementById('searchterm')) return false;
		
	var searchterm = document.getElementById('searchterm');
	
	searchterm.onfocus = function()
	{
		if(document.getElementById('searchterm').value == 'Search the site')
		{
			document.getElementById('searchterm').value = '';
		}
	}	
}




   
$(document).ready(function () 
{
	chuckfinder();
});

function chuckfinder ()
{
	if($('#chuckfinder').length == 0) return false;
	
	$('#dropdownone').change(function() 
	{
		if( $('#dropdownone').val() != '' )
		{
			
			$('#chuckfindercoltwo').html('<img src="images/ajax-loading.gif" alt="Loading" />');
			
			$.post('libs/includes/homepagechuckfinder.php', { id: $('#dropdownone').val() },
			function(data)
			{
				$('#chuckfindercoltwo').html(data);
				$('#chuckfindercolthree').html('');
				chuckfinder();
			});
			
		}
		else
		{
			$('#chuckfindercoltwo').html('');
			$('#chuckfindercolthree').html('');
		}
		
		$('#chuckfindercolfour').html('');
	});
	
	
	$('#dropdowntwo').change(function() 
	{
		if( $('#dropdowntwo').val() != '' )
		{
			
			$('#chuckfindercolthree').html('<img src="images/ajax-loading.gif" alt="Loading" />');
			
			$.post('libs/includes/homepagechuckfinder.php', { productid: $('#dropdowntwo').val() },
			function(data)
			{
				$('#chuckfindercolthree').html(data);
				chuckfinder();
			});
			
		}
		else
		{
			$('#chuckfindercoltwo').html('');
			$('#chuckfindercolthree').html('');
		}
		
		$('#chuckfindercolfour').html('');
		
	});
	
	
	$('#dropdownthree').change(function() 
	{
		if( $('#dropdownthree').val() != '' )
		{
			$('#chuckfindercolfour').html('<img src="images/ajax-loading.gif" alt="Loading" />');
			
			$.post('libs/includes/homepagechuckfinder.php', { pdfid: $('#dropdownthree').val() },
			function(data)
			{
				//alert(data);
				$('#chuckfindercolfour').html(data);
				chuckfinder();
				
				//alert($('#chuckfindercolfour').html());
			});
			
		}
		else
		{
			$('#chuckfindercolfour').html('');
		}
	});
	
}



