﻿var xmlHttp
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function getParams(){
     strComment=document.getElementById("TextBox1").value;
     strCommentstripped=strComment.replace(/ /gi, "");
     strName = document.getElementById("TextBox2").value;
     strNamestripped=strName.replace(/ /gi, "");
     if(strNamestripped.length<1){
        alert("Please enter a Name")
        return
     }
     if(strCommentstripped.length<5){
        alert("Please enter a Comment greater than 5 chars.")
        return
     }
     if(strComment.search(/</i)!=-1){
     alert("no html is allowed in comments");
     return
     }
     if(strName.search(/</i)!=-1){
     alert("no html is allowed in comments");
     return
     }
     showResult(strComment, strName);
 }
function clearAll(){
	
 document.getElementById("TextBox1").value="";
 document.getElementById("TextBox2").value="";
 return	
	
}

function showResult(str, user)
{
if (str.length<2)
 { 
clearAll();
 return
 }

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
//alert(str + user);
//setCookie('srch_term', str, 14);//set cookie
//var url="liveSearch.aspx"
var url = "doComment.aspx"
url=url+"?q="+str + "&u=" + user
url=url+"&sid="+Math.random()
document.getElementById('loading').style.display="";
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById('loading').style.display="none";
 document.getElementById('livecomment').style.display="";
 document.getElementById('livecomment').style.border="1px dotted red";
 document.getElementById('livecomment').innerHTML=xmlHttp.responseText;
 clearAll();

 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}