
//////////////////////all////////////////////////////////////////////
// FILE: web4cards.js
// AUTHORS: Victor Leong (20000605)
// Bob start add
//  			Bob Klein (BK)
// revision   comments
// ---------- ---------------------------------------------------
// 2000091501 modified function: validateOption, added code to detect existance of a File. (BK)
// Bob end add
// DESCRIPTION: holds all the javascript for w4c site 
///////////////////////////////////////////////////////////////////
var nav4 = ((navigator.appName == "Netscape") &&
                     (parseInt(navigator.appVersion) >= 4));
var modalWin = new Object();
var dialogTop = "300"; //moves the opened window across screen
var dialogLeft = "200";//moves the opened window up and down screen
var dialogSettings;
var emailRe = /^(\w+)([-\.]{1}\w+)*([@])(\w+)([-\.]{1}\w+)+$/;
var phoneRe = /^\(?\d{3}\)?([-\.\s])?\d{3}([-\.\s])?\d{4}$/;
var postalRe = /^([A-CEGHJ-NPR-TVXY]\d[A-CEGHJ-NPR-TV-Z])([-\s])?(\d[A-CEGHJ-NPR-TV-Z]\d)$|^(\d{5})([-\s])?(\d{4})$|^(\d{5})$|^[A-Z]{1,2}[0-9R][0-9A-Z](\s)?\d[A-Z]{2}$/;
var prodlistRe = /^(\d*)\#(\d*)\#([YN])/;
var MAX_NUM_OF_CARDS = 5;

String.prototype.trim = function() {

 // skip leading and trailing whitespace
 // and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

      
//------------------------------------------------------------------------------
//  Function:  setFinalValue (javascript)
//   Remarks:  called from the numeric keypad window, and is passed the final 
//             value from that window
//------------------------------------------------------------------------------
	function setFinalValue(returnedValue)
	{
		var selText;
		var selValue;
		var listLen;
		var prodCode;
		var unitLoadnum;
		var barcodeLength;
		var userInputLength;
		var isBarcode;

		selValue = returnedValue;
		userInputLength = parseInt(selValue.length);
//alert(selValue);
//alert(userInputLength);
//alert(eval(userInputLength == 0));
		if (!selValue)
		{                                                     // If null, reset and exit
  			alert("Please enter a number for the card.");
  			document.mainform.prodlist.selectedIndex = -1;
  			return false;
		}

//		if (userInputLength == 0)
//		{                                                      // Must enter something....
//  			return;
//		}

//		if(document.mainform.shipment.options.length == MAX_NUM_OF_CARDS)
//		{
//			alert("You can only select " + MAX_NUM_OF_CARDS + " cards.");
//			return false;
//		}
	               	                                       // No, add to shipment list
		selText = document.mainform.prodlist[document.mainform.prodlist.selectedIndex].text;

		selText = selText + ": " + selValue;

		prodCode = document.mainform.prodlist[document.mainform.prodlist.selectedIndex].value;
//alert(prodCode);

		//regular expression to grab as many digits from beginning of string as possible
		if (!nav4) 	//IE only
		{
			prodCode = /^(\d*)\#(\d*)\#([YN])/g.exec(prodCode);
		}
		else			//netscape
		{
			prodCode = prodlistRe.exec(prodCode)
		}
		
		prodCode = RegExp.$1;
		barcodeLength = RegExp.$2;
		isBarcode = RegExp.$3;
//alert(prodCode);
//alert(barcodeLength);
//alert(isBarcode);

//verify that userinput is equal to max allowed
		if ((parseInt(userInputLength) == parseInt(barcodeLength)) || (isBarcode == "N"))
		{
			listLen = document.mainform.shipment.options.length++;
			document.mainform.shipment.options[listLen].text  = selText;

			//make the value format = (barcode_type # barcode length : user barcode value)
			document.mainform.shipment.options[listLen].value  = prodCode + "#" + barcodeLength + ":" + selValue ;

			//lockEnterBox();

		}
		else
		{
			alert("The value entered does not match the expected " + barcodeLength + " characters for this card type. Try again.");
			return false;
			//document.mainform.prodlist.options.selectedIndex = -1;
		}		

		return true;
	}//end function setFinalValue

//============ END of Functions for Numeric Keypad ====================================

//============ Code pertaining to selection screen ====================================
//------------------------------------------------------------------------------
//  Function:  delFromList (javascript)
//   Remarks:  triggered by 'onChange' event to the Shipment List, removes line
//             item from the list
//------------------------------------------------------------------------------
	function delFromList(element)                         // Start delFromList function
	{
		var delFlag;
		var listLen;
		var ctr;
		var barcodeLength;

		delFlag = window.confirm("Remove this item \"" + element.options[element.selectedIndex].text.substring(0, 40) +"\" from the \"Card Numbers Entered\" list?");
		if (!delFlag)
		{
			element.options.selectedIndex = -1;
			return;
		}

		//code to insert selected code back to prodlist select box
		selText = element.options[element.selectedIndex].text.substring(0, 40);
		prodCode = element[element.selectedIndex].value;

		//regular expression to grab as many digits from beginning of string as possible
		if (!nav4) //IE only
		{
			prodCode = /^(\d*)\#(\d*)/g.exec(prodCode);
		}
		else       //Netscape
		{
			prodCode = prodlistRe.exec(prodCode)
		}

		prodCode = RegExp.$1;
		barcodeLength = RegExp.$2;

		// remove barcode number

		selText = (selText.trim()).substring(0, (selText.trim()).length - barcodeLength -2);

		//code to remove from shipment select box
		listLen = document.mainform.shipment.options.length;
		ctr = element.selectedIndex;

		// Move list items up one row
		for (ctr; (ctr < listLen-1); ctr++)
		{
			element.options[ctr].text = element.options[ctr + 1].text;
			element.options[ctr].value = element.options[ctr + 1].value;
		}                            

		document.mainform.shipment.options.length = listLen - 1; // Shorten list length by one
		element.options.selectedIndex = -1;								//deselect element in select box

		return;
	} // End delFromList function


//------------------------------------------------------------------------------
//  Function:  selectWholeShipment (javascript)
//   Remarks:  before form is submitted using the "continue to pick image" button, select all
//             items from shipment list. if none warn user. if exceeds the maximum
//					allowed passed to sub then warn user.
//------------------------------------------------------------------------------
	function selectWholeShipment()
	{
		var listLen;
		var ctr;

		listLen = document.mainform.shipment.options.length;

		// If shipment is empty, add an empty list item
		// to replace any data that may already be in the session
//		alert("listLen == " + listLen);
		if (listLen == 0)  {
			document.mainform.shipment.options.length++;
			listLen++;
			document.mainform.shipment.options[0].text = '';
			document.mainform.shipment.options[0].value = '';
		}

		for (ctr=0; (ctr < listLen); ctr++)
			document.mainform.shipment.options[ctr].selected = 1;

//		if (document.mainform.unlistedshipment.options.length)
//		{
		listLen = document.mainform.unlistedshipment.options.length;
			
		// If unlistedshipment is empty, add an empty list item
		// to replace any data that may already be in the session
//		alert("listLen == " + listLen);
		if (listLen == 0)  {
			document.mainform.unlistedshipment.options.length++;
			listLen++;
			document.mainform.unlistedshipment.options[0].text = '';
			document.mainform.unlistedshipment.options[0].value = '';
		}

		for (ctr=0; (ctr < listLen); ctr++) 
			document.mainform.unlistedshipment.options[ctr].selected = 1;
	
	return true;
	} // End selectWholeShipment function


// functions for the MyBarCodeCard rework 11/2003
function removeNumber(objElement)
{
	if(objElement.options.selectedIndex == -1)
	{
		if (objElement.options.length == 0)
		{
			alert("There is nothing to remove!");
		}
		else
		{
			alert("Select a Card to remove!");
		}
	}
	else
	{
		delFromList(objElement);
	}
}

function validateNumber(number)
{
	var selectedindex = document.mainform.prodlist.selectedIndex;
    var finalValue = number.toUpperCase();

    setFinalValue(finalValue);
	//selected last selection
	document.mainform.prodlist[selectedindex].selected ="selected";

    return;
}

function findBarcodeLength()
{
	if(!(validateTotalNumberOfCards()))
		return;

	barcodeLength = 0;

	if(document.mainform.prodlist.selectedIndex != -1)
	{
		prodCode = document.mainform.prodlist[document.mainform.prodlist.selectedIndex].value;

		//regular expression to grab as many digits from beginning of string as possible
		if (!nav4) 	//IE only
		{
			prodCode = /^(\d*)\#(\d*)\#([YN])/g.exec(prodCode);
		}
		else			//netscape
		{
			prodCode = prodlistRe.exec(prodCode)
		}

		prodCode = RegExp.$1;
		barcodeLength = RegExp.$2;
	}
	return barcodeLength;

}

function findBarcodeLengthForPopup()
{
	if(!(validateTotalNumberOfCards()))
		return;

	barcodeLengthStr = "";

	if(document.mainform.prodlist.selectedIndex != -1)
	{
		prodCode = document.mainform.prodlist[document.mainform.prodlist.selectedIndex].value;

		//regular expression to grab as many digits from beginning of string as possible
		if (!nav4) 	//IE only
		{
			prodCode = /^(\d*)\#(\d*)\#([YN])/g.exec(prodCode);
		}
		else			//netscape
		{
			prodCode = prodlistRe.exec(prodCode)
		}

		prodCode = RegExp.$1;
		barcodeLength = RegExp.$2;
		isBarcode = RegExp.$3;
		if (isBarcode == 'Y')
			barcodeLengthStr = barcodeLength + ' digit ';
	}
	return barcodeLengthStr;

}

function addListedCard()
{
	var theLength = findBarcodeLengthForPopup();
	if (theLength === undefined)
		return;
	var theNumber = window.prompt('Enter your ' + theLength + 'number here:', '');
	if (theNumber == null)
		return;
	validateNumber(theNumber);

}
//***********************************************
//    Functions for unlisted cards page
//***********************************************

function addToUnlistedShipment()
{
    var theItems = document.getElementById("mainform").elements;
    var theList = document.getElementById('unlistedshipment');
    var numCards = parseInt(theList.options.length);

	if ((validateTotalNumberOfCards())
		&& (hasValueByRef(theItems['cardname'], 'the card name'))
		&& (hasValueByRef(theItems['cardcompany'], 'the card company'))
		&& (hasValueByRef(theItems['cardnum'], 'your card number')))
	{
		var newCardText = theItems['cardname'].value 
				+ " [" + theItems['cardcompany'].value + "]:"
				+ theItems['cardnum'].value
				+ (theItems['barcode_yes'].checked ? " (b)" : "");
		var newCardValue = theItems['cardname'].value 
				+ ":" + theItems['cardcompany'].value
				+ ":" + theItems['cardnum'].value
				+ ":" + (theItems['barcode_yes'].checked ? "Y" : "N");
		theList.options.length++;
		theList.options[numCards].text = newCardText;
		theList.options[numCards].value = newCardValue;
		theItems['cardname'].value = "";
		theItems['cardcompany'].value = "";
		theItems['cardnum'].value = "";
	}
	
}

function removeFromUnlistedShipment()
{
	var theList = document.getElementById("unlistedshipment");
	var len = theList.options.length;
	var theItem = theList.selectedIndex;
	if (theItem < 0)
		return;
	delFlag = window.confirm("Remove this item \"" + theList.options[theItem].text +"\" from the \"Your New Cards\" list?");
	if (!delFlag)
	{
		theList.selectedIndex = -1;
		return;
	}

	for (var i = theItem; i < len - 1; i++)
	{
		theList.options[i].text = theList.options[i + 1].text;
		theList.options[i].value = theList.options[i + 1].value;
	}
	theList.options.length--;
	theList.selectedIndex = -1;
	
}

function validateListLengthAndSubmit()
{

	var theShipment = document.getElementById("shipment");
   	var theUnlistedShipment = document.getElementById("unlistedshipment");
   	var listed = parseInt(theShipment.options.length);
   	var unlisted = parseInt(theUnlistedShipment.options.length);
//	alert("listed = " + listed + ", unlisted = " + unlisted + ", listed + unlisted = " + parseInt(listed + unlisted));
	if ((listed + unlisted) < 1)  {
		alert('Please ensure you have at least 1 barcode in total bewteen the "Card Numbers Entered" and the "Your New Cards" list boxes.');
		return false;
	} else if ((listed + unlisted) > MAX_NUM_OF_CARDS)  {
		alert('Please ensure you only have ' + MAX_NUM_OF_CARDS + ' barcodes in total bewteen the "Card Numbers Entered" and the "Your New Cards" list boxes.');
		return false;
	} else
		return selectWholeShipment();
} // End validateListLengthAndSubmit function

function validateTotalNumberOfCards()
{
   	var theShipment = document.getElementById("shipment");
   	var theUnlistedShipment = document.getElementById("unlistedshipment");
   	var listed = parseInt(theShipment.options.length);
   	var unlisted = parseInt(theUnlistedShipment.options.length);
//	alert("listed = " + listed + ", unlisted = " + unlisted + ", listed + unlisted = " + parseInt(listed + unlisted));
	if ((listed + unlisted) >= MAX_NUM_OF_CARDS)  {
		alert('Please ensure you only have ' + MAX_NUM_OF_CARDS + ' barcodes in total bewteen the "Card Numbers Entered" and the "Your New Cards" list boxes.');
		return false;
	} else
		return true;
}


//============ END of Functions for Selection boxes ====================================

//------------------------------------------------------------------------------
//  Function:  validateUserInfo 
//   Remarks:  Validates all required fields are entered on the userInfo screen
//------------------------------------------------------------------------------
	
	// this is a re-implemenation based on brand-new and shiny xhtml page
	function validateUserInfo()
	{
		var errorFlag;
		var fnameFlag;
		var lnameFlag;
		var addyFlag;
		var cityFlag;
		var provinceFlag;
		var countryFlag;
		var postalFlag;
		var phoneFlag;
		//var emailFlag;
			
		//initialize error Flags
		errorFlag = false;
		fnameFlag = false;
		lnameFlag = false;
		addyFlag = false;
		cityFlag = false;
		provinceFlag = false;
		countryFlag = false;
		postalFlag = false;
		phoneFlag = false;
		//emailFlag = false;
		
		//check to see if the fields are empty amd change errorFlag
		if (document.getElementById("firstname").value.length == 0)
		{
			fnameFlag = true;
			errorFlag = true;
		}
		else if (document.getElementById("lastname").value.length == 0)
		{
			lnameFlag = true;
			errorFlag = true;
		}
		else if (document.getElementById("addr1").value.length == 0)
		{
			addyFlag = true;
			errorFlag = true;
		}

		else if (document.getElementById("cityinfo").value.length == 0)
		{
			cityFlag = true;
			errorFlag = true;
		}
		else if (document.getElementById("province").value.length == 0)
		{
			provinceFlag = true;
			errorFlag = true;
		}
		else if (document.getElementById("country").value.length == 0)
		{
			countryFlag = true;
			errorFlag = true;
		}
		else if (document.getElementById("postcode").value.length == 0)
		{
			postalFlag = true;
			errorFlag = true;
		}
		
		// Is there a problem?
		if (errorFlag)
		{
			alert("You have missed entering in a required field. Please try again.");

		}
		else
		{
		    //  OK, all the required fields have been filled in.  But are they properly formatted?
		    if ((validatePostal())) // && (validateEmail()))
		    {
		        //  Almost there.  If a phone number has been entered we check it for validity (we don't need a phone number,
		        //  though, but it should be properly formatted if it's there)
		        if ((document.getElementById("phone").value.length > 0) ? validatePhone() : true)
		        {
		            document.mainform.submit();
		            return true;
		        }
		    }

		}

		
		// set focus
		if (fnameFlag)
		{
			document.getElementById("firstname").focus();	
			return false;
		}
		if (lnameFlag)
		{
			document.getElementById("lastname").focus();	
			return false;
		}
		if (addyFlag)
		{
			document.getElementById("addr1").focus();	
			return false;
		}
		if (cityFlag)
		{
			document.getElementById("cityinfo").focus();	
			return false;
		}
		if (provinceFlag)
		{
			document.getElementById("province").focus();	
			return false;
		}
		if (postalFlag)
		{
			document.getElementById("postcode").focus();	
			return false;
		}

		
	} //End validateUserInfo function


//------------------------------------------------------------------------------
//  Function:  validateEmail (javascript)
//   Remarks:  Validates email address for the proper format 
//------------------------------------------------------------------------------
	function validateEmail()
	{
		var OK;
		if (!nav4)	// For IE only
		{
        	OK =/^(\w+)([-\.]{1}\w+)*([@])(\w+)([-\.]{1}\w+)+$/g.exec(document.getElementById("email").value);
		}
		else			//Netscape
		{
			OK = emailRe.exec(document.getElementById("email").value);
		}
		if (!OK)
		{
			window.alert ("Email address should be formatted as 'someone@somewhere.com'.");
			document.getElementById("email").focus();
			document.getElementById("email").value = '';	
		}
		if (OK == null)
		    return false;
		return OK;
	}//end of function validateEmail


//------------------------------------------------------------------------------
// Function: validatePhone (javascript)
//	Remarks:  Validates phone for the proper format (XXX) XXX-XXXX 
//					where brackets space . or - are optional
//------------------------------------------------------------------------------
	function validatePhone()
	{
		var OK;
		if (!nav4)	// For IE only
		{
			//validate phone. optional() and - space . as delimitors
			OK = /^\(?\d{3}\)?([-\.\s])?\d{3}([-\.\s])?\d{4}$/g.exec(document.getElementById("phone").value)
		}
		else			//Netscape
		{
			OK = phoneRe.exec(document.getElementById("phone").value);		
		}	
		
		if (!OK)
		{
			window.alert (document.getElementById("phone").value + " is not valid! Please format your phone number with brackets optional (XXX) XXX-XXXX")
			document.getElementById("phone").focus();
			document.getElementById("phone").value = '';
		}	
		if (OK == null)
		    return false;
		return OK;
	}//end of function validatePhone

//------------------------------------------------------------------------------
// Function: validatePostal (javascript)
//	Remarks:  Validates postal code for the proper format WDW DWD or DDDDD....
//					where W is a letter and D is a Digit (space or - optional)
//------------------------------------------------------------------------------
	function validatePostal()
	{
		var OK;
		
		document.getElementById("postcode").value = document.getElementById("postcode").value.toUpperCase()

		if (!nav4)	// For IE only
		{
			//validate postal code with character exceptions
			OK = /^([A-CEGHJ-NPR-TVXY]\d[A-CEGHJ-NPR-TV-Z])([-\s])?(\d[A-CEGHJ-NPR-TV-Z]\d)$|^(\d{5})([-\s])?(\d{4})$|^(\d{5})$|^[A-Z]{1,2}[0-9R][0-9A-Z](\s)?\d[A-Z]{2}$/g.exec(document.getElementById("postcode").value);
		}
		else			//Netscape
		{
			OK = postalRe.exec(document.getElementById("postcode").value);
		}			

		if (!OK)
		{
			window.alert (document.getElementById("postcode").value + " is not formatted as a valid postal or zip code!");
			document.getElementById("postcode").focus();
			document.getElementById("postcode").value = '';
		}	
		if (OK == null)
		    return false;
		return OK;
	}//end of function validatePostal()
	

function validateFile()
{
	var cu = document.getElementById("custom_upgrade");
	var file = document.getElementById("picture_file");
	if (!cu)
	{
		return true;
	}
	if ((cu.checked) && (file.value.length == 0))
	{
		alert("You've indicated that you want to upgrade your Card, but you haven't chosen an image.");
		return false;
	}
	if ((!(cu.checked)) && (file.value.length > 0))
	{
		alert("You've chosen an image, but you haven't indicated that you want to upgrade your Card.");
		return false;
	}
	return true;
	
}




function checkPIN(pin, form)
{
	var obj = document.getElementById(pin);

	if (obj.value.length == 0)
	{
		alert("You have missed entering a PIN or password! Please try again.");

	}
	else if (validateEmail())
	{
	    obj.value = obj.value.toUpperCase();
//	    alert(obj + " is now " + document.getElementById(pin).value + ".");
        document.getElementById(form).submit();
		return true;

	}
	return false;
}


function checkMandatoryField(element, human_readable_element_name)
{
    if (document.getElementById(element).value.length > 0)
        return true;
    else
    {
        alert(human_readable_element_name + " must have a value.");
        return false;
    }
}

function makeRecipientList()
{
    var str = "";
    var nr = document.getElementById("txtNumberOfCards").value;
    if ((isNaN(nr)) || (nr == "") || (nr < 1))
    {
        alert("Please enter the number of cards you would like to send.");
        return null;   
    }
    // alert("The number is " + nr + ".");
	str += "			<table width=\"100%\"  border=\"0\" cellspacing=\"1\" cellpadding=\"1\">\n";
	str += "                <tr align=\"left\">\n";
	str += "                  <td width=\"230\" valign=\"top\" scope=\"col\" colspan=\"2\">Recipient List</td>\n";
	str += "                </tr>\n";
	str += "                <tr align=\"left\" class=\"formfield\">\n";
	str += "                  <td width=\"230\" valign=\"top\" scope=\"col\">Name</td>\n";
	str += "                  <td scope=\"col\">Email Address </th>\n";
	str += "                </tr>\n";
	for (var i = 0; i < nr; i++)  {
		str += "                <tr class=\"formfield\">\n";
		str += "                  <td width=\"230\"><input type=\"text\" id=\"txtRecvName" + i + "\" name=\"txtRecvName" + i + "\" size=\"25\"></td>\n";
		str += "                  <td><input type=\"text\" id=\"txtRecvEmail" + i + "\" name=\"txtRecvEmail" + i + "\" size=\"40\"></td>\n";
		str += "                </tr>\n";
	}
	str += "			</table>\n";
	str += "				<p>";
	str += "			<input type=\"checkbox\" name=\"chkMoreInfo\" id=\"chkMoreInfo\" /> Please send me information on special offers and promotions from MyBarCodeCard&#174;.</p>";
	str += "<p>\n";
	str += "		        <input class=\"button\" name=\"btnSubmit\" type=\"submit\" id=\"btnSubmit\" value=\"Next >>\">\n";
	str += "</p>\n";
	document.getElementById("spanRecipientList").innerHTML = str;

}

function buildRecipientList()  {
    if (!((hasValueByRef(document.getElementById("txtGiverName"), "your name")) && (validateEmailByRef(document.getElementById("txtGiverEmail")))))
        return false;
	var theList = document.getElementById("lstRecipients");
	var len = theList.options.length;
	if ((len == 1) && (theList.options[len - 1].value == "-999999"))
	{
	    alert("Please enter at least one recipient to send a gift card to.");
	    return false;
	}
	var rl = new Array();
	for (var i = 0; i < len; i++)
		rl[i] = theList.options[i].value;
	document.getElementById("hdnRecipientList").value = rl.join("#");
	return true;
		
}

function hasValueByRef(ref, str)  {
	if (ref.value == "")  {
		window.alert("Please enter a value for " + str + ".");
		ref.focus();
		return false;
	}
	else
		return true;
}
//------------------------------------------------------------------------------
//  Function:  validateEmailByRef (javascript)
//   Remarks:  Validates email address for the proper format given an object reference
//------------------------------------------------------------------------------
	function validateEmailByRef(ref)
	{
		var OK;
		if (!nav4)	// For IE only
		{
        	OK =/^(\w+)([-\.]{1}\w+)*([@])(\w+)([-\.]{1}\w+)+$/g.exec(ref.value);
		}
		else			//Netscape
		{
			OK = emailRe.exec(ref.value);
		}
		if (!OK)
		{
			window.alert ("Make sure your email addresses are formatted as 'someone@somewhere.com'.");
			ref.focus();
			ref.value = '';	
		}
		if (OK == null)
		    return false;
		return OK;
	}//end of function validateEmailByRef
	
function validateResellForm()
{
    var theItems = document.getElementById("mainform").elements;
	if ((hasValueByRef(theItems['name'], 'your name'))
			&& (hasValueByRef(theItems['locinfo'], 'your location'))
			&& (hasValueByRef(theItems['phone'], 'your phone'))
			&& (validatePhone())
			&& (hasValueByRef(theItems['email'], 'your email'))
			&& (validateEmail()))
		return true;
	else
		return false;
       
}

function addToRecipientList()
{
	var theName = document.getElementById("txtName");
	var theEmail = document.getElementById("txtEmail");
	var theList = document.getElementById("lstRecipients");
	if ((hasValueByRef(theName, "the recipient\'s name")) && (validateEmailByRef(theEmail)))  {
		var len = theList.options.length;
		if ((len == 1) && (theList.options[len - 1].value == "-999999"))
			len = 0;
		else
			theList.options.length++;
		theList.options[len].text = theName.value + "  ===>  " + theEmail.value;
		theList.options[len].value = theName.value + ":" + theEmail.value;
		theName.style.background = "#FFFFFF";
		theEmail.style.background = "#FFFFFF";
		theName.value = "";
		theEmail.value = "";
	}
}

function removeFromRecipientList()
{
	var theList = document.getElementById("lstRecipients");
	var len = theList.options.length;
	var theItem = theList.selectedIndex;
	if (theItem < 0)
		return;
	for (var i = theItem; i < len - 1; i++)
	{
		theList.options[i].text = theList.options[i + 1].text;
		theList.options[i].value = theList.options[i + 1].value;
	}
	theList.options.length--;
	if (theList.options.length == 0)
	{
		theList.options.length++;
		theList.options[0].text = "------ No Entries In The List ------";
		theList.options[0].value = "-999999";
	}
	theList.selectedIndex = -1;
	
	
}


function validateFundraisingForm()
{
    var theItems = document.getElementById("mainform").elements;
	if ((hasValueByRef(theItems['name'], 'your name'))
			&& (hasValueByRef(theItems['address'], 'your address'))
			&& (hasValueByRef(theItems['city'], 'your city or town'))
			&& (hasValueByRef(theItems['stateprov'], 'your state or province'))
			&& (hasValueByRef(theItems['zippostalcode'], 'your zip or postal code'))
			&& (hasValueByRef(theItems['phone'], 'your phone'))
			&& (validatePhone())
			&& (hasValueByRef(theItems['email'], 'your email'))
			&& (hasValueByRef(theItems['orgname'], 'the name of your organization'))
			&& (validateEmail()))
		return true;
	else
		return false;
       
}