
// Define Namespace
var CITYLINK = {};

CITYLINK.Common = {

    validatePostcode : function(postcode)
    {
        var rgxPostcode = new RegExp("^[A-Za-z]{1,2}[0-9]{1,2}[A-Za-z]? ?[0-9]{1}[A-Za-z]{2}$","i");
        if (postcode.match(rgxPostcode) == null) {
            return false;
        }
        return true;
    }

}

$.fn.extend({
    hintText: function(text)
    {
        this.data('hintText', text);
        if(this.val() == '' || this.val() == text) {
            this.val(text);
            this.addClass('input-hint');
        }
        this.focus(function(){
            if($(this).val() == text) {
                $(this).val('');
                $(this).removeClass('input-hint');
            }
        });
        this.blur(function(){
            if($(this).val() == '') {
                $(this).val(text);
                $(this).addClass('input-hint');
            }
        });
        this.keypress(function(){
            $(this).removeClass('input-warning');
        });
        form = this.parents('form');
        if(form.data('hintText') == undefined) {
            form.submit(function(){
                ok = true;
                inputs = $(this).find('input');
                inputs.each(function(){
                    if($(this).data('hintText') != undefined) {
                        if($(this).val() == '' || $(this).val() == $(this).data('hintText')) {
                            $(this).addClass('input-warning');
                            ok = false;
                        }
                    }
                });
                return ok;
            });
            form.data('hintText', 'function added');
        }
    }
});

$('document').ready(function(){

    $('#squery').hintText('Search our site');
    $('#parcel_ref_num').hintText('Consignment No./Ref No.');
	$('#postcode.track_num').hintText('Delivery Postcode');
	$('#postcode.data-input').hintText('Delivery Postcode');
	$('#postcode_directions.data-input').hintText('Please Enter Your Postcode...');
    $('#custno').hintText('City Link Account number...');

});


