var scrollTime=500;var fadeTime=3000;var xmlHttp;var area;var bid;var skip;var type;function doGet(pname,parea,val1,val2){area=parea;xmlHttp=GetXmlHttpObject();if(xmlHttp==null){alert("Browser does not support HTTP Request");return}var url="view/"+pname+".php";url=url+"?val1="+val1;url=url+"&val2="+val2;url=url+"&sid="+Math.random();xmlHttp.onreadystatechange=stateChanged;xmlHttp.open("GET",url,true);xmlHttp.send(null)}function stateChanged(){if(xmlHttp.readyState==1){document.getElementById("loading").style.visibility="visible"}if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){if(area=="a"){document.getElementById("allcontent").innerHTML=xmlHttp.responseText}else if(area=="l"){document.getElementById("lcolumn").innerHTML=xmlHttp.responseText}else if(area=="m"){document.getElementById("mcolumn").innerHTML=xmlHttp.responseText}else{document.getElementById("rcolumn").innerHTML=xmlHttp.responseText}document.getElementById("loading").style.visibility="hidden";if(type!="comment"){$('html,body').animate({scrollTop:0},scrollTime)}type=""}}function doPost(pname,id){bid=id;var url;var params;type=pname;xmlHttp=GetXmlHttpObject();if(xmlHttp==null){alert("Browser does not support HTTP Request");return}if(pname=="blog"){var myForm=document.getElementById("blogForm");var category=myForm.category.value;var title=myForm.title.value;var content=myForm.content.value;url="controller/postBlog.php";params="category="+category;params=params+"&title="+title;params=params+"&content="+content;params=params+"&sid="+Math.random()}else if(pname=="comment"){var myForm=document.getElementById("comForm");var name=myForm.name.value;var website=myForm.website.value;var email=myForm.email.value;var comment=myForm.comment.value;name=name.replace(/</g,"");name=name.replace(/>/g,"");comment=comment.replace(/</g,"");comment=comment.replace(/>/g,"");url="controller/postComment.php";params="bid="+bid;params=params+"&name="+name;params=params+"&comment="+comment;if(website!=""){if(!(website.startsWith("http://")))website="http://"+website;params=params+"&web="+website}if(email!=""){params=params+"&mail="+email}params=params+"&sid="+Math.random()}else if(pname=="category"){var myForm=document.getElementById("categoryForm");var category=myForm.category.value;url="controller/postCategory.php";params="category="+category;params=params+"&sid="+Math.random()}xmlHttp.open("POST",url,true);xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlHttp.setRequestHeader("Content-length",params.length);xmlHttp.setRequestHeader("Connection","close");xmlHttp.onreadystatechange=postStateChanged;xmlHttp.send(params)}function postStateChanged(){if(xmlHttp.readyState==1){document.getElementById("loading").style.visibility="visible"}if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){document.getElementById("loading").style.visibility="hidden";if(type=="blog"){document.getElementById("inmsg").innerHTML="<h2>New blog has been posted!</h2>";$("#msg").fadeIn("slow");setTimeout("hideMessage()",fadeTime);doGet('main','a',1,null)}else if(type=="comment"){document.getElementById("inmsg").innerHTML="<h2>Thank you for commenting!</h2>";$("#msg").fadeIn("slow");setTimeout("hideMessage()",fadeTime);doGet("comments","l",bid,1)}else if(type=="category"){document.getElementById("inmsg").innerHTML="<h2>New category added!</h2>";$("#msg").fadeIn("slow");setTimeout("hideMessage()",fadeTime);doGet("main","a",1,null)}}}function doAction(action,cid,id){bid=id;var url;if(action=="db"){type="blog";url="controller/deleteBlog.php";url=url+"?bid="+bid;url=url+"&sid="+Math.random()}else if(action=="dc"){type="comment";url="controller/deleteComment.php";url=url+"?cid="+cid;url=url+"&bid="+id;url=url+"&sid="+Math.random()}xmlHttp.onreadystatechange=deleteStateChanged;xmlHttp.open("GET",url,true);xmlHttp.send(null)}function deleteStateChanged(){if(xmlHttp.readyState==1){document.getElementById("loading").style.visibility="visible"}if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){document.getElementById("loading").style.visibility="hidden";if(type=="blog"){document.getElementById("inmsg").innerHTML="<h2>Blog successfully deleted!</h2>";$("#msg").fadeIn("slow");setTimeout("hideMessage()",fadeTime);doGet("main","a",1,null)}else if(type=="comment"){document.getElementById("inmsg").innerHTML="<h2>Comment successfully deleted!</h2>";$("#msg").fadeIn("slow");setTimeout("hideMessage()",fadeTime);doGet("comments","l",bid,1)}}}function hideMessage(){$("#msg").fadeOut("slow")}function GetXmlHttpObject(){var xmlHttp=null;try{xmlHttp=new XMLHttpRequest()}catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")}}return xmlHttp}function validateCommentForm(thisform){document.getElementById("nameError").style.visibility="hidden";document.getElementById("emailError").style.visibility="hidden";document.getElementById("commentError").style.visibility="hidden";with(thisform){var valid=true;if(validateRequired(name)==false){document.getElementById("nameError").style.visibility="visible";valid=false}if(validateRequired(email)==false){document.getElementById("emailError").style.visibility="visible";valid=false}if(validateRequired(comment)==false){document.getElementById("commentError").style.visibility="visible";valid=false}return valid}}function validateRequired(field){with(field){if(value==null||value==""){return false}if(id=="email"){var regex=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;return regex.test(value)}else if(id=="name"){if(value=="Aaron Hewlett"){}else{}}return true}}String.prototype.startsWith=function(s){return this.indexOf(s)==0}
