Zadig.Request = function(url, async, post, callback)
{
	this.callback = callback;
	this.xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	this.xmlhttp.onreadystatechange = Zadig.bind(this.stateChange, this);
  var method = 'GET' ;
 	if(post != null)
    	method = 'POST' ;
  
  
  this.xmlhttp.open(method, url, async);
  if(method == "POST")
  	 this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  this.xmlhttp.send(post);
  
}
Zadig.Request.prototype.stateChange = function()
{   
	if (this.xmlhttp.readyState == 4)
		if (this.xmlhttp.status == 200)
				this.callback(this.xmlhttp.responseText);
}
Zadig.toJson = function (obj)
{
	var json = '';
	var comma = '';
	if((typeof obj == 'array'))
	{
		json += '[';
		for(var i=0; obj.length; i++)
		{
			json += comma + this.toJson(obj[i]);
			comma = ', ';
		}
		json += ']';
		return json;
	}
	if(typeof obj == 'object')
	{
		json += '{';
		for(var i in obj)
		{
			json += comma + '"' + i + '" : ' + this.toJson(obj[i]);
			comma = ', ';
		}
		json += '}';
		return json;
	}
	if(typeof obj == 'string')
	{
    obj = obj.replace(/&/g, '%26').replace(/\r?\n/g,'\\'+'r'+'\\'+'n');
		return '"' + obj.replace(/"/g, '\\"')  +'"';
	}
	if(typeof obj == 'number')
	{
		return obj;
	}
}

Zadig.Cookies = {};
Zadig.Cookies.read = function()
{
	var s = document.cookie;
	s.replace(/(\w+?)=(.*?)(; |$)/g, function(a, b, c)
	{
		if(!c) return;
		Zadig.Cookies[b] = unescape(c); 
		
	});
}

Zadig.Cookies.write  = function(cookie, value)
{
	Zadig.Cookies[cookie] = value;
	document.cookie= cookie+"="+escape(value)+";";
}
Zadig.Cookies.remove  = function(cookie)
{
	var date = new Date();
	date.setTime(date.getTime()-1);
	document.cookie= cookie+"=; expires="+ date.toGMTString();
	Zadig.Cookies.read();
}
Zadig.Cookies.read();


Zadig.Watcher = 
{
'watch':function(prop)
{
	//prop.oldValue = null;
	if(Zadig.Watcher.list == undefined)
	{
		Zadig.Watcher.list = prop;
		Zadig.Watcher.last = prop; 
		//prop.oldValue = prop['obj']['prop'];
		Zadig.Watcher.checkRef = setInterval(Zadig.Watcher.check,33);
		return prop;
	}
	//prop.oldValue = prop['obj']['prop'];
	Zadig.Watcher.last.next=prop;
	Zadig.Watcher.last = prop;
	return prop; 
},
'check':function()
{
	var i = Zadig.Watcher.list;
	while(i != undefined)
	{
		if(i.obj[i.prop]!= i.oldValue)
		{ 
			i.fn(i);
			i.oldValue = i.obj[i.prop];
		}   
		i = i.next;
	}
}
,
'unwatch':function(e)
{
	var i = Zadig.Watcher.list;
	if(e == i) 
	{
		if(e.next!= undefined )
	 		Zadig.Watcher.list=e.next;
	 	else
	 	{	
	 		Zadig.Watcher.list=undefined;
	 		clearInterval(Zadig.Watcher.checkRef );
	 	}
	 	return;
	}
	while(i != undefined)
	{
		if(e == i.next)
		{ 
			i.next = i.next.next;
			return;
		}
		i = i.next;
	}
}
}