
/**
	***---------------------------------------------------------***
	*	SiteGlobals.js
	***---------------------------------------------------------***
	*	Artware Studios
	*	Send A Blessing
	*	16 December 2006	tb
	*
	*	This file is included in all content pages.  
	*	It includes Javascript utility functiions.
	*		Global variables are not used in  frameset.php --> index.html  because there seemed to be 
	*		problems referencing them given the structure of that page for keeping pages framed..
	*/

/***	General Purpose Functions	***   ***   ***	General Purpose Functions	***   ***/
function stopFeaturedCard()
{//Stop playing the featured card on the home page.  Does NOT work.
	document.featuredCard.TStopPlay("_level10/YogaDuet");
}//function stopFeaturedCard()

function sizeWindow()
{
	window.resizeTo(1024, 768);
}//function sizeWindow()

function screenSize()
{//NOTE:  This function needs to be placed in a separate page to determine which presentPage.php to use.
	var h = screen.height;
	var w = screen.width;
//		alert("Screen Size: " + w + " x "+ h);	//Detection works in Netscape & IE
	if (w<900) 
	{
		return true;
	}
	return false;
}//function screenSize()

var smallScreen = screenSize();

function noSubmitOnEnter()
{//Prevents Return key from submitting the form from elements where the function is called onkeypress.
	return !(window.event && window.event.keyCode == 13);
}//function noSubmitOnEnter()

function focusNameField(isActive)
{
	if (isActive) 
	{
		document.forms[0].name.focus();
	}
}//function focusNameField(isActive)

function focusEmailField(isActive)
{
	if (isActive) 
	{
		document.forms[0].emailAddress.focus();
	}
}//function focusEmailField(isActive)

function isEmpty(theElement)
{//For checking strings.
	var theValue = theElement.value;
	if ((theValue === null) || (theValue.length === 0)) 
	{
		return true;
	}
	else 
	{
		return false;
	}
}//function isNotEmpty(theElement)

function closeWindow()
{//Called from within mainFrame.
		window.close();
}//function closeWindow()

function replaceMainFrame(theURL)
{//Called from within mainFrame.
		parent.mainFrame.location.href = theURL;
}//function replaceMainFrame($url)

function writeDayOptions()
{
	var dayOptions = '<option value="00">day</option>';
	for (i=1; i<32; i++)
	{
		dayOptions +=  '<option value="' + i + '">' + i  +'</option>';
	}
	return dayOptions;
}//function writeDayOptions()

function writeMonthOptions()
{
	var monthOptions = '<option value="00">mo</option>';
	monthOptions +=  '<option value="01">Jan</option>';
	monthOptions +=  '<option value="02">Feb</option>';
	monthOptions +=  '<option value="03">Mar</option>';
	monthOptions +=  '<option value="04">Apr</option>';
	monthOptions +=  '<option value="05">May</option>';
	monthOptions +=  '<option value="06">Jun</option>';
	monthOptions +=  '<option value="07">Jul</option>';
	monthOptions +=  '<option value="08">Aug</option>';
	monthOptions +=  '<option value="09">Sep</option>';
	monthOptions +=  '<option value="10">Oct</option>';
	monthOptions +=  '<option value="11">Nov</option>';
	monthOptions +=  '<option value="12">Dec</option>';
	return monthOptions;
}//function writeMonthOptions()

function writeYearOptions()
{
	var theDate = new Date();
	var theYear = theDate.getFullYear();
//alert("theYear" + theYear);//OK
	var yearOptions = '<option value="0000">yr</option>';
	for (i=0; i<100; i++)
	{
		yearOptions +=  '<option value="' + theYear + '">' + theYear  +'</option>';
		theYear = theYear - 1;
	}
	return yearOptions;
}//function writeYearOptions()
/***	General Purpose Functions	***   ***   ***	General Purpose Functions	***   ***/

/***	Functions for  personalizeCardPage.php	***   ***   ***	Functions for  personalizeCardPage.php	***   ***/
//	NOTE:  Utilities for this page are now located in  PersonalizeTools.js .
var addressIndex = -1;
var addressWindow = null;
var archiveWindow = null;

function sentAlert(wasSent, theRecipient)
{
	if (wasSent) 
	{
		alert("Your card has been sent to " + theRecipient + ".");	
	}
}//function sentAlert(yesOrNo)

function noneCheckedAlert(noneChecked)
{
	if (noneChecked) 
	{
		alert("Please Select Recipient from your address list.");
	}
}//function sentAlert(yesOrNo)

function getRecipientName(theArray, theIndex)
{
	var theName = '';
	if (theIndex < 0) 
	{
		theName = '';
	}
	else 
	{
		theName = theArray[theIndex].name;
	}
	return theName;
}//function getRecipientName(theArray, theIndex)

function writeSendYearOptions()
{//Year options for sending cards
	var theDate = new Date();
	var theYear = theDate.getFullYear();
//alert("theYear" + theYear);//OK
	var yearOptions = '<option value="0000">yr</option>';
	for (i=0; i<2; i++)
	{
		yearOptions +=  '<option value="' + theYear + '">' + theYear  +'</option>';
		theYear = theYear + 1;
	}
	return yearOptions;
}//function writeSendYearOptions()

function enableDates()
{//Enables or disables date pulldows as radio buttions change.
	var theValue = document.forms[0].dateToSend.value;
alert("theValue: " + theValue);
	if (theValue === 0)
	{
		document.forms[0].dayList.disabled="false";
		document.forms[0].monthList.disabled="false";
		document.forms[0].yearList.disabled="false";
	}//if
	else
	{
		document.forms[0].dayList.disabled="true";
		document.forms[0].monthList.disabled="true";
		document.forms[0].yearList.disabled="true";
	}//else
}//function enableDates()

function openAddressWindow(theAddressIndex, theNumberOfAddresses)
{
//alert("openAddressWindow - theAddressIndex & theNumberOfAddresses:   " + theAddressIndex + "  " + theNumberOfAddresses);
	if ( (theAddressIndex < 0) && (theNumberOfAddresses > 99) )
	{
		alert("Your Address Book is full.\nPlease delete an address to add a new one.");
		return;
	}
	else
	{
		addressIndex = theAddressIndex;
		var theStringIndex = theAddressIndex.toString();
alert("pre opening window  -  theStringIndex:  " + theStringIndex);		//alert() shows fine.
		var newURL = "addressPage.php?ai=" + theStringIndex;							//On next alert,  newURL  is undefined.
alert("pre opening window  -  theURL:  " + newURL);
		addressWindow = window.open(newURL,'addressWindow','height=310,width=428,top=200,left=100');
alert("post opening window  -  newURL:  " + newURL);
//ALTERNATIVE:
//		addressWindow = window.open("theStringURL", "addressWindow", "height=310,width=428,top=200,left=100");
//alert("post opening empty window  -  addressWindow=  " + addressWindow);
//		addressWindow.location.href = unescape(theURL);
//alert("post location.href window  -  addressWindow.location.href=  " + addressWindow.location.href); //about:blank
		addressWindow.focus();
	}
}//function openAddressWindow(theAddressIndex)

function openArchiveWindow(theAddressIndex)
{
	addressIndex = theAddressIndex;
//alert("Called  openArchiveWindow  with index: " + addressIndex);
	var theURL = "archivePage.php?ai=" + theAddressIndex.toString();	//The page & parameter for getting an address for archive.
	addressWindow = window.open(theURL, "archiveWindow", "height=310,width=428,top=200,left=100");
}//function openArchiveWindow(theAddressIndex)
/***	Functions for  personalizeCardPage.php	***   ***   ***	Functions for  personalizeCardPage.php	***   ***/

/***	Functions for  addressPage.php	***   ***   ***	Functions for  addressPage.php	***   ***/
function setButtonClicked(theButtonName)
{
	document.forms[0].buttonName.value = theButtonName;
}//function setButtonClicked(buttonName)

var cancelClicked = false;
function setCancel()
{
	cancelClicked = true;
}//function setCancel()

function checkAddressInfo()
{//For  addressPage.php .
	if (cancelClicked)
	{
		window.close();
	}//if (!cancelClicked)
	else
	{//Not checked if 
		var theName = document.forms[0].name;	//firstName
		if (isEmpty(theName))
		{
			alert("Please enter the recipient's name.");
			theName.focus();
			return false;
		}
		var theEmail = document.forms[0].email;
		if (isEmpty(theEmail))
		{
			alert("Please enter the recipient's email address.");
			theEmail.focus();
			return false;
		}
	}//else
	cancelClicked = false;	//Check for duplicate listings either in  opener.addressArray()  on the client or in  addressInfoUpdate.php  on the server.
	return true;
}//function checkAddressInfo()

function setDayOption(elementIndex, theDayIndex)
{
	document.forms[0].elements[elementIndex].selectedIndex = theDayIndex;
}//function setDayOption(theForm, theElement, theDayIndex)

function setMonthOption(elementIndex, theMonthIndex)
{
	document.forms[0].elements[elementIndex].selectedIndex = theMonthIndex;
}//function setMonthOption(theForm, theElement, theDayIndex)

function setYearOption(elementIndex, theYearIndex)
{
	document.forms[0].elements[elementIndex].selectedIndex = theYearIndex;
}//function setMonthOption(theForm, theElement, theDayIndex)

function setDateOptions(dayElement, dayIndex, monthElement, monthIndex, yearElement, yearIndex)
{
	setDayOption(dayElement, dayIndex);
	setMonthOption(monthElement, monthIndex);
	setYearOption(yearElement, yearIndex);
}//function setDateOptions(dayElement, monthElement, yearElement, dayIndex, monthIndex, yearIndex)
/***	Functions for  addressPage.php	***   ***   ***	Functions for  addressPage.php	***   ***/

/***	Functions for  yourInfoPage.php	***   ***   ***	Functions for  yourInfoPage.php	***   ***/
function checkJoinInfo(formName)
{//For  yourInfoPage.php .
	var agreeBox = document[formName].agreeCheckbox;
	var agreed = agreeBox.checked;
	if (!agreed)
	{
		alert("Please agree to Conditions of Use by checking the box.");
		agreeBox.focus();
		return false;
	}
	var theEmail = document[formName].Email;
	if (isEmpty(theEmail))
	{
		alert("A valid email address is required to join.");
		theEmail.focus();
		return false;
	}
	var pass1 = document[formName].USER1;	//password1
	var pass2 = document[formName].USER2;	//password2
	if (isEmpty(pass1))
	{
		alert("You must enter a valid password.");
		pass1.focus();
		return false;
	}
	if ( (isEmpty(pass2)) || !(pass1.value === pass2.value) )
	{
		alert("The password entries must be identical.  Please re-enter them.");
		pass2.value = '';
		pass1.value = '';
		pass1.focus();
		return false;
	}
	var name1 = document[formName].USER3;	//firstName
	if (isEmpty(name1))
	{
		alert("Please enter your first name.");
		name1.focus();
		return false;
	}
	var name2 = document[formName].USER4;	//lastName
	if (isEmpty(name2))
	{
		alert("Please enter your last name.");
		name2.focus();
		return false;
	}
	var scrName = document[formName].USER5;	//screenName
	if (isEmpty(scrName))
	{
		alert("Please enter a screen name.  It will appear in the main menu when you log in");
		scrName.focus();
		return false;
	}
	return true;
}//function checkJoinInfo(formName)

function composeScreenName(formName)
{//USER variables are for passing through the Verisign transaction process.
	var theWholeName = document[formName].NAME;
	var theFirstName = document[formName].USER3.value;	
	var theLastName = document[formName].USER4.value;
	var scrName = document[formName].USER5;
	var theScreenName = theFirstName + " " + theLastName;
	theWholeName.value = theScreenName;
	if (theScreenName.length > 25) 
	{
		theScreenName.slice(0, 25);
	}
	scrName.value = theScreenName;
}//function composeScreenName(formName)
/***	Functions for  yourInfoPage.php	***   ***   ***	Functions for  yourInfoPage.php	***   ***/

/***	Functions for  contactUsPage.php	***   ***   ***	Functions for  contactUsPage.php	***   ***/
function checkContactUsInfo(formName)
{
	var nameTextField = document[formName].nameTextField;	
	if (isEmpty(nameTextField))
	{
		alert("Please enter your name.");
		nameTextField.focus();
		return false;
	}
	var emailTextField = document[formName].emailTextField;
	if (isEmpty(emailTextField))
	{
		alert("Please enter your email address.");
		emailTextField.focus();
		return false;
	}
	var questionTextField = document[formName].questionTextField;	
	if (isEmpty(questionTextField))
	{
		alert("Please enter the details of your question or comment.");
		questionTextField.focus();
		return false;
	}
//	alert("Thank you for your input");
	return true;
}//function checkContactUsInfo(formName)

function contactMessageResponse(contactError, contactMessageSent)
{
	if (contactError) 
	{
		alert("There was an unexpected problem sending your message.\n  Please try again.");	
	}
	else if (contactMessageSent)
	{
		alert("Your message has been sent.\n  Thank you for your input.");	
	}//else if
}//function contactMessageResponse()
/***	Functions for  contactUsPage.php	***   ***   ***	Functions for  contactUsPage.php	***   ***/

/***	Functions for  thumbnailPage.php	***   ***   ***	Functions for  thumbnailPage.php	***   ***/
var previewWindow = null;
function previewCard(theCardID)
{//Opens previewWindow & plays card.
	var theURL = "previewCardPage.php?cid=" + theCardID;
	if ( (previewWindow == null) || (previewWindow.closed) )
	{
		previewWindow = window.open(theURL,'previewWindow','height=750,width=950,top=10,left=20');
	}
	else
	{
		previewWindow.resizeTo(950, 750);
		previewWindow.location.href = theURL;
	}
}//function previewCard(theCardID)

function displayAboutCard(theCardID)
{//Displays information about the card in the  previewWindow .  Called from the preview window.
	var theURL = "aboutCardPage.php?cid=" + theCardID;
	if ( (previewWindow == null) || (previewWindow.closed) )
	{
		previewWindow = window.open(theURL,'previewWindow','height=750,width=650,top=10,left=20');
	}
	else
	{
		previewWindow.resizeTo(650, 750);
		previewWindow.location.href = theURL;
	}
}//function displayAboutCard(theCardID)

/***	Functions for  thumbnailPage.php	***   ***   ***	Functions for  thumbnailPage.php	***   ***/

/***	Functions for  previewCardPage.php	***   ***   ***	Functions for  previewCardPage.php	***   ***/
function returnToSite(theURL)
{//Go to  personalizeCardPage.php  with previewed card selected to Send This Card  OR
 //Go to  membershipInfoPage.php  to Join.
	opener.parent.location.href = theURL;
	window.close();
}//function returnToSite(theURL)
/***	Functions for  previewCardPage.php	***   ***   ***	Functions for  previewCardPage.php	***   ***/

/***	Functions for  thumbnailPage.php	***   ***   ***	Functions for  thumbnailPage.php	***   ***/
function changeImage(theImageName, theFileName)
{
	document[theImageName].src = theFileName;
}//function changeImage(theImageName, theFileName)

function writeThumbnail(theIndex, theCardArray)
{//The parameter references an element in the JS cardArray.
	var theCardID = theCardArray[theIndex].cardID;					//HAS NO PROPERTIES
	var theCardName = theCardArray[theIndex].cardName;
	var thePosted = theCardArray[theIndex].posted;
	var theThumbHTML = '';
	if (thePosted == "1")
	{
		theThumbHTML += '<div id="thumbNailIconBar"></div>';
		theThumbHTML += '<div id="thumbNail">';
		theThumbHTML += '<a href="#"';
		theThumbHTML += ' onclick="previewCard(' + theCardID + ')"';
		theImageName = "'" + theCardName + "Th'";
		theOutFileName = "'http://www.sendablessing.com/images/thumbnails/" + theCardName + "_Th.gif'";
		theOverFileName = "'http://www.sendablessing.com/images/thumbnails/" + theCardName + "_Th_Over.gif'";
		theThumbHTML += ' onmouseover="changeImage(' + theImageName + ', ' +  theOverFileName + ')"';
		theThumbHTML += ' onmouseout="changeImage(' + theImageName + ', ' +  theOutFileName + ')">';
		theThumbHTML += ' <img border=0 name="' + theCardName + 'Th" src="http://www.sendablessing.com/images/thumbnails/' + theCardName + '_Th.gif" alt="' + theCardName + '" title="' + theCardName + '" height="86" width="86"/></a>';
		theThumbHTML += '</div>';
	}//if (posted)
	else
	{
		theThumbHTML += '<div id="thumbNailIconBar"></div>';
		theThumbHTML += '<div id="thumbNail">';
//		theThumbHTML += '<a href="#">';
		theThumbHTML += ' <img border=0 name="' + theCardName + 'Th" src="http://www.sendablessing.com/images/thumbnails/' + theCardName + '_Th.gif"  alt="' + theCardName + '" height="86" width="86"/>';
		theThumbHTML += '</div>';
	}//else
	document.write(theThumbHTML);
}//function writeThumbnail(theIndex)
/***	Functions for  thumbnailPage.php	***   ***   ***	Functions for  thumbnailPage.php	***   ***/

function writeThumbsHTML(theNumberOfCards, theCardArray)
{
	for (var i=0; i<theNumberOfCards; i++)
	{
		writeThumbnail(i, theCardArray);
	}
}//function writeThumbsHTML()

/***	Functions used in Library files	***/
function transferEmail(formName)
{//Used in  /lib/LoginManager.php
	var emailField = document[formName].emailAddress;
	var newURL = "emailPassword.php?email=" + emailField.value;
	window.location.href = newURL;
}//function transferEmail(formName)
/***	Functions used in Library files	***/


