function comment_form_validate($form) {
  var error=false;

  if ($form.find("#id_name").val() == "") {
    $form.find('#spanUserNameErr').html("No, that's not it! Try again...");
    error = true;
  } else {
    $form.find('#spanUserNameErr').html("");
  }

  if (! /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test($form.find('#id_email').val())) {
    $form.find('#spanMailErr').html("You can't fool us, try again...");
    error = true;
  } else {
    $form.find('#spanMailErr').html("");
  }

  if (! /(?:https?:\/\/)?(?:[a-z0-9]+\.)?[^.]+\.[a-z]{2,8}(?:\.[a-z]{2,8})?/.test($form.find("#id_url").val()) && $.trim($form.find('#id_url').val()) !== '') {
    $form.find('#spanURLErr').html("Wrong format there...");
    error = true;
  } else {
    $form.find('#spanURLErr').html("");
  }

  if ($form.find("#id_comment").val() == "") {
    $form.find('#spanContentErr').html("Why would you leave this blank?")
    error = true;
  } else {
    $form.find('#spanContentErr').html("");
  }

  return !error;
}

$(document).ready(function () {
	$('form.comment_form').bind("submit",function(e) {
		$thisform = $(this);
		$email = $(this).find('#id_email');
		var validated = comment_form_validate($(this));
		if (validated) {
			$.ajax({
				type:'POST',
				dataType:'json',
				url:'/mc/validate-email/',
				data: {email:$email.val()},
				success:function(response) {
					if (response.success === 'true') {
						$thisform.unbind('submit').trigger('submit');
						return false;
					} else {
						alert ('Please login to post comment.');
						return false;
					}
				},
				error:function() {
					alert('An error occured while contacting the server. Please try again');
					return false;
				}
			});
		}
		return false;
	});
});


/* contents of base.js below */


var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;


function JSFX_FloatDiv(id, sx, sy)
{
 var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
 var px = document.layers ? "" : "px";
 window[id + "_obj"] = el;
 if(d.layers)el.style=el;
 el.cx = el.sx = sx;el.cy = el.sy = sy;
 el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

 el.floatIt=function()
 {
 var pX, pY;
 pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
 document.documentElement && document.documentElement.clientWidth ?
 document.documentElement.clientWidth : document.body.clientWidth;
 pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
 document.documentElement.scrollTop : document.body.scrollTop;
 if(this.sy<0)
 pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
 document.documentElement.clientHeight : document.body.clientHeight;
 this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
 this.sP(this.cx, this.cy);
 setTimeout(this.id + "_obj.floatIt()", 2);
 }
 return el;
}



 function callSearch() {
 //alert('called');
 //      debugger;
        var keyword = document.getElementById('txtGlobalSearch').value;

       // window.open(serverURL + "search/" + keyword + "/");
       keyword = trim(keyword)
        if (keyword != "Search..." && keyword != "") {
            var locationstr = serverURL + "search=" + keyword;
            window.location = locationstr;
        }

    }

    function SearchKeyDown(e) {
        if (window.event) { e = window.event; }
        if (e.keyCode == 13) {
            callSearch();
        }
    }



function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}





    function showNavigation(flag) {

        if (flag == 1) {

            document.getElementById("navstate").className = "navigation_open";
        }
        else {

            document.getElementById("navstate").className = "";
        }
    }



    function js_waterMark_Focus(txtElem, strWatermark) {

        txtElem =  document.getElementById(txtElem);
        if (txtElem.value == strWatermark) txtElem.value = '';
    }

    function js_waterMark_Blur(txtElem, strWatermark) {

        txtElem = document.getElementById(txtElem);
        if (txtElem.value == '') txtElem.value = strWatermark;
    }


	   /*function setCookie() {
            var d = new date();
            d = d + 365;

            document.cookie = "username=vaibhav; expires =" + d;
            document.cookie = "mail=vaibhav.tapare@gmail.com;expires =" + d;
            document.cookie = "url=http://www.google.com; expires ="+ d;

        }*/


		function set_cookie ( name, value,  domain, secure )
		{


		  var cookie_string = name + "=" + escape ( value );


		var exdate=new Date();
        exdate.setDate(exdate.getDate()+365);


			cookie_string += "; expires=" + exdate.toGMTString();


		  if ( domain )
				cookie_string += "; domain=" + escape ( domain );

		  if ( secure )
				cookie_string += "; secure";

		  document.cookie = cookie_string;
		}


        /*function retriveCookie() {

            var x = document.cookie;
            alert(x);
             alert(get_cookie("mail"));



        }*/

        function get_cookie(cookie_name) {

            var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

            if (results)
                return (unescape(results[2]));
            else
                return null;
        }
        
