﻿/*
 * Common.js
 * Copyright (c) 2005-2010 
 */

//--------------------------------------------------------------------------------------//
//	Verify popup
//
// Arguments(s):     val - (window) window to verify
// Remarks:  Check that the window we just tried to open was successfully opened.
//           If it was not, display a message telling the user that their popup blocker
//           has blocked the window.
//--------------------------------------------------------------------------------------//
function VerifyPopup(val) {
	if (val == null) 	{
		var popupBlockedNotification = "Your browser appears to be blocking popups.  " + 
			"This content appears in a separate window to allow you to view it at " +
			"the same time that you continue using LambdaforLess.  " +
			"To access this content, you will need to allow this popup.  For many popup blockers " +
			"this can be done by holding down the CTRL key while clicking the link or button."
		alert(popupBlockedNotification);
	} else {
		// If window exists, put the focus on it, in case it was already
		// open, but buried under other windows.
		val.focus();
	}	
}//end VerifyPopup

//--------------------------------------------------------------------------------------//
//	Generic AJAX failure handler.
//	
// Argument(s):           err - (str) 
//                userContext - (str) 
//                 methodName - (str)
//--------------------------------------------------------------------------------------//
function AJAX_Failure(err,userContext,methodName) {
   var msg = "An unexpected error has occurred.\n\n";
   
   msg += "Error:  " + err.get_message() + "\n\n";
   
   if (debugFlag) {
      msg += err.get_stackTrace() + "\n\n";
   }
   
   msg += "If you continue to experience difficulties, please contact us at 1-800-776-9583.";

   alert(msg);
}//end AJAX_Failure

//--------------------------------------------------------------------------------------//
//	Validates a field and displays a message.
//
// Argument(s): fieldName - (str) field to validate
// Returns:     true (was valid) / false (was not valid)
// Remarks:     Must have jQuery included
//--------------------------------------------------------------------------------------//
function ValidateField (fieldName) {
	if (jQuery.trim($(fieldName).val()) == "") {
		return (false);
	} else {
		return (true);
	}
}//end ValidateField

//--------------------------------------------------------------------------------------//
//	Open HTML OK modal popup
//	
// Argument(s):         msg - (str) message as a string
//                modalName - name of modal div
//                        w - (int) width of the modal popup, 500 by default
//                        h - (int) height of the modal popup, 350 by default
// Remarks:     Must have jQuery included
//--------------------------------------------------------------------------------------//
function OpenOKModal_html(msg,modalName,w,h) {
   if(!w) w=500;
   if(!h) h=350;
   
   $("#" + modalName).dialog("destroy");

	$("#" + modalName).html(msg).dialog(
	{
		width: 500,
		height: 350,
		modal: true,
		show: "fold",
		hide: "fold",
		buttons: { "Ok": function() { $(this).dialog("close"); }}
	});
}//end OpenOKModal_html

//--------------------------------------------------------------------------------------//
//	Open OK modal popup
//	
// Argument(s):   modalName - (str) message as a string
//                        w - (int) width of the modal popup, 500 by default
//                        h - (int) height of the modal popup, 250 by default
// Remarks:     Must have jQuery included
//--------------------------------------------------------------------------------------//
function OpenOKModal(modalName,w,h) {
   if(!w) w=500;   
   if(!h) h=250;
   
   $("#" + modalName).dialog("destroy");
   
   $("#" + modalName).dialog(
   {
	   width: w,
	   height: h,
	   modal: true,
	   show: "fold",
	   hide: "fold",
	   buttons: { "Ok": function() { $(this).dialog("close"); }}
   });
}//end OpenOKModal
