$(document).ready(function(){
    /*
    var sel_loc_tab;    
    $("#locations_tabs a").click(function(){
        spl = $(this).attr('id').split('_');
        if(spl[1]==sel_loc_tab) return false;
        $(".location_content").slideUp();    
        $("a").removeClass('active_tab');    
        $("#ltab_"+spl[1]).addClass('active_tab');    
        $("#location_content_"+spl[1]).fadeIn();    
        sel_loc_tab = spl[1];
    });  
    */
    $('.mainLnav li a').click(function(){
        if($(this).parent().hasClass('on')){
            return false;
        }
        $('.mainLnav li').removeClass('on');
        $(this).parent().addClass('on');        
        var thisa = $(this);
        $('.midcolpages:visible, .side-tabs:visible').fadeOut('fast', function(){
            $('#user_prefered_' + thisa.attr('id')).fadeIn();
            $('#side_tab_' + thisa.attr('id')).fadeIn();
        });        
        return false;
    });
    
    $('.quizAnswer').click(function(){$('.quizBody').slideToggle();return false;});
    
});


jQuery.validators = {
    url: /^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$/,
    number: /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/,
    string: /[a-zA-Z]+/,
    email: /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z_])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]?\.)+[a-zA-Z]{2,9}\.?([a-zA-Z]+)?)$/,            
    required: /^.+$/
}
jQuery.fn.validate = function() {
    i = 0;
    target = jQuery(this)[0];
    if(/input/i.test(target.nodeName)) {
        jQuery.each(jQuery.validators, function(x, y) {            
            if(jQuery(target).hasClass(x) && !y.test(jQuery(target).attr('value'))) {
                i++;
            }
        });     
    } else  { i++; }
    return (i == 0) ? true : false;
};
$.extend($.expr[':'], {
    valid: "$(a).validate();",
    invalid: "!$(a).validate();"
});

function URLEncode(url) //Function to encode URL.
{
// The Javascript escape and unescape functions do not correspond
// with what browsers actually do...
var SAFECHARS = "0123456789" + // Numeric
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
"abcdefghijklmnopqrstuvwxyz" +
"-_.!~*'()"; // RFC2396 Mark characters
var HEX = "0123456789ABCDEF";

var plaintext = url;
var encoded = "";
for (var i = 0; i < plaintext.length; i++ ) {
var ch = plaintext.charAt(i);
if (ch == " ") {
encoded += "+"; // x-www-urlencoded, rather than %20
} else if (SAFECHARS.indexOf(ch) != -1) {
encoded += ch;
} else {
var charCode = ch.charCodeAt(0);
if (charCode > 255) {
encoded += "+";
} else {
encoded += "%";
encoded += HEX.charAt((charCode >> 4) & 0xF);
encoded += HEX.charAt(charCode & 0xF);
}
}
}
return encoded;
}; 