
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////    Create Multi-Message String     ///////////////////////////////
///////////////////////////////    Create Single-Message String    ///////////////////////////////
///////////////////////////////        Missing Data Errors         ///////////////////////////////
///////////////////////////////        Account Data Errors         ///////////////////////////////
///////////////////////////////      Duplicate Email Address       ///////////////////////////////
///////////////////////////////         Credit Card Errors         ///////////////////////////////
///////////////////////////////        Discount CodeErrors         ///////////////////////////////
///////////////////////////////            Login Errors            ///////////////////////////////
///////////////////////////////         Gedcom File Errors         ///////////////////////////////
///////////////////////////////      Multimedia Upload Errors      ///////////////////////////////
///////////////////////////////         Contact Us Errors          ///////////////////////////////
///////////////////////////////       E-mail Message Failure       ///////////////////////////////
///////////////////////////////     E-mail Message Successful      ///////////////////////////////
///////////////////////////////   FamilySearch Interface Errors    ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////    Create Multi-Message String     ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var createMultiMsgString = function(errStack)
{
	var jsMessage = "<div class=\"errMessage\">"; 
	jsMessage += errStack.join("</div><div class=\"listItem\">");
	jsMessage += "</div>";

	return jsMessage;
};




//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////    Create Single-Message String    ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var createSingleMsgString = function(errStack)
{
	var jsMessage = "<div class=\"errMessage\">";
	jsMessage	+=	errStack[0]; 
	jsMessage	+=	"</div>"; 

	return jsMessage;
};




//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////        Missing Data Errors         ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var errMissingData	= function(jsErrorCodeArray)
{
	errStack = new Array();
	var msgType			=	1;
	var msgTitle		=	'Missing Data!';
	var msgWidth		=	250;
	var msgHeight		=	'auto';

	for(nextError=0; nextError < jsErrorCodeArray.length; nextError++)
	{
		switch(jsErrorCodeArray[nextError])
		{
			case	19:
				errStack.push('&bull;  Account Nickname');
				break;
			
			case	1:
				errStack.push('&bull;  First Name');
				break;
			
			case	2:
				errStack.push('&bull;  Last Name');
				break;

			case	3:
				errStack.push('&bull;  Phone Number');
				break;

			case	4:
				errStack.push('&bull;  Billing Address');
				break;

			case	5:
				errStack.push('&bull;  Billing City');
				break;

			case	6:
				errStack.push('&bull;  Billing State');
				break;

			case	7:
				errStack.push('&bull;  Billing Postal Code');
				break;

			case	8:
				errStack.push('&bull;  Billing Country');
				break;

			case	9:
				errStack.push('&bull;  E-mail Address');
				break;

			case	10:
				errStack.push('&bull;  Re-Enter E-mail');
				break;

			case	11:
				errStack.push('&bull;  Password');
				break;

			case	12:
				errStack.push('&bull;  Confirm Password');
				break;

			case	13:
				errStack.push('&bull;  Password Hint');
				break;

			case	14:
				errStack.push('&bull;  Credit Card Type');
				break;

			case	15:
				errStack.push('&bull;  Name on credit card');
				break;

			case	16:
				errStack.push('&bull;  Valid Credit Card Number');
				break;

			case	17:
				errStack.push('&bull;  Credit card Expire Month');
				break;

			case	18:
				errStack.push('&bull;  Credit card Expire Year');
				break;

			default:
		}
	}

	errStack.unshift('Please enter the following: ')

	var msgString = createMultiMsgString(errStack);
	openMsgModal(msgType,msgTitle,msgString,msgWidth,msgHeight);
};


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////        Account Data Errors         ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var errAccountData	= function(jsErrorCode)
{
	errStack = new Array();
	var msgType			=	1;
	var msgTitle		=	'Error!';
	var msgWidth		=	300;
	var msgHeight		=	'auto';

	switch(jsErrorCode)
	{
		// E-mail addresses don't match
		case	101:
			errStack.push('The "Re-Enter E-mail" field does not match the "E-mail Address" field.');
			break;
		
		case	102:
			errStack.push('You have Entered an Invalid E-mail Address.');
			break;

		// Passwords don't match
		case	103:
			errStack.push('The "Confirm Password" field does not match the "Password" field.');
			break;
		
		// Password is less than 6 characters in length
		case	104:
			errStack.push('The password needs to be at least 6 characters in length.');
			break;

		case	105:
			errStack.push('You have Entered an Invalid E-mail Address.');
			break;

		default:
	}

	var msgString = createSingleMsgString(errStack);
	openMsgModal(msgType,msgTitle,msgString,msgWidth,msgHeight);

};


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////      Duplicate Email Address       ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var errDuplicateEmail	= function(jsErrorCode)
{
	errStack = [];
	var msgType			=	4;
	var msgTitle		=	'Existing Account?';
	var msgWidth		=	300;
	var msgHeight		=	'auto';
	var msgConfirm		=	'';

	if (jsErrorCode	==	102)
	{
		// Duplicate e-mail address
		errStack.push("Do you currently have an account established with AGES-online as an Owner or a username set up on someone else's account?");
		msgConfirm = "<div class=\"ok-modal bottom\"><a href=\"javascript:;\" title=\"Yes\" class=\"button\" onclick=\"document.subscribeForm.submit();modalWindow.close();\">Yes<\/a><a href=\"javascript:;\" title=\"No\" class=\"button\" onclick=\"javascript:modalWindow.close();errAccountData(" + jsErrorCode + ");\">No<\/a><\/div>";
	}
	var msgString = createSingleMsgString(errStack);
	openConfirmModal(msgType,msgTitle,msgString,msgWidth,msgHeight,msgConfirm);
};


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////         Credit Card Errors         ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var errCreditCard	= function(jsErrorCode)
{
	errStack = new Array();
	var msgType			=	1;
	var msgTitle		=	'Error!';
	var msgWidth		=	300;
	var msgHeight		=	'auto';

	switch(jsErrorCode)
	{
		// Invalid Credit Card Number
		case	106:
			errStack.push('Please enter a vaild Credit Card number');
			break;

		// Invalid Credit Card Type
		case	107:
			errStack.push('Please select a vaild Credit Card Type');
			break;
		
		// Expired Credit Card 
		case	108:
			errStack.push('You have entered an expired Credit Card date.');
			break;

		default:
	}
	var msgString = createSingleMsgString(errStack);
	openMsgModal(msgType,msgTitle,msgString,msgWidth,msgHeight);
};


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////        Discount CodeErrors         ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var errDiscountCode	= function(jsErrorCode)
{
	errStack = new Array();
	var msgType			=	1;
	var msgTitle		=	'Error!';
	var msgWidth		=	300;
	var msgHeight		=	'auto';

	switch(jsErrorCode)
	{
		// Invalid Credit Card Number
		case	109:
			errStack.push('Please enter a vaild Promotion Code.');
			break;

		default:
	}
	var msgString = createSingleMsgString(errStack);
	openMsgModal(msgType,msgTitle,msgString,msgWidth,msgHeight);
};


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////            Login Errors            ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var errLogin	= function(jsErrorCode)
{
	errStack = new Array();
	var msgType			=	1;
	var msgTitle		=	'Login Failed!';
	var msgWidth		=	300;
	var msgHeight		=	'auto';

	switch(jsErrorCode)
	{
		// Invalid Username 
		case	201:
			errStack.push('You have entered an invalid username or password, please try again.');
			break;

		// Invalid Password
		case	202:
			errStack.push('You have entered an invalid username or password, please try again.');
			break;

		// Inactive account
		case	203:
			errStack.push('The account which you are attempting to access is inactive.');
			break;
		
		case	204:
			errStack.push('Your access has been deactivated by the account owner.');
			break;
		
		case	205:
			errStack.push('The account which you are attempting to access is inactive.');
			break;
		
		case	206:
			errStack.push('You have entered an invalid username, please try again.');
			break;
		
		default:
	}
	var msgString = createSingleMsgString(errStack);
	openMsgModal(msgType,msgTitle,msgString,msgWidth,msgHeight);
};


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////         Gedcom File Errors         ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var gedcomFileError	= function(errMsg)
{
	var msgType			=	1;
	var msgTitle		=	'Gedcom Import Failed!';
	var msgWidth		=	300;
	var msgHeight		=	'auto';

	var msgString = "<div class=\"errMessage\">" + errMsg + "</div>";

	openMsgModal(msgType,msgTitle,msgString,msgWidth,msgHeight);
	
};


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////      Multimedia Upload Errors      ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var multimediaUploadError	= function(jsErrorCode,jsFileExtension,jsMessage1,jsMessage2,jsMessage3)
{
	var msgType				=	1;
	var msgTitle			=	'Multimedia Upload Failed!';
	var msgWidth			=	300;
	var msgHeight			=	'auto';

	var msgString			=	"<div class=\"errMessage\">";
	var eFileExtension		= (jsFileExtension);
	var eMessage1			= (jsMessage1);
	var eMessage2			= (jsMessage2);
	var eMessage3			= (jsMessage3);

	switch(jsErrorCode)
	{
		case "1":
			msgString	=	msgString + "You have attempted to upload an invalid file type, ." + eFileExtension + ".<br />";
			break;
			
		case "5":
			msgString	=	msgString + 'The file name has a "&" in the title.  Please rename the file and try again.<br />' + eMessage1 + '<br />' + eMessage2 + '<br />' + eMessage3;
			break;
			
		case "6":
			msgString	=	msgString + 'You do not have enough storage space available to upload this image.<br /><br />Image size: ' + eMessage1 + ' bytes<br />Available space: ' + eMessage2 + ' bytes';
			break;
			
		default:
			msgString	=	msgString + 'The application encountered an unknown error.  An email has been sent to AGES Support for resolution.<br />';
	}
	
	msgString	=	msgString + "</div>";
	openMsgModal(msgType,msgTitle,msgString,msgWidth,msgHeight);

};


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////         Contact Us Errors          ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var	contactUsErrors = function(jsErrorCode)
{
	var errorCode	=	(jsErrorCode);
	var msgType		=	1;
	var msgWidth	=	300;
	var msgHeight	=	'auto';
	var msgString	=	"";

	switch(errorCode)
	{
		case	1:
			msgString = 'Please enter your Name and click "Submit".';
			break;
	
		case	2:
			msgString = 'Please enter your E-mail address and click "Submit".';
			break;
		
		case	3:
			msgString = 'Please enter your Phone number and click "Submit".';
			break;
		
		case	4:
			msgString = 'Please enter message text and click "Submit".';
			break;
		
		case	5:
			msgString = 'Please enter a valid email address and click "Submit".';
			break;
		
		case	6:
			msgString = 'The Character Mix you entered is incorrect, please refresh your screen and try again.';
			break;

		default:
			msgString = 'Please verify all fields are populated correctly.';
	}
	msgString		=	"<div class=\"errMessage\">" + msgString + "</div>";
	openMsgModal(msgType,'Error Alert!',msgString,msgWidth,msgHeight);
}


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////       E-mail Message Failure       ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var	emailSentFail = function()
{
	var msgType		=	1;
	var msgWidth	=	300;
	var msgHeight	=	'auto';

	var msgString	= 'The email server has encountered a problem.<br /><br />  Sorry for the inconvenience, please try again later.';
	msgString		=	"<div class=\"errMessage\">" + msgString + "</div>";
	openMsgModal(msgType,'Error Alert!',msgString,msgWidth,msgHeight);
}


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////     E-mail Message Successful      ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var	emailSentSuccess = function()
{
	var msgType		=	2;
	var msgWidth	=	300;
	var msgHeight	=	'auto';

	var msgString	=	'Your message has been submitted successfully!';
	msgString		=	"<div class=\"errMessage\">" + msgString + "</div>";
	openMsgModal(msgType,'Success',msgString,msgWidth,msgHeight);
}


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////                                    ///////////////////////////////
///////////////////////////////   FamilySearch Interface Errors    ///////////////////////////////
///////////////////////////////                                    ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var interfaceError = function(errorCode,errorSubcode,errorMessage)
{
	// set local variables
	var msgType		=	1;
	var msgWidth	=	300;
	var msgHeight	=	'auto';
	var msgString	=	'';
	var msgButtons	=	null;
	var msgTitle	=	'Error Alert!';

	// initialize input variables
	if(!errorSubcode)
	{
		errorSubcode	=	'0';
	}
	if(!errorMessage)
	{
		errorMessage	=	'';
	}

	switch(errorCode)
	{
		case	'400':
			if (errorSubcode		==	'1' )		// insufficient query information
			{
				msgString	=	errorCode + ": Insufficient data was provided.  Please verify your entries and try again.";
				break;
			}

			else if(errorSubcode	==	'2' )		// invalid place
			{
				msgString	=	errorCode + ": Invalid data was provided.  Please verify your entries and try again.";
				break;
			}

			else								// Bad Request. Generic client error or multiple client errors.
			{
				msgString	=	errorCode + ": An Error has occurred between AGES-online and FamilySearch.  A message has been sent to the support team and they are looking in to the issue.  Please try again later.";
				break;
			}

		case	'401':							// Unauthorized. The user has invalid credentials or the session ID is missing, invalid, or has expired. This error also appears if the query string contains multiple question marks or the session parameter contains letters in an incorrect case.
			msgType		=	4;
			msgTitle	=	'Attention!';
			msgButtons	=	'<div class=\"ok-modal\"><a href=\"javascript:;\" title=\"OK\" class=\"button\" onclick=\"opener.location.href=\'\/application\/interfaces\/interfaces.cfm?idPage=118\';opener.focus();self.close();\">OK<\/a><a href=\"javascript:;\" title=\"Cancel\" class=\"button\" onclick=\"javascript:modalWindow.close();\">Cancel<\/a><\/div>';

			msgString	=	"Your FamilySearch session has timed out.  Click the OK button to login again." ;
			break;
	
		case	'403':							// Forbidden. The user does not have sufficient rights to perform the operation.
			msgString	=	errorCode + ": You do not have permission from FamilySearch to access the requested data.";
			break;
	
		case	'404':							// Not Found. This request contained an invalid ID or a bad URI.
			msgString	=	errorCode + ": An Error has occurred between AGES-online and FamilySearch.  A message has been sent to the support team and they are looking in to the issue.  Please try again later.";
			break;
	
		case	'415':							// Unsupported media type, invalid content-type in header, or invalid character encoding.
			msgString	=	errorCode + ": An Error has occurred between AGES-online and FamilySearch.  A message has been sent to the support team and they are looking in to the issue.  Please try again later.";
			break;
	
		case	'430':							// Bad version. Incorrect version of the object.
			msgString	=	errorCode + ": An Error has occurred between AGES-online and FamilySearch.  A message has been sent to the support team and they are looking in to the issue.  Please try again later.";
			break;
	
		case	'500':							// Server Error. A generic server error or multiple server errors occurred. If you get this error, please report it through devnet@familysearch.org. You can also post it to the FamilySearch Developer Network (FSDN).
			msgString	=	errorCode + ": An Error has occurred on the FamilySearch server.   A message has been sent to the AGES-online support team and they will notify FamilySearch of the issue.  Please try again later.";
			break;
	
		case	'503':							// Service Unavailable. FamilySearch or the service that you are using is not currently available. Or you are being throttled.
			msgString	=	errorCode + ": An Error has occurred on the FamilySearch server.   A message has been sent to the AGES-online support team and they will notify FamilySearch of the issue.  Please try again later.";
			break;
		default:
			msgString	=	errorCode + ": An Error has occurred on the FamilySearch server.   A message has been sent to the AGES-online support team and they will notify FamilySearch of the issue.  We're sorry for the inconvenience.  Please try again later.";
	}

	// call modal window
	msgString		=	"<div class=\"errMessage\">" + msgString + "</div>";
	openMsgModal(msgType,msgTitle,msgString,msgWidth,msgHeight,msgButtons);
};

