function ptah(ptah_param) {
	if (ptah_param)
		document.location.href = 'site.aspx?i=' + ptah_param;
	else {
		c = 'http:/' + '/' + document.location.hostname;
		if (document.getElementsByTagName) {
			a = document.getElementsByTagName("a");
			for (l = 0; l < a.length; l++)
				if ((a[l].href.substring(0, c.length) != c || a[l].rel == 'external' || a[l].href.indexOf('?i=xu') != -1) && a[l].rel != 'javascript')
					a[l].target = "_blank"
		}
		document.body.innerHTML = document.body.innerHTML.replace(/{email:([\w\.-]+)\\([\w\.-]+)}/g, '$1@$2')
	}
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, '') };

function byid(byid_id) {
	return document.getElementById(byid_id)
}

function vali_account() {

	vali_array = [];
	if (byid('a_forename').value.trim() == '' || byid('a_surname').value.trim() == '')
		vali_array.push('you haven\'t told us your full name');
	if (byid('a_newmail').value.indexOf('@') == -1)
		vali_array.push('you haven\'t entered an email address');
	if (byid('a_password').value.trim() == '')
		vali_array.push('you haven\'t entered a password');
	if (byid('a_password').value.trim() != byid('a_confirm').value.trim())
		vali_array.push('you haven\'t entered your password into the confirmation box correctly');
	if (byid('a_phone').value.trim() == '' || byid('a_phone').value.trim() == '')
		vali_array.push('you haven\'t entered a phone number');

	return vali_help('account/saved', vali_array);

}

function vali_password() {

	vali_array = [];
	if (byid('p_email').value.trim() == '')
		vali_array.push('you haven\'t entered an email address');

	return vali_help('password/retrieved', vali_array);

}

function vali_contact() {

	vali_array = [];
	if (byid('c_name').value.trim() == '')
		vali_array.push('you haven\'t told us your name');
	if (byid('c_email').value.indexOf('@') == -1)
		vali_array.push('you haven\'t entered an email address');
	if (byid('c_comments').value.trim() == '')
		vali_array.push('you haven\'t entered a comment');

	return vali_help('message/sent', vali_array)

}

function vali_vpa() {

	vali_array = [];

		if (byid('v_name').value.trim() == '')
			vali_array.push('you haven\'t told us your pet\'s name');
		if (byid('v_species').value.trim() == '')
			vali_array.push('you haven\'t told us your pet\'s species');
		if (byid('v_dob').value.trim() == '')
			vali_array.push('you haven\'t told us your pet\'s date of birth');
		if (byid('v_weight').value.trim() == '')
			vali_array.push('you haven\'t told us your pet\'s weight');

	return vali_help('pet/saved', vali_array)

}


function vali_basket() {

	vali_array = [];

		if (byid('d_recipient').value.trim() == '')
			vali_array.push('you haven\'t told us your delivery recipient name');
		if (byid('d_address').value.trim() == '')
			vali_array.push('you haven\'t told us your delivery address');
		if (byid('d_postcode').value.trim() == '')
			vali_array.push('you haven\'t told us your delivery postcode');
		if (byid('d_country').value.trim() == '')
			vali_array.push('you haven\'t told us your delivery country');

	return vali_help('order/processed', vali_array)

}

function vali_help(vali_objname, vali_array) {

	vali_str = '';
	vali_mess = vali_objname.split('/');
	if (vali_array.length != 0) {
		vali_str = 'Your ' + vali_mess[0] + ' could not be ' + vali_mess[1] + ' because ';
		for (l = 0; l < vali_array.length; l++)
			vali_str += (l == 0 ? '' : (l == vali_array.length - 1 ? ' and ' : ', ')) + vali_array[l];
		vali_str += '.'
	}
	byid('vali_help').innerHTML = vali_str;
	return vali_array.length == 0

}

function bask_remove(bask_remove_id) {
	byid('bq_' + bask_remove_id).value = '0';
	byid('bask_recalc').click()
}

function bask_subbutton(bask_subbutton_str) {
	byid('bask_checkout').value = bask_subbutton_str;
	byid('bask_form').submit()
}

function vpet_select(vpet_thingie) {
	vpet_split = vpet_thingie.split('\\');
	byid('v_name').value = vpet_split[0];
	byid('v_species').value = vpet_split[1];
	byid('v_dob').value = vpet_split[2];
	byid('v_weight').value = vpet_split[3]
}

function catv_options() {
	byid('soptfoot').style.display = 'inline';
	byid('soptbody').style.display = 'inline';
	byid('sopthead').style.display = 'none'
}
