var globalVar;
var globalObj;
var selectedNode;
var isRegistredUser;
var isEditingOffer;
var NodeEdit;
var isUser;
var unapproved;
function NodeChange(arrayNode_id, url) 
{
	this.node_id = arrayNode_id;
	this.url = url;
	
			///// method /////
	this.SendData = function(id)
	{
		this.node = document.getElementById(id);
		selectedNode = this.node;
		var urlSend = this.url + "?node=" + this.node.value;
		this.xmlObj = new xmlHttp(this);
		this.RemoveObj();		
		this.xmlObj.SendRequest(urlSend, "post")
		this.Loading(true);
	}
	
	this.GetData = function()
	{
		this.Loading(false);
		this.GetDataDrawObj(this.xmlObj.GetResponseText())
	}
	
	this.GetDataDrawObj = function(strResponse)
	{
		if (strResponse.search('<!--yes-->') == -1)
		{
			var Div = document.getElementById(this.node_id["parentNodesDiv"]);
			var lastObj = document.getElementById(this.node_id["nodeDiv"] + this.getNodeLevel(this.node.id));
			var newNodeDiv = document.createElement('div');
			newNodeDiv.id = this.node_id["nodeDiv"] + (this.getNodeLevel(this.node.id) + 1);
			newNodeDiv.innerHTML = this.xmlObj.GetResponseText()
			newNodeDiv.style.cssText = "float:none;"
			newNodeDiv.style.paddingRight = "10px"
			lastObj.style.cssText = "float:left;";
			lastObj.style.paddingRight = "10px"
			Div.appendChild(newNodeDiv);
		}
		else
		{
			var Div = document.getElementById(this.node_id["OfferPropertyDiv"]);
			var lastObj = document.getElementById(this.node_id["nodeDiv"] + this.getNodeLevel(this.node.id));
			var newNodeDiv = document.createElement('div');
							
			newNodeDiv.id = this.node_id["nodeDiv"] + (this.getNodeLevel(this.node.id) + 1);
			newNodeDiv.innerHTML = this.xmlObj.GetResponseText()
			newNodeDiv.style.paddingRight = "10px"
			lastObj.style.cssText = "float:none;";
		
			Div.appendChild(newNodeDiv);
		}
	}
	
	this.RemoveObj = function()
	{
		var RemoveObj = document.getElementById(this.node_id["nodeDiv"] + (this.getNodeLevel(this.node.id) + 1));
		var index = 1;
		while(RemoveObj != null)
		{
			RemoveObj.parentNode.removeChild(RemoveObj);index++;
			RemoveObj = document.getElementById(this.node_id["nodeDiv"] + (this.getNodeLevel(this.node.id) + index));
		}
		this.node.style.cssText = "float:none;"
	}
	
	this.loadImages = function()
	{
		this.LoadingImage = new Image();
		this.LoadingImage.src = "/images/loading.gif";
	}
	
	this.Loading = function(active)
	{
		if (active == true) {
			var juryFocus = document.getElementById(this.node_id["focus"]);
			var Div = document.getElementById(this.node_id["parentNodesDiv"]);
			var lastObj = document.getElementById(this.node_id["nodeDiv"] + this.getNodeLevel(this.node.id));
			
			this.loadingDiv = document.createElement('div');
			this.loadingDiv.id = this.node_id["nodeDiv"] + (this.getNodeLevel(this.node.id) + 1);
			this.loadingDiv.appendChild(this.LoadingImage);
			this.loadingDiv.style.cssText = "float:none;"
			this.loadingDiv.style.paddingRight = "10px"
			
			lastObj.style.cssText = "float:left;";
			lastObj.style.paddingRight = "10px"
			
			Div.appendChild(this.loadingDiv);
			juryFocus.focus();
		}
		else {
			this.loadingDiv.parentNode.removeChild(this.loadingDiv);
			var lastObj = document.getElementById(this.node_id["nodeDiv"] + this.getNodeLevel(this.node.id));
			lastObj.style.cssText = "float:none;";
		}
	}
	
	this.getNodeLevel = function(id)
	{
		for(var i = 1; i < 10; i++)
		{
			if ((id == (this.node_id['node'] + i))||(id == (this.node_id['nodeDiv'] + i)))
			{return i;}
		}
		return 0;
	}
}

function xmlHttp(SendingObj)
{

	///// construct Request object /////
	if (window.XMLHttpRequest) {
	 	try {
	  		this.obj = new XMLHttpRequest();
	  	} 
	  	catch (e) {
	  	}
	  }
	else {
  	if (window.ActiveXObject) {
  		try {
  			this.obj = new ActiveXObject('Msxml2.XMLHTTP');
  		} 
  		catch (e) {
  			try {
  				this.obj = new ActiveXObject('Microsoft.XMLHTTP');
  			} 
  			catch (e) {
  			}
  		}
  	}
	}
	
	globalObj = this.obj;
	globalVar = SendingObj;
				///// method /////
	this.SendRequest = function(url, method)
	{
		if (this.obj==null)
	 	{
	 		alert ("Browser does not support HTTP Request")
	 		return
		}
		this.obj.onreadystatechange = this.Complete; 
		this.obj.open(method,url,true);
		this.obj.send(null);
	}
	
	this.Complete = function()
	{
		this.obj = globalObj;
		if (this.obj.readyState == 4 || this.obj.readyState == "complete")
		{
			globalVar.GetData();
		}
	}
	
	this.GetResponseText = function()
	{
		return this.obj.responseText;
	}
}
	

