action = null;
var _sendMailType_ = null;
var _sendMailxid_ = null;

function NoLoginFunction() {
	
}
NoLoginFunction.prototype = new DXMLHttpRequestShell();
NoLoginFunction.constructor = NoLoginFunction;
NoLoginFunction.prototype.onLoad = function() {
    if (this.getResponseText() == "OK") {
		if(action == "mail") {
			window.location = BASE_URL + activeID + "/newmail.html"
		} else if (action == "favorite") {
			this.fastGetUrl(BASE_URL + activeID + "/addfavorites.html");
			window.location = BASE_URL + "favorites-vendors/" + currentCategory + ".html"
		} else if(action == "note") {
			window.location = BASE_URL + dataProvider.vendorId + "/addnote.html"
		} else if(action == "calendar") {
			window.location = BASE_URL + "calendar.html";
		} else if(action == "budget") {
			window.location = BASE_URL + "budget.html";
		} else if(action == "guest") {
			window.location = BASE_URL + "guests.html"
		} else if(action == "mailbox") {
			window.location = BASE_URL + "mail.html"			
		} else if(action == "notes") {
			window.location = BASE_URL + "notes.html"			
		} else if(action == "cmail") {
			window.location = BASE_URL + activeID + "/newcouplesmail.html";
		} else if(action == "cfavorite") {
			this.fastGetUrl(BASE_URL + activeID + "/addcustomerfavorites.html");
			window.location = BASE_URL + "favorites-couples.html";
		} else if(action == "gift") {
			window.location = BASE_URL + "gift.html";
		} else {
			window.location = BASE_URL;
		} 
    } else {
    	this.ErrorMessage('Грешно име или парола!');
    }
}
NoLoginFunction.prototype.send = function() {
    this.init();

    uname = document.getElementById("idname").value;
    passwd =  document.getElementById("idpass").value;

    if( uname == "" || passwd == "") {
    	this.clear();
		document.getElementById("trname").style.color="#DA1347";
		document.getElementById("trpasswd").style.color="#DA1347";
		document.getElementById("aMsg").innerHTML = 'Всички полета са задължителни!';
    	return;
    } else {
    	document.getElementById("trname").style.color="";
    	document.getElementById("trpasswd").style.color="";
   		this.fastPostUrl("nologin.html", "username=" + uname + "&pass=" + passwd);
   	}
}
NoLoginFunction.prototype.clear = function() {
    	document.getElementById("idname").value = "";
    	document.getElementById("idpass").value = "";
}
NoLoginFunction.prototype.clearClose = function(msg) {
		document.getElementById("flashPlayer").style.visibility = "visible";
		if (document.getElementById("vendorsGalleryPane").style.height != "460px") {
			document.getElementById("Zoom").style.visibility = "visible";
		}
		document.getElementById("loginRequired").style.display = "none";
		document.getElementById("trname").style.color="";
		document.getElementById("trpasswd").style.color="";
		document.getElementById("upload").style.display = "none";
		document.getElementById("aMsg").innerHTML = "";
		document.getElementById("message").value = "I found this while doing some wedding research.  Check it out:";
		resizeHandler.openWindow = false;
		this.clear();
}
NoLoginFunction.prototype.ErrorMessage = function(msg) {
	document.getElementById("aMsg").innerHTML = msg;
	this.clear();
}

function GetNewPassword() {}
GetNewPassword.prototype = new DXMLHttpRequestShell();
GetNewPassword.constructor = GetNewPassword;
GetNewPassword.prototype.onLoad = function() {
	document.getElementById("errorMailMessage").innerHTML = "";
	if (this.getResponseText() == 1) {
		document.getElementById("errorMailMessage").innerHTML = "Полето е задължително";	
	} else if (this.getResponseText() == 2) {
		document.getElementById("errorMailMessage").innerHTML = "Електронната поща е грешна";
	} else if(this.getResponseText() == 3) {
		document.getElementById("errorMailMessage").innerHTML = "Не съществува такава електронна поща";
	} else {
		closeTransparentWindow();
	}
}
GetNewPassword.prototype.send = function(mail) {
	this.init();
	this.fastPostUrl("forgot-password.html", "mail=" + mail);
}

function alertMessage(whoMessage, newAction) {
	if(whoMessage == 2) {
		action = newAction;
		document.getElementById("popupWindowTitle").innerHTML = "Вход в системата";
		document.getElementById("blanket").style.display = "block";
		document.getElementById("popupBoxContainer").style.display = "block";
		document.getElementById("centerPopUpContainer").style.display = "block";
		setTransparentPosition("popupBoxContainer");
	}
}

function forgotPassword() {
	document.getElementById("popupWindowTitle").innerHTML = "Забрвена парола";
	document.getElementById("blanket").style.display = "block";
	document.getElementById("popupBoxContainer").style.display = "block";
	document.getElementById("lostPassword").style.display = "block";
	setTransparentPosition("popupBoxContainer");
}

function sendPassword() {
	mail = document.getElementById("lostmail").value;
	
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(mail)) {
		document.getElementById("lostmail").style.border = "red 1px solid";
		return;
	}	
	var getPassword = new GetNewPassword();
	getPassword.send(mail);
}

function sendLetter(type, xid) {
	document.getElementById("blanket").style.display = "block";
	document.getElementById("sendLink").style.display = "block";
	setTransparentPosition("sendLink");
	_sendMailType_ = type;
	_sendMailxid_ = xid;
}
