function submitLogin()
{
	var blnSubmit = "true"

	if (document.frmMOMCom.strEmailAddress.value.length)
 	{
 		document.frmMOMCom.strAction.value = 'emailLogin';
		document.frmMOMCom.submit();
 	} else {	
		if (!document.frmMOMCom.strUsername.value.length) 
		{
			blnSubmit = false;
			alert('Please provide your username.');
			document.frmMOMCom.strUsername.focus();
		} 
		else if (!document.frmMOMCom.strPassword.value.length ) 
		{
			blnSubmit = false;
			alert('Please provide your password.');
			document.frmMOMCom.strPassword.focus();
		}

		if (blnSubmit)
		{
			document.frmMOMCom.strAction.value = 'login';
			document.frmMOMCom.submit();
		}	
	}
}	

function validateMember()
{
	var blnValid = "true"
	 
	if (!document.frmMOMCom.strNameFirst.value.length)
	{
		blnValid = false;
		alert('Please provide your first name.');
		document.frmMOMCom.strNameFirst.focus();
	} 
	else if (!document.frmMOMCom.strNameLast.value.length)
	{
		blnValid = false;
		alert('Please provide your last name.');
		document.frmMOMCom.strNameLast.focus();
	}
	else if (!document.frmMOMCom.strEmailAddress.value.length)
	{
		blnValid = false;
		alert('Please provide your email address.');
		document.frmMOMCom.strEmailAddress.focus();
	}	
	else if (!document.frmMOMCom.strEmailAddress2.value.length)
	{
		blnValid = false;
		alert('Please provide a confirmation email address.');
		document.frmMOMCom.strEmailAddress2.focus();
	}
	/*
	else if (!document.frmMOMCom.strAreaCode.value.length)
	{
		blnValid = false;
		alert('Please provide your area code.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strAreaCode.focus();
	}
	else if (document.frmMOMCom.strAreaCode.value.length!=3)
	{
		blnValid = false;
		alert('Area code must be three numbers.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strAreaCode.focus();
	}
	else if (!isNumber(document.frmMOMCom.strAreaCode.value))
	{
		blnValid = false;
		alert('Area code must be three numbers.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strAreaCode.focus();
	}
	else if (!document.frmMOMCom.strPhonePrefix.value.length)
	{
		blnValid = false;
		alert('Please provide your phone prefix.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strPhonePrefix.focus();
	}
	else if (document.frmMOMCom.strPhonePrefix.value.length!=3)
	{
		blnValid = false;
		alert('Phone prefix must be three numbers.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strPhonePrefix.focus();
	}
	else if (!isNumber(document.frmMOMCom.strPhonePrefix.value))
	{
		blnValid = false;
		alert('Phone prefix three numbers.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strPhonePrefix.focus();
	}
	else if (!document.frmMOMCom.strPhoneLine.value.length)
	{
		blnValid = false;
		alert('Please provide your phone line.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strPhoneLine.focus();
	}
	else if (!isNumber(document.frmMOMCom.strPhoneLine.value))
	{
		blnValid = false;
		alert('Phone line must be four numbers.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strPhoneLine.focus();
	}
	else if (document.frmMOMCom.strPhoneLine.value.length!=4)
	{
		blnValid = false;
		alert('Phone line must be four numbers.  Telephone format should be "XXX-XXX-XXXX."');
		document.frmMOMCom.strPhoneLine.focus();
	}
	*/
	else if (!document.frmMOMCom.strAddress1.value.length)
	{
		blnValid = false;
		alert('Please provide your street address.');
		document.frmMOMCom.strAddress1.focus();
	}
	else if (!document.frmMOMCom.strCity.value.length)
	{
		blnValid = false;
		alert('Please provide your city.');
		document.frmMOMCom.strCity.focus();
	}
	else if (!getSelectObjValue(document.frmMOMCom.strStateCode).length)
	{
		blnValid = false;
		alert('Please provide your state.');
		document.frmMOMCom.strStateCode.focus();
	}
	else if (!document.frmMOMCom.strPostalCode.value.length)
	{
		blnValid = false;
		alert('Please provide your zip/postal code.');
		document.frmMOMCom.strPostalCode.focus();
	}
	else if (!document.frmMOMCom.strUsername.value.length)	
	{
		blnValid = false;
		alert('Please provide a username.');
		document.frmMOMCom.strUsername.focus();
	}
	else if (!document.frmMOMCom.strPassword.value.length)	
	{
		blnValid = false;
		alert('Please provide a password.');
		document.frmMOMCom.strPassword.focus();
	}
	else if (!document.frmMOMCom.strPassword2.value.length)
	{
		blnValid = false;
		alert('Please provide a confirmation password.');
		document.frmMOMCom.strPassword2.focus();
	} 
	else if (document.frmMOMCom.strEmailAddress.value != document.frmMOMCom.strEmailAddress2.value)
	{
		blnValid = false;
		alert('The email addresses entered do not match.');
		document.frmMOMCom.strEmailAddress.focus();
	}
	else if (document.frmMOMCom.strPassword.value != document.frmMOMCom.strPassword2.value)
	{
		blnValid = false;
		alert('The passwords entered do not match.');
		document.frmMOMCom.strEmailAddress.focus();
	}									
	
	return blnValid;
}

function dspAdminMembers()
{
	document.frmMOMCom.strAction.value = 'dspAdminMembers';		
	document.frmMOMCom.submit();
}

function dspAdminMbrInfo(intMemberID)
{
	var url = 'index.cfm?strAction=dspAdminMbrInfo&intMemberID=' + intMemberID;
	window.location = url; 
}

function saveMember()
{
	if(validateMember())
	{
		document.frmMOMCom.strAction.value = 'saveMember';		
		document.frmMOMCom.submit();
	}	
}
function delAdminMbrInfo()
{
	if(confirm('Are you sure you want to delete this member?'))
	{
		document.frmMOMCom.strAction.value = 'delAdminMbrInfo';		
		document.frmMOMCom.submit();
	}	
}

function dspAdminMbrProfile(intMemberID)
{
	var url = 'index.cfm?strAction=dspAdminMbrProfile&intMemberID=' + intMemberID;
	window.location = url; 
}

function dspAdminMbrRecipeBox(intMemberID)
{
	var url = 'index.cfm?strAction=dspAdminMbrRecipeBox&intMemberID=' + intMemberID;
	window.location = url; 
}

function dspAdminMbrComms(intMemberID)
{
	var url = 'index.cfm?strAction=dspAdminMbrComms&intMemberID=' + intMemberID;
	window.location = url; 
}

function delAdminMbrComms()
{
	if(confirm('Are you sure you want to delete this member communications?'))
	{
		document.frmMOMCom.strAction.value = 'delAdminMbrComms';		
		document.frmMOMCom.submit();
	}	
}
function validateRecipe()
{
	var blnValid = "true"

	if (!document.frmMOMCom.strRecipeName.value.length) 
	{
		blnValid = false;
		alert('Please provide a recipe name.');
		document.frmMOMCom.strRecipeName.focus();
	}
	else if (!parseInt(getSelectObjValue(document.frmMOMCom.intRecipeCatID)))
	{
		blnValid = false;
		alert('Please select a recipe category.');
		document.frmMOMCom.intRecipeCatID.focus();
	}		 
	else if (!document.frmMOMCom.strKeywords.value.length ) 
	{
		blnValid = false;
		alert('Please provide at least one keyword.');
		document.frmMOMCom.strKeyword.focus();
	}
	else if (!document.frmMOMCom.strPDFFile.value.length ) 
	{
		blnValid = false;
		alert('Please provide PDF recipe file.');
		document.frmMOMCom.strPDFFile.focus();
	}	

	return blnValid;
}	
function saveRecipe()
{
	if (validateRecipe()) 
	{
		document.frmMOMCom.strAction.value = 'saveRecipe';
		document.frmMOMCom.submit();
	}	
}

function validateRecipeBox()
{
	var blnValid = "true"
	// Place validation script here.
	return blnValid;
}	

function saveRecipeBox()
{
	if (validateRecipeBox()) 
	{
		document.frmMOMCom.strAction.value = 'saveRecipeBox';
		document.frmMOMCom.submit();
	}	
}	

function saveCommunication()
{
	document.frmMOMCom.strAction.value = 'saveCommunication';
	document.frmMOMCom.submit();
}

function getCommunication(intCommID)
{
	document.frmMOMCom.intCommID.value = intCommID;	
	document.frmMOMCom.strAction.value = 'dspCommunication';
	document.frmMOMCom.submit();
}	


function displayChildData()
{
	var strNameDiv = '';
	var strBDayDiv = '';

	for(var i=0; i<aryChildData.length; i++)
	{
		strNameDiv += '<input type="text" name="strChildName_' + parseInt(i+1) + '" value="' + aryChildData[i].strName + '" size="16">';
		strBDayDiv += '<input type="text" name="strChildBday_' + parseInt(i+1) + '" value="' + aryChildData[i].strBDay + '" size="16">';
	}
	$('divChildNames').innerHTML = strNameDiv;
	$('divChildBDays').innerHTML = strBDayDiv;	
}	

function addChild()
{
	var i = aryChildData.length;
	aryChildData[i] = new Array();
	aryChildData[i] = {'strName':'','strBDay':''}
	displayChildData();
}
				
function validateProfile()
{
	var so;
	var tmpValue
	var blnValid = "true";
	
	so = document.frmMOMCom.intFavMOMProd1;
	tmpValue = parseInt(getSelectObjValue(so));
	if(!tmpValue && blnValid)
	{
		blnValid = false;
		alert('Please select a favorite MaltOMeal product.');
		document.frmMOMCom.intFavMOMProd1.focus();
	} 
	/*
	so = document.frmMOMCom.intFavMOMProd2;
	tmpValue = parseInt(getSelectObjValue(so));
	if(!tmpValue && blnValid)
	{
		blnValid = false;
		alert('Please select another favorite MaltOMeal product.');
		document.frmMOMCom.intFavMOMProd2.focus();
	}
	
	so = document.frmMOMCom.intFavMOMProd3;
	tmpValue = parseInt(getSelectObjValue(so));
	if(!tmpValue && blnValid)
	{
		blnValid = false;
		alert('Please select another favorite MaltOMeal product.');
		document.frmMOMCom.intFavMOMProd3.focus();
	}

	so = document.frmMOMCom.intFavMOMProd4;
	tmpValue = parseInt(getSelectObjValue(so));
	if(!tmpValue && blnValid)
	{
		blnValid = false;
		alert('Please select another favorite MaltOMeal product.');
		document.frmMOMCom.intFavMOMProd4.focus();
	}	*/	
	
	so = document.frmMOMCom.intFavMOMRtlr;
	tmpValue = parseInt(getSelectObjValue(so));
	if(!tmpValue && !document.frmMOMCom.strOtherRtlr.value.length  && blnValid)
	{
		blnValid = false;
		alert('Please select a retailer or\nprovide another of your own choosing.');
		document.frmMOMCom.intFavMOMRtlr.focus();
	}
	if(blnValid)
	{
		blnValid = false;
		for (var i=0; i<document.frmMOMCom.strGroupIDs.length; i++)
		{
			if(document.frmMOMCom.strGroupIDs[i].checked)
			{
				blnValid = true;
				break;
			}	
		}
		if (!blnValid)	
		{
			alert('Please select at least one identity group.');
			document.document.frmMOMCom.strGroupIDs[0].focus();
		}
	}
	return blnValid
}

function saveProfile()
{
	if (validateProfile())
	{	
		document.frmMOMCom.intChildren.value = 0;//aryChildData.length; - 12\22\06 - maqureshi - not using childdata anymore
		document.frmMOMCom.strAction.value = 'saveProfile';
		document.frmMOMCom.submit();
	}	
}
function delAdminMbrProfile()
{
	if(confirm('Are you sure you want to delete this member\'s preference profile?'))
	{
		document.frmMOMCom.strAction.value = 'delAdminMbrProfile';		
		document.frmMOMCom.submit();
	}	
}

function searchRecipe()
{
	var blnSubmit = "true"
	 
	if (!document.frmMOMCom.strSrchText.value.length)
	{
		blnSubmit = false;
		alert('Please provide a keyword, product or recipe category.');
		document.frmMOMCom.strSrchText.focus();
	} else	{		
		document.frmMOMCom.submit();
	}	
}

function saveRecipeMbr()
{
	
	var blnSubmit = "true"
	if (blnSubmit)
	{
		document.frmMOMCom.strSrchText.value = '';
		document.frmMOMCom.submit();
	}	
}

function delAdminMbrRecipeBox()
{
	if(confirm('Are you sure you want to empty this member\'s recipe box?'))
	{
		document.frmMOMCom.strAction.value = 'delAdminMbrRecipeBox';		
		document.frmMOMCom.submit();
	}	
}

function calcSavings()
{
	var intUnits = parseInt(getSelectObjValue(document.frmMOMCom.intUnits));
	var intPrice = parseFloat(getSelectObjValue(document.frmMOMCom.intPrice));
	document.frmMOMCom.intSavings.value = formatCurrency(intUnits * intPrice);
}

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10) cents = "0" + cents;

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));

	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function getRadioValue(rb)
{
	for (var i=0; i<rb.length; i++)
   	{
   		if (rb[i].checked)
      	{
      		return rb[i].value;
      	}
   	}
}

function getSelectObjValue(so) 
{
	return so.options[so.selectedIndex].value;
}

function getSelectObjText(so) 
{
	return so.options[so.selectedIndex].text;
}

function setSelectObj(so,value) 
{
	for (i=0; i<so.options.length; i++) 
	{
		if (so.options[i].value == value)
		{
			so[i].selected = true;
			break;
		}	
	}
}

function getCheckBox(chkbx)
{
	if (chkbx.checked)
		return true;
	else 
		return false;
}

function popWin(url)
{
	var winFeatures = "toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1,status=0";
	var winSize = ""; //"width=800,height=600";
	var winLoc	= ""; //"left=50,top=50";
	var winDefs = winFeatures + winSize + winLoc;
	var popWin = window.open(url, 'popWin', winDefs);
}	

function popRecipe(intID)
{
	var url = 'index.cfm?strAction=dspPopRecipe&blnPopUp=1&intRecipeID=' + intID;
	popWin(url); 
}

var $;
if (!$ && document.getElementById) {
	$ = function()
	{
    	var elements = new Array();
   	 	for (var i = 0; i < arguments.length; i++)
		{
      		var element = arguments[i];
      		if (typeof element == 'string') element = document.getElementById(element);
      		if (arguments.length == 1) return element;
      		elements.push(element);
    	}
    	return elements;
	}
} else if (!$ && document.all) {
	$ = function() 
	{
    	var elements = new Array();
    	for (var i = 0; i < arguments.length; i++)
    	{
      		var element = arguments[i];
      		if (typeof element == 'string') element = document.all[element];
            if (arguments.length == 1) return element;
      	    elements.push(element);
    	}
    	return elements;
  	}
}

function isNumber(strInput) {
	var strTest = new Number(strInput).toString();
	if (strTest != "NaN") {
		//alert("Input is a number");
		return true;
	}
	else {
		//alert("Input is not a number");
		return false;
	}
}


//Global window handle and count
var win = null;
var count = 0;

function ManageWindow(href, hwnd, h, w, scroll, menu) {
	var specs = "";

	//Create a NEW window name (handle)
	hwnd += count++;

	//Format the string for the window specs
	specs = 'toolbar=0,location=0,left=150,right=150,directories=0,status=0,menubar='+ menu +',scrollbars='+ scroll +',resizable=1,copyhistory=0,width='+ w +',height='+ h;

	// Close the window if it is open
	if( win && !win.closed ) {
	win.close();
	}

	// Open a new window
	win=window.open(href, hwnd, specs)

	// Make sure the window is ON TOP
	win.focus();  //NOT in ie

	//Reset the 'count' variable if it gets too big
	count = count > 500 ? 0 : count;
}		
