/**
*   Initialize Page
*/
$(document).ready(function() {
    FormHighlight();
    InitWatermarks();
});

/**
*   Catch Console Errors
*/
if (typeof (console) === 'undefined') {
    console = new function() { };
    console.log = function() { };
}

/**
*   Initialize Watermarks On Text Input
*/
function InitWatermarks() {
    $('.watermarked')
            .each(function() {
                if ($(this).val() === $(this).attr('title')) $(this).addClass('watermark');
            })
            .focus(function() {
                if ($(this).val() == $(this).attr('title')) {
                    $(this).val('').removeClass('watermark');
                }
            })
            .blur(function() {
                if ($(this).val() == '') {
                    $(this).addClass('watermark').val($(this).attr('title'));
                }
            }).each(function() {
                if ($(this).val() == '') {
                    $(this).addClass('watermark').val($(this).attr('title'));
                }
                else {
                    $(this).removeClass('watermark');
                }
            });
}

/**
*   Initialize Form Input Highlights
*/
function FormHighlight() {
    $('input[type="text"], input[type="password"], select, textarea, input[type="checkbox"]').focus(function() {
        if ($(this).attr('type') != 'checkbox') {
            $(this).addClass('focus').prevAll('label:first').addClass('focus');
        }
        else {
            $(this).next('label').addClass('focus');
        }
    });

    $('input[type="text"], input[type="password"], select, textarea, input[type="checkbox"]').blur(function() {
        $('input[type="text"], input[type="password"], select, label, textarea, input[type="checkbox"]').removeClass('focus');
    });
}

/**
*   Add Hash To Url
*/
function AddHash(hash) {
    //pageTracker._trackPageview('/market/' + hash);
    if ('#' + hash == window.location.hash) {
        window.location.hash = new String((new Date().getMilliseconds()));
    }
    window.location.hash = hash;
}