//===========================================================
// kontrola na zdublowane adresy e-mail wyświetlane w katalogu firm
function AjaxMailKontakt(o, id)
{	var myAjax = new Ajax.Request(
		  'ajax/ajax_mail_kontakt.php', 
		  {	 method: 'get',
			 parameters: "id="+id+"&value=" + o.value,
			 onComplete: setMailKontakt,
			 onFailure: showAlert
		  });
}

function setMailKontakt(retVal) 
{	var a = retVal.responseText;
	var o = document.getElementById("katalog_mail");
	if(a.length > 1)
	{	o.value = "E-mail "+a+" jest zarejestrowany. Nie można go użyć ponownie.";
		o.parentNode.style.backgroundColor = "#ffc";
		o.style.backgroundColor = "#ffc";
		o.style.color = "#a00";
		o.style.fontWeight = "300";
		o.onfocus = function () {this.value='';}
		mail_exist = true;
	}
	else
	{	o.parentNode.style.backgroundColor = "#fff";
		o.style.backgroundColor = "#fff";
		o.style.color = "#000";
		o.style.fontWeight = "700";
		o.onfocus = function () {;}
		mail_exist = false;
	}
}

//===========================================================
// kontrola NIP-u
function AjaxNIP(o, id)
{	var myAjax = new Ajax.Request(
		  'ajax/ajax_nip.php', 
		  {	 method: 'get',
			 parameters: "id="+id+"&value=" + o.value,
			 onComplete: setNIP,
			 onFailure: showAlert
		  });
}

function setNIP(retVal) 
{	var a = retVal.responseText;
	var o = document.getElementById("faktura_nip");
	if(a.length > 1)
	{	o.value = "NIP "+a+" jest już zarejestrowany. Popraw.";
		o.parentNode.style.backgroundColor = "#ffc";
		o.style.backgroundColor = "#ffc";
		o.style.color = "#a00";
		o.style.fontWeight = "300";
		o.onfocus = function () {this.value='';}
		mail_exist = true;
	}
	else
	{	o.parentNode.style.backgroundColor = "#fff";
		o.style.backgroundColor = "#fff";
		o.style.color = "#000";
		o.style.fontWeight = "700";
		o.onfocus = function () {;}
		mail_exist = false;
	}
}

//===========================================================
// kontrola unikalności LOGINU
function AjaxLogin(o)
{	var myAjax = new Ajax.Request(
		  'ajax/ajax_login.php', 
		  {	 method: 'get',
			 parameters: "value=" + o.value,
			 onComplete: setLogin,
			 onFailure: showAlert
		  });
}

function setLogin(retVal) 
{	var a = retVal.responseText;
	var o = document.getElementById("katalog_login");
	if(a.length > 1)
	{	o.value = "Login "+a+" jest istnieje. Wybierz inny.";
		o.parentNode.style.backgroundColor = "#ffc";
		o.style.backgroundColor = "#ffc";
		o.style.color = "#a00";
		o.style.fontWeight = "300";
		o.onfocus = function () {this.value='';}
		mail_exist = true;
	}
	else
	{	o.parentNode.style.backgroundColor = "#fff";
		o.style.backgroundColor = "#fff";
		o.style.color = "#000";
		o.style.fontWeight = "700";
		o.onfocus = function () {;}
		mail_exist = false;
	}
}

//==========================================================================
// funkaja wspólna
function showAlert(retVal)
{	return true;
}
