$(document).ready(
    function() {
	$("header h1").click(function(){
				 console.log("out");
				 window.location = "/";
				 return false;
				 
			     });
	
	$(".post").addClass("drop-shadow curved curved-vt-2");
	$(".com").addClass("drop-shadow curved curved-vt-2");
	$("input[name='post']").addClass("drop-shadow curved curved-vt-2");
	$("#commitwrap").addClass("drop-shadow curved curved-vt-2");
	$("input[name='preview']").hide();
	$("#posts form").addClass("drop-shadow curved curved-vt-2");
	

	var rtbl = document.getElementById('repo_tbl');
	if (rtbl){
	    var n_rows = rtbl.getElementsByTagName('tr').length;
	    for (var i=1;i<n_rows;++i){
		var row = document.getElementById('r_row_'+i);
		row.onclick = function(){
		    window.location = this.childNodes[1].childNodes[0].href;
		};
	    }
	}



	debug = true;
	
	
	
	$("input[name='post']").click(function() {
					  //Remove error messages
					  $('.comment-error').remove();

					  //Do form validation here. Blank state/email regex.
					  var errorz = true;
					  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					  if ($('#id_name').val() == "") { $('#id_name').css({'border':'2px solid red'});  errorz = false;}
					  if ($('#id_email').val() == ""){ $('#id_email').css({'border':'2px solid red'});  errorz = false;}
					  else if (!emailReg.test($('#id_email').val())){ $('#id_email').css({'border':'2px solid red'});  errorz = false;}
					  if ($('#id_comment').val() == ""){ $('#id_comment').css({'border':'2px solid red'});  errorz = false;}

					  if (!errorz){return false;}

					  var params = $('form').serialize();

					  $.post('/ajax/commentz/postz/', params, function(data) {
						     if (data.status == "success") {
							 // If the post was a success, disable the Post button to
							 // prevent accidental duplication.
							 $('input.submit-post').attr('disabled', 'disabled');

							 
							 $('form').hide()
							     .html('<p class="comment-thanks">Comment successfully' +
								   ' posted and awaiting moderation.</p>')
							     .show('fast');
						     } else if (data.status == "debug") {
							 if (debug) {
							     // If the site is currently in development, list the debug
							     // errors.
							     $('form').before('<div class="comment-error">' +
									      data.error + '</div>');
							 } else {
							     // Otherwise, display a generic server error message.
							     $('form').before('<div class="comment-error">' +
									      'There has been an internal error with the server.</div>');
							 }
						     } else {
							 // If there were errors with the form, I add them to the
							 // page above my comment form with a "comment-error" div.
							 $('form').before('<div class="comment-error">' +
									  data.error + '</div>');
						     }
						 }, "json");
					  
					  return false;
				      });

    });
