function openWindow(url,name,width,height)
{
	props = "width=" + width + ",height=" + height + ",scrollbars";
	window.open(url,name,props);
}

function showGalleryImage(gallery_id)
{
	url = "showgalleryimage.php?gallery_id=" + gallery_id;
  	var win = openWindow(url,"gallery",450,450);
}
    
function checkLogin(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.email.value == "")
    {
        errors += "- email must be completed.\n";
        valid = false;
    }

    if (f.password.value == "")
    {
        errors += "- password must be completed.\n";
        valid = false;
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function checkQuote(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.name.value == "")
    {
        errors += "- name must be completed.\n";
        valid = false;
    }
    
    if (f.email.value == "")
    {
        errors += "- email must be completed.\n";
        valid = false;
    }


    if (f.quantity.value == "")
    {
        errors += "- quantity must be completed.\n";
        valid = false;
    }
    
    if (f.product.value == "")
    {
        errors += "- product must be completed.\n";
        valid = false;
    }
    
    if (f.address.value == "")
    {
        errors += "- address must be completed.\n";
        valid = false;
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
    	
}

function checkContact(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.name.value == "")
    {
        errors += "- name must be completed.\n";
        valid = false;
    }
    
    if (f.email.value == "")
    {
        errors += "- email must be completed.\n";
        valid = false;
    }


    if (f.enquiry.value == "")
    {
        errors += "- enquiry must be completed.\n";
        valid = false;
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
    	
}

function checkCustomerDetails(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.contact_name.value == "")
    {
        errors += "- contact_name must be completed.\n";
        valid = false;
    }

    if (f.email.value == "")
    {
        errors += "- email must be completed.\n";
        valid = false;
    }
 
    if (f.password.value == "" || f.passwordc.value == "")
    {
         errors += "- password and password confirmation must be completed.\n";
         valid = false;
    }
    else
    {
		if (f.password.value != f.passwordc.value)
		{
        	 errors += "- password and password confirmation do not match.\n";
			valid = false;
		}    
    }
    
    if (f.billing_line1.value == "")
    {
        errors += "- billing_line1 must be completed.\n";
        valid = false;
    }
    
    if (f.billing_town.value == "")
    {
        errors += "- billing_town must be completed.\n";
        valid = false;
    }
    
    if (f.billing_county.value == "")
    {
        errors += "- billing_county must be completed.\n";
        valid = false;
    }
      
    if (f.billing_postcode.value == "")
    {
        errors += "- billing_postcode must be completed.\n";
        valid = false;
    }

    
    if (f.shipping_line1.value == "")
    {
        errors += "- shipping_line1 must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_town.value == "")
    {
        errors += "- shipping_town must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_county.value == "")
    {
        errors += "- shipping_county must be completed.\n";
        valid = false;
    }
        
    if (f.shipping_postcode.value == "")
    {
        errors += "- shipping_postcode must be completed.\n";
        valid = false;
    }
       
    if (f.tel.value == "")
    {
        errors += "- telephone must be completed.\n";
        valid = false;
    }
    
    if (f.all_day_contact_tel.value == "")
    {
        errors += "- daytime telephone must be completed.\n";
        valid = false;
    }
    
    if(!f.agree_terms.checked)
    {
        errors += "- terms and conditions must be read and agreed to.\n";
        valid = false;
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function copyAddress(f)
{
		f.shipping_line1.value = f.billing_line1.value;
		f.shipping_line2.value = f.billing_line2.value;
		f.shipping_line3.value = f.billing_line3.value;
		f.shipping_town.value = f.billing_town.value;
		f.shipping_county.value = f.billing_county.value;
		//f.shipping_postcode.value = f.billing_postcode.value;
}

function checkForgotPass(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.forgot_email.value == "")
    {
        errors += "- Email address must be completed.\n";
        valid = false;
    }
   
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function checkPostcodeForm(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.chosen_qty.value == "")
    {
        errors += "- Quantity must be completed.\n";
        valid = false;
    }
   
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function changeUnloadingFee(url,s)
{
	var change_unloading_fee = s[s.selectedIndex].value;
	url += "?change_unloading_fee="  +  change_unloading_fee;
	
	document.location.href=url;
}