function resendPassAPI(email) {
	this.messagingServer = false;
	this.version = undefined;
	this.email = email;
	
	if (baseURL != "undefined" && (typeof baseURL) != "undefined") {
		this.baseURL = baseURL;
	}
	
	this.getMessagingServer();
}

resendPassAPI.prototype.resendPassword = function () {
	if (this.messagingServer == undefined || this.version == undefined) { return false; }//if missing any one of these
	var requestFile = this.baseURL + "proxy/" +this.messagingServer+'/messages_'+this.version+'/process/resendPassword.php';
	var obj = this; //scope
	$.ajax({
		url: requestFile,
		type: "GET",
		async: false,
		data: { email: this.email },
		error: function (xhr, textStatus, errorThrown) {
			if (xhr.responseText.indexOf("</WResult>") > 0) { //catch xml errors again - stupid IE.
					xmlDoc = obj.loadXML(xhr.responseText); 
					x = xmlDoc.childNodes[0].childNodes;
					errorCode = x[1].childNodes[0].firstChild.nodeValue; //code
					errorDescription = x[1].childNodes[1].firstChild.nodeValue; //description
					//obj.onRegisterError(errorCode, errorDescription, this.Params );
					obj.onError(errorDescription);
			} else {
				//obj.onError(xhr, textStatus);
				obj.onError(textStatus);
			}
			
		},		
		success: function(responseText) {
		
			if (((typeof responseText) == 'xml') || (((typeof responseText) == 'string') && (responseText.indexOf("</WResult>") > 0))) {
				xmlDoc = obj.loadXML(responseText);
				x = xmlDoc.childNodes[0].childNodes;
				//type node x[1].nodeName;
				responseType = x[0].firstChild.nodeValue //should be error
				if (responseType == 'Error') {
					errorCode = x[1].childNodes[0].firstChild.nodeValue;
					errorDescription = x[1].childNodes[1].firstChild.nodeValue;
					//obj.onRegisterError(errorCode, errorDescription, this.Params );
					obj.onError(errorDescription);
				} else {
					alert("Unexpected Response Type: "+responseType);
				}
			} else if (responseText == "0") {
				
				alert('Your password has been sent to your e-mail address');
				obj.onSuccess();
			} else {
				alert("Unexpected Return Value: "+responseText);
				return false;
			}
		}
	});
}

resendPassAPI.prototype.getMessagingServer = function() {
	var obj = this; //scope
	$.ajax({
		async: false,
		cache: false,
		dataType: "json",
		type: "POST",
		data: { user: this.email },
		//data: { user: 'none' },
		success: function(data, textStatus) {

			if (data['error'] == undefined) {
				obj.messagingServer = data['server'];
				obj.version = data['version'];
			} else {
				alert('Couldn\'t find user')
			}
		},
		error: function(XHR, textStatus, errorThrown) {
			obj.onError(XHR, textStatus);
		},
		url: this.baseURL + "ajax/getUserLoginServer.php"
	});
}

resendPassAPI.prototype.loadXML = function(text) {
	try { //Internet Explorer  
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(text);
	} catch(e) {
		try { //Firefox, Mozilla, Opera, etc.
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(text,"text/xml");
		} catch(e) {alert(e.message)}
	}
	return xmlDoc;
}
resendPassAPI.prototype.onError = function(msg) {
	alert(msg);
}
resendPassAPI.prototype.onSuccess = function() {
	var email =  $('#resendPassEmail').val();
	$('#username').val(email);
	
	$('#loginForm').css( { 'display':''});
	$('#resendFrom').css( { 'display':'none'});
}