PartExchange = {
	loadPeForm: function(id){
		    if(!id){
			    var el = $('#detail-id');
			    if(el) id=el.val();
		    }
		var dialog = $('#dialog');
		var dialogContent = $('#dialog-content');
		dialogContent.html("<div class='ajax-loading-icon'></div><div class='basket-bar'>Loading Part Exchange form...</div>");
		var obj = dialog.modal({ 
			close: false,
			overlayClose: true,
			escClose: true
		});
		
		PartExchange.popup = obj;

		$('#simplemodal-overlay').click(function(){PartExchange.closePopup();});
		//$('#simplemodal-container').click(function(){PartExchange.closePopup();});

		$('#dialog').load("/extensions/product_detail/partExchangeProduct.php",{product_uid:id});

		// Reloads the basket on RHS of page
		//setTimeout("$('#basket_expand').load('/extensions/checkout/refreshBasket.php');",500);

		return false;
	},
	sendEmail: function(id){
		if(!id){
                            var el = $('#detail-id');
                            if(el) id=el.val();
                    }
		if($('#pe-name').val()=='' || $('#pe-email').val()=='' || $('#pe-contact').val()=='' || $('#pe-item').val()=='' || $('#pe-condition').val()=='') {
			$('#pe-message').html('Please fill in all fields before submitting your details.');
		}	else	{
			//$('#pe-message').html('Submitting form');
			$('#pe-message').html('Thank you for contacting us.<br />We will be in contact with you soon.');
			$('#pe-message').load("/extensions/product_detail/partExchangeProduct.php",{product_uid:id,name:$('#pe-name').val(),email:$('#pe-email').val(),contact:$('#pe-contact').val(),item:$('#pe-item').val(),condition:$('#pe-condition').val()});
			return setTimeout('PartExchange.closePopup();','2500');
		}
		//alert('testing'+$('#pe-name').val());
		//return false;
	},
	closePopup: function(){
		PartExchange.popup.close();
		$('#dialog').hide();
		return false;
	}
};
