$(document).ready(function()
{
	$('.pcat').hover(function() { $(this).addClass('apcat'); }, function() { $(this).removeClass('apcat'); });
	$('.subcat').hover(function() { $(this).addClass('asubcat'); }, function() { $(this).removeClass('asubcat'); });
	$('.p_block').hover(function() { $(this).addClass('p_block_o'); }, function() { $(this).removeClass('p_block_o'); });
	$('.pg').hover(function() { $(this).addClass('pga'); }, function() { $(this).removeClass('pga'); });

	$('.p_row').hover(function() { $(this).addClass('p_row_o'); }, function() { $(this).removeClass('p_row_o'); });

	$('.hvrimg').live('mouseover', function(e){ 
		var src = $(this).attr('src');
		src = src.replace('.gif','_o.gif');
		$(this).attr('src',src);
	});

	$('.hvrimg').live('mouseout', function(e){ 
		var src = $(this).attr('src');
		src = src.replace('_o.gif','.gif');
		$(this).attr('src',src);
	});

	loadCart();
	cacheImages();
});


function addtocart(prod_id)
{
	ajaxLoad('#atc','/applets/addtocart.php?qty=1&prod_id=' + prod_id);
}


function addtocart_qtyform(prod_id)
{
	qty = document.qtyform.qty.value;
	ajaxLoad('#atc2','/applets/addtocart.php?qty=' + qty + '&prod_id=' + prod_id);
}

function addtocart_row(prod_id)
{
	ajaxLoad('#atc_row_' + prod_id,'/applets/addtocart_nocart.php?qty=1&prod_id=' + prod_id);
}

function ajaxLoad(id,url)
//loads ajax page to a specific div
{
	$(id).html('<img src="/images/v3/ajax-loader.gif">');
	$(id).load(url);
}

function loadCart()
{
	if ($('#cart').length != 0) ajaxLoad('#cart','/applets/cart.php?r=' + Math.random());	
}


function cacheImages()
{
	var imageArray = ['/images/v3/nav_home_o.gif','/images/v3/nav_contact_o.gif','/images/v3/nav_hours_o.gif','/images/v3/nav_banking_o.gif','/images/v3/nav_stores_o.gif','/images/v3/nav_delivery_o.gif','/images/v3/asn_shoponline_o.gif','/images/v3/asn_webblog_o.gif','/images/v3/asn_photogal_o.gif','/images/v3/asn_forums_o.gif','/images/v3/btn_back_o.gif','/images/v3/btn_addtocart_o.gif','/images/v3/checkout_o.gif','/images/v3/go_o.gif'];
	var icache = $('body').append('<div id="img-cache" style="display:none/>').children('#img-cache');
 
	$.each(imageArray, function (i, val) {
  		$('<img/>').attr('src', val).appendTo(icache);
	});
}


function frm_searchcheck()
{
	if ((document.searchform.str.value == 'Enter Text')||(document.searchform.str.value == ''))
	{
		alert('Please enter text to search for');
		document.searchform.str.focus();
		return false;
	}
}

function frm_unsetsearch()
{
	if (document.searchform.str.value == 'Enter Text')
		document.searchform.str.value = '';
}

function frm_setsearch()
{
	if (document.searchform.str.value == '')
		document.searchform.str.value = 'Enter Text';
}


function frm_fsearchcheck()
{
	if ((document.fsearchform.str.value == 'Enter Text')||(document.fsearchform.str.value == ''))
	{
		alert('Please enter text to search for');
		document.fsearchform.str.focus();
		return false;
	}
}

function frm_funsetsearch()
{
	if (document.fsearchform.str.value == 'Enter Text')
		document.fsearchform.str.value = '';
}

function frm_fsetsearch()
{
	if (document.fsearchform.str.value == '')
		document.fsearchform.str.value = 'Enter Text';
}



function frm_nlcheck()
{
	if ((document.nlform.FormValue_Email.value == 'Enter Email')||(document.nlform.FormValue_Email.value == ''))
	{
		alert('Please enter your email address');
		document.nlform.FormValue_Email.focus();
		return false;
	}
}


function frm_unsetnl()
{
	if (document.nlform.FormValue_Email.value == 'Enter Email')
		document.nlform.FormValue_Email.value = '';
}

function frm_setnl()
{
	if (document.nlform.FormValue_Email.value == '')
		document.nlform.FormValue_Email.value = 'Enter Email';
}

function frm_brandcheck()
{
	if (document.brandform.brandstr.selectedIndex == 0)
	{
		alert('Please select a brand');
		document.brandform.brandstr.focus();
		return false;
	}
}



function tellafriend_validate()
{
	f = document.tellafriend_form;
	
	
	if (f.name.value.length < 1)
	{
		alert("Please enter your name.");
		f.name.focus();
  		return(false);
	}
   	if (f.email.value.length < 5)
	{
		alert("Please enter your email addres.");
		f.email.focus();
  		return(false);
	}
   	if (f.friendname.value.length < 1)
	{
		alert("Please enter your firend\'s name.");
		f.friendname.focus();
  		return(false);
	}
   	if (f.friendemail.value.length < 5)
	{
		alert("Please enter your friend\'s email addres.");
		f.friendemail.focus();
  		return(false);
	}
   	if (f.msg.value.length < 1)
	{
		alert("Please enter a message to send to your friend.");
		f.msg.focus();
  		return(false);
	}	
	
   	if (f.codevalidate.value.length < 5)
	{
		alert("Please enter the security code displayed.");
		f.codevalidate.focus();
  		return(false);
	}	
}




