//########################################
//### RAINMAKER ITV SPECIFIC FUNCTIONS ###
//########################################



/*** DROP-DOWN MENU FUNCTIONS ***/


 /*** DROP-DOWN MENU BOX ***/

	function DROPMENUinitialise()
		{

		  document.write("<div id='DROPMENUarea' style='float:left;position:absolute;display:none;z-index:100;background-color:"+client_values["menu_background_out"]+";border-left:1px solid "+client_values["menu_border"]+";border-right:1px solid "+client_values["menu_border"]+";border-top:1px solid "+client_values["menu_border"]+";text-align:left' onmouseover='DROPMENUclear();' onmouseout='DROPMENUhideDelay(event);'></div>");

		}


 /*** CREATE THE DROP-DOWN MENU ***/

	function DROPMENUmake(obj,channel_name,minimum_width,top_position_adjustment)
		{

			// => close any open menus
				DROPMENUclear();

			// => if no programs exist for this channel
				if(!channel_program[channel_name])
					{
						// => hide any menu currently open
							DROPMENUhide();

						// => return
							return;
					}

			// => create drop-down menu levels
				if(page["url_segment"][1]=="custom")
					{
						var url_start="/"+page["url_segment"][1]+"/"+page["url_segment"][2]+"/";
					}
				else
					{
						var url_start="/";
					}

				var a="<div id='DROPMENUmenu' style='float:left;'>";

				for(program_name in channel_program[channel_name])
					{

						var sub_programs_exist=typeof channel_sub[channel_name]!="undefined"&&typeof channel_sub[channel_name][program_name]!="undefined";

						a+="<div style='position:relative;'>";

							// => program
							a+="<div id='DROPMENUarea_program_"+channel_program[channel_name][program_name]["oid"]+"' onmouseover=\"DROPMENUshowSub('"+channel_name.replace(/'/g,"\\'")+"','"+program_name.replace(/'/g,"\\'")+"');this.style.backgroundColor='"+client_values["menu_background_over"]+"';\" onmouseout='this.style.backgroundColor=\"\";' onclick='DROPMENUhide();document.location=\""+url_start+(page["url_segment"][1]=="custom"?"video/":"pages/")+channel_program[channel_name][program_name]["url"]+"\";' style='position:relative;border-bottom:1px solid "+client_values["menu_border"]+";' class='cursor'>";

								a+="<table cellpadding='4' cellspacing='0'>";
								a+="<tr>";
								a+="<td style='white-space:nowrap;'>"+program_name+(channel_program[channel_name][program_name]["new"]?dropmenuNewIcon():"")+"</td>";
								a+="<td align='right' style='padding-left:5px;'>"+(sub_programs_exist?"<div style='width:4;height:7px;font-size:1px;' class='arrow_right_white_4x7'></div>":"")+"</td>";
								a+="</tr>";
								a+="</table>";

							a+="</div>";

							// => sub-programs
							if(sub_programs_exist)
								{

									a+="<div id='DROPMENUarea_sub_"+channel_program[channel_name][program_name]["oid"]+"' style='display:none;position:absolute;top:-1px;background-color:"+client_values["menu_background_out"]+";'>";
									
									a+="<div style='border-left:1px solid "+client_values["menu_border"]+";border-right:1px solid "+client_values["menu_border"]+";border-top:1px solid "+client_values["menu_border"]+";'>";
		
									for(var sub_program_name in channel_sub[channel_name][program_name])
										{
			
											var sub_sub_programs_exist=typeof channel_sub_sub[channel_name]!="undefined"&&typeof channel_sub_sub[channel_name][program_name]!="undefined"&&typeof channel_sub_sub[channel_name][program_name][sub_program_name]!="undefined";
		
											a+="<div onmouseover=\"DROPMENUshowSubSub(\'"+channel_name.replace(/'/g,"\\'")+"\',\'"+program_name.replace(/'/g,"\\'")+"\',\'"+sub_program_name.replace(/'/g,"\\'")+"\');this.style.backgroundColor=\'"+client_values["menu_background_over"]+"\';\" onmouseout='this.style.backgroundColor=\"\";' style='position:relative;'>";
				
												a+="<div onclick='DROPMENUhide();document.location=\""+url_start+"pages/"+channel_sub[channel_name][program_name][sub_program_name]["url"]+"\";' style='border-bottom:1px solid "+client_values["menu_border"]+";' class='cursor'>";
						 
													a+="<table cellpadding='4' cellspacing='0'>";
													a+="<tr>";
													a+="<td style='white-space:nowrap;'>"+sub_program_name+(channel_sub[channel_name][program_name][sub_program_name]["new"]?dropmenuNewIcon():"")+"</td>";
													a+="<td style='padding-left:5px;padding-right:20px;'>"+(sub_sub_programs_exist?"<div style='width:4;height:7px;font-size:1px;' class='arrow_right_white_4x7'></div>":"")+"</td>";
													a+="</tr>";
													a+="</table>";
						 
												a+="</div>";
		
												// => sub-sub-programs
												if(sub_sub_programs_exist)
													{
									
														a+="<div id='DROPMENUarea_sub_sub_"+channel_sub[channel_name][program_name][sub_program_name]["oid"]+"' style='display:none;position:absolute;top:-1px;background-color:"+client_values["menu_background_out"]+";'>";
														
														a+="<div style='border-left:1px solid "+client_values["menu_border"]+";border-right:1px solid "+client_values["menu_border"]+";border-top:1px solid "+client_values["menu_border"]+";'>";
													 
															for(var sub_sub_program_name in channel_sub_sub[channel_name][program_name][sub_program_name])
																{
												
																	 a+="<div onmouseover='this.style.backgroundColor=\""+client_values["menu_background_over"]+"\";' onmouseout='this.style.backgroundColor=\"\";' onclick='DROPMENUhide();document.location=\""+url_start+"pages/"+channel_sub_sub[channel_name][program_name][sub_program_name][sub_sub_program_name]["url"]+"\";' style='border-bottom:1px solid "+client_values["menu_border"]+";' class='cursor'>";
															 
																		a+="<table cellpadding='4' cellspacing='0'>";
																		a+="<tr>";
																		a+="<td style='white-space:nowrap;padding-right:20px;'>"+sub_sub_program_name+(channel_sub_sub[channel_name][program_name][sub_program_name][sub_sub_program_name]["new"]?dropmenuNewIcon():"")+"</td>";
																		a+="</tr>";
																		a+="</table>";
															 
																	 a+="</div>";
												
																}
													 
														a+="</div>";
													 
														a+="</div>";
									
													}
		
		
											a+="</div>";
		
										}
		
									a+="</div>";
		
									a+="</div>";
		
								}

						a+="</div>";

					}

				a+="</div>";

				var dropmenuobj=areaID("DROPMENUarea");

				dropmenuobj.innerHTML=a;

				areaShow(dropmenuobj);

			// => get the maximum width of a "program"
				var max_width=minimum_width;
			
				var total_programs=0;
			
				for(var tmp_program_name in channel_program[channel_name])
					{
						if(total_programs==0)
							{
								var program_height=areaID("DROPMENUarea_program_"+channel_program[channel_name][tmp_program_name]["oid"]).childNodes[0].clientHeight;
							}
						
						max_width=Math.max(max_width,areaID("DROPMENUarea_program_"+channel_program[channel_name][tmp_program_name]["oid"]).childNodes[0].clientWidth);
						
						total_programs++;
					}
		
			// => adjust the width of programs to the maximum program width
				for(var tmp_program_name in channel_program[channel_name])
					{
						areaID("DROPMENUarea_program_"+channel_program[channel_name][tmp_program_name]["oid"]).style.width=max_width+"px";
					}

			// => position the drop-down menu
				var drop_pos=areaPos(obj,false,true);

				dropmenuobj.style.left=(drop_pos["x"]-(dropmenuobj.offsetWidth-obj.offsetWidth))+"px";
				dropmenuobj.style.top=(drop_pos["y"]+obj.offsetHeight+top_position_adjustment)+"px";

/*
	function DROPMENUoffset(obj,offset)
		{

			var total_offset=eval("obj.offset"+offset);
			
			var parent_obj=obj.offsetParent;
			
			while(parent_obj!=null)
				{
					total_offset=eval("total_offset+parent_obj.offset"+offset);
					parent_obj=parent_obj.offsetParent;
				}
			
			return total_offset;

		}
*/

			// => show scroll-bar if more than 20 programs
				if(total_programs>20)
					{
						areaID("DROPMENUmenu").style.overflowY="auto";
						areaID("DROPMENUmenu").style.height=((program_height+1)*20)+"px";
						areaID("DROPMENUmenu").style.width=parseInt(dropmenuobj.clientWidth)+"px";
					}

		}

	function DROPMENUclear()
		{

			if(page["menu_delay_hide"])
				{
					clearTimeout(page["menu_delay_hide"]);
					
					page["menu_delay_hide"]=undefined;
				}

		}

	function DROPMENUhideDelay(e)
		{

			if((document.all&&!areaID("DROPMENUarea").contains(e.toElement))||(e.currentTarget!=e.relatedTarget&&!DROPMENUhideContains(e.currentTarget,e.relatedTarget)))
				{
					DROPMENUhideDelayDo();
				}

		}

	function DROPMENUhideContains(a,b)
		{

			while(b.parentNode)
				{
					b=b.parentNode;
					
					if(b==a)
						{
							return true;
						}
				}

			return false;

		}

	function DROPMENUhideDelayDo()
		{

			page["menu_delay_hide"]=setTimeout(DROPMENUhide,500);

		}

	function DROPMENUhide()
		{

			areaShow("DROPMENUarea",1);

		}

	function dropmenuNewIcon()
		{

			return "<img src='/media/itv/icon_new.gif' align='absmiddle' style='width:35px;height:12px;margin-left:3px;' title='New!'>";

		}


	function DROPMENUshowSub(channel_name,program_name)
		{
		
			// => show sub-programs
				for(var tmp_program_name in channel_program[channel_name])
					{
						areaShow("DROPMENUarea_sub_"+channel_program[channel_name][tmp_program_name]["oid"],tmp_program_name!=program_name);
					}
		
			// => get the maximum width of a "program" and "sub-program"
				var max_program_width=0;
				var max_sub_width=0;
			
				for(var tmp_program_name in channel_program[channel_name])
					{

						if(tmp_program_name==program_name)
							{

								max_program_width=Math.max(max_program_width,areaID("DROPMENUarea_program_"+channel_program[channel_name][tmp_program_name]["oid"]).clientWidth);
	
								var tmp_obj=areaID("DROPMENUarea_sub_"+channel_program[channel_name][tmp_program_name]["oid"]);
								
								if(tmp_obj)
									{
										max_sub_width=Math.max(max_sub_width,tmp_obj.clientWidth);
									}

							}

					}
		
			// => adjust the position/width of sub-programs
				for(var tmp_program_name in channel_program[channel_name])
					{

						if(tmp_program_name==program_name)
							{

								var tmp_obj=areaID("DROPMENUarea_sub_"+channel_program[channel_name][tmp_program_name]["oid"]);
	
								if(tmp_obj)
									{
										tmp_obj.style.left=max_program_width+"px";
										tmp_obj.style.width=max_sub_width+"px";
									}

							}

					}

		}


	function DROPMENUshowSubSub(channel_name,program_name,sub_program_name)
		{
		
			// => show sub-sub-programs
				for(var tmp_sub_program_name in channel_sub[channel_name][program_name])
					{
						areaShow("DROPMENUarea_sub_sub_"+channel_sub[channel_name][program_name][tmp_sub_program_name]["oid"],tmp_sub_program_name!=sub_program_name);
					}
		
			// => get the maximum width of a "sub-program"
				var max_sub_width=0;
			
				for(var tmp_program_name in channel_program[channel_name])
					{
						var tmp_obj=areaID("DROPMENUarea_sub_"+channel_program[channel_name][tmp_program_name]["oid"]);
						
						if(tmp_obj)
							{
								max_sub_width=Math.max(max_sub_width,tmp_obj.clientWidth);
							}
					}
		
			// => get the maximum width of a "sub-sub-program"
				var max_sub_sub_width=0;
			
				for(var tmp_sub_sub_program_name in channel_sub[channel_name][program_name])
					{
						var tmp_obj=areaID("DROPMENUarea_sub_sub_"+channel_sub[channel_name][program_name][tmp_sub_sub_program_name]["oid"]);
						
						if(tmp_obj)
							{
								max_sub_sub_width=Math.max(max_sub_sub_width,tmp_obj.clientWidth);
							}
					}

			// => adjust the position/width of sub-sub-programs
				for(var tmp_sub_program_name in channel_sub[channel_name][program_name])
					{
						
						var tmp_obj=areaID("DROPMENUarea_sub_sub_"+channel_sub[channel_name][program_name][tmp_sub_program_name]["oid"]);
						
						if(tmp_obj)
							{
								tmp_obj.style.left=(max_sub_width-2)+"px";
								tmp_obj.style.width=max_sub_sub_width+"px";
							}
						
					}

		}




















/*** AREA SCROLL ***/

	function areaScroll(id,left_top,scroll_distance,timeout,more_function)
		{

			// => continue if the up/down scroll button is still being pressed
			if(areaScrollDirection!=0)
				{

					// => move the blurb area up/down depending on the direction selected
						eval("areaID('"+id+"').scroll"+(left_top=="left"?"Left":"Top")+"+=(areaScrollDirection*"+scroll_distance+");");

					// => run again in a short period
						setTimeout("areaScroll('"+id+"','"+left_top+"',"+scroll_distance+","+timeout+",'"+(more_function?more_function:"")+"');",timeout);

					// =>
						if(more_function)
							{
								eval(more_function);
							}

				}

		}





/*** URL FUNCTIONS ***/


 /*** FIX THE URL FOR CHANNELS/PROGRAMS ***/
 
  function URLfix(url)
   {

    url=url.toLowerCase();
	url=url.replace(/\s/g,"_");
	url=url.replace(/\'/g,"%27");
	url=url.replace(/\?/g,"%3F");
    url=url.replace(/\|/g,"");

    return url;

   }


/*** BLURB => MORE/LESS ***/

 function BLURBshow(blurb_id,show)
  {
   areaID("AREAblurb_"+blurb_id+"-more0").style.display=show?"":"none";
   areaID("AREAblurb_"+blurb_id+"-more1").style.display=show?"none":"";
  }















//##############################
//### GENERIC MAIN FUNCTIONS ###
//##############################







if(typeof page=="undefined")
	{
		page=[];
	}


/*** STATS ***/

	if(page["ip_address"]!=""&&page["ip_address"]!=cookieGet("ip_address"))
		{
			// document.write("<img src='/stats/log/' style='position:absolute;width:1px;height:1px;'>");
		}


/*** GENERAL FUNCTIONS ***/


/*** GLOBAL VALUES ***/

		page["url_segment"]=location["pathname"].split("/");

	// => user values
		user=[];




/*** CAPTURE ALL KEY PRESSES ***/

	keyStore=function(e)
		{
			keyObj=e=e||window.event;

			if(e.keyCode)
				{
					keyCode=keyObj.keyCode;
				}
			else if(e.which)
				{
					keyCode=keyObj.which;
				}

			keyCharacter=String.fromCharCode(keyCode).toLowerCase();
		}

	keyCode=null;
	document.onkeydown=keyStore;



/*** ONLOAD ***/

	// => add functions to run once the page has loaded
		page["onload"]="";

	// => the status of whether the page has loaded
		page["loaded"]=false;
		pageLoadedAdd("page['loaded']=true;");
				
	// => load functions once the page has loaded
		window.onload=new Function("setTimeout(\"eval(page['onload'])\");");

		function pageLoadedAdd(string)
			{
				// => if the page has already loaded, run the function
					if(page["loaded"]==true)
						{
							eval(string);
						}
					else
						{
							page["onload"]+=string;
						}
			}






	/*** BROWSER ***/
	
		// => is internet explorer and what version?
			page["browser_ie"]=browserAgent().search(/msie/)>=0&&browserAgent().search(/(opera|safari|webtv|mac)/)==-1;
			page["browser_ie_version"]=0;

			var tmp=browserAgent().match(/msie\s*([\d\.]+)/);

			if(tmp)
				{
					page["browser_ie_version"]=tmp[1]/1;
				}

			function browserAgent()
				{
					return navigator.userAgent.toLowerCase();
				}

		// => the amount scrolled down the browser window
		function browserScrollPosition()
			{
			
				if(window.pageYOffset)
					{
						return window.pageYOffset;
					}
				else
					{
						return document.documentElement.scrollTop;
					}
				
			}

		// => the height of the viewable browser window (does not include scrolling)
			// type => either "width" or "height"
		function browserSizeViewable(type)
			{
				var type_new=type=="width"?"Width":"Height";

				if(window.innerHeight)
					{
						return eval("window.inner"+type_new);
					}
				else
					{
						var size=eval("document.documentElement.client"+type_new);
						
						if(size>0)
							{
								return size;
							}
						else
							{
								return eval("document.documentElement.scroll"+type_new)-4; // -4 adjustment is for IE
							}
					}
			}


		// => the total height of the browser window (including scrolling)
		function browserSizeTotal(type)
			{
				var type_new=type=="width"?"Width":"Height";

				// => get the size of the browser window
					if(window.innerHeight&&window.scrollMaxY)
						{
							var size=eval("window.inner"+type_new+"+window.scrollMax"+(type=="width"?"X":"Y"));
						}
					else
						{
							var size=eval("document.documentElement.scroll"+type_new)-4; // -4 adjustment is for IE
						}

				// => if the page isn't scrolled then some browsers only show the height up to the end of the page and therefore the entire viewable screen height is not correct. if the size calculated above is less than the calculated viewable area then use the calculated viewable area
					return Math.max(browserSizeViewable(type),size);
			}

/*
		// => scroll the page up/down if there is less than "margin" space between the object given and the top/bottom of the browser window
			// margin => the minimum distance (pixels) between the object and the top/bottom of the browser window before the page scrolls up/down => optional (default = 50)
		function browserScrollCheck(id,margin)
			{

				// => values
					var scrollTop=browserScrollPosition();

					var objPosTop=areaPos(id)["y"];
					var objPosBottom=objPosTop+areaID(id).scrollHeight;

					if(!margin&&margin!==0)
						{
							margin=50;
						}

					var browserHeight=browserSizeViewable("height");

				// => scroll down?
					if(((browserHeight+scrollTop)-objPosBottom)<margin)
						{
							window.scrollTo(0,objPosBottom-(browserHeight/2));
						}

				// => scroll up?
					if((objPosTop-scrollTop)<margin)
						{
							window.scrollTo(0,objPosTop-(browserHeight/2));
						}

			}
*/



	/*** LINE FUNCTIONS ***/

		// => left to right
			function lineFade(type,width,color)
				{

					styleAddPNG(".line_fade_"+type+"_"+color+"_"+width,"/media/images/lines/fade_"+type+"_"+color+"_"+width+".png");

					return "<div style='width:"+width+"px;height:1px;overflow:hidden;' class='line_fade_"+type+"_"+color+"_"+width+"'></div>";

				}




/*** STYLE => ADD A STYLE RULE IN THE STYLESHEET ***/

	// rule => the css rule, eg ".class_name"
	// file => the location of the png file
	function styleAddPNG(rule,png)
		{

			// => create the rule depending on the user's browser
				if(page["browser_ie"])
					{
	
styleAdd(rule,"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=scale,src='"+png+"');");
					}
				else
					{
						styleAdd(rule,"background-image:url("+png+");");
					}

		}

	styleRules=[];

	// rule => the css rule, eg ".class_name"
	// string => the style specification, eg: "background-color:#FFFFFF;"
	function styleAdd(rule,string)
		{

			// => add the rule if it doesn't exist
				if(typeof styleRules[rule]=="undefined")
					{

						// => add the rule to the list so the style isn't created again
							styleRules[rule]=true;

						// => get the stylesheet object
							if(document.createStyleSheet) // => ie
								{
									var sheet=document.createStyleSheet();
								}
							else // => DOM standard
								{
									var styleElement=document.createElement("style");
									document.getElementsByTagName("head")[0].appendChild(styleElement);
									var sheet=styleElement.styleSheet?styleElement.styleSheet:styleElement.sheet;
								}

						// => add style
							if(!sheet) // => opera and other browsers with no DOM stylesheet support
								{

									// => build the html for the <style> element from the rule
										styleElement.innerHTML=rule+"{"+string+"}";

								}
							else if(sheet.addRule) // => ie
								{

									// => add the rule
										sheet.addRule(rule,string,0);

								}
							else if(sheet.insertRule) // => DOM standard
								{

									// => add the rule
										sheet.insertRule(rule+"{"+string+"}",0); // ,sheet.cssRules.length
								}

					}

		}







	/*** OVERLAY LAYER ***/

		for(var b=0; b<=3; b++)
			{
				document.write("<div id='area_overlay_transparent_"+b+"' style='position:absolute;display:none;z-index:999;width:100%;'></div>");
			}


	page["overlay_layer_current"]=-1;

	// document.write("<div id='area_overlay_text' style='position:absolute;display:none;z-index:100;opacity:1;filter:alpha(opacity=100);-moz-opacity:1;'></div>");

	// string => the string to put into the area => OPTIONAL
				// => if not given the overlay area is hidden
	// title => exists if to use a title at the top of the box => OPTIONAL
	// transparent_level => exists if the transparent level of the background overlay is not the default 50 => OPTIONAL
	// align_top => exists if the area is to be positioned at the top instead of the default middle => OPTIONAL
		// => a number is given if to position the box ?px from the top
	// no_box => exists if the area doesn't need to have a border and box around it => OPTIONAL
	function overlayMake(title,string,transparent_level,align_top,no_box,close_link,close_button)
		{

			// => stop the "loading" interval if it is being used
				if(typeof overlayLoadingInterval!="undefined"&&overlayLoadingInterval!=null)
					{
						clearInterval(overlayLoadingInterval);
						overlayLoadingInterval=null;
					}

			// => fill/empty the overlay "text" area				
				if(string)
					{

						// => if upper level is being used
							//if(upper_layer)
								{
									page["overlay_layer_current"]++;
								}

							var overlay_obj=areaID("area_overlay_transparent_"+page["overlay_layer_current"]);

						// => update the transparent level
							overlay_obj.className="transparent_"+(transparent_level?transparent_level:50);

						// => "transparent" layer height
							overlay_obj.style.height=browserSizeTotal("height")+"px";

						// => show "select" boxes because "select" boxes go over the top of the overlay
							page["overlay_close_"+page["overlay_layer_current"]]=(close_link?close_link:"overlayMake();");

							areaHideSelectBoxes(true);

							var a="";

							// => padding if the scroll position is not at the top of the page
								if(browserScrollPosition()>0)
									{
										a+="<div style='height:"+browserScrollPosition()+"px;overflow:hidden;font-size:0px;'></div>"
									}

							// => content table
								a+="<div class='link_white_underline'>";
								
								a+="<table cellpadding='10' cellspacing='0' style='width:100%;height:"+browserSizeViewable("height")+"px;'>";
								a+="<tr>";
								a+="<td"+(align_top?" valign='top'"+(isNaN(align_top)?"":" style='padding-top:"+align_top+"px;'"):"")+" align='center'>"
								
								// => this text box is focussed on after the area has been created to prevent the page from scrolling down further
								a+="<input id='overlay_focus' type='text' style='position:absolute;width:0px;left:-10px;'>";

								a+="<table cellpadding='0' cellspacing='0'>";
								a+="<tr>";
								a+="<td align='left' class='overlay_text'>";

								if(no_box)
									{
										a+=string;
									}
								else
									{
										a+="<table cellpadding='0' cellspacing='0' class='overlay_box'>";
										a+="<tr>";
										a+="<td>";
										
										a+="<div style='position:relative;'>";
										a+="<div align='center' onclick=\""+page["overlay_close_"+page["overlay_layer_current"]]+"\" style='position:absolute;right:-1px;padding:2px;padding-left:7px;padding-right:7px;' class='font_ll overlay_box_close cursor' title='Close'><b>X</b></div>";
										a+="</div>";
										
										a+="<div id='overlay_box_style' style='padding:10px;'>";

										// => title - optional
											if(title)
												{
													a+="<div style='padding-right:25px;'>";
														a+="<div class='font_lll'><b>"+title+"</b></div>";
	
														a+=lineFade("left_to_right",230,"white");
	
														a+="<div style='width:300px;height:10px;overflow:hidden'></div>";
													a+="</div>";
												}

										// => area
											a+=string;

										// => "close" button
											if(close_button)
												{
													a+="<div style='height:15px;overflow:hidden'></div>";

													a+="<div align='center'>";
													a+="<input type='button' value='"+(typeof close_button=="string"?close_button:" OK ")+"' onclick=\""+page["overlay_close_"+page["overlay_layer_current"]]+"\" style='padding-left:5px;padding-right:5px;' class='overlay_button'>";
													a+="</div>";
												}
										
										a+="</div>";


										a+="</td>";
										a+="</tr>";
										a+="</table>";
									}

								a+="</td>";
								a+="</tr>";
								a+="</table>";

								a+="</td>";
								a+="</tr>";
								a+="</table>";
								
								a+="</div>";

								areaPut("area_overlay_transparent_"+page["overlay_layer_current"],a);
								areaShow("area_overlay_transparent_"+page["overlay_layer_current"]);

							// => the "escape" key hides the box
								overlay_obj.onkeyup=overlayMakeEscape;

/*
							// => focus on the box so that the "escape" key function above works
								// => focussing on the box moves the page to the top, so scroll the browser window to the previous position
								var scroll_pos=browserScrollPosition();

								overlay_obj.focus();

								window.scrollTo(0,scroll_pos);
*/

							// => focus on the overlay in a short period of time - doing so immediately doesn't work in IE
								// => any areaSelect() calls in this period are added to the list to be performed after this timeout period
								page["overlay_focus_timeout"]=setTimeout("page['overlay_focus_timeout']=undefined;clearTimeout(page['overlay_focus_timeout']);for(var b in page['overlay_focus_timeout_do']){areaSelect(page['overlay_focus_timeout_do'][b]);};page['overlay_focus_timeout_do']=undefined;");

								page["overlay_focus_timeout_do"]=["overlay_focus"];

					}
				else
					{

						var overlay_obj=areaID("area_overlay_transparent_"+page["overlay_layer_current"]);

						if(page["overlay_layer_current"]<0)
							{
								page["overlay_layer_current"]=0;
							}

						areaPut(overlay_obj,"");
						
						areaShow(overlay_obj,1);

						// => the "escape" key now does nothing
							overlay_obj.onkeyup=null;

						// => if upper level is being used
							//if(upper_layer)
								{
									page["overlay_layer_current"]=Math.max(page["overlay_layer_current"]-1,-1);
								}

						// => show "select" boxes again
							areaHideSelectBoxes();

					}

		}

		// => hide the overlay if the "escape" key is pressed
		function overlayMakeEscape(e)
			{
				if(keyCode==27)
					{
						eval(page["overlay_close_"+page["overlay_layer_current"]]);
					}
			}

		// => create the "loading" overlay
			// string => the string to use if not the default "LOADING" => optional
		function overlayMakeLoading(string,small_size,no_graphic,return_str)
			{

				// => the size (width/height) of the "loading" area
					var loading_size=small_size?80:98;

				// => create the overlay
					var a;

					a="<div align='center' id='area_overlay_loading'>";
			
					var show_loading_graphic=false;/*!no_graphic&&!(page["browser_ie"]&&page["browser_ie_version"]<7);*/
			
					if(show_loading_graphic)
						{
							a+="<div style='position:relative;width:"+loading_size+"px;height:"+loading_size+"px;overflow:hidden;'>";
							a+="<div id='area_overlay_loading_img' style='position:relative;left:0px;width:"+(loading_size*8)+"px;height:"+loading_size+"px;' class='overlay_loading_"+(small_size?"small":"big")+"'></div>";
							a+="</div>"
							a+="<div style='height:10px;overflow:hidden;'></div>";
						}

					a+="<div align='center' style='letter-spacing:5px;' class='font_white font_ll"+(small_size?"":"ll")+"'><b>"+(string?string:"LOADING").toUpperCase()+"</b></div>";

					a+="</div>";

				// => return the string or put it into the overlay
					if(return_str)
						{
							// => create the "loading" effect
								if(show_loading_graphic)
									{
										overlayLoadingIndex=0;
										overlayLoadingInterval=setInterval("overlayMakeLoadingInterval("+loading_size+");",150);
									}

							// => return the string
								return a;
						}
					else
						{
							// => create the overlay
								overlayMake(false,a,false,false,true);

							// => create the "loading" effect
								if(show_loading_graphic)
									{
										overlayLoadingIndex=0;
										overlayLoadingInterval=setInterval("overlayMakeLoadingInterval("+loading_size+");",150);
									}
						}

			}

		// => the "loading" interval that is called to change the "loading" image
		function overlayMakeLoadingInterval(loading_size)
			{

				// => move onto the next image
					overlayLoadingIndex=overlayLoadingIndex>6?0:overlayLoadingIndex+1;

				// => update the image
					areaID("area_overlay_loading_img").style.left="-"+(overlayLoadingIndex*loading_size)+"px";

			}

		// => return success/failure
			// error => success if empty
		function overlayMakeLoadingReturn(form_name,error,return_str)
			{

				// => stop the rotating loading graphic
					if(typeof overlayLoadingInterval!="undefined"&&overlayLoadingInterval!=null)
						{
							clearInterval(overlayLoadingInterval);
							overlayLoadingInterval=null;
						}

				// => show the "saved"/"error" overlay
					var a="<div align='center' onclick='clearTimeout(overlayMakeLoadingReturnTimeout);overlayMake();' class='cursor' title='Click to close'><div style='width:174px;height:174px;' class='overlay_"+(error?"error":"saved")+"'></div></div>";

					if(error)
						{
							a+="<div style='width:300px;padding:5px;border:1px solid #FF0000;background-color:#FF9595;color:#FF0000;'>"+error+"<div style='height:5px;overflow:hidden;'></div><div align='center'>[ <a href='javascript:clearTimeout(overlayMakeLoadingReturnTimeout);overlayMake();' style='color:#FF0000'>Close</a> ]</div></div>";	
						}

				// => if "success"
					if(!error)
						{
							// => reset the "data_changed" values
								data_changed=false;

								if(typeof dataChangedReset!="undefined")
									{
										dataChangedReset();
									}

							// => hide the "success" overlay in 2 seconds
								overlayMakeLoadingReturnTimeout=setTimeout("clearTimeout(overlayMakeLoadingReturnTimeout);overlayMake();",2000);
						}

				// => re-enable the "save" button
					if(form_name)
						{
							document.forms[form_name]["submit"].disabled=false;
						}

				// => 
					if(return_str)
						{
							return a;
						}
					else
						{
							if(areaID("area_overlay_loading"))
								{
									areaPut("area_overlay_loading",a);
								}
							else
								{
									overlayMake(false,a,false,false,true,"clearTimeout(overlayMakeLoadingReturnTimeout);overlayMake();");
								}
						}

			}

		// => add functions to the overlay area on "keyup"
			// overwrite_existing => used if to remove any existing onkeyup functions
		function overlayAddKeyUp(str,remove_existing)
			{
				var overlay_obj=areaID("area_overlay_transparent_"+page["overlay_layer_current"]);
				
				overlay_obj.onkeyup=new Function((remove_existing?"":areaStripFunction(overlay_obj).onkeyup)+str);
			}



/*** SCROLLING TEXT FUNCTIONS ***/

	// => initialise scrolling text
	function scrollInitialise(id,speed,spacer,scroll_regardless)
		{
			// => create the "scrolling" array if it hasn't been created previously
				if(typeof page["scrollers"]=="undefined")
					{
						page["scrollers"]=[];
					}

			// => make the scroll area only 1 line
				var id_obj=areaID(id);
				id_obj.style.overflow="hidden";
				id_obj.style.whiteSpace="nowrap";

			// => continue loading the scroll once the page has loaded
				pageLoadedAdd("page['scrollers']['"+id+"']=new scrollInitialiseLoaded('"+id+"',"+speed+",\""+spacer+"\","+scroll_regardless+");");
		}

	// => continue loading the scroll once the page has loaded
	function scrollInitialiseLoaded(id,speed,spacer,scroll_regardless)
		{
			// => get the area object
				id=areaID(id);

			// => don't scroll the area if the width is less than the available width
				if(!scroll_regardless&&parseInt(id.scrollWidth)<parseInt(id.clientWidth))
					{
						return;	
					}

			// => adjust the properties of the scrolling text area
				id.style.position="relative";
				id.style.overflow="hidden";
				id.style.whiteSpace="nowrap";
				id.onmouseover=new Function("page['scrollers']['"+id.id+"'].pause=true;");
				id.onmouseout=new Function("page['scrollers']['"+id.id+"'].pause=false;");

			// => change the height of the scrolling area
				id.style.height=parseInt(id.clientHeight)+"px";

			// => duplicate the scrolling area
				area_str=areaGet(id,true)+spacer;

				var a="";

				a+="<div id='"+id.id+"_1' style='position:absolute;left:0px;'>"+area_str+"</div>";
				a+="<div id='"+id.id+"_2' style='position:absolute;left:0px;'>"+area_str+"</div>";
				a+="<div id='"+id.id+"_3' style='position:absolute;left:0px;'>"+area_str+"</div>";

				areaPut(id,a);

				this.area1=areaID(id.id+"_1");
				this.area2=areaID(id.id+"_2");
				this.area3=areaID(id.id+"_3");

			// => the current area
				this.current=1;

			// => adjust scrolling width
				this.scrollWidth=parseInt(this.area1.scrollWidth);

			// => position the areas
				this.area2.style.left=parseInt(this.scrollWidth)+"px";
				this.area3.style.left=parseInt(this.scrollWidth*2)+"px";

				this.position1=0;
				this.position2=parseInt(this.scrollWidth);
				this.position3=this.position2*2;

			// => the area begins scrolling by default
				this.pause=false;

			// => scroll the text
				setInterval("scrollInitialiseInterval('"+id.id+"');",speed);
		}

	// => scroll the area
	function scrollInitialiseInterval(id)
		{
			// => only scroll the area if the scrolling area is not paused
				if(page["scrollers"][id].pause==false)
					{
						// => scroll the area back 1 pixel
							page["scrollers"][id].position1--;
							page["scrollers"][id].position2--;
							page["scrollers"][id].position3--;
						// => 
							if(eval("page['scrollers'][id].position"+page["scrollers"][id].current)==(-page["scrollers"][id].scrollWidth))
								{
									eval("page['scrollers'][id].position"+page["scrollers"][id].current+"=page['scrollers'][id].scrollWidth*2");

if(page["scrollers"][id].current==1)
{
	page["scrollers"][id].current=2;
}
else if(page["scrollers"][id].current==2)
{
	page["scrollers"][id].current=3;	
}
else
{
	page["scrollers"][id].current=1;
}
								}

				page["scrollers"][id].area1.style.left=page["scrollers"][id].position1+"px";
				page["scrollers"][id].area2.style.left=page["scrollers"][id].position2+"px";
				page["scrollers"][id].area3.style.left=page["scrollers"][id].position3+"px";
					}
		}


	/*** FORM FUNCTIONS ***/

		// => create an array of form values
			// form => form name
			// get_all => exists if to get all values for form fields regardless of whether they have values, ticked, etc. -> optional

		// result
			// get_all				-	off					on

			// checkbox				-	string/array*		string/array*
			// radio				-	string				array
			// select(single)		-	string				array
			// select(multiple)		-	array				array
			// all others			-	string				string

			// * = a string if only 1 checkbox option OR an array if multiple checkbox options

		function formArray(form,get_all)
			{

				var form_obj=document.forms[form];
				var form_array=[];
				var form_names_exist=[];

				for(var b=0; b<form_obj.length; b++)
					{
						var fieldName=form_obj[b].name;

						if(fieldName)
							{

								// => remove "[]" from the field name
									var fieldNameUse=fieldName.replace(/\[\]/,"");

								// => add the form field depending on whether it contains multiple items or not
									if(typeof form_array[fieldNameUse]=="undefined")

										{
											if(fieldName.search(/\[\]/)>-1)
												{
													form_array[fieldNameUse]=[];
												}
											else
												{
													form_array[fieldNameUse]="";
												}
										}

								// => get the form box name/value depending on its type
									if(form_obj[b].type=="checkbox")
										{

											// => if the form name already exists and it is a string, convert it to an array
												if(form_names_exist[fieldNameUse]&&typeof form_array[fieldNameUse]=="string")
													{
														var tmp_option=form_array[fieldNameUse];

														form_array[fieldNameUse]=[];
														
														if(tmp_option!="")
															{
																form_array[fieldNameUse].push(tmp_option);
															}
													}

											// => add the value if the value is added regardless or if it's checked
												if(get_all||form_obj[b].checked)
													{
														if(typeof form_array[fieldNameUse]=="object")
															{
																form_array[fieldNameUse].push(form_obj[b].value);
															}
														else
															{
																form_array[fieldNameUse]=form_obj[b].value;
															}
													}

										}
									else if(form_obj[b].type=="radio")
										{

											// => add the value
												if(get_all) // => add the value regardless
													{
														if(typeof form_array[fieldNameUse]!="object")
															{
																form_array[fieldNameUse]=[];
															}
														form_array[fieldNameUse].push(form_obj[b].value);
													}
												else if(form_obj[b].checked) // => the value is checked
													{
														form_array[fieldNameUse]=form_obj[b].value;
													}

										}
									else if(form_obj[b].type=="select-multiple"||(get_all&&form_obj[b].type=="select"))
										{

											// => this item is an array
												form_array[fieldNameUse]=[];

											// => iterate through items in the select box
												for(var c=0; c<form_obj[b].length; c++)
													{
														if(get_all||form_obj[b].options[c].selected)

															{
																form_array[fieldNameUse].push(form_obj[b].options[c].value);
															}
													}

										}
									else if(form_obj[b].type!="submit"&&form_obj[b].type!="button")
										{
											if(fieldName.search(/\[\]/)>-1)
												{
													form_array[fieldNameUse].push(areaValueGet(form_obj[b]));
												}
											else
												{
													form_array[fieldNameUse]=areaValueGet(form_obj[b]);
												}
										}
									else
										{
											form_array[fieldNameUse]=undefined;
											
											continue;
										}
								
								form_names_exist[fieldNameUse]=true;
							}
					}

				var form_array_new=[];

				for(var b in form_array)
					{
						if(typeof form_array[b]!="undefined")
							{
								form_array_new[b]=form_array[b];
							}
					}

				return form_array_new;

			}







/*** RANDOM CHARACTERS ***/

	function randomLetters(length)
		{

			var string="";

			for(var b=0; b<length; b++)
				{
					string+="abcdefghijklmnopqrstuvwxyz".charAt(numberRandom(26));
				}

			return string;

		}





	/*** AREA FUNCTIONS ***/


		/*** AREA => ELEMENT OBJECT ***/

			// id => id name of the element
			function areaID(id)
				{
					return typeof id!="object"?document.getElementById(id):id;
				}

		/*** AREA => PUT STRING INTO AN AREA ***/

			// id => box id OR object
			// string => string
			// add => exists if to add to the existing html => optional
			function areaPut(id,string,add)
				{
					if(add)
						{
							areaID(id).innerHTML+=string;
						}
					else
						{
							areaID(id).innerHTML=string;
						}
				}

		/*** AREA => GET STRING STRING FROM AN AREA ***/

			// id => box id OR object
			// html => exists if to get the html instead of the text only => default is text
			function areaGet(id,html)
				{
					if(html)
						{
							return areaID(id).innerHTML;
						}
					else
						{
							return areaID(id).innerText;
						}
				}

		/*** AREA => SET OPACITY LEVEL ***/

			// opacity => opacity level: 0 - totally transparent, 100 - no transparency
			function areaOpacitySet(id,opacity)
				{
					var id=areaID(id);

					id.style.opacity=opacity/100;
					id.style.filter="alpha(opacity="+opacity+")";
				}

			function areaOpacityString(opacity)
				{
					return "opacity:"+(opacity/100)+";filter:alpha(opacity="+opacity+");-moz-opacity:"+(opacity/100)+";";	
				}


		/*** AREA => GET THE CONTENTS OF A FUNCTION ***/

		function areaStripFunction(function_string)
			{
				return (function_string+"").substring((function_string+"").indexOf("{")+1,(function_string+"").lastIndexOf("}")-1);	
			}


	/*** AREA => ADD VERTICAL SCROLLERS TO AN AREA ***/

		// area_height => the height of the scroll area
		// scroll_outside => exists if the scroll bars are to go on the outside of the area
		function areaScrollersAdd(area_name,height_per_item,area_height,fix_width_areas,scroll_outside)
			{

				setTimeout("areaScrollersAddDo('"+area_name+"',"+height_per_item+","+area_height+","+(fix_width_areas?1:0)+","+(scroll_outside?1:0)+");",50);

			}

		function areaScrollersAddDo(area_name,height_per_item,area_height,fix_width_areas,scroll_outside)
			{

				// => inner scroll area
					var scroll_area_scroll=areaID(area_name+"_scroll");

				// => height per item in the scroll area (this is the default height, although the height of items can change - ie, get bigger/smaller
					page["scroller_"+area_name+"_height_per"]=height_per_item;

				// => the number of items to show within the screen
					// => 80% of the screen height is used
					page["scroller_"+area_name+"_show"]=Math.floor(area_height/page["scroller_"+area_name+"_height_per"]);

				// => the height of the restricted scroll area
					var tmp_height_new=page["scroller_"+area_name+"_show"]*page["scroller_"+area_name+"_height_per"];

				// => if the scroll area height is more than the shown area, adjust the height
					if(parseInt(scroll_area_scroll.scrollHeight)>tmp_height_new)
						{
							// => outer scroll area
								var scroll_area=areaID(area_name);

							// => these should be done on the page since this script is called from a timeout and the suggest function can therefore run before this
							// => making the scroll area float to the "left" removes the 100% default of a div
								// scroll_area.style.styleFloat="left";

							// => the scroll area must be positioned "relative" so that things such as suggestion boxes are positioned correctly
								// scroll_area.style.position="relative";

							// => add scroll bars
								try
									{
										scroll_area.style.overflow="-moz-scrollbars-vertical";
									}
								catch(err)
									{
										scroll_area.style.overflowY="auto";
									}

							// => adjust height of outer scroll area
								scroll_area.style.height=tmp_height_new+"px";

							// => adjust width of inner scroll area
								var new_width=parseInt(scroll_area.scrollWidth)+(scroll_outside?0:-18);

								scroll_area_scroll.style.width=new_width+"px";

							// => adjust width of outer scroll area if scroll bars are to go on the outside of the area
								if(scroll_outside)
									{
										scroll_area.style.width=(parseInt(scroll_area.scrollWidth)+18)+"px";
									}

							// => adjust width of any other areas since adding scrollbars adjusts the width of the inner scroll area
								if(fix_width_areas)
									{
										for(var b in fix_width_areas)
											{
												areaID(fix_width_areas[b]).style.width=new_width+"px";
											}
									}

							// => add "runningHeight" values depending on the scroll area type
								var scroll_area_rows=areaID(area_name+"_rows");

								if(scroll_area_rows)
									{

										if(scroll_area_rows.tagName.toUpperCase()=="TABLE")
											{
												scroll_area_rows=scroll_area_rows.childNodes[0];
		
												var running_height=0;
		
												for(var b=0; b<scroll_area_rows.childNodes.length; b++)
													{
														scroll_area_rows.childNodes[b].runningHeight=running_height;
		
														running_height+=parseInt(scroll_area_rows.childNodes[b].scrollHeight);
													}
		
											}

									}

						}

			}

		function areaScrollersMoveUpDown(area_name,current_item)
			{

				// => "runningHeight" hasn't been set on objects if the scroller isn't used
					if(typeof areaID(current_item).runningHeight=="undefined")
						{
							return;	
						}
				
				// => current item position
					var current_item_top=areaID(current_item).runningHeight;
					var current_item_bottom=current_item_top+parseInt(areaID(current_item).scrollHeight);

				// => scroll area height
					var current_scroll_height=parseInt(areaID(area_name).style.height);

					var current_scroll_top=areaID(area_name).scrollTop;
					var current_scroll_bottom=current_scroll_top+current_scroll_height;

				// => adjust the scroll position if the current item is outside the viewable area
					if(current_item_top<current_scroll_top) // => scroll up
						{
							areaID(area_name).scrollTop=current_item_top;
						}
					else if(current_item_bottom>current_scroll_bottom) // => scroll down
						{
							areaID(area_name).scrollTop=current_item_bottom-current_scroll_height;
						}

			}


	/*** AREA => FIX WIDTH OF HEADING CELLS WITH THE WIDTH OF DATA CELLS ***/

		// use_data_width_only => this is used if the heading cell widths are not to be used in calculating the width of columns - ie, only data cells
		function areaFixHeadingCellsWidth(heading_row,data_row,use_data_width_only)
			{

				setTimeout("areaFixHeadingCellsWidthDo('"+heading_row+"','"+data_row+"',"+(use_data_width_only?1:0)+");",50);

			}

		function areaFixHeadingCellsWidthDo(heading_row,data_row,use_data_width_only)
			{

				// => get rows
					heading_row=areaID(heading_row);

					var data_index=0;
					
					while(data_index<1000)
						{
							data_row_obj=areaID(data_row+"_"+data_index);

							if(data_row_obj)
								{
									break;
								}

							data_index++;
						}

					if(!data_row_obj)
						{
							return;
						}

				// => get table padding values
					data_row_table=data_row_obj;
				
					while(true)
						{
							if(data_row_table.tagName.toUpperCase()=="TABLE")
								{
									break;
								}
								
							data_row_table=data_row_table.parentNode;
						}
				
					var tablePadding=parseInt(data_row_table.cellPadding);
					
					if(isNaN(tablePadding))
						{
							tablePadding=0;
						}

				// => iterate through data columns
					var cellWidths=[];

					for(var b=0; b<data_row_obj.childNodes.length; b++)
						{

							// => data row id
								var datarow=data_row_obj.childNodes[b].datarow;

								if(!datarow)
									{
										continue;
									}

							// => left/right padding for the column
								var paddingLeft=parseInt(data_row_obj.childNodes[b].style.paddingLeft);						
								var paddingRight=parseInt(data_row_obj.childNodes[b].style.paddingRight);

								if(isNaN(paddingLeft))
									{
										paddingLeft=tablePadding;
									}
								if(isNaN(paddingRight))
									{
										paddingRight=tablePadding;
									}

							// => calculate column width
								var cell_subtract=/*(data_row_obj.childNodes[b].offsetWidth-data_row_obj.childNodes[b].clientWidth)*/-paddingLeft-paddingRight;

							// => iterate through heading columns
								for(var c=0; c<heading_row.childNodes.length; c++)
									{
							
										if(datarow==heading_row.childNodes[c].datarow)
											{

												// => bring the column with the thinnest width up to the same width as the widest column
													if(!use_data_width_only&&(parseInt(heading_row.childNodes[c].clientWidth)+cell_subtract)>(parseInt(data_row_obj.childNodes[b].clientWidth)+cell_subtract))
														{
															data_row_obj.childNodes[b].width=(parseInt(heading_row.childNodes[c].clientWidth)+cell_subtract)+"px";
														}
													else
														{
															heading_row.childNodes[c].width=(parseInt(data_row_obj.childNodes[b].clientWidth)+cell_subtract)+"px";
														}

												break;

											}

									}

						}

			}




		/*** AREA => PREVENT TEXT FROM BEING SELECTED IN AN AREA ***/
			/*
			function areaDisableTextSelection(id)
				{
					id=areaID(id);
					
					if(typeof id.onselectstart!="undefined") // => ie
						{
							id.onselectstart=function(){return false;}
						}
					else if(typeof id.style.MozUserSelect!="undefined") // => firefox
						{
							id.style.MozUserSelect="none";
						}
					else // => all others
						{
							id.onmousedown=function(){return false;}
							id.style.cursor="default";
						}
				}
			*/




		/*** AREA => STRIP "<SCR-IPT>" TAGS SO THAT THEY CAN BE RUN SEPARATELY FROM THE HTML ***/

			function areaStripJS(string)
				{

					// => get any "<scr-ipt>" area(s)
						var string=string.replace(/<\/script>/g,"^");

						var scriptMatch=false;

						if(scriptMatch=string.match(/<script>[^\^]+/g))
							{
								// => combine the "script" areas found
									scriptMatch=scriptMatch.join(";").replace(/<script>/g,"");

								// => remove script area(s) from the "editor" string
									string=string.replace(/<script>[^\^]+\^/g,"");
							}

						return {"html":string,"script":scriptMatch};
				}



		/*** AREA => VALUE ***/
		
			// id => box id or object
			// ignore_example => exists if to return the value regardless of whether the "font_box_example" class is used on the input box
			// no_trim => exists if to not trim the value
			function areaValueGet(id,ignore_example,no_trim)
				{
					var id=areaID(id);

					if(!id.type)
						{
							return "";
						}
					if(id.type=="checkbox")
						{
							return id.checked?1:"";
						}
					else if(id)
						{
							// => the value is empty if an "example" value is entered into the input field
								if(ignore_example||!id.className||id.className.search(/(font_box_example|font_grey)/)==-1)
									{
										if(no_trim)
											{
												return id.value;
											}
										else
											{
												return stringTrim(id.value);
											}
									}
								else
									{
										return "";
									}
						}
					else
						{
							return "";	
						}
				}

			// id => box id or object
			// add => exists if the value is added to the end instead of over-riding the entire value
			function areaValueSet(id,value,add)
				{

					if(typeof value=="undefined")
						{
							return;	
						}

					var id=areaID(id);

					if(!id)
						{
							return;

						}

					if(id.type=="checkbox")
						{
							id.checked=value?true:false;
						}
					else if(typeof id.length!="undefined"&&id[0]&&(!id.type||!id.type.match(/^select/i)))
						{
							for(var b=0; b<id.length; b++)
								{
									if(areaValueGet(id[b])==value)
										{
											id[b].checked=true;
											
											break;
										}
								}
						}
					else
						{
							if(add)
								{
									id.value+=value;
								}
							else
								{
									id.value=value;
								}
						}
					
				}

	/*** ENABLE/DISABLE A FIELD ***/

		function areaDisable(id,disable)
			{

				if(typeof id.length!="undefined"&&id[0])
					{

						for(var b=0; b<id.length; b++)
							{
								id[b].disabled=disable;
							}

					}
				else
					{
						id.disabled=disable;
					}

			}


/* DEPRECATE
			function areaFocus(id)
				{
					var id=areaID(id);

					if(!id)
						{
							return false;	
						}

					if(id.type=="text")
						{
							// => focussing in IE doesn't seem to work with this on
							id.select();
							id.value+="";
						}

					id.focus();

					return true;
				}
*/

			function areaSelect(id)
				{

					if(page["overlay_focus_timeout"])
						{
							page["overlay_focus_timeout_do"].push(id);
							
							return true;
						}

					var id=areaID(id);

					if(!id||id.disabled||id.type=="hidden")
						{
							return false;
						}

					var b=id;

					while(true)
						{
							if(b&&b.style)
								{
									if(b.style.display&&b.style.display=="none")
										{
											return false;
										}

									var b=b.parentNode;
								}
							else
								{
									break;	
								}
						}

					id.focus();

					if(id.type=="text"||id.type=="textarea") // id.type.substr(0,6)!="select"&&id.type!="button"&&id.type!="submit"(
						{
							id.select();
						}

					return true;
				}

		/*** AREA => SHOW/HIDE ***/

			// id => box id OR object
			// hide => exists if to hide the area OR return whether the area is currently showing => OPTIONAL
					// 1 => hide the area
					// 2 => return whether the area is currently showing
			function areaShow(id,hide)
				{
					// => IF (returning whether the area is currently showing)
						// 1 => currently showing
						// 0 => currently hidden
						if(areaID(id))
							{
								return eval("areaID(id).style.display"+(hide?hide==1?"='none'":"=='none'?0:1":"='';"));
							}

						return false;

				}


		/*** AREA => GET THE POSITION OF AN ELEMENT WITHIN THE PAGE ***/

			// local => exists if to get the position of the element within its container (optional)
				// => default is to get the element position on the page
			// include_scrolling => by default, if the page is scrolled vertically/horizontally, this scrolling is not included in the position.
			function areaPos(obj,local,include_scrolling)
				{

					var curleft=0;
					var curtop=0;

					obj=areaID(obj);

					if(obj.offsetParent)
						{
							curleft=obj.offsetLeft-obj.scrollLeft;
							curtop=obj.offsetTop-obj.scrollTop;

							if(!local)
								{
									while(obj=obj.offsetParent)
										{
											// => subtract any x/y scrolling since this is "unseen" and doesn't impact the position of the element on the viewable screen
												curleft+=obj.offsetLeft-(include_scrolling?0:obj.scrollLeft);
												curtop+=obj.offsetTop-(include_scrolling?0:obj.scrollTop);
										}
								}
						}

					var array=[];
					array["x"]=curleft;
					array["y"]=curtop;

					return array;
	
				}

		/*** AREA => A IE v6 (OR LOWER) FIX TO HIDE "SELECT" BOXES WHEN SOMETHING IS NEEDED TO GO OVER THE TOP OF IT ***/

			// hide => exists if to hide => OPTIONAL
				// => default is to show the "select" boxes
			function areaHideSelectBoxes(hide)
				{

					// => IE v <7 messes up select boxes by showing them above everything else
					if(document.all)
						{

							// => overlay forms
								var area_obj=areaID("area_overlay_transparent_"+page["overlay_layer_current"]);

								var overlay_showing=areaShow(area_obj,2);

								if(overlay_showing)
									{
		
										var overlay_forms=[];
		
										var overlay_str=areaGet(area_obj,true);

										var tmp_matches=overlay_str.match(/\<form[^\>]+\>/gi);

										if(tmp_matches)
											{
												for(var b=0; b<tmp_matches.length; b++)
													{

														var tmp_match_name=tmp_matches[b].match(/name=['"]*([^'"\s\>]+)[^\>]+/i)

														if(tmp_match_name)
															{
																overlay_forms[tmp_match_name[1]]=true;	
															}

													}
											}
		
									}

							// => iterate through forms
								for(var b=0; b<document.forms.length; b++)
									{

										if(document.forms[b].ignoreselectboxes)
											{
												continue;
											}

										// => continue if (overlay is not showing) or (overlay is showing and this form is in the overlay)
											if(!overlay_showing||(overlay_showing&&overlay_forms[document.forms[b].name]))
												{

											for(var c=0; c<document.forms[b].length; c++)
												{
													if(document.forms[b][c].type.search(/select/i)>=0)
														{
															// => show/hide the area
														if(hide)
															{
																// => hide the area if it is not already hidden
																	if(areaShow(document.forms[b][c],2))
																		{
																			document.forms[b][c].style.selectFix="1";
													
																			document.forms[b][c].style.visibility="hidden";
																		}
																	else
																		{
																			document.forms[b][c].style.selectFix="";
																		}
															}
														else if(document.forms[b][c].style.selectFix=="1")
															{
																document.forms[b][c].style.visibility="visible";
															}
												}
												
												
												}
												
										}
								}

						}

				}




	/*** COOKIE FUNCTIONS ***/


		/*** COOKIE => SET COOKIE ***/

			// expire => exists if the cookie is to expire in 30 days (default is for the cookie to expire at the end of the current browser session) => optional
			// path => exists if the path is not the entire site => optional
					// => eg, "data/accounts"
			function cookieSet(name,value,expire,path)
				{

					document.cookie=name+"="+urlEncode(value)+";path=/"+(path?path+"/":"")+(expire?";expires="+new Date(new Date()/1+2592000000).toGMTString():"");

				}



		/*** COOKIE => GET COOKIE ***/

			function cookieGet(name)
				{

					var cookie_value=eval("(';'+document.cookie+';').match(/;\\s*"+name+"=([^;]*)/)");

					if(cookie_value)
						{
							return urlDecode(cookie_value[1]);
						}
					else
						{
							return "";
						}

				};




		/*** COOKIE => DELETE COOKIE ***/

			function cookieDelete(name,path)
				{

					document.cookie=name+"=;path=/"+(path?path+"/":"")+";expires=Thu, 01-Jan-1970 00:00:01 GMT";

				};



		/*** COOKIE => CHECK WHETHER COOKIES ARE ENABLED ***/

			function cookieCheck()
				{
					// => set a cookie
						cookieSet("cookie_test","1");

					// => get the value of the cookie that was set above
						var cookie_result=cookieGet("cookie_test")?true:false;

					// => remove the cookie
						cookieDelete("cookie_test");

					// => return whether the cookie was stored -> ie, whether cookies are enabled or not
						return cookie_result;
				}




	/*** ARRAY FUNCTIONS ***/


		/*** ARRAY => COPY AN ARRAY ***/

			function arrayCopy(array)
				{

					var new_array=[];

					for(var b in array)
						{
							if(typeof array[b]=="object")
								{
									new_array[b]=arrayCopy(array[b]);
								}
							else
								{
									new_array[b]=array[b];
								}
						}

					return new_array;

				}


		/*** ARRAY => SORT ***/

			// => array must be in the format: array_name[a][b] => where [b] is sorted 

			// array => array to sort
			// column => column index(es) to sort if the array to sort is a multi-dimensional array => OPTIONAL
			// direction => sort direction
					// asc => ascending
					// desc => descending
			// keep_indexes => exists if to keep the original array indexes after sorting
					// => this won't be needed if you want to iterate through an array afterwards as the indexes will be all over the place - eg, 4,1,7,8, etc.
			function arraySort(array,columns,direction,keep_indexes,binary_sort)
				{

					// => add the index position to each array item
						if(keep_indexes)
							{

								for(var b in array)
									{
										if(columns)
											{
												array[b]["array_index"]=b;
											}
										else
											{
												array[b]={"value":array[b],"array_index":b};
											}
									}

							}

						page["sort_values"]={"columns":columns,"direction":direction,"binary_sort":binary_sort,"blank_char":String.fromCharCode(0)};

						array.sort(arraySortCompare);

					// => fix array indexes
						if(keep_indexes)
							{

								var new_array=[];
	
								for(var b in array)
									{
										if(columns)
											{
												var tmp_array=[];
	
												for(var c in array[b])
													{
														if(c!="array_index")
															{
																tmp_array[c]=array[b][c];
															}
													}
											}
										else
											{
												var tmp_array=array[b]["value"];
											}
	
										new_array[array[b]["array_index"]]=tmp_array;
									}

								return new_array;

							}
						else
							{
								return array;
							}

				};

			function arraySortCompare(value_a,value_b)
				{

					if(typeof page["sort_values"]["columns"]=="object")
						{

							// => iterate through columns to sort
								for(var d in page["sort_values"]["columns"])
									{

										var tmp_compare=arraySortCompareValue(value_a[page["sort_values"]["columns"][d]],value_b[page["sort_values"]["columns"][d]],page["sort_values"]["direction"][d]);

										if(tmp_compare!=0)
											{
												return tmp_compare;
											}

									}

								return 0;

						}
					else
						{

							if(page["sort_values"]["columns"])
								{
									return arraySortCompareValue(value_a[page["sort_values"]["columns"]],value_b[page["sort_values"]["columns"]],page["sort_values"]["direction"]);
								}
							else if(typeof value_a=="object")
								{
									return arraySortCompareValue(value_a["value"],value_b["value"],page["sort_values"]["direction"]);
								}
							else
								{
									return arraySortCompareValue(value_a,value_b,page["sort_values"]["direction"]);
								}

						}

				}

			function arraySortCompareValue(value_a,value_b,direction)
				{

					value_a=String(value_a).toLowerCase();
					value_b=String(value_b).toLowerCase();

					if(page["sort_values"]["binary_sort"])
						{
							var tmp_compare=value_a<value_b?-1:1;
						}
					else
						{
							var tmp_compare=arraySortCompareNatural(value_a,value_b);
						}

					return direction=="desc"?-tmp_compare:tmp_compare;

				}

			function arraySortCompareNatural(value_a,value_b)
				{

					// => source from: http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm/
/*
					// =>
						if(typeof value_a!="string")
							{alert("Error - sort string type: "+typeof value_a);
								return -1;
							}
						if(typeof value_b!="string")
							{alert("Error - sort string type: "+typeof value_b);
								return -1;
							}
*/
					// => setup temp-scope variables for comparison evaluation
						var xN=value_a.replace(/([-]{0,1}[0-9.]{1,})/g,"~$1~").split("~");
						var yN=value_b.replace(/([-]{0,1}[0-9.]{1,})/g,"~$1~").split("~");

					// => natural sorting through split numeric strings and default strings
						var numS=Math.max(xN.length,yN.length);
					
						for(var b=0; b<numS; b++)
							{
								if((parseFloat(xN[b])||xN[b])<(parseFloat(yN[b])||yN[b]))
									{
										return -1;
									}
								else if((parseFloat(xN[b])||xN[b])>(parseFloat(yN[b])||yN[b]))
									{
										return 1;
									}
							}
	
						return 0;
	
				}




		/*** ARRAY => SORT ***/

			function array_alert(array)
				{

					var a="";
					
					for(var b in array)
						{
							a+=b+" - "+array[b]+"\r\n";	
						}

					alert(a);

				}







	/*** MOUSE FUNCTIONS ***/
	
	
		/*** MOUSE => CURSOR POSITION ***/

			// note => an object must have "style='position:relative;'" added to it if the cursor position within the layer that is needed otherwise it won't work in mozilla browsers

			// event => event object
			function mousePosition(event)
				{

					var b;

					// => cursor position array
						// ['x'] => x position
						// ['y'] => y position
						b=[];

					// => get cursor position depending on the user's browser
						if(window.event) // => ie
							{
								b["x"]=event.offsetX;
								b["y"]=event.offsetY;
							}
						else // => mozilla
							{
								b["x"]=event.layerX;
								b["y"]=event.layerY;
							}

						if(!b["x"])
							{
								b["x"]=0;	
							}
						if(!b["y"])
							{
								b["y"]=0;	
							}

						return b;

				}


		/*** MOUSE => IS THE CURSOR NO LONGER OVER THE SPECIFIED AREA ID ***/

			function mouseOverArea(e,id)
				{

					return (document.all&&!areaID(id).contains(e.toElement))||(e.currentTarget!=e.relatedTarget&&!headerMenuOutContains(e.currentTarget,e.relatedTarget));

				}


		/*** MOUSE => MOUSE WHEEL ***/

			// => event handler for mouse wheel event
				function mouseWheelHandler(event)
					{
						// => event object
							if(!event) // => IE
								{
									event=window.event;
								}

						// => get wheel direction
        					var delta=0;

							if(event.wheelDelta)
								{
									// => IE/Opera
										delta=event.wheelDelta/120;

									// => in Opera 9, delta differs in sign as compared to IE
										if(window.opera)
											{
												delta=-delta;
											}
								}
							else if(event.detail)
								{
									// => Mozilla
										// => sign of delta is different than in IE and delta is multiple of 3
										delta=-event.detail/3;
								}

						// => if delta is nonzero, handle it
							// + => scroll up
							// - => scroll down
							if(delta!=0)
								{
									eval(page["mouse_wheel_function"]+"(-delta);");
								}
//alert(browserScrollPosition());

						// => prevent default actions caused by mouse wheel
							if(event.preventDefault)
								{
									event.preventDefault();
								}

							event.returnValue=false;

					}

			// => initialise
				function mouseWheelSet(function_name)
					{

						page["mouse_wheel_function"]=function_name;

						if(window.addEventListener) // => mozilla
							{
									window.addEventListener("DOMMouseScroll",mouseWheelHandler,false);
							}
						else // => ie
							{
								window.onmousewheel=mouseWheelHandler;
								document.onmousewheel=mouseWheelHandler;
							}

					}

				function mouseWheelUnset()
					{

						if(window.removeEventListener) // => mozilla
							{
									window.removeEventListener("DOMMouseScroll",mouseWheelHandler);
							}
						else // => ie
							{
								window.onmousewheel=null;
								document.onmousewheel=null;
							}

					}



	/*** URL FUNCTIONS ***/


		/*** URL => ENCODE ***/

			// string => string to encode
			function urlEncode(string) //### ORIGINALLY CALLED "EscapeIt"
				{

					// => encode using the default javascript encoding
						string=escape(string);

					// => some characters are NOT encoded properly
						string=string.replace(/\+/g,"%2B");
						string=string.replace(/\//g,"%2F");

					// => return the encoded string
						return string;

				};


		/*** URL => DECODE ***/

			// string => string to encode
			function urlDecode(string) //### ORIGINALLY CALLED "EscapeIt"
				{

					// => decode using the default javascript decoding
						string=unescape(string);

					// => return the decoded string
						return string;

				};





	/*** STRING FUNCTIONS ***/


		/*** STRING => CONVERT SINGLE/DOUBLE QUOTES TO HTML ENTITIES ***/

			function stringEntities(string)
				{

					if(typeof string=="undefined")
						{
							return "";
						}

					string=string.replace(/'/g,"&#39;");
					string=string.replace(/"/g,"&#34;");

					return string

				}


		/*** STRING => CONVERT SINGLE/DOUBLE QUOTES TO HTML ENTITIES ***/

			function stringEntitiesAll(string)
				{

					if(typeof string=="undefined")
						{
							return "";
						}

					string=string.replace(/&/g,"&amp;");
					string=string.replace(/'/g,"&#39;");
					string=string.replace(/"/g,"&#34;");
					string=string.replace(/"/g,"&quot;");
					string=string.replace(/</g,"&lt;");
					string=string.replace(/>/g,"&gt;");

					return string

				}


		/*** STRING => BACKSLASH DOUBLE QUOTES ***/
		
			function stringSlash(string)
				{

					if(typeof string=="undefined")
						{
							return "";
						}

					return string.replace(/"/,"\\\"");
					
				}


		/*** STRING => PAD ***/

			// pad_left => exists if to pad the string to the left of the string -> OPTIONAL
					// => default is to pad the string to the right
			function stringPad(string,length,pad_char,pad_left)
				{

					var pad_bit="";
					
					string=String(string);
					
					while((pad_bit.length+string.length)<length)
						{
							pad_bit+=pad_char;
						}

					return (pad_left?pad_bit:"")+string+(pad_left?"":pad_bit);

				}


		/*** STRING => TRIM ***/

			function stringTrim(string)
				{

					return String(string).replace(/^[\s\r\n]+|[\s\r\n]+$/g,"");

				}



		/*** STRING => THE "TITLE" TAG FOR AN ELEMENT ***/

			function stringTitle(string)
				{

					if(typeof string=="undefined")
						{
							return "";
						}

					// => remove line breaks
						string=string.replace(/\n|\r/g,"");

					// => replace quotes with their html equivalent
						string=string.replace(/'/g,"&#39;");
						string=string.replace(/"/g,"&#34;");

					// => replace spaces with "&nbsp;"
						string=string.replace(/ /g,"&nbsp;");

					return string;

				}


		/*** STRING => EMAIL VALIDATE ***/

			function stringEmailValidate(email)
				{
		
					if(email.match(/^([a-z0-9\!\#\$\%\*\/\?\|\^\{\}\`\~\&\'\+\-\=\_]+)(\.[a-z0-9\!\#\$\%\*\/\?\|\^\{\}\`\~\&\'\+\-\=\_]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i))
						{
							return true;
						}
					else
						{
							return false;
						}
		
				}




	/*** DATE ***/

		function dateMonths()
			{
				return ["January","February","March","April","May","June","July","August","September","October","November","December"];	
			}

		function dateDays()
			{
				return ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];	
			}

		// format => an alphabet index string for time pieces
					// a => year (4 digits)
					// b => year (2 digits)
					// c => month number => january = 1
					// d => month number (2 digits) => january = 01
					// e => month name
					// f => month name (3 characters)
					// g => date
					// h => date (2 digits)
					// i => st, nd, rd, th (for date)
					// j => day name
					// k => day name (3 characters)
					// l => hour
					// m => minutes (2 digits)
					// n => seconds (2 digits)
					// o => am/pm
		// date => the date in one of these formats:
			// string => 1983-08-16 00:00:00
			// date obj => new Date();
		// army_time => if the 24-hour clock is to be used
		// return_obj => exists if to return the date object
		function dateFormat(format,date,army_time,return_obj)
			{
				
				// => get date bits
					if(typeof date=="string")
						{
					var dateBits=[];
					dateBits["year"]=date.substr(0,4)/1;
					dateBits["month"]=date.substr(5,2)/1;
					dateBits["date"]=date.substr(8,2)/1;
					dateBits["hour"]=date.substr(11,2)/1;
					dateBits["minute"]=date.substr(14,2)/1;
					dateBits["second"]=date.substr(17,2)/1;
				
					var dateObj=new Date(dateBits["year"],dateBits["month"]-1,dateBits["date"],dateBits["hour"],dateBits["minute"],dateBits["second"]);
						}
					else
						{
							var dateObj=date;
						}

				// => return the date object if needed
					if(return_obj)
						{
							return dateObj;
						}

				// => iterate through the "format" string
					var a="";
				
					for(var b=0; b<format.length; b++)
						{
							
							var tmpIndex=format.charAt(b);

							if(tmpIndex=="a") // => year (4 digits)
								{
									a+=dateObj.getFullYear();
								}
							else if(tmpIndex=="b") // => year (2 digits)
								{
									a+=String(dateObj.getFullYear()).substr(2);
								}
							else if(tmpIndex=="c") // => month number => january = 1
								{
									a+=dateObj.getMonth()+1;
								}
							else if(tmpIndex=="d") // => month number (2 digits) => january = 01
								{
									a+=stringPad(dateObj.getMonth()+1,2,"0",true);
								}
							else if(tmpIndex=="e") // => month name
								{
									a+=dateMonths()[dateObj.getMonth()<0?11:dateObj.getMonth()];
								}
							else if(tmpIndex=="f") // => month name (3 characters)
								{
									a+=dateMonths()[dateObj.getMonth()<0?11:dateObj.getMonth()].substr(0,3);
								}
							else if(tmpIndex=="g") // => date
								{
									a+=dateObj.getDate();
								}
							else if(tmpIndex=="h") // => date (2 digits)
								{
									a+=stringPad(dateObj.getDate(),2,"0",true);
								}
							else if(tmpIndex=="i") // => st, nd, rd, th (for date)
								{
									if(dateObj.getDate()==1||dateObj.getDate()==21||dateObj.getDate()==31)
										{
											a+="st";
										}
									else if(dateObj.getDate()==2||dateObj.getDate()==22)
										{
											a+="nd";
										}
									else if(dateObj.getDate()==3||dateObj.getDate()==23)
										{
											a+="rd";
										}
									else
										{
											a+="th";
										}
								}
							else if(tmpIndex=="j") // => day name
								{
									a+=dateDays()[dateObj.getDay()];
								}
							else if(tmpIndex=="k") // => day name (3 characters)
								{
									a+=dateDays()[dateObj.getDay()].substr(0,3);
								}
							else if(tmpIndex=="l") // => hour
								{
				
									if(army_time) // => 24-hour
										{
											a+=(dateObj.getHours()<10?"0":"")+dateObj.getHours();
										}
									else // => 12-hour
										{
						
											if(dateObj.getHours()==0)
												{
													a+="12";
												}
											else if(dateObj.getHours()>12)
												{
													a+=String(dateObj.getHours()-12);
												}
											else
												{
													a+=String(dateObj.getHours());
												}
										}

								}
							else if(tmpIndex=="m") // => minutes (2 digits)
								{
									a+=stringPad(dateObj.getMinutes(),2,"0",true);
								}
							else if(tmpIndex=="n") // => seconds (2 digits)
								{
									a+=stringPad(dateObj.getSeconds(),2,"0",true);
								}
							else if(tmpIndex=="o") // => am/pm
								{
									if(army_time)
										{
											a+="";
										}
									else
										{
											if(dateObj.getHours()<12)
												{
													a+="am";
												}
											else
												{
													a+="pm";
												}
										}
								}
							else
								{
									a+=tmpIndex;
								}

						}
				
					return a;
				
			}






	/*** NUMBER FUNCTIONS ***/


		/*** NUMBER => FORMAT ***/

			// decimals => the number of decimals to round to -> OPTIONAL
					// => default is to not round the number at all
			// commas => whether to add commas for thousands -> OPTIONAL
			// decimals_exact => the exact number of decimals to show regardless -> OPTIONAL
			function numberFormat(number,decimals,commas,decimals_exact)
				{

					// => decimals
						if(decimals||decimals===0)
							{
								decimals=stringPad("1",decimals+1,"0");

								number=Math.round(number*decimals)/decimals;
							}
						else
							{
								number=String(number);
							}

					// => split the number by decimal
						number=String(number).split(".");

					// => add commas
						if(commas)
							{

								var reg_exp=/(-?\d+)(\d{3})/;

								while(reg_exp.test(number[0]))
									{
										number[0]=number[0].replace(reg_exp,"$1,$2");
									}

							}

					// => exact number of decimals
						if(decimals_exact)
							{
								// => pad to the exact number of decimal places needed
									number[1]=stringPad(number[1]?number[1]:"",decimals_exact,"0");
							}

					return number[0]+(typeof number[1]!="undefined"?"."+number[1]:"");

				}


		/*** NUMBER => RANDOM NUMBER ***/

			function numberRandom(max_num)
				{
					return Math.floor(Math.random()*(max_num?max_num:999999999));
				}




	/*** ROLLOVER FUNCTIONS ***/


		/*** ROLLOVER => TRANSPARENT TABLE ROW ***/

			function rolloverTransparent(obj,over)
				{

					tmp_top=obj;


for(var b=0; b<tmp_top.childNodes.length; b++)
	{

		var tmp_classname=tmp_top.childNodes[b].className;

		var match;

		if(match=tmp_classname.match(/transparent_(\d+)/))
			{
				tmp_top.childNodes[b].className=tmp_classname.replace(/transparent_(\d+)/,"transparent_"+(match[1]/1+(over?15:-15)));
			}

	}

				}








	// request_type => exists if the page fetched is in "xml" format => OPTIONAL
				// function_name => this is the function to run once the xml page has been fetched
	// post => an array of post fields => OPTIONAL
				// array["field_name"]="value";
	// loading => exists if to show the "loading" overlay => OPTIONAL
	scriptLoading=[];
	
	function scriptGet(url,post,request_type,loading)
		{

			// => if the script is still being loaded from a previous attempt, abort it
				var loading_name=url.replace(/\?[^¶]+/,"");
				
				if(scriptLoading[loading_name])
					{
						if(scriptLoading[loading_name].readyState!=0)
							{
								scriptLoading[loading_name].abort();
							}
					}

			// => create the request
				var request_obj=null;
				
				if(window.XMLHttpRequest)
					{
						request_obj=new XMLHttpRequest();
					}
				else if(window.ActiveXObject)
					{
						request_obj=new ActiveXObject("Microsoft.XMLHTTP");
					}

				if(request_obj)
					{

						// => show the "loading" overlay if needed
							if(loading)
								{
									overlayMakeLoading(typeof loading=="string"?loading:"loading");
								}

						request_obj.open(post?"POST":"GET",url,true);
						request_obj.onreadystatechange=function(){scriptProcess(request_obj,request_type,loading,loading_name)};

						if(post)
							{

								request_obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

								post_fields=[];

								for(var b in post)
									{
										b=stringTrim(b);

										if(typeof post[b]!="undefined")
											{
												if(typeof post[b]=="object")
													{
														var count_obj=0;
														
														for(var c in post[b])
															{
																post_fields.push(b+"["+c+"]="+urlEncode(stringTrim(post[b][c])));
																		
																count_obj++;
															}

														if(count_obj==0)
															{
																post_fields.push(b+"=");
															}
													}
												else
													{
														post_fields.push(b+"="+urlEncode(stringTrim(post[b])));
													}
											}
									}

			                   request_obj.send(post_fields.join("&"));

							}
						else
							{
								request_obj.send(null);
							}


						// => store the script being loaded so that it can be aborted if the same script is loaded before this one finishes
							scriptLoading[loading_name]=request_obj;

					}
				else
					{
						overlayMake("Bad Browser","This browser does not support the sending of this request.",false,false,false,false,true);
					}

		}

	function scriptProcess(request_obj,request_type,loading,loading_name) 
		{

			// => if the request is "complete"
				if(request_obj.readyState==4)
					{

						// => the script is no longer loading
							scriptLoading[loading_name]=undefined;

						// => if the request is successful
							if(request_obj.status==200)
								{

									// => hide the "loading" overlay if it was created
										if(loading)
											{
												overlayMake();
											}

									// => evaluate the request depending on the request type
										if(request_type&&request_obj.responseText.substr(0,5)=="<xml>") // => xml
											{
												xmlArray=xml2array(request_obj.responseXML,[]);

												eval(request_type+"(xmlArray);");
											}
										else // => javascript
											{
												eval(request_obj.responseText)
											}

								}
							else
								{
									overlayMake("Script Error","There was a problem retrieving the data from the server:<br><br>"+request_obj.status+"<br><br>"+request_obj.statusText+"<br><br>"+stringEntitiesAll(request_obj.responseText),false,false,false,false,true);
								}

					}

		}





// => xml document object
// => running array
function xml2array(xmlDoc,array)
	{

		// => iterate through child objects
			for(var b=0; b<xmlDoc.childNodes.length; b++)
				{
					xml2array(xmlDoc.childNodes[b],array);
				}

		// => if this is a value object
			if(xmlDoc.parentNode&&xmlDoc.parentNode.nodeName&&xmlDoc.nodeValue)
				{

					// => create an array of all the levels for this node
						var tmp_parent="";
						var tmp_array=[];

						while(true)
							{

								tmp_parent+=".parentNode";

								var tmp_parent_obj=eval("xmlDoc"+tmp_parent);

								if(tmp_parent_obj&&tmp_parent_obj.nodeName!="xml"&&tmp_parent_obj.nodeName.charAt(0)!="#")
									{
										tmp_array.push(tmp_parent_obj.nodeName)	
									}
								else
									{
										break;
									}

							}

					// => create arrays for the levels
						var array_string="";

						for(var b=tmp_array.length-1; b>=0; b--)
							{

								// => continue depending on whether the "key" is an item
									if(tmp_array[b]=="item")
										{

											// => get the position to add this value to in the array
												var count_tmp=0;

												while(true)
													{

														// => stop the count if the array doesn't exist
															if(eval("typeof array"+array_string+"["+count_tmp+"]=='undefined'"))
																{
																	break;
																}

														// => stop the count if there is an item below this one and it doesn't exist
															if(tmp_array[b-1]&&eval("typeof array"+array_string+"["+count_tmp+"][\""+tmp_array[b-1]+"\"]=='undefined'"))
																{
																	break;
																}

														// => add to the counter
															count_tmp++;

													}

											// => add the item to the end
												array_string+="[\""+count_tmp+"\"]";

										}
									else
										{
											array_string+="[\""+tmp_array[b]+"\"]";
										}

								// => create the array if it doesn't exist
									if(eval("typeof array"+array_string+"!='object'"))
										{
											eval("array"+array_string+"=[];");
										}

							}

					// => add the value
						if(xmlDoc.nodeValue=="#~#")
							{
								tmp_value="";
							}
						else
							{
								tmp_value=xmlDoc.nodeValue;
							}

						eval("array"+array_string+"=tmp_value");

				}

		return array;

	}








	/*** SELECT BOX FUNCTIONS ***/


		/*** SELECT BOX => SWAP ITEMS BETWEEN 2 SELECT BOXES ***/

			// from => moving "from" box id
			// to => moving "to" box id
			function selectboxSwap(from,to)
				{

					// => get box objects
						from=areaID(from);
						to=areaID(to);

					// => de-select items selected in the "to" box
						to.selectedIndex=-1

					// => swap selected items
						var b=0;

						while(b<from.length)
							{

								// => move the item to the "to" box if it is selected
									if(from.options[b].selected)
										{

											// => add the item to the "to" box
												to.options[to.length]=new Option(from.options[b].text,from.options[b].value,0,true);

											// => remove the item from "from" box
												from.options[b--]=null;

										}

								// => add to counter
									b++;

							}

				}



		/*** SELECT BOX => MOVE SELECTED ITEMS ***/

			// box => box id
			// direction
						// up => move up
						// down => move down
			function selectboxMove(box,direction)
				{

					// => get the box object
						box=areaID(box);

					// => a selection must be made
						if(box.selectedIndex!=-1)
							{

								// => iterate through items
									var items=[];

									for(var b=0; b<box.length; b++)
										{

											// move the item if it is selected
												if(box.options[b].selected)
													{

														// => the item cannot be moved if:
															// => moving up and index == 0
															// => moving down and the index is the last item
															if((direction=="up"&&b==0)||(direction=="down"&&b==box.length-1))
																{
																	return;
																}
															else
																{
																	items.push(b);
																}

													}

										}

								// => change positions depending on the direction
									var positionCurrent=direction=="down"?items.length-1:0;

									for(var b in items)
										{

											// => values
												var positionOld=items[positionCurrent]; // => original position
												var positionNew=positionOld+(direction=="up"?-1:1); // => new position

											// => swap positions
												var valuesOld=[box.options[positionNew].text,box.options[positionNew].value];

												box.options[positionNew].text=box.options[positionOld].text;
												box.options[positionNew].value=box.options[positionOld].value;

												box.options[positionOld].text=valuesOld[0];
												box.options[positionOld].value=valuesOld[1];

												box.options[positionNew].selected=1;
												box.options[positionOld].selected=0;

											// => move onto the next item selected
												positionCurrent+=(direction=="up"?1:-1);

										}

							}

				}



		/*** SELECT BOX => REMOVE ITEM/S FROM A SELECT BOX ***/

			// box => box id
			function selectboxRemove(box)
				{

					// => get the box object
						box=areaID(box);

					// => iterate through items
						for(var b=0; b<box.length; b++)
							{

								// => remove the item if it is selected
									if(box.options[b].selected)
										{

											// => remove the item
												box.options[b]=null;
											
											// => "b" needs to be subtracted since this index needs to be checked again for the next item
												b--;

										}

							}

				}
