function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//dropdown menu item mouseover colour changes (background of item and text colour)
var dd_txtcolor_over = '#eae8d8';
var dd_txtcolor_out = '#004221';
var dd_bgcolor_over = '#004221';
var dd_bgcolor_out = '#eae8d8';

function setColor(objName, fg, bg)
{
  obj = MM_findObj(objName);
  if (obj.style)
  {
    obj.style.color = fg;
    obj.style.backgroundColor = bg;
  }
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkOldBrowser()
{
	//check if the user's browser is new.  If not, we present them with a alert message indicating that they aren't seeing the site the way it was intended
	if (!document.getElementById)
	{
		//Old Browser!  Check if old Opera, IE, or NN.
		var browserMsg = "The browser you are using is outdated.  Although you will still be able to read our information, your browser prevents you from viewing the site the way it is intended.\n\nWould you like to download the latest version of your browser (in a new window)?";
		
		if (navigator.userAgent.indexOf("Opera") > 0)
		{
			if(confirm(browserMsg))
				window.open("http://www.opera.com");
		}
		else if (navigator.appName == "Microsoft Internet Explorer")
		{
			if(confirm(browserMsg))
				window.open("http://www.microsoft.com/windows/ie/downloads/critical/ie6sp1/default.asp");
		}
		else if (navigator.appName == "Netscape")
		{
			if(confirm(browserMsg))
				window.open("http://channels.netscape.com/ns/browsers/download.jsp");
		}
	}
}

function MM_displayStatusMsg(msgStr) { 
  status=msgStr;
  document.MM_returnValue = true;
}

function openPopup(thePage, theWidth, theHeight, theWindowName)
{
	//This function accepts the page to be loaded, the width and height of the popup, and the name of the window so that
	//new popups open in their own window and not in other ones
	
	//POPUP PROPERTIES CODE
	var popWin, theProperties, popWidth, popHeight, leftPos, topPos;
	var scrollbars = 0;
	
	popWidth = theWidth;
	popHeight = theHeight + 20;
	
	//open in center
	leftPos = (screen.width-popWidth)/2;
	topPos = (screen.height-popHeight)/2;
	
	//popup only has scrollbars
	theProperties = "menubar=0,toolbar=0,resizable=no,scrollbars=" + scrollbars + ",width=" + popWidth + ",height=" + popHeight + ",left=" + leftPos + ",top=" + topPos;
	
	//Open a popup window
	popWin = window.open(thePage, theWindowName, theProperties);
	popWin.focus();
}

function openerLoc(theLoc)
{
	//this function accepts a URL, and sets the href of the window that opened the popup to theLoc
	if(self.opener)
	{
		self.opener.focus();
		self.opener.location.href = theLoc;
	}
}

// ************************* JAVASCRIPT FOR FORM ON TELL-A-FRIEND PAGE  ***************************************
//Form validation
function validate(theForm,button)
{
	if(!blankField(theForm))//calls name check
		return false;
		
	if(!checkMail(theForm))//calls email in correct format function
		return false;
		
	if(!checkLength(theForm))
		return false;
		
	if(button == '1')
	{
		//alert("put some fancy open the pop up window crap here!!!");
		var cardSelected;
		var result;
		
		if (theForm.ecard[0].checked)
		{
			cardSelected = "card1";
		}
		else if (theForm.ecard[1].checked)
		{
			cardSelected = "card2";
		}
		else if (theForm.ecard[2].checked)
		{
			cardSelected = "card3";
		}
		else 
		{
			cardSelected = "card4";
		}
		//Insert a <br /> into the preview page whenever someone presses the enter button on keyboard.
		result = escape(theForm.message.value) //encode textarea string's carriage returns
	
		//textarea.value=unescape(textarea.value) unescape all other encoded characters
		//result = "hello_there%0D%0Ahow_are_you.";
		var theURL = "/popups/preview.php?message=" + result + "&ecard=" + cardSelected;	
		openPopup(theURL, 700, 300, "PreviewWindow");
		}

	return true;
}
// Test to make sure name and email fields are not blank
function blankField(theForm)
{
	theField = new Array("your name", "your email", "your friend's email","a message")
	for(var i=0; i<=3;i++)
	{
		if(theForm.elements[i].value == "")
		{
			alert("You did not enter " + theField[i]);
			theForm.elements[i].focus();
			theForm.elements[i].select();
			return false;
		}
		theForm.elements[i].name
	}
	return true;
}
// Make sure first character on line isn't empty by error
function notBlank(theForm)
{
	for(var i=0; i<=3; i++)
	{
		if(theForm.elements[i].value.charAt(0) == " ")
		{
			alert("Please do not enter a space in the first part of field");
			theForm.elements[i].focus();
			theForm.elements[i].select();
			return false;
		}
	}
	return true;
}

// Make sure valid email address
function checkMail(theForm)
{
	var yourEmail = theForm.elements[1].value;
	var friendEmail = theForm.elements[2].value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(yourEmail))
		{
			alert("Please enter a valid email address");
			theForm.elements[1].focus();
			theForm.elements[1].select();
			return false;
		}
		
	if (!filter.test(friendEmail))
		{
			alert("Please enter a valid email address");
			theForm.elements[2].focus();
			theForm.elements[2].select();
			return false;
		}

	return true;
}

function checkLength()
{
	//this function checks the length of the text area box
	if(document.ecardForm.message.value.length > 500)
	{	
		alert("Please keep your message to your friend under 500 characters.");
		document.ecardForm.message.focus();
		document.ecardForm.message.select()
		return false;
	}
	
	return true;
}