var myrules = {
  '.prod_quantity' : function(el){
    el.onchange = function(){
      $('basketForm').submit();
    }
  },
  '#delivery_select' : function(el){
    el.onchange = function(){
      $('basketForm').submit();
    }
  },
  '.delete' : function(el){
    el.onclick = function(){
      return confirm('Are you sure you want to delete this product?');
    }
  },
  '#same_as_invoice' : function(el){
    el.onclick = function() {
      if($('same_as_invoice').checked == true) {
      //if($('same_as_invoice').value == 'same') {
        //alert($('invoice_title').selectedIndex);      
		 var ddlValue="";
		 var SetIndex=0;
		 var x=document.getElementById("delivery_country");
		 for (i=0;i<x.length;i++)
			{
			 if(x.options[i].text==$('invoice_country').options[$('invoice_country').selectedIndex].text)
				{
				 ddlValue=x.options[i].text; 
				 SetIndex=i;
				 
				}
				
			 
			}
			if(ddlValue!="")
		  {
				$('delivery_title').selectedIndex = $('invoice_title').selectedIndex;
				$('delivery_firstname').value = $('invoice_firstname').value;
				$('delivery_surname').value = $('invoice_surname').value;
				$('delivery_address1').value = $('invoice_address1').value;
				$('delivery_address2').value = $('invoice_address2').value;
				$('delivery_town').value = $('invoice_town').value;
				$('delivery_county').value = $('invoice_county').value;
				 $('delivery_postcode').value = $('invoice_postcode').value;
				 $('delivery_country').options[SetIndex].value;
                $('delivery_country').selectedIndex = SetIndex;

				 $('delivery_country').options[SetIndex].value=$('invoice_country').options[$('invoice_country').selectedIndex].text;

		  }
		  else
				{
					alert("Your delivery address is not appropriate for " + $('delivery_select').options[$('delivery_select').selectedIndex].text);
					 $('same_as_invoice').checked =false;
					  
				} 
      }
    }
  },
 '#proceed_to_checkout' : function(el){
   el.onclick = function() {
     if($('confirm').checked == true) {
       return true;
     }
	 else {
       alert('Please agree to our terms of sale before proceeding to payment.'); 
       $('confirm_text').style.textDecoration = "underline";
       return false;
     }
   }
 }
};

Behaviour.register(myrules);

