
//******** Functions for store shopping pages ***********

// Pre-cache the images and display them on the product page
function load_images() 
{ var I, numpics;
  var tn_Table = document.getElementById("tntable");
  var imgNodelist = tn_Table.getElementsByTagName("img");
  numpics = imgNodelist.length;
  for(I = 0; I < numpics; I++) //Cache the images
  	 { if( prod[I] != "?" ) 
	 	 {  imgcache[I] = new Image(); 
	  		imgcache[I].src = "images/06s/" + prod[I] + ".jpg"; }
	 }
  for(I = 0; I < numpics; I++) imgNodelist[I].src = imgcache[I].src;
  
  // Create objects for use in other procs
  Radio_Table = document.getElementById("radiobtns");
  BtnList = Radio_Table.getElementsByTagName("input");
  SpanList = Radio_Table.getElementsByTagName("span");

  // Specify the PayPal Account ID for the buttons
  document.buyform.business.value = "paypal@safaripark.org";
  document.showcartform.business.value = "paypal@safaripark.org";
}

function select_item(selected_id)
{ mSelected_Prod = selected_id;
  document.getElementById("prodimg").src = imgcache[mSelected_Prod].src;
  document.getElementById("prodname").firstChild.data = itemname[mSelected_Prod];
  document.getElementById("proddesc").firstChild.data = itemdesc[mSelected_Prod];
  
  // Reset all the size selection radio buttons to enabled and not checked
  var I;  for(I = 0; I < BtnList.length; I++)
  			{ BtnList[I].checked = false; BtnList[I].disabled = false; }
  mSelected_Price = "";  // Indicate that no size/price has been selected
  
  // Change prices and availability of the product sizes/prices
  eval( "prod" + mSelected_Prod + "()" );
}

function select_size(sizenum, sizedesc) 
{ mSelected_Price = prices[sizenum];
  document.buyform.item_name.value = itemname[mSelected_Prod] + " - " + sizedesc;
  document.buyform.item_number.value = prod[mSelected_Prod];
  document.buyform.amount.value = mSelected_Price;
  // document.buyform.add.value = quantity to buy
}

function formcheck() 
{ if( mSelected_Price > "") return true
  else { alert("Please select a size."); return false; }
}

//******** End of functions for store shopping pages ***********


//******** Functions for the main store shopping page ***********
function acct() 
{ document.buyform1.business.value = "paypal@safaripark.org";
  document.buyform2.business.value = "paypal@safaripark.org";
  document.buyform3.business.value = "paypal@safaripark.org";
  document.buyform4.business.value = "paypal@safaripark.org";
  document.showcartform.business.value = "paypal@safaripark.org";
}

function showpic(htmfile, nwidth, nheight)
{
if(window_opened) newwin.close();
newwin = open(htmfile,"Menu","width=" + nwidth + ",height=" + nheight + ",resizable,");
window_opened = true;
newwin.focus();
}
//******** End of functions for main store shopping page ***********


//******** Functions for donation page ***********

function usedfor(p_usedfor) { mSelected_Use = p_usedfor; }

function don_amount(p_donamt) { mSelected_Amt = p_donamt; }

function donate_formcheck() 
{ if (mSelected_Use.length == 0)
		{ alert("Please select the purpose of your donation."); 
  	      return false; }

  if( mSelected_Amt == 0 ) 
  		{ alert("Please select the amount of your donation."); 
  	      return false; }
  
  if( mSelected_Amt == -1 ) //Other amount was selected
  		if( !check_donamt(document.all.otheramt) ) return false;
		  
  document.donateform.item_name.value = "Donation for " + mSelected_Use;
  document.donateform.item_number.value = "Donation";
  document.donateform.amount.value = mSelected_Amt;
  // document.donateform.add.value = quantity to buy
  return true;
}

function check_donamt(p_txtamt)
{ //check the otheramt text field for a valid dollar amount
	  if(p_txtamt.value.length == 0) 
		{ alert("Please enter the amount of your donation.");
		  p_txtamt.focus(); }
	  else if(isNaN(p_txtamt.value))
	    	 { alert("Please enter a dollar amount without the '$' sign.");
		  	   p_txtamt.focus(); }
	  	   else
		     { mSelected_Amt = parseFloat(p_txtamt.value);
			   if(mSelected_Amt > 1000) 
	    		 { alert(" Web site donations are accepted up to a maximum of $1000." 
				 	   + "\n For larger amounts please contact us directly.");
		  	  	  mSelected_Amt = -1;
				  p_txtamt.focus(); }
			   else if(mSelected_Amt < 10) 
			  		 { alert("The minimum donation amount is $10. Please change the amount.");
		  	  	  	   mSelected_Amt = -1;
		  	  	  	   p_txtamt.focus(); }
					else return true; //The entered amount is ok.
			 }
	  return false; //The entered amount is bad. 
}

//******** End of functions for donation page ***********


function dotest()
  { //alert("do test");
    alert("document.smallpic.length=" + document.smallpic.length);
	alert("document.radioform.prodsize.length=" + document.radioform.prodsize.length);
  //alert(document.forms[0].elements[0].value);
    //alert(document.forms[0].item_name.value);
    //alert(document.buyform.item_name.value);
	//alert(document.buyform.item_number.value);
    //alert(document.buyform.amount.value);
    //alert(document.buyform.add.value);
	//document.buyform.submit.disabled = false; - Can't disable the button
    // alert(document.all.prodname.innerText);
    // document.all.prodname.innerText = "New Product Name";
	
	//var sp = 0, sz = 1, prix ;
	//prix = eval( "price" + sp + "[sz]" );
	//alert(prix);
  }

