function validateSearch(form)
{
	if (form.searchfield.value == "" || form.searchfield.value == form.searchfield.defaultValue)
	{
		alert("Please enter a search term");
		form.searchfield.focus();
		return false;
	}
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=380,height=420,left = 412,top = 294');");
}

function OnEnterSearch()
{
     window.location = 'stocklist\results.aspx?searchfield='+ctl00_searchfield.value;
}

function validateSearch(form)
{
	if (document.aspnetForm.ctl00_Centercontentplaceholder_.searchfield.value == "" || document.aspnetForm.ctl00_Centercontentplaceholder_.searchfield.value == document.aspnetForm.ctl00_Centercontentplaceholder_.searchfield.defaultValue)
	{
		alert("Please enter a search term");
		document.aspnetForm.ctl00_Centercontentplaceholder_.searchfield.focus();
		return false;
	}
}

function postcodeAnywhere() 
{ 
	var pca_window_name; 
	var pca_url;
		
	pca_url = 'popup.aspx?postcode=' + document.aspnetForm.ctl00_Centercontentplaceholder_txtPostCode.value;
	pca_window_options = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=600,height=350'; 
	window.open (pca_url, 'PCA' , pca_window_options); 
} 

function editAddress()
{
	if (document.aspnetForm.ctl00_Centercontentplaceholder_lstDelivery.selectedIndex > 0)
	{
		location.href = '/users/address.aspx?address=' + document.aspnetForm.ctl00_Centercontentplaceholder_lstDelivery[document.aspnetForm.ctl00_Centercontentplaceholder_lstDelivery.selectedIndex].value + '&ReturnUrl=%2fshop%2fprep.aspx';
	}
	else
	{
		alert("Please select an address to edit!");
	}	
}
				
function editCard()
{
	if (document.aspnetForm.ctl00_Centercontentplaceholder_lstCards.selectedIndex > 0)
	{
		location.href = '/users/card2.aspx?card=' + document.aspnetForm.ctl00_Centercontentplaceholder_lstCards[document.aspnetForm.ctl00_Centercontentplaceholder_lstCards.selectedIndex].value + '&ReturnUrl=%2fshop%2fprep.aspx';
	}
	else
	{
		alert("Please select a credit/debit card to edit!");
	}	
}

function addToCart(item)
{
	if (document.aspnetForm.ctl00_Centercontentplaceholder_txtQty.value != "" & !isNaN(document.aspnetForm.ctl00_Centercontentplaceholder_txtQty.value))
	{
		if (parseFloat(document.aspnetForm.ctl00_Centercontentplaceholder_txtQty.value) < parseFloat(document.aspnetForm.ctl00_Centercontentplaceholder_hidMin.value) || parseFloat(document.aspnetForm.ctl00_Centercontentplaceholder_txtQty.value) > parseFloat(document.aspnetForm.ctl00_Centercontentplaceholder_hidMax.value))
		{
			document.aspnetForm.ctl00_Centercontentplaceholder_txtQty.value = document.aspnetForm.ctl00_Centercontentplaceholder_hidMin.value;
			alert("There are restrictions of the maximum and minimum number of this item you may order. Please try again.");
			document.aspnetForm.ctl00_Centercontentplaceholder_txtQty.focus();
		}
		else
		{
			location.href = "http://ehattons.com/addtocartbylinkv3.aspx?StockId=" + item + "&qty=" + document.aspnetForm.ctl00_Centercontentplaceholder_txtQty.value + "&ReturnTo=" + escape(location.href);
		}
	}
	else
	{
		alert("Please enter a numeric quantity to add to your cart");
		document.aspnetForm.ctl00_Centercontentplaceholder_txtQty.focus();
	}
}

function addToCartQtyPriceID(item, qtypriceid, packqty) {
    qtypriceqty = parseFloat(document.getElementById("ctl00_Centercontentplaceholder_hdnQtyPriceQty" + qtypriceid).value);
    
    qty = document.getElementById("ctl00_Centercontentplaceholder_txtQty" + qtypriceid).value;

    if (qty != "" & !isNaN(qty)) {
        if (parseInt(qty) < parseInt(document.aspnetForm.ctl00_Centercontentplaceholder_hidMin.value) || parseInt(qty) > parseInt(document.aspnetForm.ctl00_Centercontentplaceholder_hidMax.value)) {
            document.getElementById("ctl00_Centercontentplaceholder_txtQty" + qtypriceid).value = document.aspnetForm.ctl00_Centercontentplaceholder_hidMin.value;
            alert("There are restrictions of the maximum and minimum number of this item you may order. Please try again.");
            document.getElementById("ctl00_Centercontentplaceholder_txtQty" + qtypriceid).focus();
        }
        else {
            qty = qty * parseInt(packqty);
            location.href = "/addtocartbylinkv3.aspx?StockId=" + item + "&qty=" + (parseInt(qty)) + "&ReturnTo=" + escape(location.href);
        }
    }
    else {
        alert("Please enter a numeric quantity to add to your cart");
        document.getElementById("ctl00_Centercontentplaceholder_txtQty" + qtypriceid).focus();
    }
}
			
function addToWishlist(item)
{
    if (document.aspnetForm.ctl00_Centercontentplaceholder_txtWishQty.value != "" & !isNaN(document.aspnetForm.ctl00_Centercontentplaceholder_txtWishQty.value))
	{
	    location.href = "/users/addtowishlist.aspx?StockId=" + item + "&qty=" + document.aspnetForm.ctl00_Centercontentplaceholder_txtWishQty.value;
	}
	else
	{
		alert("Please enter a numeric quantity to add to your wishlist");
		document.aspnetForm.ctl00_Centercontentplaceholder_txtWishQty.focus();
	}
}

function Redirect(url)
{
    location.href=url;
}

function ChangePage(id)
{
	// save the page clicked
	document.aspnetForm.ctl00_Centercontentplaceholder_PageNumber.value = id;
	// call the __doPostBack function to post back the form and execute the PageClick event
	__doPostBack('PageClick','');
}
	
function clearText(thefield){
	if (thefield.value=="Search Term" || thefield.value=="Enter Email Here:"){
		thefield.value = "";
	}
}

function printPage()
{
	window.print();
}

function newsletterSignup()
{
	document.forms[0].action = "http://ui.constantcontact.com/d.jsp";
	document.forms[0].target = "_blank";
	document.forms[0].submit();
}

function newsletterSignupHomePage()
{
	var email = document.getElementById('ml_signup').value
	
	if (email == '')
	{
		alert('Please enter your email address!');
	}
	else
	{
		location.href = 'http://ui.constantcontact.com/d.jsp?ea=' + email + '&m=1101625934567&p=oi';
	}
}

current = 1;

function changeTextSize(){
	offset = parseFloat(document.getElementById('tsmenu').value);
	nuvalue = current + offset;
	eval('document.getElementById(\'mainbody\').style.fontSize = \'' + nuvalue + 'em\'');
	Set_Cookie('textsize', document.getElementById('tsmenu').value, 365, '/', '', '');
}

function setTextSize(){
	offset = Get_Cookie('textsize');
	if (offset == null){
		offset = '0';
	}	
	document.getElementById('tsmenu').value = offset;
	changeTextSize();
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function changeImageSource(id, src, bigsrc)
{
	document.getElementById(id).src = src;
	document.getElementById("ctl00_Centercontentplaceholder_lnkImage").href = bigsrc;
	return false;
	//alert(document.getElementById(id).src);
}

function validateQuestion() {
    var question = document.getElementById("ctl00_Centercontentplaceholder_txtQuestionText").value;

    var index = question.indexOf("<");
    if (index >= 0) {
        alert("Please do not enter the character \"<\" ");
        return false;
    }
    else
    {
        index = question.indexOf(">");
        if (index >= 0) {
            alert("Please do not enter the character \">\" ");
            return false;
        }
        else {
            return true;
        }
    }
}
