// JavaScript Document
function js_Trim(str)
{
	var rstr = str.replace(/^\s+|\s+$/g, ""); 
	return rstr;
}
function check_unique(ctrl, type, divName, action, id) 
{
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) 
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) 
	{
		 self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	var strURL="checkUnique.php?type=" + type +"&action="+action+"&id="+ id +"&val="+ctrl.value;
	self.xmlHttpReq.open('GET', strURL, true);
	self.xmlHttpReq.onreadystatechange = function() { 
		if (self.xmlHttpReq.readyState == 4) 
		{
		   if (self.xmlHttpReq.status==200)
		   {
				var responseStr = js_Trim(self.xmlHttpReq.responseText); 
				var arr = Array();
				arr = responseStr.split('|');

				if(arr[0] == 0)
				{
				  ctrl.value = '';
				  ctrl.focus();
				  document.getElementById(divName).style.color = '#990000';
				}
				else
				  document.getElementById(divName).style.color = '#009900';
				document.getElementById(divName).innerHTML = arr[1];
		   }
		}
	  } 
	self.xmlHttpReq.send(null);		
}
