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_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_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];}
}
function MM_effectGrowShrink(targetElement, duration, from, to, toggle, referHeight, growFromCenter)
{
	Spry.Effect.DoGrow(targetElement, {duration: duration, from: from, to: to, toggle: toggle, referHeight: referHeight, growCenter: growFromCenter});
}

function MM_effectAppearFade(targetElement, duration, from, to, toggle)
{
	Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}

function letternumber(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function sethtmlfieldvalue (currentform,destination,val) {
//	alert('in here');
//warning no error checking yet
	eval('document.'+currentform+'.'+destination+'.value = "'+val+'"');
}
	
function gethtmlfieldvalue (currentform,destination) {
	//warning no error checking yet
	return eval('document.'+currentform+'.'+destination+'.value');
	
}


function setmessage(message)
{
//document.getElementById("message").innerHTML =message;
document.getElementById("message2").innerHTML ="<BR>"+message;
//return document.MM_returnValue;

}
//generic getvalue function - this will retrieve a value via ajax and set it to the destination form and destination form field
function getvalue (table,pkname,pkvalue,field,destform,destination) {
		var temp;
		document.getElementById('xmlretrieved').value = 'false';
		ajaxgetvalue(table,pkname,pkvalue,field,destform,destination);
	//	var i = 1;
	//	do { //do nothing while we wait for xml to comeback - set to true in ajaxgetvalue when retrieved
		//i = i + 1;		
		//alert('in loop!');
	//	} while ((document.getElementById('xmlretrieved').value == 'false'));
		
		i = 1;
		
//alert( 'mlretrieved');
		temp = document.getElementById('tempvar').value;
		return temp;
		

}


function ajaxgetvalue(tblname,pkname,pkvalue,fieldname,destform,destination) 
{
//for this function to work you must have an input field called tempvar to hold the value being passed back--- I changed func so that you have to specify the destination of where this value will go to deal with the issues I encountered with asynchronous retrieval of values.  This just tells javascript where the value has to go ...
// use getvalue function
var xmlhttp=false;
var resp ='';
var url = 'ajaxgetdbvalue.php?tablename='+tblname+'&pkname='+pkname+'&pkvalue='+pkvalue+'&fieldname='+fieldname;
//alert(url);
//destination = '_itemname';
//destform = 'designer39';
//alert('dest1'+destination);
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}	
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			resp = xmlhttp.responseText;
			//			alert('resp'+resp);
			//tempvar = ''+resp;
			document.getElementById('tempvar').value = resp;	
			//document.getElementById('tempvar2').value = resp;	
			eval('document.'+destform+'.'+destination+'.value = resp');
			
		//	alert('dest'+destination);
			} else {

			}//closes if else statement
			
	}//closes function
		
		//ert(a)
		xmlhttp.send(null);	
		document.getElementById('xmlretrieved').value = 'true';
	//	a = document.getElementById('tempvar').value;
	 //   return a;
	// document.getElementById('xmlretrieved').value = true;
}

//only allows numbers to be entered into a field
function isNumberKey(evt) {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 45 || charCode > 57))
            return false;

         return true;
// example of usage- put this event handler in a text field: onkeypress="return isNumberKey(event)"

      }
//adds a new loader event to get around onload being in template
function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      oldonload(); 
	      func(); 
	    } 
	  } 	
	}
//example of adding a load event:
//addLoadEvent(function() { 
// enter what you want to happen on load in here						
//} )

	
//rounds numbers to 2 decimals
function round2(original) {
return Math.round(original*100)/100;  //returns 28.45
}


//SUBMIT ONLY ONCE
/*
* This notice must be untouched at all times.

submitonlyonce.js    
The latest version is available at
http://sarat.xcelens.co.uk/2005/06/08/submit-only-once-forms/

Copyright (c) 2005 Sarat Pediredla. All rights reserved.
Last modified: 09/06/2005

This code snippet adds submit only once functionality to any forms on your site.

USAGE:
Just include the script at the end of your page before the closing </body> tag like follows (assuming the js file is in the same directory as your html file ),



LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

For more details on the GNU Lesser General Public License,
see http://www.gnu.org/copyleft/lesser.html
*/

function doSubmitOnce(currentForm)
{
	// Run through elements and disable submit buttons
	for(i=0;i<currentForm.length;i++)
	{
		var currentElement = currentForm.elements[i];
		if(currentElement.type.toLowerCase() == "submit")
			currentElement.disabled = true;
	}
}


// We need to register our submit once function on all forms
if(document.all||document.getElementById) 
{	
	// Run through all forms on page
	for(i=0;i<document.forms.length;i++)
	{
		var currentForm = document.forms[i];
		// Register event handler
		// Use quirksmode idea for flexible registration by copying existing events
		var oldEventCode = (currentForm.onsubmit) ? currentForm.onsubmit : function () {};
		currentForm.onsubmit = function () {oldEventCode(); doSubmitOnce(currentForm)};
	}
}




	