function showSignInTab() {
        signInOpen = 1;
		$('#sign-in-tab a').addClass('open');
		$('#forgot-password-form p').show();
		$('#forgot-password-form p.instructions').removeClass('extend');
		$('#forgot-password-form p.instructions').html('If you have forgotten your password we can send a new one to your registered email address. Enter the email address you use to sign in to Click&amp;Mail.');
		$('#sign-in').slideDown();
}
	

function GetUniqueCacheID() {
    var date = new Date();
    var timestamp = date.getTime();
    return timestamp;
}

var gAjaxPending = false;
var gPromoCodeValid = true;

$(document).ready(function() {

    //SIGN IN / FORGOT PASSWORD BLOCKS
    $('#sign-in').hide();
    $('#forgot-password').hide();
    var signInOpen = 0;
    var forgotPass = 0;

    $('#sign-in-tab a').click(
		function() {
		    if (signInOpen == 0) {
		        signInOpen = 1;
		        $('#sign-in-tab a').addClass('open');
		        $('#forgot-password-form p').show();
		        $('#forgot-password-form p.instructions').removeClass('extend');
		        $('#forgot-password-form p.instructions').html('If you have forgotten your password we can send a new one to your registered email address. Enter the email address you use to sign in to Click&amp;Mail.');
		        $('#sign-in').slideDown();
		        return false;
		    } else {
		        if (forgotPass == 1) {
		            $('#forgot-password').slideUp();
		        }
		        signInOpen = 0;
		        $('#sign-in-tab a').removeClass('open');
		        $('#sign-in').slideUp();
		        return false;
		    }
		}
	);

    var myaccStatus = document.URL;
    myaccStatus = myaccStatus.substr(myaccStatus.indexOf("myacc=") + 6, 4);
    //alert(myaccStatus);

    if (myaccStatus == "true") {
        signInOpen = 1;
        $('#sign-in-tab a').addClass('open');
        //$('#forgot-password-form p').show();
        //$('#forgot-password-form p.instructions').removeClass('extend');
        //$('#forgot-password-form p.instructions').html('If you have forgotten your password we can send a new one to your registered email address. Enter the email address you use to sign in to Click&amp;Mail.');
        $('#sign-in').show();
    }

    $('#sign-in-button a').click(
		function() {
		    showSignInTab();
		}
	);

    $('#sign-in-cancel-button').click(
		function() {
		    $('#sign-in').slideUp();
		    signInOpen = 0;
		    $('#sign-in-tab a').removeClass('open');
		    $('#sign-in').slideUp();
		    return false;
		}
	);


    $('#forgot-password-button').click(
		function() {
		    forgotPass = 1;
		    $('#forgot-password').slideDown();
		    return false;
		}
	);

    $('#forgot-password-cancel-button').click(
		function() {
		    forgotPass = 0;
		    $('#forgot-password').slideUp();
		    return false;
		}
	);

    //SIGN OUT
    $('#sign-out-button').click(
		function() {

		    $.get(baseURL + 'ajax/DoLogout.aspx?time=' + GetUniqueCacheID(), {},
			function(data) {
			    //alert(data);
			    if (data == 'OK') {
			        window.location = baseURL;
			    }
			});

		    return false;
		}
	);

    //SIGN IN
    var allowSignIn = 1;

    $('#si_submit_button').click(
		function() {

		    if (allowSignIn == 1) {



		        allowSignIn = 0;
		        $('#sign-in-form .loader').css({ display: 'block' });

		        var si_username = $('#si_user').attr('value');
		        var si_password = $('#si_pass').attr('value');
		        $.get(baseURL + 'ajax/AttemptLogin.aspx?time=' + GetUniqueCacheID(), { ea: si_username, pw: si_password },
				function(data) {
				    //alert(data);
				    if (data == 'EMAIL-ERROR') {
				        $('#si_user').parent().addClass('error');
				        $('#si_user').parent().after().siblings('strong').text('Please enter a valid email address');
				        allowSignIn = 1;
				    } else if (data == 'PASSWORD-ERROR') {
				        $('#si_user').parent().removeClass('error');
				        $('#si_user').parent().after().siblings('strong').text('');
				        $('#si_pass').parent().addClass('error');
				        $('#si_pass').parent().after().siblings('strong').text('Password not recognised');
				        allowSignIn = 1;
				    } else if (data == 'GENERAL-ERROR') {
				        $('#si_user').parent().removeClass('error');
				        $('#si_user').parent().after().siblings('strong').text('The system could not log you in at this time. Please try again later.');
				        $('#si_pass').parent().removeClass('error');
				        $('#si_pass').parent().after().siblings('strong').text('');
				        allowSignIn = 1;
				    } else {
				        var myaccStatus = document.URL;
				        myaccStatus = myaccStatus.substr(myaccStatus.indexOf("myacc=") + 6, 4);


				        if (myaccStatus == "true") {
				            window.location = baseURL + 'my-account/pay-as-you-go/';
				        }
				        else {
				            window.location = baseURL + 'my-account/?msg=w';
				        }
				    }
				    $('#sign-in-form .loader').css({ display: 'none' });
				});
		    }

		    return false;
		}
	);

    //FORGOT PASSWORD
    var allowForgotPassword = 1;

    $('#fp_submit_button').click(
		function() {

		    if (allowForgotPassword == 1) {

		        allowForgotPassword = 0;
		        $('#forgot-password-form .loader').css({ display: 'block' });

		        var fp_username = $('#fp_user').attr('value');

		        $.get(baseURL + 'ajax/ForgottenPassword.aspx?time=' + GetUniqueCacheID(), { ea: fp_username },
				function(data) {
				    if (data == 'EMAIL-ERROR') {
				        $('#fp_user').parent().addClass('error');
				        $('#fp_user').parent().after().siblings('strong').text('Email address not recognised.');
				        allowForgotPassword = 1;
				    } else if (data == 'GENERAL-ERROR') {
				        $('#fp_user').parent().removeClass('error');
				        $('#fp_user').parent().after().siblings('strong').text('The system could not reset your password at this time. Please try again later.');
				        allowForgotPassword = 1;
				    } else {
				        $('#fp_user').parent().removeClass('error');
				        $('#forgot-password-form p').hide();
				        $('#forgot-password-form .instructions').html('<strong>Thank you</strong>. Your password has been reset. An email has been sent to your account with your new password.<br />&nbsp;<br />&nbsp;').addClass('extend').show();
				        allowForgotPassword = 1;
				    }
				    $('#forgot-password-form .loader').css({ display: 'none' });
				});
		    }

		    return false;
		}
	);

    //FAQs
    $('.faq-set dt').hover(
		function() {
		    $(this).css({ cursor: 'pointer' });
		    $(this).addClass('hover');
		}, function() {
		    $(this).removeClass('hover');
		}
	);

    $('.faq-set dt').toggle(
		function() {
		    $(this).addClass('open');
		    $(this).next('dd').slideDown();
		}, function() {
		    $(this).removeClass('open');
		    $(this).next('dd').slideUp();
		}
	);

    //INSTRUCTIONS
    $('.instructions-set dt').hover(
		function() {
		    $(this).css({ cursor: 'pointer' });
		    $(this).addClass('hover');
		}, function() {
		    $(this).removeClass('hover');
		}
	);

    $('.instructions-set dt').toggle(
		function() {
		    $(this).addClass('open');
		    $(this).next('dd').slideDown();
		}, function() {
		    $(this).removeClass('open');
		    $(this).next('dd').slideUp();
		}
	);

    //FORM ERROR REPORTING
    function assignError(this_field, this_text) {
        $(this_field).parent().addClass('error');
        $(this_field).parent().after().siblings('span.error-details').text(this_text).show();
    }

    function removeError(this_field) {
        $(this_field).parent().removeClass('error');
        $(this_field).parent().after().siblings('span.error-details').hide();
    }

    function assignErrorGeneral(this_object, this_text) {
        $(this_object).text(this_text).show();
    }

    function removeErrorGeneral(this_object) {
        $(this_object).hide();
    }

    //QUICK CONTACT FORM
    var allowQF = 1;

    $('.qf_send_button').click(
		function() {

		    if (allowQF == 1) {

		        allowQF = 0;
		        removeErrorGeneral('#quick-form p.confirmation');

		        var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

		        var qf_message = $('.qf_message').attr('value');
		        var qf_name = $('.qf_name').attr('value');
		        var qf_email = $('.qf_email').attr('value');

		        if (qf_message == '' || qf_name == '' || qf_email == '') {
		            //CHECK FIELDS
		            assignErrorGeneral('#quick-form p.error', 'All fields are required');
		            allowQF = 1;
		        } else if (!emailFilter.test(qf_email)) {
		            assignErrorGeneral('#quick-form p.error', 'Please enter a valid email address');
		            allowQF = 1;
		        } else {
		            removeErrorGeneral('#quick-form p.error');
		            $('#quick-form .loader').css({ display: 'block' });

		            assignErrorGeneral('#quick-form p.confirmation', 'Thank you. Sending your message..');
		            //$('.qf_message').val('');
		            //$('.qf_name').val('');
		            //$('.qf_email').val('');
		            allowQF = 1;
		            $('#quick-form .loader').css({ display: 'none' });
		            __doPostBack('btnSend', 'btnSend_Click'); // this is a hyperlink in html not a user control
		        }

		    }

		    return false;

		}
	);

    //REGISTRATION STEP 1
    $('.reg_title').blur(
		function() {

		    var reg_title = $('.reg_title').attr('value');
		    if (reg_title == '') {
		        //CHECK TITLE
		        assignError('.reg_title', 'This information is required');
		    } else {
		        removeError('.reg_title');
		    }

		}
	);
    $('.reg_firstname').blur(
		function() {

		    var reg_firstname = $('.reg_firstname').attr('value');
		    if (reg_firstname == '') {
		        //CHECK FIRSTNAME
		        assignError('.reg_firstname', 'This information is required');
		    } else {
		        removeError('.reg_firstname');
		    }

		}
	);
    $('.reg_lastname').blur(
		function() {

		    var reg_lastname = $('.reg_lastname').attr('value');
		    if (reg_lastname == '') {
		        //CHECK LASTNAME
		        assignError('.reg_lastname', 'This information is required');
		    } else {
		        removeError('.reg_lastname');
		    }

		}
	);
    $('.reg_company').blur(
		function() {

		    var reg_company = $('.reg_company').attr('value');
		    if (reg_company == '') {
		        //CHECK COMPANY
		        assignError('.reg_company', 'This information is required');
		    } else {
		        removeError('.reg_company');
		    }

		}
	);
    $('.reg_email').blur(
		function() {

		    var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		    var reg_email = $('.reg_email').attr('value');
		    if (reg_email == '') {
		        //CHECK EMAIL
		        assignError('.reg_email', 'This information is required');
		    } else if (!emailFilter.test(reg_email)) {
		        //VALIDATE EMAIL
		        assignError('.reg_email', 'Please enter a valid email address');
		    } else {
		        removeError('.reg_email');
		    }

		}
	);
    $('.reg_email_conf').blur(
		function() {

		    var email_address = $(".reg_email").attr("value");
		    var email_address_conf = $(this).attr("value");

		    if (email_address_conf != email_address || email_address_conf == "") {
		        //CHECK EMAIL CONFIRMATION
		        assignError('.reg_email_conf', 'Your email address must match');
		    } else {
		        removeError('.reg_email_conf');
		    }

		}
	);
    $('.reg_password').blur(
		function() {

		    var requiredLength = 6;
		    var reg_password = $('.reg_password').attr('value');
		    if (reg_password == '') {
		        //CHECK PASSWORD
		        assignError('.reg_password', 'This information is required');
		    } else if (reg_password.length < requiredLength) {
		        //CHECK PASSWORD LENGTH
		        assignError('.reg_password', 'Your password must be at least 6 characters');
		    } else {
		        removeError('.reg_password');
		    }

		}
	);
    $('.reg_password2').blur(
		function() {

		    var reg_password = $('.reg_password').attr('value');
		    var reg_password2 = $('.reg_password2').attr('value');
		    if (reg_password2 == '') {
		        //CHECK PASSWORD2
		        assignError('.reg_password2', 'This information is required');
		    } else if (reg_password2 != reg_password) {
		        //COMPARE PASSWORD2 TO PASSWORD
		        assignError('.reg_password2', 'Your passwords don\'t match');
		    } else {
		        removeError('.reg_password2');
		    }

		}
	);


    function validatePromoCode() {
        gPromoCodeValid = false;

        var reg_promo = $('.reg_promo').attr('value');

        if (reg_promo != '') {

            $('.continue').addClass('continue-disabled');

            assignError('.reg_promo', 'Validating promotional code');

            $.get(baseURL + 'ajax/CheckPromotionCode.aspx?time=' + GetUniqueCacheID(), { pc: reg_promo },
				function(data) {

				    if (data == 'INVALID') {

				        assignError('.reg_promo', 'Invalid promotional code');
				        gPromoCodeValid = false;
				    } else {

				        removeError('.reg_promo');
				        gPromoCodeValid = true;

				        //$('.reg_continue_step1').click();

				    }
				    gAjaxPending = false;
				    $('.continue').removeClass('continue-disabled');
				}
			    );

        } else {
            removeError('.reg_promo');
            gPromoCodeValid = true;
            gAjaxPending = false;
        }
    }

    $('.reg_promo').blur(
		function() {

		    validatePromoCode();

		}
	);




    $('.reg_password_optional').blur(
		function() {

		    //			var requiredLength = 6;
		    //			var reg_password = $('.reg_password_optional').attr('value');
		    //			var reg_password2 = $('.reg_password2_optional').attr('value');
		    //			if((reg_password!='')||(reg_password2!='')) {
		    //			    if(reg_password == '') {
		    //				    //CHECK PASSWORD
		    //				    assignError('.reg_password_optional', 'This information is required');
		    //			    } else if(reg_password.length < requiredLength) {
		    //				    //CHECK PASSWORD LENGTH
		    //				    assignError('.reg_password_optional', 'Your password must be at least 6 characters');
		    //			    } else {
		    //				    removeError('.reg_password_optional');
		    //			    }
		    //			    }

		}
	);
    $('.reg_password2_optional').blur(
		function() {

		    //			var reg_password = $('.reg_password_optional').attr('value');
		    //			var reg_password2 = $('.reg_password2_optional').attr('value');
		    //			if((reg_password!='')||(reg_password2!='')) {
		    //			    if(reg_password2 == '') {
		    //				    //CHECK PASSWORD2
		    //				    assignError('.reg_password2_optional', 'This information is required');
		    //			    } else if(reg_password2 != reg_password) {
		    //				    //COMPARE PASSWORD2 TO PASSWORD
		    //				    assignError('.reg_password2_optional', 'Your passwords don\'t match');
		    //			    } else {
		    //				    removeError('.reg_password2_optional');
		    //			    }
		    //			}
		    //		
		}
	);

    $('.reg_continue_step1').click(
		function() {


		    //VALIDATE FIELDS			
		    var allClear = 1;
		    var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		    var requiredLength = 6;

		    var reg_title = $('.reg_title').attr('value');
		    var reg_firstname = $('.reg_firstname').attr('value');
		    var reg_lastname = $('.reg_lastname').attr('value');
		    var reg_company = $('.reg_company').attr('value');
		    var reg_email = $('.reg_email').attr('value');
		    var reg_email_conf = $('.reg_email_conf').attr('value');
		    var reg_password = $('.reg_password').attr('value');
		    var reg_password2 = $('.reg_password2').attr('value');

		    if (reg_title == '') {
		        //CHECK TITLE
		        assignError('.reg_title', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_title');
		    }
		    if (reg_firstname == '') {
		        //CHECK FIRSTNAME
		        assignError('.reg_firstname', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_firstname');
		    }
		    if (reg_lastname == '') {
		        //CHECK LASTNAME
		        assignError('.reg_lastname', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_lastname');
		    }
		    if (reg_company == '') {
		        //CHECK COMPANY
		        assignError('.reg_company', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_company');
		    }
		    if (reg_email == '') {
		        //CHECK EMAIL
		        assignError('.reg_email', 'This information is required');
		        allClear = 0;
		    } else if (!emailFilter.test(reg_email)) {
		        //VALIDATE EMAIL
		        assignError('.reg_email', 'Please enter a valid email address');
		        allClear = 0;
		    } else {
		        removeError('.reg_email');
		    }
		    if (reg_email_conf != reg_email || reg_email_conf == '') {
		        //CHECK EMAIL CONF
		        assignError('.reg_email_conf', 'Your email address must match');
		        allClear = 0;
		    } else {
		        removeError('.reg_email_conf');
		    }
		    if (reg_password == '') {
		        //CHECK PASSWORD
		        assignError('.reg_password', 'This information is required');
		        allClear = 0;
		    } else if (reg_password.length < requiredLength) {
		        //CHECK PASSWORD LENGTH
		        assignError('.reg_password', 'Your password must be at least 6 characters');
		        allClear = 0;
		    } else {
		        removeError('.reg_password');
		    }
		    if (reg_password2 == '') {
		        //CHECK PASSWORD2
		        assignError('.reg_password2', 'This information is required');
		        allClear = 0;
		    } else if (reg_password2 != reg_password) {
		        //COMPARE PASSWORD2 TO PASSWORD
		        assignError('.reg_password2', 'Your passwords don\'t match');
		        allClear = 0;
		    } else {
		        removeError('.reg_password2');
		    }

	

		    if (!gPromoCodeValid) {
		        assignError('.reg_promo', 'Invalid promotional code');
		        allClear = 0;
		    }

		



		    if (allClear == 0) {
		        //SHOW MAIN ERROR ALERT
		        assignErrorGeneral('p.error', 'There was an error with the form. Please correct the highlighted fields and try again.');
		    } else {
		        //PROCEED WITH SUBMISSION
		        removeErrorGeneral('p.error');


		        $.get(baseURL + 'ajax/CheckEmailUnique.aspx?time=' + GetUniqueCacheID(), { ea: reg_email },

				function(data) {

				    if (data == 'EMAIL-USED') {
				        assignError('.reg_email', 'This email address is already in use, please choose another email address.');

				        allClear = 0;
				    } else if (data == 'GENERAL-ERROR') {
				        assignError('.reg_email', 'An error has occured, please try again later.');

				        allClear = 0;
				    } else if (data == 'OK') {
				        if ((!gAjaxPending && $('.continue').parent().find('.continue-disabled').length == 0) && (gPromoCodeValid)) {
				            __doPostBack('btnContinueFromStep1', 'btnContinueFromStep1_Click');
				        }

				    }
				}

				);





		    }


		    return false;

		}
	);

    //REGISTRATION STEP 2
    $('.reg_address1').blur(
		function() {

		    var reg_address1 = $('.reg_address1').attr('value');
		    if (reg_address1 == '') {
		        //CHECK ADDRESS
		        assignError('.reg_address1', 'This information is required');
		    } else {
		        removeError('.reg_address1');
		    }

		}
	);
    $('.reg_city').blur(
		function() {

		    var reg_city = $('.reg_city').attr('value');
		    if (reg_city == '') {
		        //CHECK CITY
		        assignError('.reg_city', 'This information is required');
		    } else {
		        removeError('.reg_city');
		    }

		}
	);
    $('.reg_postcode').blur(
		function() {

		    var reg_postcode = $('.reg_postcode').attr('value');
		    if (reg_postcode == '') {
		        //CHECK POSTCODE
		        assignError('.reg_postcode', 'This information is required');
		    } else {
		        removeError('.reg_postcode');
		    }

		}
	);

    $('.reg_continue_step2').click(
		function() {

		    //VALIDATE FIELDS			
		    var allClear = 1;

		    var reg_address1 = $('.reg_address1').attr('value');
		    var reg_city = $('.reg_city').attr('value');
		    var reg_postcode = $('.reg_postcode').attr('value');

		    if (reg_address1 == '') {
		        //CHECK ADDRESS
		        assignError('.reg_address1', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_address1');
		    }
		    if (reg_city == '') {
		        //CHECK CITY
		        assignError('.reg_city', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_city');
		    }
		    if (reg_postcode == '') {
		        //CHECK POSTCODE
		        assignError('.reg_postcode', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_postcode');
		    }

		    if (allClear == 0) {
		        //SHOW MAIN ERROR ALERT
		        assignErrorGeneral('p.error', 'There was an error with the form. Please correct the highlighted fields and try again.');
		    } else {
		        //PROCEED WITH SUBMISSION
		        removeErrorGeneral('p.error');

		        __doPostBack('btnContinueFromStep2', 'btnContinueFromStep2_Click');

		    }

		    return false;

		}
	);

    $('.reg_save_settings').click(
		function() {

		    //VALIDATE FIELDS			
		    var allClear = 1;
		    var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		    var requiredLength = 6;

		    var reg_title = $('.reg_title').attr('value');
		    var reg_firstname = $('.reg_firstname').attr('value');
		    var reg_lastname = $('.reg_lastname').attr('value');
		    var reg_email = $('.reg_email').attr('value');
		    var reg_password = $('.reg_password_optional').attr('value');
		    var reg_password2 = $('.reg_password2_optional').attr('value');
		    var reg_address1 = $('.reg_address1').attr('value');
		    var reg_city = $('.reg_city').attr('value');
		    var reg_postcode = $('.reg_postcode').attr('value');

		    if (reg_title == '') {
		        //CHECK TITLE
		        assignError('.reg_title', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_title');
		    }
		    if (reg_firstname == '') {
		        //CHECK FIRSTNAME
		        assignError('.reg_firstname', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_firstname');
		    }
		    if (reg_lastname == '') {
		        //CHECK LASTNAME
		        assignError('.reg_lastname', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_lastname');
		    }
		    if (reg_email == '') {
		        //CHECK EMAIL
		        assignError('.reg_email', 'This information is required');
		        allClear = 0;
		    } else if (!emailFilter.test(reg_email)) {
		        //VALIDATE EMAIL
		        assignError('.reg_email', 'Please enter a valid email address');
		        allClear = 0;

		    } else {
		        removeError('.reg_email');
		    }

		    if ((reg_password != '') || (reg_password2 != '')) {

		        if (reg_password == '') {
		            //CHECK PASSWORD
		            assignError('.reg_password_optional', 'This information is required');
		            allClear = 0;
		        } else if (reg_password.length < requiredLength) {
		            //CHECK PASSWORD LENGTH
		            assignError('.reg_password_optional', 'Your password must be at least 6 characters');
		            allClear = 0;
		        } else {
		            removeError('.reg_password_optional');
		        }

		        if (reg_password2 == '') {
		            //CHECK PASSWORD2
		            assignError('.reg_password2_optional', 'This information is required');
		            allClear = 0;
		        } else if (reg_password2 != reg_password) {
		            //COMPARE PASSWORD2 TO PASSWORD
		            assignError('.reg_password2_optional', 'Your passwords don\'t match');
		            allClear = 0;
		        } else {
		            removeError('.reg_password2_optional');
		        }
		    }
		    if (reg_address1 == '') {
		        //CHECK ADDRESS
		        assignError('.reg_address1', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_address1');
		    }
		    if (reg_city == '') {
		        //CHECK CITY
		        assignError('.reg_city', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_city');
		    }
		    if (reg_postcode == '') {
		        //CHECK POSTCODE
		        assignError('.reg_postcode', 'This information is required');
		        allClear = 0;
		    } else {
		        removeError('.reg_postcode');
		    }

		    if (allClear == 0) {
		        //SHOW MAIN ERROR ALERT
		        $('p.error').text('There was an error with the form. Please correct the highlighted fields and try again.').show();
		    } else {
		        //PROCEED WITH SUBMISSION
		        $('p.error').hide();

		        __doPostBack('btnSaveSettings', 'btnSaveSettings_Click');



		        //window.location=baseURL+'/my-account/';

		    }

		    return false;

		}
	);

    //CONTACT US
    $('.cf_firstname').blur(
		function() {
		    var cf_firstname = $('.cf_firstname').attr('value');
		    if (cf_firstname == '') {
		        //CHECK FIRSTNAME
		        assignError('.cf_firstname', 'This information is required');
		    } else {
		        removeError('.cf_firstname');
		    }

		}
	);
    $('.cf_lastname').blur(
		function() {
		    var cf_lastname = $('.cf_lastname').attr('value');
		    if (cf_lastname == '') {
		        //CHECK LASTNAME
		        assignError('.cf_lastname', 'This information is required');
		    } else {
		        removeError('.cf_lastname');
		    }

		}
	);
    $('.cf_email').blur(
		function() {
		    var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		    var cf_email = $('.cf_email').attr('value');
		    if (cf_email == '') {
		        //CHECK EMAIL
		        assignError('.cf_email', 'This information is required');
		    } else if (!emailFilter.test(cf_email)) {
		        //VALIDATE EMAIL
		        assignError('.cf_email', 'Please enter a valid email address');
		    } else {
		        removeError('.cf_email');
		    }

		}
	);
    $('.cf_message').blur(
		function() {
		    var cf_message = $('.cf_message').attr('value');
		    if (cf_message == '') {
		        //CHECK MESSAGE
		        assignError('.cf_message', 'This information is required');
		    } else {
		        removeError('.cf_message');
		    }

		}
	);

    var allowCF = 1;

    $('.cf_send_button').click(
		function() {

		    if (allowCF == 1) {

		        allowCF = 0;
		        removeErrorGeneral('p.confirmation');

		        //VALIDATE FIELDS			
		        var allClear = 1;
		        var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

		        var cf_firstname = $('.cf_firstname').attr('value');
		        var cf_lastname = $('.cf_lastname').attr('value');
		        var cf_email = $('.cf_email').attr('value');
		        var cf_message = $('.cf_message').attr('value');

		        if (cf_firstname == '') {
		            //CHECK FIRSTNAME
		            assignError('.cf_firstname', 'This information is required');
		            allClear = 0;
		        } else {
		            removeError('.cf_firstname');
		        }
		        if (cf_lastname == '') {
		            //CHECK LASTNAME
		            assignError('.cf_lastname', 'This information is required');
		            allClear = 0;
		        } else {
		            removeError('.cf_lastname');
		        }
		        if (cf_email == '') {
		            //CHECK EMAIL
		            assignError('.cf_email', 'This information is required');
		            allClear = 0;
		        } else if (!emailFilter.test(cf_email)) {
		            //VALIDATE EMAIL
		            assignError('.cf_email', 'Please enter a valid email address');
		            allClear = 0;
		        } else {
		            removeError('.cf_email');
		        }
		        if (cf_message == '') {
		            //CHECK MESSAGE
		            assignError('.cf_message', 'This information is required');
		            allClear = 0;
		        } else {
		            removeError('.cf_message');
		        }

		        if (allClear == 0) {
		            //SHOW MAIN ERROR ALERT
		            assignErrorGeneral('p.error', 'There was an error with the form. Please correct the highlighted fields and try again.');
		            allowCF = 1;
		        } else {
		            //PROCEED WITH SUBMISSION
		            removeErrorGeneral('p.error');
		            $('#contact-form .loader').css({ display: 'block' });

		            assignErrorGeneral('p.confirmation', 'Please wait..');
		            //$('.cf_firstname').val('');
		            //$('.cf_lastname').val('');
		            //$('.cf_email').val('');
		            //$('.cf_message').val('');
		            //$('#contact-form :checkbox').attr('checked','');
		            allowCF = 1;
		            $('#contact-form .loader').css({ display: 'none' });

		            __doPostBack('btnSendMessage', 'btnSendMessage_Click');
		        }

		    }

		    return false;

		}
	);

    //FIND ADDRESS
    if ($(".reg_postcode").attr("value") != "") {
        $("tr.select-address").show();
    }

});

//ACTION TRACKING
function trackAction(action, page, title, media, type) {
	
	page = page.substr(page.indexOf("clickandmail.co.uk/"));
	
	var track_path = "/" + action + "/" + page + "/" + title;
	
	if(media) track_path += "/" + media;
	if(type) track_path += "/" + type;
	
	track_path = unescape(track_path);
	firstTracker._trackPageview(track_path);
	
}
