working = false;
objId = "";

function change(id, newClass)
{
	identity=document.getElementById(id);
	identity.className=newClass;
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();

function ajax(url,id,options) 
{
	
	if (!working && http)
	{
		working = true;
		var data = options;
		objId = id;	
		http.open("POST", url, true);
 		http.onreadystatechange = handleHttpResponse;
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		http.send(data);
	}
	else
	{
		alert("The connection is busy.");
	}
}


function handleHttpResponse() 
{
  if (http.readyState == 4)
	{
		if (http.status==200)
    	{
			working = false;
			document.getElementById(objId).innerHTML = http.responseText;
		}
		else
		{
			alert("Error!");
			working = false;
		}
	}
}

function createCookie(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 readCookie(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 eraseCookie(name)
{
	createCookie(name,"",-1);
}
