// JavaScript Document
// image rollovers
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 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;
}

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];}
}

//end image rollovers
MM_preloadImages('images/navBar_donate_on.gif','images/navBar_links_on.gif','images/navBar_program_on.gif','images/navBar_news_on.gif','images/navBar_readStory_on.gif','images/navBar_theFacts_on.gif')


//Donation Page
function setSelection(theForm, selField)
{
	 for (var i = 0; i < theForm.donation_amount.length; i++)
  {
    if (theForm.donation_amount[i].value == selField)
    {
      theForm.donation_amount[i].checked = true
      break
    }
  }
}

function FormValidator(theForm)
{
	var ret = true;
	var bandMin = true;
	var val = theForm.other_amount.value;
	i=theForm.donation_amount.length
	
	myOption = -1;
	for (i=theForm.donation_amount.length-1; i > -1; i--)
	{
		if (theForm.donation_amount[i].checked)
		{
			myOption = i;
			theDon = theForm.donation_amount[i].value;
		}
	}

	if (myOption == -1) 
	{
		alert("Please select a donation amount.");
		return false;
	}

	i = 4;
	if (theForm.donation_amount[i].checked)
	{
		if (isNaN(val))
		{
			// not a number
			ret = false;
		}
		else
		{
			//round to US currency
			num = val;
			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));
			val = (num + '.' + cents);
			
			
			// a number, let's see if it's greater than zero
			if (val < .01)
			{
				ret = false;
			}
			else
			{
				theDon = val;
			}
			
		}
		if (!ret)
		{
			alert("Please enter a valid donation.");
			theForm.other_amount.select();
			theForm.other_amount.focus();
		}
	}
	
	
	
	theForm.amount.value = theDon;
	theForm.item_name.value = "Donation";// + " " + whichBand;
	return ret;
}

function watchVideo(id)
{
	document.getElementById("videoPlayerBox").innerHTML = '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/'+id+'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+id+'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
	document.getElementById("videoOptions").innerHTML = '<a href="mailto:?subject=You%20have%20received%20a%20video%20from%20JourneySafe%21&body=http%3A//www.journeysafe.com/video?v='+id+';">email this</a> | <a href="javascript:hideVideo();">close</a>';
	x = findElementPos( document.getElementById("MainFloat") );
	document.getElementById("videoPlayer").style.left=x[0]+'px';
	document.getElementById("videoPlayer").style.top=x[1]+'px';
	axblast( document.getElementById("videoPlayerBox") );
	document.getElementById("videoPlayer").style.display='block';
}

function hideVideo()
{
	document.getElementById("videoPlayer").style.display='none';
	document.getElementById("videoPlayerBox").innerHTML = '';
}



function readMoreInline(hide, show)
{
	document.getElementById(hide).style.display='none';
	document.getElementById(show).style.display='block';
}

function showChart()
{
	var x = findElementPos( document.getElementById("sidebarPL") );
	x[0] = x[0] - 550;
	x[1] = x[1] - 180;
	document.getElementById("truthChart").style.left=x[0]+'px';
	document.getElementById("truthChart").style.top=x[1]+'px';
	document.getElementById("truthChart").style.display='block';
}

function hideChart()
{
	document.getElementById("truthChart").style.display='none';
}

function axblast(id) {
/*
Embedded Objects Active X Warning Remover for IE
A dutch work arround
Use: put your embed code (flash,movie, etc)
between a div tag with an id.
trigger the axblast(your_div_id);
*/
if (id == undefined) { return false; }
// Rewrite code for IE browsers only
// Get the object HTML from div
if (document.all && document.all["+id+"]) { HTML = document.all["+id+"].innerHTML; }
// Write the same HTML back - couldnt be easier (-.0)
if (document.all && document.all["+id+"]) { document.all["+id+"].innerHTML = HTML; }
}



function findElementPos(obj)
{  
  var curleft=0;
  var curtop = 0;
  if( obj.offsetLeft == 0 || obj.offsetTop == 0 ) {
    
    if (obj.offsetParent) {
      curleft = obj.offsetLeft
      curtop = obj.offsetTop
      while (obj = obj.offsetParent) {
        curleft += obj.offsetLeft
        curtop += obj.offsetTop
      }
    }    
  }
  else {
    curleft = obj.offsetLeft;
    curtop = obj.offsetTop;
  }
  return [curleft,curtop];  
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}
 

	
function swapImage(obj, outImage, overImage, action)
{
	if (action == 'over')
		obj.src = overImage;
	else
		obj.src = outImage;
}

function registerGolf(theType)
{
	window.location = '/News_And_Events/golf/register.asp?type=' + theType;
}

function validateInputMoney(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
         if (charCode > 31 && (charCode < 45 || charCode > 57 || charCode == 47 || charCode == 45))
            return false;
}