// jQuery No Conflict
var $j = jQuery.noConflict();
// JavaScript Document
$j(document).ready( function($) {
	$("#commentForm").validate( {
		messages : {
			required : 'Campo Obligatorio'
		},
		submitHandler : function() {
			$("#commentForm").ajaxSubmit( {
				success : showResponse
			});
		},
		highlight : function(element, errorClass) {
			$(element).addClass('errorClass');
		},
		unhighlight : function(element, errorClass) {
			$(element).removeClass('errorClass');
		}
	});

	$("#loading").ajaxStart( function() {
		$("#enviar").attr("disable", "true");
		$(this).show();
	});
	function showResponse(responseText, statusText) {
		if (gup('redirect') == 'sendMail') {
			var tmpUri = document.getElementsByTagName('base')[0].href;
			var uri = '?id=234';
			document.location.href = tmpUri + uri;
			return null;
		} else {
			alert(responseText);
		}
		$("#enviar").attr("disable", "false");
		$('#commentForm').find('input[type=text],input[type=password]').each( function() {
			$(this).val('');
		});
	}
});

function gup(name) {
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var tmpURL = window.location.href;
	var results = regex.exec(tmpURL);
	if (results == null)
		return false;
	else
		return results[1];
}

