function addToStore(value){

	        if(getCookie('cart_1')==''){setCookie(value,'cart_1'); window.location='/order';}else
         	if(getCookie('cart_2')==''){setCookie(value,'cart_2'); window.location='/order';}else
         	if(getCookie('cart_3')==''){setCookie(value,'cart_3'); window.location='/order';}else
         	if(getCookie('cart_4')==''){setCookie(value,'cart_4'); window.location='/order';}else
         	setCookie(value,'cart_5'); window.location='/order';
	
	
	
}


function setCookie(value,name)
         {

         	
         //If name is the empty string, it places a ; at the beginning
         //of document.cookie, causing clearCookies() to malfunction.
         if(name != '')
            document.cookie = name + '=' + value+'; path=/;'
           
         }

function getCookie(name)
         {
         //Without this, it will return the first value 
         //in document.cookie when name is the empty string.
         //alert(document.cookie);
         if(name == '')
            return('');
         
         name_index = document.cookie.indexOf(name + '=');
         
         if(name_index == -1)
            return('');
         
         cookie_value =  document.cookie.substr(name_index + name.length + 1, 
                                                document.cookie.length);
         
         //All cookie name-value pairs end with a semi-colon, except the last one.
         end_of_cookie = cookie_value.indexOf(';');
         if(end_of_cookie != -1)
            cookie_value = cookie_value.substr(0, end_of_cookie);

         //Restores all the blank spaces.
         space = cookie_value.indexOf('+');
         while(space != -1)
              { 
              cookie_value = cookie_value.substr(0, space) + ' ' + 
              cookie_value.substr(space + 1, cookie_value.length);
							 
              space = cookie_value.indexOf('+');
              }

         return(cookie_value);
         }
         
 
 function preselectMyItem(itemToSelect,cart_number)
{

  // Get a reference to the drop-down
  if(cart_number==1)var myDropdownList = document.order_form.image_name_1;
  if(cart_number==2)var myDropdownList = document.order_form.image_name_2;
  if(cart_number==3)var myDropdownList = document.order_form.image_name_3;
  if(cart_number==4)var myDropdownList = document.order_form.image_name_4;
  if(cart_number==5)var myDropdownList = document.order_form.image_name_5;


  // Loop through all the items
  for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++)
  {    
    if (myDropdownList.options[iLoop].value == itemToSelect)
    {
      // Item is found. Set its selected property, and exit the loop
      myDropdownList.options[iLoop].selected = true;
      break;
    }
  }

}

function submitOrder(){

if(validate($('email').value)){}else{alert('please enter a valid email address.');return;}
	
		if($('first_name').value==''){alert('please enter your first name');return;}else
			if($('last_name').value==''){alert('please enter your last name');return;}else
				if($('phone').value==''){alert('please enter your phone number');return;}else
					if($('address').value==''){alert('please enter your address');return;}else
						var vars=Form.serialize($('order_form'));
						var url='/patterson_mailer.php';
						new Ajax.Request(url,{postBody:vars,onSuccess:function(){alert('Thank you for submitting your order, '+$('email').value+'. We will respond shortly.');}})	
					
					
					
}



function validate(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }else{return true;}
   
}