
var xmlhttp;
var insertHTML;

function loadXMLDoc(url,insertDiv)
{
xmlhttp=null;
insertHTML=insertDiv
if (window.XMLHttpRequest)
  {// code for all new browsers
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5 and IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change()
{ 
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
//  alert(xmlhttp.status)
  if (xmlhttp.status==200)
    {// 200 = OK
  //  alert('ok1')
    //alert(xmlhttp.responseText)
    document.getElementById(insertHTML).innerHTML=""
   	var newdiv = document.createElement("div");
	newdiv.innerHTML = xmlhttp.responseText
	var container = document.getElementById(insertHTML);
	container.appendChild(newdiv);
   
    //document.getElementById(insertHTML).innerHTML=
 //    alert(document.getElementById(insertHTML).firstChild.nodeValue);
    }
  else
    {
    //alert("Problem retrieving server data");
    }
  }
}

function insertView1(){
id=document.getElementById("blogentryid").innerHTML
//insertWaitIcon("blogentryid")
//alert(webDbPath()+'/Comments?OpenPage&RestrictToCategory='+id)
insertFragment(webDbPath()+'/Comments?OpenPage&RestrictToCategory='+id+"&RandomKey=" + Math.random() * Date.parse(new Date()),'comments')
}

function insertCommentForm(){
id=document.getElementById("blogentryid").innerHTML
//alert(webDbPathFromField()+'/Comment?OpenPage&blogentryid='+id)
insertFragment(webDbPathFromField()+'/Comment?OpenPage&blogentryid='+id,'commentform')
}

function insertFragment(url,insertDiv){
loadXMLDoc(url,insertDiv)
}

function webDbPath(){
a=location.pathname.toLowerCase()
b=a.substring(0,a.lastIndexOf(".nsf"))+".nsf"
return b
}

function webDbPathFromField(){
return document.getElementById("webdbpath").innerHTML
}

function saveComment() {

xmlhttp=null;
//insertHTML=insertDiv
if (window.XMLHttpRequest)
  {// code for all new browsers
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5 and IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  url=webDbPathFromField()+"/Comment?createdocument"
  //alert(url)
  a=document.getElementById("commentname").value
  //a=document.getElementById("commentname").firstChild.nodeValue
  b=document.getElementById("commentemail").value
  c=document.getElementById("commentwebsite").value
  d=document.getElementById("commentbody").value
  e=document.getElementById("blogentryid").innerHTML
 
  xmlhttp.onreadystatechange=state_Change1;
  xmlhttp.open("POST",url,true);
  xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded" )
//alert("&commentName=" + escape(a)+"&commentmail="+escape(b)+"&commentwebsite="+escape(c)+"&commentbody="+escape(d)+"&blogentryid="+escape(e));
xmlhttp.send("commentName=" + escape(a)+"&commentEmail="+escape(b)+"&commentWebsite="+escape(c)+"&commentBody="+escape(d)+"&blogEntryID="+escape(e));
	
  } 
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change1()
{ 
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  //alert(xmlhttp.status)
  if (xmlhttp.status==200)
    {// 200 = OK
  //  alert('ok1')
    //alert(xmlhttp.responseText);
    alert("Your comment has been saved")
   	document.getElementById("commentform").innerHTML=""
   	insertView1()
    //document.getElementById(insertHTML).innerHTML=
 //    alert(document.getElementById(insertHTML).firstChild.nodeValue);
    }
  else
    {
    //alert(xmlhttp.status)
    alert("There was a problem saving your comment");
    }
  }
  }

function showBelowBody(){
a=document.getElementById("afterbody");
a.style.visibility="visible"
}

function insertWaitIcon(id){
a=document.getElementById(id)
a.innerHTML='<img src="'+webDbPathFromField()+ '/wait.gif!OpenImageResource" width="20" height="20">'
}





