function clearSearch()
{
	document.getElementById('searchField').value = '';
}
function addSearchTxt()
{
	var srchFld = document.getElementById('searchField').value;
	
	 if (srchFld == '')
			{
				document.getElementById('searchField').value = 'Site search...';
			}
}

function manufacturerUpdater(){
	$("#manufacturers").change(function(){
		if ( $("select#manufacturers option:selected").val() !=0 ){
			document.location.href = "/2-" + $("select#manufacturers option:selected").val() + "/manufacturers/product-listing";
		}
	});
}

function categoryUpdater(){
	$("#quickBrowse").change(function(){
		if ( $("select#quickBrowse option:selected").val() !=0 ){
			subCategoryAjax($("select#quickBrowse option:selected").val());
		}
	});
}

function subCategoryAjax(categoryid){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById("SubCategoryOptions").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","/modules/product/subcategory.asp?cid="+categoryid,true);
	xmlhttp.send();
}


function subCategoryUpdater(){
	$("#subcategory").change(function(){
		if ( $("select#subcategory option:selected").val() !=0 ){
			thirdCategoryAjax($("select#subcategory option:selected").val());
		}
	});
}

function thirdCategoryAjax(categoryid){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById("ThirdCategoryOptions").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","/modules/product/thirdcategory.asp?cid="+categoryid,true);
	xmlhttp.send();
}


function slideShow() {
	var children = $(".welcomeBoxTop").children().size();
	if( children > 1 ) {

	//Set the opacity of all images to 0
	$('.welcomeBoxTop div.BannerRotating').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('.welcomeBoxTop div.BannerRotating:first').css({opacity: 1.0});
	

	$('.welcomeBoxTop div.BannerRotating:first').addClass('show');
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	}
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('.welcomeBoxTop div.BannerRotating.show')?  $('.welcomeBoxTop div.BannerRotating.show') : $('.welcomeBoxTop div.BannerRotating'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('.welcomeBoxTop div.BannerRotating:first') :current.next()) : $('.welcomeBoxTop div.BannerRotating:first'));	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('.welcomeBoxTop .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('.welcomeBoxTop .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );

}

$(document).ready(function(){
	manufacturerUpdater();
	categoryUpdater();
	subCategoryUpdater();
	subCategoryAjax(0);
	thirdCategoryAjax(0);
	
	slideShow();
	
	bool_submit = false;
	
	checkSubmit = function() {
		if(!bool_submit) {
			return false;
		}
	}
	
	submitFormCart = function(action) {
		bool_submit = true;
		$('#H_Action').val(action);
		$("#CounterForm").submit();
		return false;
	}
	
	$("#ShipLocation").change(function(){
		submitFormCart('Recalculate');
	});
	
	$(".cartQTY").blur(function(){
		submitFormCart('Recalculate');
	});
	
	$('#link_go_to_my_cart').css( 'cursor', 'pointer' );
	
});
