		 
		    // change images to buttons on menu top and header menu
	  	function change_to_alt_event(obj)
	  		{
	  		 if (obj!=null)
	   			obj.style.backgroundImage="url('images/header-add-r.jpg')";  
	  		}
	  
	  	function change_to_normal_event(obj)
	  		{
	   		 if (obj!=null)
	   			obj.style.backgroundImage="url('images/header-add-trans.gif')";   
	  		} 


function getInnerText(node,ignorewhitespace)
{
 var text = "";
 // if the node has children, loop through them
 if(node.hasChildNodes())
 {
  var children = node.childNodes;
  for(var i=0; i<children.length; i++)
  {
   // if node is a text node append it
   if(children[i].nodeName == "#text")
   {
    if(ignorewhitespace)
    {
     if(!/^\s+$/.test(children[i].nodeValue))
     {
      text = text.concat(children[i].nodeValue);
     }
    }
    else
    {
     text = text.concat(children[i].nodeValue);
    }
   }
   // if node is a line break append \n
   else if(children[i].nodeName == "BR")
   {
    text = text.concat("\n");
   }
   // otherwise call this function again to get the text
   else
   {
    text = text.concat(getInnerText(children[i]));
   }
  }
 }
 // it has no children, so get the text
 else
 {
  // if node is a text node append it
  if(node.nodeName == "#text")
  {
   text = text.concat(node.nodeValue);
  }
  // if node is a line break append \n
  else if(node.nodeName == "BR")
  {
   text = text.concat("\n");
  }
 }
 return text;
}

	function setError(focusField, errorDivId, msg) {
	
	    errorDiv = document.getElementById(errorDivId);
	
	    if(!errorDivId) {
	      errorDiv = document.getElementById('struts_error');
	    }
	    
		errorDiv.innerHTML = msg;
		
		if(focusField) {
			focusField.focus();
		}
		
	}

	//format dd/mm/yyyy
	function getDate(strDate) {
	  
	   	dt = new Date();
	    dt.setDate( strDate.substring(0,2) );
	    dt.setMonth( strDate.substring(3,5) - 1 );
	    dt.setFullYear( strDate.substring(6,10) );
	    
	    return dt;
	   
	}

	//format dd/mm/yyyy
	function getDayStart(strDate) {
	  
	   	dt = new Date();
	    dt.setDate( strDate.substring(0,2) );
	    dt.setMonth( strDate.substring(3,5) - 1 );
	    dt.setFullYear( strDate.substring(6,10) );
	    dt.setHours(0);
	    dt.setMinutes(0);
	    dt.setSeconds(0);
	    dt.setMilliseconds(0);
	    
	    return dt;
	   
	}

	//format dd/mm/yyyy
	function getDayEnd(strDate) {
	  
	   	dt = new Date();
	    dt.setDate( strDate.substring(0,2) );
	    dt.setMonth( strDate.substring(3,5) - 1 );
	    dt.setFullYear( strDate.substring(6,10) );
	    dt.setHours(23);
	    dt.setMinutes(59);
	    dt.setSeconds(59);
	    dt.setMilliseconds(999);
	    
	    return dt;
	   
	}

	function getEndOfTheDay() {
	  
	   	dt = new Date();
	    dt.setHours(23);
	    dt.setMinutes(59);
	    dt.setSeconds(59);
	    dt.setMilliseconds(999);
	    
	    return dt;
	   
	}

  
  function getAttribute(elemId, attr) {
	
	  var elem = document.getElementById(elemId);
	  
	  for( var x = 0; x < elem.attributes.length; x++ ) {
		if( elem.attributes[x].nodeName.toLowerCase() == attr ) {
			
				return elem.attributes[x].nodeValue;
				
		}
	  }

   }	
   
   // date differences 
  function YDDiff(years,days) {
		this.years = years;
		this.days = days;
		}
		
	YDDiff.prototype.toString = function() {
	return this.years;// + "y" + this.days +"d";
	};

   function diffYearAndDate(d1,d2) {
	// ensure d1 <= d2
	if (d1 > d2) { return diffYearAndDate(d2,d1); }

	// find n whole years later than d1 in d2's year.
	var dt = new Date(d1);
	dt.setFullYear(d2.getFullYear());
	// n whole years later > d2
	var overflow = (dt > d2);
	// max whole years later than d1 less than d2
	dt = new Date(d1);
	dt.setFullYear(d2.getFullYear() - overflow);
	// whole years from d1 to dt
	var years = dt.getFullYear() - d1.getFullYear();
	// days from dt to d2, less than whole year from dt
	var days = Math.round((d2 - dt)/864e5);
	return new YDDiff(years,days);
	}  
   
// wager ticket modal dialog   
var ticket_ModalDisplay = false;   
var ticket_Obj;

function ticket_openDialog(ticketId)
{
		if (!ticket_ModalDisplay)
		{
			ticket_ModalDisplay = true;
			ticket_Obj = new DHTMLSuite.modalMessage();	// We only create one object of this class
			ticket_Obj.setWaitMessage('Loading window - please wait....');
			ticket_Obj.setShadowOffset(5);	// Large shadow
			ticket_Obj.width=600;
			ticket_Obj.height=340;
			ticket_Obj.setSource("viewTicket.do?ticketId=" + ticketId);
			ticket_Obj.display();
		}     
	}	

function ticket_close()
	{     
		ticket_Obj.close();
		ticket_ModalDisplay = false;
	}
   
   
	  function padleft(val, ch, num) {
            var re = new RegExp(".{" + num + "}$");
            var pad = "";

            do  {
                pad += ch;
            }while(pad.length < num)

            return re.exec(pad + val);
        }
        function padright(val, ch, num){
            var re = new RegExp("^.{" + num + "}");
            var pad = "";

            do {
                pad += ch;
            } while (pad.length < num)

            return re.exec(val + pad);
        }	    
   
 // quit for registration
 	var regQuitObj;
			
	function regQuit()
		{
			// load transfer popup
			regQuitObj = new DHTMLSuite.modalMessage();	// We only create one object of this class
			regQuitObj.setWaitMessage('Loading window - please wait....');
			regQuitObj.setShadowOffset(5);	// Large shadow
			regQuitObj.width=613;
			regQuitObj.height=400;
			regQuitObj.isMovable = true;
			regQuitObj.setSource("registrationQuit.do");
			regQuitObj.display();
		}	
					
	function regQuit_Cancel()
		{
			regQuitObj.close();
		}  
   
   
function openW(mypage,myname,w,h,features) {
	
	if(screen.width) {
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	} else {
	    winl = 0;
	    wint =0;
	}
	if (winl < 0) 
	  winl = 0;
	if (wint < 0) 
	  wint = 0;

	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
	
}   

function ismaxlength(obj, mlength){

  if (obj.value.length>mlength)
	obj.value = obj.value.substring(0,mlength)
	
}

//-------------------------Custom onload functionality --------------

var functionsToCallOnLoad;
if(functionsToCallOnLoad==null){
	functionsToCallOnLoad = new Array;
}

	
/*
 * Registers a fucntion to be called on window.onload
 */
function registerFuntionToCallOnLoad(tFunction){
	//alert("Adding "+tFunction+" to call onload");
	functionsToCallOnLoad.push(tFunction);	
}
	
/*
 * Called on window.onload, it then calls any functions that have been registered using the 
 * registerFuntionToCallOnLoad function
 */
function myOnLoad(){
	for(var i=0; i < functionsToCallOnLoad.length;i++){

		functionsToCallOnLoad[i].call();
	}
}
	
window.onload = function () {
	myOnLoad();		
};
//-----------------------------------------------------------

function RetrieveFormattedTime()
{
	var digital = new Date();
	var hours = digital.getHours();
	var minutes = digital.getMinutes();
	var seconds = digital.getSeconds();
	var amOrPm = "AM";
	if (hours > 11) amOrPm = "PM";
	if (hours > 12) hours = hours - 12;
	if (hours == 0) hours = 12;
	if (minutes <= 9) minutes = "0" + minutes;
	if (seconds <= 9) seconds = "0" + seconds;
	dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm;
	return dispTime;
}

// Clock for using Server Time
<!-- Original:  Tomleung (lok_2000_tom@hotmail.com) This tag should not be removed-->
<!--Server time ticking clock v2.0 Updated by js-x.com-->
function MakeArrayday(size)
{
  this.length = size;
  for(var i = 1; i <= size; i++)
    this[i] = "";
  return this;
}
function MakeArraymonth(size)
{
  this.length = size;
  for(var i = 1; i <= size; i++)
    this[i] = "";
  return this;
}

var hours;
var minutes;
var seconds;
var timer=null;
function sClock(h, m, s)
{
  hours=h;
  minutes=m;
  seconds=s;
  work();
  if(timer){clearInterval(timer);timer=null;}
  timer=setInterval("work();",1000);
}

function twoDigit(_v)
{
  if(_v<10)_v="0"+_v;
  return _v;
}

function work()
{
  if (!document.layers && !document.all && !document.getElementById) return;
  var runTime = new Date();
  var dn = " AM";
  var shours = hours;
  var sminutes = minutes;
  var sseconds = seconds;
  if (shours >= 12)
  {
    dn = " PM";
    shours-=12;
  }
  if (!shours) shours = 12;
  sminutes=twoDigit(sminutes);
  sseconds=twoDigit(sseconds);
  //shours  =twoDigit(shours  );
  movingtime = ""+ shours + ":" + sminutes +":"+sseconds+"" + dn;
  if (document.getElementById)
    document.getElementById("time_field").innerHTML=movingtime;
  else if (document.layers)
  {
    document.layers.time_field.document.open();
    document.layers.time_field.document.write(movingtime);
    document.layers.time_field.document.close();
  }
  else if (document.all)
    time_field.innerHTML = movingtime;

  if(++seconds>59)
  {
    seconds=0;
    if(++minutes>59)
    {
      minutes=0;
      if(++hours>23)
      {
        hours=0;
      }
    }
  }
}
      
		function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}
		
		function getWindowWidth() {
			var windowWidth = 0;
			if (typeof(window.innerWidth) == 'number') {
				windowWidth = window.innerWidth;
			}
			else {
				if (document.documentElement && document.documentElement.clientWidth) {
					windowWidth = document.documentElement.clientWidth;
				}
				else {
					if (document.body && document.body.clientWidth) {
						windowWidth = document.body.clientWidth;
					}
				}
			}
			return windowWidth;
		}
		
		function centerElementOnWindow(contentElement) {
						
			if (document.getElementById) {
		
				var scroll_val_h = 0;
				if (window.pageYOffset)
					scrool_val_h = window.pageYOffset;

				if (document.body.scrollTop)
					scroll_val_h = document.body.scrollTop;
					
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
					var contentHeight = contentElement.offsetHeight;
										
					//if (contentHeight==0) contentHeight = 450;
					if (windowHeight - contentHeight > 0) {
															
						contentElement.style.position = 'absolute';
						contentElement.style.top = (((windowHeight) / 2) - (contentHeight / 2)+scroll_val_h) + 'px';
					}
					else {
						contentElement.style.position = 'absolute';
						contentElement.style.top = 50;
					}
				}
				
				
				//document.body.scrollTop:window.pageYOffset
				
				var windowWidth = getWindowWidth();
				if (windowWidth > 0) {
				
					var scroll_val_w = 0;
					if (window.pageXOffset)
						scroll_val_w = window.pageXOffset;

					if (document.body.scrollLeft)
						scroll_val_w = document.body.scrollLeft;
				
				
					var contentWidth = contentElement.offsetWidth;
					if (windowWidth - contentWidth > 0) {
						contentElement.style.position = 'absolute';
						contentElement.style.left = (((windowWidth) / 2) - (contentWidth / 2)+scroll_val_w) + 'px';
					}
					else {
						contentElement.style.position = 'static';
					}
				}
				
			}
		}
	  
// cristian
// TagType is optional 
 
function getNodeByIdName(objParent,idName,TagType)	
{
//alert("intrat");
var childList = new Array(100);
	childList[0]=objParent;
	var childNr=1;



	for (i=0;i<childNr;i++)
	{
		var objToGoChild = childList[i];


		for(var childIndex = 0; childIndex < objToGoChild.childNodes.length; childIndex++ ) 
			{
		 	
		 	/*if ((objToGoChild.childNodes[childIndex].tagName=="DIV")||
		 	(objToGoChild.childNodes[childIndex].tagName=="SPAN")||
		 	(objToGoChild.childNodes[childIndex].tagName=="TABLE")||
		 	(objToGoChild.childNodes[childIndex].tagName=="TR")||
		 	(objToGoChild.childNodes[childIndex].tagName=="TD"))
		 		{*/
		 			childList[childNr] = objToGoChild.childNodes[childIndex];
				 	childNr++;
				//}
			
			
					
			if (TagType!=null)
			{
				if (((objToGoChild.childNodes[childIndex].id==idName)||(objToGoChild.childNodes[childIndex].name==idName))&&(objToGoChild.childNodes[childIndex].tagName == TagType))
					{ 
						//alert("gasit - "+objToGoChild.childNodes[childIndex].tagName + " - "+objToGoChild.childNodes[childIndex].name);
						return(objToGoChild.childNodes[childIndex]);
					}		
			} else 
				if (objToGoChild.childNodes[childIndex].id==idName)
				{ 
					//alert("gasit - "+objToGoChild.childNodes[childIndex].tagName);
					return(objToGoChild.childNodes[childIndex]);
				}		
			
			}
			
	}


return null;
}  
	  
	  
	  
	  
// add handlers for movable pop-up	  //cristian
	  
function setMoveWindow ()
	{
	 	var mainModalDiv = document.getElementById("DHTMLSuite_modalBox_contentDiv");
	
		if (mainModalDiv==null)
			{
	 			 setTimeout("setMoveWindow()",1500);
	 			 return;
	 		}

		var idwithEls = null;

		idwithEls=getNodeByIdName(mainModalDiv,"DHTMLSuite_modalBox_contentDiv_move");
			
		if (idwithEls==null)
			{
	 			 setTimeout("setMoveWindow()",1500);
	 			 return;
	 		}


		var agt=navigator.userAgent.toLowerCase();
			
		//alert((document.all)?document.body.scrollTop:window.pageYOffset);
		
		idwithEls.style.top = "-"+mainModalDiv.style.top;
		idwithEls.style.left = "-"+mainModalDiv.style.left;
		idwithEls.style.width = mainModalDiv.style.width;		
		idwithEls.style.height = mainModalDiv.style.height;
			
		var dragObjss = new DHTMLSuite.dragDropSimple({ elementReference: idwithEls, cloneNode:false });
		//centerElementOnWindow(mainModalDiv);
		//mainModalDiv.style.display = "block";
		
		
		// added by cristian
	}	  
	  
function isDefined(variable)
{
	return eval('(typeof(' + variable + ') != "undefined");');
}


// when the key enter is pressed on a field from a form 
// the form is submited
function handleKeyPress(e,form){
		var key=e.keyCode || e.which;
			if (key==13)
				{
				 form.submit();
				}
		}

/* 
	It is used display or collapse the selected races from modal pop-up, Wager ticket, statement
*/
function displayRaces(obj, show, hide)
{
	var divElement = getNodeByIdName(document.getElementById("DHTMLSuite_modalBox_contentDiv"),"ticket_selections_div","DIV");
	
	if (divElement.style.display == "none")
		{
			obj.innerHTML = hide;
			divElement.style.display = "block";
		}
		else
		{
			obj.innerHTML = show;
			divElement.style.display = "none";
			//alert(document.getElementById('ticket_selections_div_').style.display);
		}		
}

function event_mouse_class_over(obj)
	{
		obj.className = "over";
	}
	
function event_mouse_class_normal(obj)
	{
		obj.className = "";
	}
	
function iButtonOut(obj, cls)
{
obj.firstChild.className = cls;
obj.lastChild.className = cls;
}

function iButtonOver(obj, cls)
{
obj.firstChild.className = cls;
obj.lastChild.className = cls;
}	

function button_enable(obj)
{
	if ( obj.className.indexOf("_disabled") > 0 ) {
		obj.className = obj.className.substring(0, obj.className.indexOf("_disabled"));
	}
	obj.disabled = false;
}

function button_disable(obj)
{
	if ( obj.className.indexOf("_disabled") < 0 ) {
		obj.className = obj.className + "_disabled";
	}
	obj.disabled = true;
}

function button_follow_link(obj)
{
	location.href = obj.getAttribute("link");
}

function validateNumericField(e,obj)
	{
	
		var key=e.keyCode || e.which;
		
			//enter
			if (key == 13)
				{
				 return true;
				}
				
			// backspace
			if (key == 8)
				{
				 return true;
				}
			
			//tab
			if (key == 9)
				{
				 return true;
				}
	
			//keys between 0 - 9
			if (key >= 48 && key <=57)
				{
				 return true;
				}
	
			//keys between 0 - 9 fom right part of the keyboard
			if (key >= 96 && key <=105)
				{
				 return true;
				}
	
			// left key
			if (key == 37)
				{
				 return true;
				}
			
			// right key
			if (key == 39)
				{
				 return true;
				}

			//delete
			if (key == 46)
				{
				 return true;
				}
	
		return false;
	}
	
var objectEventInit = null;	
	
function setMDownEffect (evt)
	{

	if (!evt) var evt = window.event;
	if (evt.target) targ = evt.target;
	else if (evt.srcElement) targ = evt.srcElement;
	
	if ((targ.type == "button" || targ.type == "submit" || targ.type == "reset")
		&& objectEventInit == null 
		&& (targ.className == "button_menu" || 
		targ.className == "button_menu_selected" ||
		targ.className == "button_menu2" ||
		targ.className == "button_menu2_selected" ||
		targ.className == "button_menu3" ||
		targ.className == "button_menu3_selected" ||
		(targ.id.indexOf("wp_bt_button") >= 0 && (targ.className == "" || targ.className == "selected")) ||
		(targ.id.indexOf("wp_amt_button") >= 0 && (targ.className == "" || targ.className == "selected")) ||
		(targ.id.indexOf("-r") == 0 && (targ.className == "" || targ.className == "selected")) ))
		{
			objectEventInit = targ;
			var obj = targ;
			if (obj.className.indexOf("_over") < 0)
				{	
					if (obj.className == "")
						{
							obj.className = obj.className + "normal_over";
						}
						else
						{
							obj.className = obj.className + "_over";
						}
				}
		}	
	}

function setMUpEffect (evt)
	{
	
		if (objectEventInit != null 
			&& (objectEventInit.type == "button" || objectEventInit.type == "submit" || objectEventInit.type == "reset")
			&& (objectEventInit.className == "button_menu_over" 
			|| objectEventInit.className == "button_menu_selected_over" 
			|| objectEventInit.className == "button_menu2_over" 
			|| objectEventInit.className == "button_menu2_selected_over"
			|| objectEventInit.className == "button_menu3_over" 
			|| objectEventInit.className == "button_menu3_selected_over"
			|| objectEventInit.className == "normal_over"
			|| (objectEventInit.id.indexOf("wp_bt_button") >= 0 && (objectEventInit.className == "_over" || objectEventInit.className == "selected_over")) 
			|| (objectEventInit.id.indexOf("wp_amt_button") >= 0 && (objectEventInit.className == "_over" || objectEventInit.className == "selected_over")) 
			|| (objectEventInit.id.indexOf("-r") == 0 && (objectEventInit.className == "_over" || objectEventInit.className == "selected_over"))
			 ))
		{
			var obj = objectEventInit;
			
			if (obj.className.indexOf("normal_over") >= 0)
				{
					obj.className = obj.className.substr(0,obj.className.indexOf("normal_over"));
				}
				
				
			if (obj.className.indexOf("_over") >= 0)
				{
					obj.className = obj.className.substr(0,obj.className.indexOf("_over"));
				}
			
			objectEventInit = null;
		}	
	
		
	}	
	
	
/* popup error message */
/* -- *//* -- *//* -- *//* -- *//* -- */

var popupError_Obj;
var popSelectedField;
function popupErrorMessage(key, message, field) {
	var url = "errormessage.do?message=" + escape(key) + "&detail=" + escape(message);
	popupError_Obj = new DHTMLSuite.modalMessage();	// We only create one object of this class
	popupError_Obj.setShadowOffset(5);	// Large shadow
	popupError_Obj.width = 321;
	popupError_Obj.height = 265;
	popupError_Obj.setSource(url);
	popupError_Obj.isMovable = true;
	popupError_Obj.display();
	popSelectedField = null;
	if (field != null) {
		popSelectedField = field;
	}
}
function addErrorToList(errorKeys, errorMessages, errorFields, key, message, field) {
	var idx = errorKeys.push(key);
	errorMessages[idx] = message;
	errorFields[idx] = field;
}
function popupMultipleErrorMessages(keyArray, messageArray, fieldArray) {
	popSelectedField = null;
	var url = "errormessage.do?";
	var i;
	for (i = 0; i < keyArray.length; i++) {
		if (i == 0) {
			url += "message" + i + "=";
		} else {
			url += "&message" + i + "=";
		}
		url += escape(keyArray[i]) + "&detail" + i + "=" + escape(messageArray[i]);
		if ((popSelectedField == null) && (fieldArray[i] != null)) {
			popSelectedField = fieldArray[i];
		}
	}
			//message=" + escape(key) + "&detail=" + escape(message);
	popupError_Obj = new DHTMLSuite.modalMessage();	// We only create one object of this class
	popupError_Obj.setShadowOffset(5);	// Large shadow
	popupError_Obj.width = 321;
	popupError_Obj.height = 265;
	popupError_Obj.isMovable = true;
	popupError_Obj.setSource(url);
	popupError_Obj.display();
}
function displayMultipleErrorMessages(targetDiv, keyArray, messageArray, fieldArray) {
	var url = "errorlist.do?";
	var i;
	for (i = 0; i < keyArray.length; i++) {
		if (i == 0) {
			url += "message" + i + "=";
		} else {
			url += "&message" + i + "=";
		}
		url += escape(keyArray[i]) + "&detail" + i + "=" + escape(messageArray[i]);
		if ((popSelectedField == null) && (fieldArray[i] != null)) {
			popSelectedField = fieldArray[i];
		}
	}
	ajax_loadContent(targetDiv, url); 	
}
function closePopupErrorMessage() {
	popupError_Obj.close();
	if (popSelectedField != null) {
		popSelectedField.focus();
	}
	if ((popupError_Obj.url).indexOf('on_deposit.Message1') >= 0) {
		location.href="/login.do";
	}
}

//----------------------------------------------------------------
function resetCMSLinks()
	{
	    cmsPushedLink = null;
		for (i=1; i<=10; i++)
			if (document.getElementById("cmsLink" + i) != null)
				{
					var element = document.getElementById("cmsLink" + i);
					if (element.className != cmsLinkHrefClass)
						{
							if (element.className.indexOf("_over")>0)
							{
								element.className = element.className.substr(0,element.className.indexOf("_over"));
							}
						}
				}
				
	}	
	
function headerMouseOut(obj)
	{
		if (obj.id != cmsPushedLink)
			{
				if (obj.className.indexOf("_over"))
					{
						obj.className = obj.className.substr(0,obj.className.indexOf("_over"));
					}
			}
	}
	
function headerMouseOver(obj)
	{
		
		if (obj != cmsPushedLink && obj.className.indexOf("_over") < 0)
			{
				obj.className = obj.className + "_over";
			}
		//alert(obj.className);
	}	

/* Only clicked submit button is sent */
function formGetParameters(f, clickedSubmit) {

  var formElements = "";
  var firstElem = true;
  for (var n=0; n < f.elements.length; n++) {
      if(firstElem) {
        if(addFormElement(f.elements[n], clickedSubmit)) {
	        formElements += "?" + f.elements[n].name + "=" +  interpretField(f.elements[n], clickedSubmit);
	        firstElem = false;
	    }
      }  else { 
        if(addFormElement(f.elements[n], clickedSubmit)) {
	        formElements += "&" + f.elements[n].name + "=" +  interpretField(f.elements[n], clickedSubmit);
	    }
      }
  }
  return formElements;
  
}

function addFormElement(field, clickedSubmit) {

	if (field.type && field.type == "submit") {
	  if(clickedSubmit && clickedSubmit != "" && field.name != clickedSubmit) {
		return false;
	  }
	}
		
	return true;
}
	
function interpretField(field)
	{	
		var value;
		value = field.value;
		if (field.type && field.type == "checkbox")
		{
			if (field.checked == true)
				{
					value = URLEncode(value);
					return value;
				}
				else
				{
					return "";
				}
		}
		
		value = URLEncode(value);
		
		return (value);
	}
	
	
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
 
   return plaintext;
}
	
	
	