//custom jQuery functionality for puraspace
jQuery(document).ready(function() {

	//product view tabs
	jQuery('.pstab').click(function() {
		jQuery('.tabtitle.select').removeClass('select');
		jQuery(this).children('.tabtitle').addClass('select');
		jQuery('.tabcontent').html(jQuery(this).children('.tabtext').html());
		return false;
	});
	
	//checkout progress
	jQuery('#cp1').click(function() {
		accordion.openSection('opc-login');
	});
	jQuery('#cp2').click(function() {
		accordion.openSection('opc-billing');		
	});
	jQuery('#cp3').click(function() {
		accordion.openSection('opc-payment');
	});
	jQuery('#cp4').click(function() {
		accordion.openSection('opc-review');
	});
	
	jQuery('#vat_form').submit(function() {
		if(!jQuery('#vat_understood').is(':checked')){
			alert("Make sure to declare you have read and understood the requirements.");
			return false;
		}
		var emailtest = jQuery('#email_address').val();
		if (!emailtest.match(/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])/m)) {
			alert("Please enter a valid email address");
			return false;
		}
	});
	//jQuery('.section button').click(function() {
		//alert("buttonclicked");
	//});
	var myloc = String(document.location);
	if (myloc.match(/.*\?form=sent/m)) {
		alert("Thank you. Your form has been sent succesfully.");
	}
	if (myloc.match(/.*\?form=fail/m)) {
		alert("Apologies, there appears to be a temporary problem sending the form, please try to email directly enquires@puraspace.com.");
	}
});
function psSetStatus(selector){
	var thetitle=jQuery(selector).attr('id');
	if (!thetitle){
		thetitle = selector;
	}

	if (thetitle.match(/opc-billing|opc-shipping|opc_shipping_method/m)) {
		psSetVis(2);
	} else if (thetitle.match(/opc-payment/m)) {
		psSetVis(3);
	} else if (thetitle.match(/opc-review/m)) {
		psSetVis(4);
	} else {
		psSetVis(1);
	}
}

function psSetVis(number){
	jQuery('.cprogressItem.select').removeClass('select');
	if(number==1){
	jQuery('#cp1').addClass('select');
	} else if (number==2){
	jQuery('#cp2').addClass('select');
	} else if (number==3){
	jQuery('#cp3').addClass('select');
	} else if (number==4){
	jQuery('#cp4').addClass('select');
	}
}
