/**
	do obslugi sprawdzania maili

	usage:
	var check = new checkMail(email@adress.pl,divAlertId,formId)
**/

var checkMail = function(email,divAlertId,formId){
	this.email = email;
	this.filePhp = '?page=checkmail';
	this.divAlertId = divAlertId;
	this.formId = formId;

	this.check = function(){
		var params = '&email=' + this.email;
		this.call.divAlertId = this.divAlertId;
		this.call.formId = this.formId;
		YAHOO.util.Connect.asyncRequest("GET", this.filePhp + params, this.call);
	}


	this.call={

		success:function(o){

			var xml=o.responseXML.documentElement;
			var result = xml.getElementsByTagName('result');
			//alert (result[0].textContent);
			if (result[0].textContent > 0 ){
				//Czyli poprawny
				document.getElementById(this.divAlertId).style.display='none';
				if(this.formId!=""){
					//alert(this.formId);
					document.getElementById(this.formId).submit();
				}
				else{
					var news = new newsLetter();
					news.alertDiv = document.getElementById(this.divAlertId);
					news.send(document.getElementById("email").value);
				}
				return true;
			}else{
				document.getElementById(this.divAlertId).style.display='block';
				return false;
			}

		},

		failure:function(){
			document.getElementById(this.divAlertId).style.display='block';
			return false;
		}

	}


	this.check();
}


if(typeof CHECKMAIL=="undefined")
{
	var CHECKMAIL  = {


	};
}

CHECKMAIL.checkOnlyEreg = function (email,alertText){
	if (!email.match(/^[a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/)){
		if (alertText.length){
			alert(alertText);
		}
		return false;
	}
	return true;
}