function swapImgRestore() { //v3.0
  var i,x,a=document.sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function 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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array;
	for(i=0;i<(a.length-2);i+=3)if ((x=findObj(a[i]))!=null){
		document.sr[j++]=x; 
		if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
}

//added on Mar 27 2007
function updateDonation(a) {
	//alert(a.id + " **** " + a.value);
	var amount = document.getElementById("donation_amount");
	if (a.value)
	{
		amount.value = a.value;
	}
}

function paymentDestination(b){
	var amount = document.getElementById("payment_destination");
	if (b.value)
	{
		amount.value = b.value;
	}
}

function disableAmountField(b) {
	var other = document.getElementById("other_amount");
	var amount = document.getElementById("donation_amount");
	amount.value = '';
	if (b)
	{
		other.disabled = true;
	} else {
		other.disabled = false;
	}
}

//for spark form
function checkPaymentForm(fobj){
	if (validateForm(fobj, false, false, false, true, 8)) {
		var rad = fobj.elements["payment_amount"],i,chkopt='',s='',ccnumber;
		var rad2 = fobj.elements["payment_goto"], j, chkopt2='';
		var today = new Date();
		//alert(today);
		var year = 1 * (document.getElementById("cc_year").value);
		var month = 1 * document.getElementById("cc_month").value;
		//alert('Entered Year: ' + year + ' Entered Month: ' + month + '\n' + 'Today Year: ' + today.getFullYear() + ' Today Month: ' + 1+today.getMonth());

		//check the country and state
		if ((document.getElementById("country").value == "Canada" || document.getElementById("country").value == "United States") && document.getElementById("state").value == "none")
		{
			s += "Please choose the valide state.\n";
		}
		
		for (var i=0; i<rad.length; i++) {
			if (rad[i].checked == true) {
				chkopt = rad[i].value;
				break;
			}
		}

		if(chkopt == 'other' && document.getElementById("other_amount").value == '') {
			s += "Please enter a donation amount.\n";
			document.getElementById("other_amount").focus();
		}

		/*Where Do You Want Your Donation to Go*/
		if (rad2)
		{
			for (j=0; j<rad2.length; j++){
				if (rad2[j].checked == true)
				{
					chkopt2 = rad2[j].value;
					break;
				}
			}

			if (chkopt2 == '' && document.getElementById("payment_destination").value == '')
			{
				s += "Please choose one destination for your donation.\n";
			}
		}
		/*Where Do You Want Your Donation to Go*/

		if(chkopt!=''){
			if (document.getElementById("cc_owner").value == '')
			{
				s += "Please enter credit card holder name.\n";
			}	

			ccnumber=document.getElementById("cc_number").value;
			
			if(ccnumber=='' || ccnumber.length<15 || ccnumber.length>16) {
				s += "Please enter valid credit card number.\n";
			}else if(!ccnumber.match(/[0-9+]/)){
				s += "Credit card number is invalid.\n";
			}

			if(today.getFullYear()>year || (today.getFullYear()==year && 1+today.getMonth()>month))
			{
				s += "Please enter valid credit card expiration.\n";
			}

			if(document.getElementById("csc").value=='') {
				s += "Please enter the credit card verification code.\n";
			}
		}else {
			s += "Please select a donation amount.\n";//"Please select one payment method.\n";
		}
		
		/*
		if(document.getElementById("payment_destination").value == ''){
			s += "Please choose one destination.\n";
		}
		*/

		if(s) {
			alert("The following errors occured:\n"+s);
			return false;
		}
		return true;
	}
	return false;
}

// - added by tania 4 17 09
function initMaps() {
   if (document.getElementById) {
      var mapIds = initMaps.arguments;    // pass string IDs of containing map elements
      var i, j, area, areas;
      for (i = 0; i < mapIds.length; i++) {
        areas = document.getElementById(mapIds[i]).getElementsByTagName("area");

        for (j = 0; j < areas.length; j++) {  // loop thru area elements
           area = areas[j];
           area.onmousedown = imgSwap;    // set event handlers
           area.onmouseout = imgSwap;
           area.onmouseover = imgSwap;
           area.onmouseup = imgSwap;
		   //area.onclick = imgSwap;
        }
      }
   }
}

function checkPage(url) {
	
	var page = document.location.href
	evt = (evt) ? evt : event;                   // equalize event models
   var elem = (evt.target) ? evt.target : evt.srcElement;
   var imgClass = elem.parentNode.name;         // get map element name
   var coords = elem.coords.split(",");         // convert coords to clip
   var clipVal = "rect(" + coords[1] + "px " +
                           coords[2] + "px " +
                           coords[3] + "px " +
                           coords[0] + "px)";
   var imgStyle;
   
   imgStyle = document.getElementById(imgClass + "Over").style;
         imgStyle.clip = clipVal;
         imgStyle.visibility = "visible";

}

// image swapping event handling 
function imgSwap(evt) {
   evt = (evt) ? evt : event;                   // equalize event models
   var elem = (evt.target) ? evt.target : evt.srcElement;
   var imgClass = elem.parentNode.name;         // get map element name
   var coords = elem.coords.split(",");         // convert coords to clip
   var clipVal = "rect(" + coords[1] + "px " +
                           coords[2] + "px " +
                           coords[3] + "px " +
                           coords[0] + "px)";
   var imgStyle;
   
   switch (evt.type) {
     
      case "mouseout" :
         document.getElementById(imgClass + "Over").style.visibility = "hidden";
         document.getElementById(imgClass + "Down").style.visibility = "hidden";
         break;
      case "mouseover" :
         imgStyle = document.getElementById(imgClass + "Over").style;
         imgStyle.clip = clipVal;
         imgStyle.visibility = "visible";
         break

		 
	  
  	  case "mouseup" :
       document.getElementById(imgClass + "Down").style.visibility = "hidden";
         // guarantee click in IE
       if (elem.click) {
             elem.click();
         }
         break;
		 
		
   }
   evt.cancelBubble = true;
   return false;
}