function writeText (form) {
	var fields = [ "address1" , "address2" , "town" , "county" , "postcode" , "country" ];
	for(var i = 0 ; i<fields.length ; i++){
		$('#delivery_'+fields[i]+"_form").val($('#card_'+fields[i]+'_form').val());
	}
	if($('#delivery_country').length>0)     {
               $('#delivery_country').val($('#card_country').val());
       }
}

function clearText (form) {
	var fields = [ "address1" , "address2" , "town" , "county" , "postcode" , "country" ];
	for(var i = 0 ; i<fields.length ; i++){
		$('#delivery_'+fields[i]+"_form").val("");
	}
}
function copyInvoiceAddress (form,id) {
	var prefix = 'customer_model-'+id+'-';
	$('#'+prefix+'delivery_address1').val($('#'+prefix+'card_address1').val());
	$('#'+prefix+'delivery_address2').val($('#'+prefix+'card_address2').val());
	$('#'+prefix+'delivery_town').val($('#'+prefix+'card_town').val());
	$('#'+prefix+'delivery_county').val($('#'+prefix+'card_county').val());
	$('#'+prefix+'delivery_postcode').val($('#'+prefix+'card_postcode').val());
	$('#'+prefix+'delivery_country').val($('#'+prefix+'card_country').val());
	return false;
}

function showPic (whichpic) {
 if (document.getElementById) {
  document.getElementById('placeholder').src = whichpic.title;
  if (whichpic.title) {
   document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
  } else {
   document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
  }
  return false;
 } else {
  return true;
 }
}
$(function(){
	$('.accordion-toggle').addClass('havehover');
	$('.accordion-leaf').addClass('havehover');
	$('.accordion-item').addClass('havehover');
	$('.havehover').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});
});

$(document).ready(function(){

  // Generates pdf for orders
  $('.generate-pdf').click(function() {
	var id = $(this).attr('alt');
	$('.pdf-'+id).html('<img src="/filemanager/images/ajax-loader.gif" width="16px" height="16px" />');
	$(".pdf-"+id).load("/pdf/generate-order-pdf.php",{ id:id });
	$('.'+id+'-Status a').html('Invoiced');
	$('xxxxxxxxxxx').load('/mpbadminxxx/x_order/pdfIntoStockbook/'+id,{ id:id });  // Attempts to bring order record into stockbook
  });

});

