// JavaScript Document
var xmlHttp;
var newdiv;
var ni;
var numi;
var num;
var divIdName;
var numrow;

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;
}

function addEvent(lnk,j)
{

xmlHttp=GetXmlHttpObject();


ni = document.getElementById('myDiv');

 numi = document.getElementById('theValue');

 num = (document.getElementById("theValue").value -1)+ 2;
 
numi.value = num;

//
numrow = document.getElementById('totrow');
numrow.value = parseInt(numrow.value)+1;
//

divIdName = num;
newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
 var url='';
if(j=='') { 
url=lnk+'?id='+divIdName;
}
else if(j==1) {
	var gid=document.getElementById("gid").value;
	//var plotno=document.getElementById("plotno").value;
	var amgr=document.getElementById("amgr").value;
	var tldr=document.getElementById("tldr").value;
	
	url=lnk+'?id='+divIdName+'&gid='+gid+'&amgr='+amgr+'&tldr='+tldr;	
	
}
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
newdiv.innerHTML = xmlHttp.responseText;
ni.appendChild(newdiv);
}
}


function removeEvent(divNum)
{

var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);

numrow = document.getElementById('totrow');
numrow.value = parseInt(numrow.value)-1;
}
