// JavaScript Document


GLOBAL = {
	lang: {},
	tips: {},
	siteUrl: '',
	graphicsUrl: '',
	tabGroups: [],
	XMLHttpFactories: [
		function () {return new XMLHttpRequest()},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	],
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	],
	vtypes: function(){
		var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
		var password = /^.{6,31}$/;
		var numeric = /^[0-9]+(\.[0-9]+)?$/;
		return {
			'email' : function(v, o){
         return email.test(v);
      },
      'required': function(v, o) {
      	if (v) {
	      	return (v != '');
	      	return (v.length > 0);
	      }
	      return false;
      },
      'password' : function(v,o) {
      	return password.test(v);
      },
      'human' : function(v,o) {
      	if (v != '') return false;
      	return true;
      },
      'username' : function(v,o) {
      	reg1 = /^[0-9]*$/i;
      	reg2 = /^[\W_]+$/i;
      	reg3 = /^[\w\-]+$/i;
      	reg4 = /^[a-zA-Z]{1,3}[0-9]{4,}$/i;
      	reg5 = /^[-_a-zA-Z0-9]{1,5}$/i;
      	if (reg1.test(v)) return false;
      	if (reg2.test(v)) return false;
      	if (!reg3.test(v)) return false;
      	if (reg4.test(v)) return false;
      	if (reg5.test(v)) return false;
      	return true;
				
      },
      'numeric' : function(v,o) {
      	return numeric.test(v);
      },
      'compare' : function(v,v2, o) {
      	return (v == v2);
      },
      'html' : function(v,o) {
      	reg = /<[^>]+>/i;
      	if (reg.test(v)) return false;
      	return true;
      }
		};
	}(),
	findPos: function(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	},
	getWinW: function() {
		var theWidth;
		if (window.innerWidth) {
		theWidth=window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth=document.documentElement.clientWidth;
		}
		else if (document.body) {
		theWidth=document.body.clientWidth;
		}
		return theWidth;
		
	},
	getWinH: function(){
		var theHeight;
		// Window dimensions:
		if (window.innerHeight) {
		theHeight=window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight=document.documentElement.clientHeight;
		}
		else if (document.body) {
		theHeight=document.body.clientHeight;
		}
		return theHeight;
	},
	
	getRandomNumber: function(l,e) {
		var rand = Math.floor(Math.random() * l);
		rand++;
		if (e == false) return rand;
		if (parseInt(e) == parseInt(rand)) {
			var i = 0;
			var c = 0;
			while (i == 0) {
				rand = Math.floor(Math.random() * l);
				rand++;
				i = (parseInt(e) == parseInt(rand)) ? 0 : 1;
				if (c == 500) {
					break;
				}
				c++;
			}
		}
		return rand;
	},
	array_rand: function( input, num_req ) {
	    // http://kevin.vanzonneveld.net
	    // +   original by: _argos
	    // *     example 1: array_rand( ['Kevin'], 1 );
	    // *     returns 1: 0
	 
	    var Indexes = [];
	    var Ticks = num_req || 1;
	    var Check = {
	        Duplicate    : function ( input, value ) {
	            var Exist = false, Index = 0;
	            while ( Index < input.length ) {
	                if ( input [ Index ] === value ) {
	                    Exist = true;
	                    break;
	                }
	                Index++;
	            }
	            return Exist;
	        }
	    };
	 
	    if ( input instanceof Array && Ticks <= input.length ) {
	        while ( true ) {
	            var Rand = Math.floor ( ( Math.random ( ) * input.length ) );
	            if ( Indexes.length === Ticks ) { break; }
	            if ( !Check.Duplicate ( Indexes, Rand ) ) { Indexes.push ( Rand ); }
	        }
	    } else {
	        Indexes = null;
	    }
	 
	    return ( ( Ticks == 1 ) ? Indexes.join ( ) : Indexes );
	},
	getElementById: function(e){
	  if(typeof(e)=='string') {
	  	if (this.browser == 'Netscape' && this.version <= 4) {
	  		e = getNN4Element(document, e);
	  	} else {
		    if(document.getElementById) e=document.getElementById(e);
		    else if(document.all) e=document.all[e];
		    else e=null;
		  }
	  }
	  return e;
	},
	getNN4Element: function(obj, name) {
		var x = obj.layers;
		var foundLayer;
		for (var i=0;i<x.length;i++)
		{
			if (x[i].id == name)
			 	foundLayer = x[i];
			else if (x[i].layers.length)
				var tmp = getObjNN4(x[i],name);
			if (tmp) foundLayer = tmp;
		}
		return foundLayer;
	},
	getElementPosition: function(elemID){
		var offsetTrail = this.getElementById(elemID);
		var offsetLeft = 0;
		var offsetTop = 0;
		while (offsetTrail){
			offsetLeft += offsetTrail.offsetLeft;
			offsetTop += offsetTrail.offsetTop;
			offsetTrail = offsetTrail.offsetParent;
		}
		if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
			offsetLeft += document.body.leftMargin;
			offsetTop += document.body.topMargin;
		}
		return {left:offsetLeft,top:offsetTop};
	},
	getElementHeight: function(e) {
		var elem = this.getElementById(e);
		if (this.browser == 'Netscape' && this.version <= 4) {
			return elem.clip.height;
		} else {
			if (this.browser == 'Opera' && this.version <= 5) { 
				xPos = elem.style.pixelHeight;
			} else {
				xPos = elem.offsetHeight;
			}
			return xPos;
		} 
	},
	getElementWidth: function(e) {
		var elem = this.getElementById(e);
		if (this.browser == 'Netscape' && this.version <= 4) {
			return elem.clip.width;
		} else {
			if (this.browser == 'Opera' && this.version <= 5) {
				xPos = elem.style.pixelWidth;
			} else {
				xPos = elem.offsetWidth;
			}
			return xPos;
		}
	},
	GetHttpRequest: function(){
		var xmlhttp = false;
		for (var i=0;i < this.XMLHttpFactories.length;i++) {
			try {
				xmlhttp = this.XMLHttpFactories[i]();
			}
			catch (e) {
				continue;
			}
			break;
		}
		return xmlhttp;
	},
	in_array: function (  value, input) {
      var Exist = false, Index = 0;
      while ( Index < input.length ) {
          if ( input [ Index ] === value ) {
              Exist = true;
              break;
          }
          Index++;
      }
      return Exist;
  },
  urlescape: function(data){
	   data = escape(data);
	   data = data.replace('&', '\~amp\~');
	   return data;
	},
	urlunescape: function(data){
	   data=unescape(data);
	   data=data.replace('\~amp\~', '&');
	   return data;
	},
  getFormValue: function(e) {
		var val=type='';
		if (e.length) {
			for (r=0; r<e.length;r++) {
				type = e[r].type;
				break;
			}
		} else {
			type = e.type;
		}
		if (type=='') { return 'error: no type'; }
		switch (type) {
			case 'radio':
				if (e.length) {
					for (r=0; r<e.length;r++) {
						if (e[r].checked == true) { val = e[r].value; break; }
					}
				} else {
					if (e.checked) { val = e.value; }
				}
				break;
			case 'checkbox':
				if (e.checked) { val = e.value; }
				break;
			case 'select':
				val = e.options[e.selectedIndex].value;
				break;
			default:
				val = e.value; break;
		}
		return val;
	},
	getFormElementType: function(e) {
		var val=type='';
		if (e.length) {
			for (r=0; r<e.length;r++) {
				return e[r].type;
				break;
			}
		} else {
			return e.type;
		}
		if (type=='') { return false; }
	},
  getFormElementName: function(e) {
		var val=type='';
		if (e.length) {
			for (r=0; r<e.length;r++) {
				type = e[r].type;
				break;
			}
		} else {
			type = e.type;
		}
		if (type=='') { return 'error: no type'; }
		switch (type) {
			case 'radio':
				if (e.length) {
					for (r=0; r<e.length;r++) {
						val = e[r].name;
						break; 
					}
				} else {
					val = e.name;
				}
				break;
			case 'checkbox':
				val = e.name;
				break;
			case 'select':
				val = e.name;
				break;
			default:
				val = e.name; break;
		}
		return val;
	},
	getFormValues: function(what, r) {
		var params = (r) ? new Array : new String;
		var theForm = what;
		var foundElems = new Array;
		if (typeof what == 'string') {
			theForm = eval('document.' + what);
		}
		if ((typeof theForm != 'object') || (typeof theForm.elements != 'object')) {
	       return false;
	    }
		if (theForm) {
			for(i=0; i<theForm.elements.length; i++){
				var theName = this.getFormElementName(theForm.elements[i]);
				var theValue = this.getFormValue(theForm.elements[i]);
				var theType = this.getFormElementType(theForm.elements[i]);
				if (theType == 'radio') {
					if (foundElems[theName]) {
						foundElems[theName] = (theValue == '') ? foundElems[theName] : this.urlescape(theValue);
					} else {
						foundElems[theName] = (theValue == '') ? '' : this.urlescape(theValue);
					}
				} else {
					if (foundElems[theName]) {
						foundElems[theName] += "\0" + this.urlescape(theValue);
					} else {
						foundElems[theName] = this.urlescape(theValue);
					}
				}
			}
			if (r) {
				params = foundElems;
			} else {
				for (i in foundElems) {
					params += '&' + i + '=' + foundElems[i];
				}
			}
		}
		return params;
	},
	loadPage: function(u, d, m, v){
		var txt = this.loadRequest(u, m, v);
		if (txt.success) {
			var div = getElementById(d);
			if (div) {
				div.innerHTML=txt.data;
			} else {
				alert('Container DIV not found');
			}
		} else {
			return false;
		}
		return true;
	},
	wordlimiter: function(field, limit, textfield) {
		var wordscounttext = this.getElementById(textfield);
		if (!wordscounttext) {
			return 0;
		}
		var wordsfield = this.getElementById(field);
		if (!wordsfield) {
			return 0;
		}
		var wordblock = wordsfield.value;
		var wordcount = 0;
		wordblock = wordblock.replace(/\s|-/g,' ');
		words = wordblock.split(' ');
		for (i=0; i<words.length; i++) {
			if (words[i].length > 0) wordcount++;
		}
		wordscounttext.innerHTML = wordcount;
		if (wordcount > limit) {
			wordscounttext.style.color = '#990000';
			wordscounttext.style.fontWeight = 'bold';
		} else {
			wordscounttext.style.color = '';
			wordscounttext.style.fontWeight = '';
		}
	},
	charlimiter: function(field, limit, textfield) {
		var wordscounttext = this.getElementById(textfield);
		if (!wordscounttext) {
			return 0;
		}
		var wordsfield = this.getElementById(field);
		if (!wordsfield) {
			return 0;
		}
		var wordblock = wordsfield.value;
		var wordcount = 0;
		if (wordblock.length) {
			wordcount = wordblock.length;
		} else {
			words = wordblock.split('');
			for (i=0; i<words.length; i++) {
				if (words[i].length > 0) wordcount++;
			}
		}
		wordscounttext.innerHTML = wordcount;
		if (wordcount > limit) {
			wordscounttext.style.color = '#990000';
			wordscounttext.style.fontWeight = 'bold';
		} else {
			wordscounttext.style.color = '';
			wordscounttext.style.fontWeight = '';
		}
	},
	keywordlimiter: function(field, limit, textfield, delim) {
		var wordscounttext = this.getElementById(textfield);
		if (!wordscounttext) {
			return 0;
		}
		var wordsfield = this.getElementById(field);
		if (!wordsfield) {
			return 0;
		}
		var wordblock = wordsfield.value;
		var wordcount = 0;
		wordblock = wordblock.replace(/\s/g,'');
		words = wordblock.split(delim);
		for (i=0; i<words.length; i++) {
			if (words[i].length > 0) wordcount++;
		}
		wordscounttext.innerHTML = wordcount;
		if (wordcount > limit) {
			wordscounttext.style.color = '#990000';
			wordscounttext.style.fontWeight = 'bold';
		} else {
			wordscounttext.style.color = '';
			wordscounttext.style.fontWeight = '';
		}
	},
	loadUrl: function(config) { // url, popup, width, height, center
		if (!config.url) return false;
		if (config.popup && config.popup == 1) {
			var opts = new Array();
			if (config.toolbar != undefined && config.toolbar != false) opts.push("toolbar=yes");
			if (config.location != undefined && config.location != false) opts.push("location=yes");
			if (config.directories != undefined && config.directories != false) opts.push("directories=yes");
			if (config.menubar != undefined && config.menubar != false) opts.push("menubar=yes");
			if (config.scrollbars != undefined && config.scrollbars != false) opts.push("scrollbars=yes");
			if (config.resizable != undefined && config.resizable != false) opts.push("resizable=yes");
			var winName = (config.name != undefined) ? config.name : '';
			
			if (config.width) opts.push('width='+config.width);
			if (config.height) opts.push('height='+config.height);
			
			var win = window.open(config.url, winName, opts.join(','));
			if (config.center) {
				var maxW = this.getWinW; var maxH = this.getWinH; var nH = 0; var nW = 0;
				nH = (config.height) ? (maxH - config.height)/2 : 0; nW = (config.width) ? (maxW - config.width)/2 : 0;
				win.moveTo(nW, nH);
			}
			win.focus();
		} else {
			window.location.href = config.url;
		}
	},
	openModal: function(url, name, w, h) {
		
	},
	loadXMLDropdown: function(f, e, g, d, dk){
		
		if (!e) { return false; };
		if (!g) { return false; }
		if (!this.comboBoxes[g]) return false;
		if (!this.comboBoxes[g][e.name]) return false;
		if (!f) return false;
		if (!this.comboBoxes[g]['formName'] || f.name != this.comboBoxes[g]['formName']) return false;
		
		var ndk = this.currentCombo[g][dk].dataKey;
		var fld = this.currentCombo[g][dk].fieldName;
		var el = f[fld];
		var theData = new Array();
		if (d.length > 0) {
			for (i=0; i< d.length; i++) {
				var str = d[i][ndk];
				var lab = str;
				if (this.currentCombo[g][dk].count) {
					lab = lab + ' (' + d[i]['count'] + ')';
				}
				var ar = new Array(str, lab);
				theData.push(ar);
			}
			this.initMenu(el, theData, this.currentCombo[g][dk].text, this.updateComboItemValue[g][fld]);
		} else {
			el.options.length = 1;
			el.disabled = true;
			el.options[0] = new Option(this.currentCombo[g][dk].text, '', false, '');
			el.selectedIndex = 0;
		}
		this.resetCurrentComboConf();
	},
	currentCombo: [],
	resetCurrentComboConf: function(g){
		this.currentCombo[g] = {
			'dataKey': null,
			'table': null,
			'group': null,
			'count': null,
			'text': null,
			'e': null
		};
	},
	currentComboGroup: null,
	loadDDJSON: function (d, e, t, f, g, v, gp, def, c, alt) { // do, element, table, field, where, value, group, allow count
		if (!e) return [];
		var url = this.siteUrl + '/xml.cgi?do='+d+'&t='+t+'&f='+f+'&g='+g+'&v='+v+'&c='+((c) ? 1 : 0);
		var params = '';
		var fld = (alt && alt != '') ? alt : f;
		if (!this.currentCombo[gp]) {
			this.currentCombo[gp] = [];
		}
		this.currentCombo[gp][fld] = {
			'dataKey': f,
			'fieldName': fld,
			'table': t,
			'group': gp,
			'count': c,
			'text': def,
			'e': e
		};
		var fm = e.form;
		if (fm) {
			var s = fm[fld];
			if (s) {
				var txt = GLOBAL.lang.loadingSelect;
				s.options.length = 1;
				s.options[0] = new Option(txt, '', false, '');
				s.selectedIndex = 0;
				s.disabled = true;
				//debugger;
			}
		}
		var ob = {
			'group': gp,
			'field' : fld
		};
		var Response = this.loadRequest(url, 'GET', null, function(g, xml, str, e) {
			var json = g.jsonParse(str);
			var gp = e.group;
			var fld = e.field;
			g.loadXMLDropdown(g.currentCombo[gp][fld].e.form, g.currentCombo[gp][fld].e, g.currentCombo[gp][fld].group, json.data, fld);
			g.currentCombo[gp][fld] = null;
		}, false, ob);
		
		return [];
	},
	loadMultiDDJSON: function (d, e, t, f, g, v, gp, def, c) { // do, element, table, field, where, value, group, allow count
		if (!e) return [];
		var formArray = '';
		var fieldsArray = new Array();
		if (this.comboBoxes[gp][f].parent && this.comboBoxes[gp][f].parent != '') {
			var i = 0;
			var field_to_check = f;
			while (i == 0) {
				var parent = this.comboBoxes[gp][field_to_check].parent;
				fieldsArray.push(parent);
				formArray = formArray + '&' + parent + '=' + this.comboBoxes[gp][parent].currentValue;
				if (this.comboBoxes[gp][parent].parent && this.comboBoxes[gp][parent].parent != '') {
					field_to_check = parent;
				} else {
					i = 1;
				}
			}
			
		}
		
		var url = this.siteUrl + '/xml.cgi?do='+d+'&t='+t+'&f='+f+'&fs='+fieldsArray.join('|') +'&g='+g+formArray+'&c='+((c) ? 1 : 0);
		var params = '';
		if (!this.currentCombo[gp]) {
			this.currentCombo[gp] = [];
		}
		this.currentCombo[gp][f] = {
			'dataKey': f,
			'fieldName': f,
			'table': t,
			'group': gp,
			'count': c,
			'text': def,
			'e': e
		};
		var fm = e.form;
		if (fm) {
			var s = fm[f];
			if (s) {
				var txt = GLOBAL.lang.loadingSelect;
				s.options.length = 1;
				s.options[0] = new Option(txt, '', false, '');
				s.selectedIndex = 0;
				s.disabled = true;
				//debugger;
			}
		}
		var ob = {
			'group': gp,
			'field' : f
		};
		var Response = this.loadRequest(url, 'GET', null, function(g, xml, str, e) {
			var json = g.jsonParse(str);
			var gp = e.group;
			var fld = e.field;
			g.loadXMLDropdown(g.currentCombo[gp][f] .e.form, g.currentCombo[gp][f] .e, g.currentCombo[gp][f] .group, json.data, fld);
			g.currentCombo[gp][f]  = null;
		}, false, ob);
		
		return [];
	},
	loadRequest: function(u, m, v, func, a, e){
		var page_request = false;
		page_request = this.GetHttpRequest();
		if (!page_request) { return false; }
		if (a) {
			a = (a == 'true') ? true:false;
		} else {
			a = true;
		}
		if (m == 'post') {
			page_request.open( 'POST', u, a );
		} else {
			page_request.open( 'GET', u, a );
		}
		page_request.onreadystatechange = function() {
			switch (page_request.readyState) {
				case 4:
					if ( page_request.status == 200 ) {
						if (page_request.responseText) {
							if (typeof func == 'function') {
								func(GLOBAL, page_request.responseXML, page_request.responseText, e);
							}
						} else {
							
						}
						
					} else {
						
					}
				default:
					break;
			}
		}
		
		if (m == 'post') {
			page_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		}
		page_request.send(v);
		return;
	},
	browserSearchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	browserSearchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	returnBrowserClass: function(){
		return (this.browser == "Explorer")?"className":"class";
	},
	classExchange: function(div, clss) {
		div.setAttribute(this.returnBrowserClass(), clss);
	},
	
	swapImgRestore: function() { //v3.0
	  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	},

	findObj: function(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	},

	swapImage: function() { //v3.0
	  var i,j=0,x,a=this.swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=this.findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	},
	showAllTabs: function(g) {
		if (!this.tabGroups[g]) {
			this.tabGroups[g] = { currentTab: null, currentDiv: null };
		} else {
			if (this.tabGroups[g].currentTab == -1) return 0;
			if (this.tabGroups[g].availableTabs && this.tabGroups[g].availableTabs.length > 0) {
				if (this.tabGroups[g].currentTab) {
					tab = this.getElementById(this.tabGroups[g].currentTab);
					var destyle = (this.tabGroups[g].baseStyle) ? this.tabGroups[g].baseStyle : 'x-style-tab-de';
					if (this.tabGroups[g].customLabelBaseStyles && this.tabGroups[g].customLabelBaseStyles[this.tabGroups[g].currentTab]) {
						destyle = this.tabGroups[g].customLabelBaseStyles[this.tabGroups[g].currentTab];
					}
					if (tab) {
						tab.setAttribute( this.returnBrowserClass(), destyle );
					}
				}
				for (i=0; i < this.tabGroups[g].availableTabs.length; i++) {
					div = this.tabGroups[g].availableTabs[i];
					div = this.getElementById(div);
					if (div) {
						if (div.style) { div.style.display = 'block';
						} else if(div.visibility) { div.visibility = 'hide';
						} else {  }
					}
				}
				if (this.tabGroups[g].showAllImg) {
					var acstyle = (this.tabGroups[g].activeStyle) ? this.tabGroups[g].activeStyle : 'x-style-tab-ac';
					if (this.tabGroups[g].customLabelActiveStyles && this.tabGroups[g].customLabelActiveStyles[this.tabGroups[g].showAllImg]) {
						acstyle = this.tabGroups[g].customLabelActiveStyles[this.tabGroups[g].showAllImg];
					}
					tab = this.getElementById(this.tabGroups[g].showAllImg);
					if (tab) {
						tab.setAttribute(this.returnBrowserClass(), acstyle);
					}
				}
				this.tabGroups[g].currentTab = -1;
				this.tabGroups[g].currentDiv = -1;
			}
		}
	},
	hideAllTabs: function(g) {
		if (!this.tabGroups[g]) {
			this.tabGroups[g] = { currentTab: null, currentDiv: null };
		} else {
			if (this.tabGroups[g].availableTabs && this.tabGroups[g].availableTabs.length > 0) {
				for (i=0; i < this.tabGroups[g].availableTabs.length; i++) {
					div = this.tabGroups[g].availableTabs[i];
					div = this.getElementById(div);
					if (div) {
						if (div.style) { div.style.display = 'none';
						} else if(div.visibility) { div.visibility = 'visible';
						} else {  }
					}
				}
				if (this.tabGroups[g].showAllImg) {
					var destyle = (this.tabGroups[g].baseStyle) ? this.tabGroups[g].baseStyle : 'x-style-tab-de';
					tab = this.getElementById(this.tabGroups[g].showAllImg);
					if (tab) {
						tab.setAttribute(this.returnBrowserClass(), destyle);
					}
				}
			}
		}
	},
	swapTab: function(g, t, d) {
		
		if (!this.tabGroups[g]) {
			this.tabGroups[g] = { currentTab: null, currentDiv: null };
		} else {
			if (t == this.tabGroups[g].currentTab) return 1;
			if (this.tabGroups[g].currentTab != -1) {
				var tab = this.tabGroups[g].currentTab;
				var div = this.tabGroups[g].currentDiv;
				
				tab = this.getElementById(tab);
				div = this.getElementById(div);
					
				var destyle = (this.tabGroups[g].baseStyle) ? this.tabGroups[g].baseStyle : 'x-style-tab-de';
				if (this.tabGroups[g].customLabelBaseStyles && this.tabGroups[g].customLabelBaseStyles[this.tabGroups[g].currentTab]) {
					destyle = this.tabGroups[g].customLabelBaseStyles[this.tabGroups[g].currentTab];
				}
				if (tab && div) {
					tab.setAttribute( this.returnBrowserClass(), destyle );
					if (div.style) { div.style.display = 'none';
					} else if(div.visibility) { div.visibility = 'hide';
					} else { return false; }
				}
			} else {
				this.hideAllTabs(g);
			}
		}
		var acstyle = (this.tabGroups[g].activeStyle) ? this.tabGroups[g].activeStyle : 'x-style-tab-ac';
		if (this.tabGroups[g].customLabelActiveStyles && this.tabGroups[g].customLabelActiveStyles[t]) {
			acstyle = this.tabGroups[g].customLabelActiveStyles[t];
		}
		var tab = this.getElementById(t);
		var div = this.getElementById(d);
		if (tab && div) {
			tab.setAttribute(this.returnBrowserClass(), acstyle);
			if (div.style) { div.style.display = 'block';
			} else if(div.visibility) { 
			} else { return false; }
			this.tabGroups[g].currentTab = t;
			this.tabGroups[g].currentDiv = d;
		}
		
		if (this.tabGroups[g].hide_div_extra) {
			//debugger;
			//if (this.tabGroups[g].hide_div_extra.length && this.tabGroups[g].hide_div_extra.length > 0) {
				for (var i in this.tabGroups[g].hide_div_extra) {
					
					var tab = this.getElementById(i);
					if (tab) {
						if (this.tabGroups[g].hide_div_extra[i][t] && this.tabGroups[g].hide_div_extra[i][t] == 1) {
							if (tab.style) {
								tab.style.display = 'none';
							}
						} else {
							if (tab.style) {
								tab.style.display = 'block';
							}
						}
					}
				}
				
				
			//}
		}
	},
	resizeElement: function(d, w, h) {
		if (typeof d == 'string') { d = this.getElementById(d); }
		if( !d || typeof d != 'object') { return false; }
		if (w) {
			w = (w < 1) ? 1:w;
			if (d.style) { d.style.width = w + 'px'; } else if (d.width) { d.width = h;
			} else {}			
		}
		if (h) {
			h = (h < 1) ? 1:h;
			if (d.style) { d.style.height = h + 'px'; } else if (d.height) { d.height = h;
			} else {}
		}
	},
	comfirmSubmit:  function(f, msg) {
		if (typeof f == 'string') {
			f = document.forms[f];
		}
		if (f) {
			var p = confirm(msg);
			if (p) {
				f.submit();
			}
		}
		return false;
	},
	timeout: 1500,
	defaultMenuEffect: null,
  imgPath: '',
  tmId: null,
  openMenu: null,
  menus: [],
  chCSS: function(that, clss){
  	if(that != null ) {
  		this.classExchange(that, clss);
  	}
  },
	hideHdl: null,
	hideMnu: null,
	hideHdl2: null,
	hideMnu2: null,
	hideHdl3: null,
	hideMnu3: null,
	curMenu: null,
	curMenu2: null,
	curMenu3:null,
	curSel3: null,
	oldClass3: null,
	curSel: null,
	oldClass: null,
	curSel2: null,
	oldClass2: null,
	getDim: function(el){
		for (var lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
		return {x:lx,y:ly}
	},
	doHover3: function(o){if(GLOBAL.curSel!=o.id){GLOBAL.oldClass3 = o.className;o.className = "mnuSelItem3"; GLOBAL.curSel2 = o;}},
	doUnHover3: function(o){if(o!=null){o.className = GLOBAL.oldClass3;GLOBAL.curSel3 = null;GLOBAL.oldClass3 = "";}},
	doHover: function(o){if(GLOBAL.curSel!=o.id){GLOBAL.oldClass = o.className;o.className = "mnuSelItem";GLOBAL.curSel = o;}},
	doUnHover: function(o){if(o!=null){o.className = GLOBAL.oldClass;GLOBAL.curSel = null;GLOBAL.oldClass = "";}},
	doHover2: function(o){if(GLOBAL.curSel!=o.id){GLOBAL.oldClass2 = o.className;o.className = "mnuSelItem2";GLOBAL.curSel2 = o;}},
	doUnHover2: function(o){if(o!=null){o.className = GLOBAL.oldClass2; GLOBAL.curSel2 = null; GLOBAL.oldClass2 = "";}},
	showMenu2: function(cid, pid){var o = GLOBAL.getElementById(cid); var op = GLOBAL.getElementById(pid);if( o.style.display != '' ){if(o&&op){GLOBAL.hideVisibleMenus2();var dim = GLOBAL.getDim(op);o.style.top=dim.y;o.style.left=dim.x+op.clientWidth;o.style.display='';GLOBAL.curMenu2 = o;}}clearTimeout(GLOBAL.hideHdl);clearTimeout(GLOBAL.hideHdl2);},
	showMenu3: function(cid, pid) { GLOBAL.hideVisibleMenus(); GLOBAL.showMenu2( cid, pid ); },
	hideMenuEx: function(cid){clearTimeout(GLOBAL.hideHdl2);var o = GLOBAL.getElementById(cid);if(o){GLOBAL.hideHdl2 = setTimeout('GLOBAL.hideMenu2("' + cid + '");', 200);GLOBAL.hideMnu2 = o;}},
	hideMenu2: function(cid){var o = GLOBAL.getElementById(cid);if(o) o.style.display='none';},
	hideVisibleMenus2: function(){if( GLOBAL.hideMnu2 ) GLOBAL.hideMnu2.style.display='none';if( GLOBAL.hideMnu3 ) GLOBAL.hideMnu3.style.display='none';if( GLOBAL.curMenu2 ) GLOBAL.curMenu2.style.display='none';if( GLOBAL.curMenu3 ) GLOBAL.curMenu3.style.display='none';},

	hideInputs: function(){if(navigator.appVersion.indexOf('MSIE')>-1){var objs = document.getElementsByTagName('select');for( var i = 0; i < objs.length; i++ ){if( objs[i].style.display!='none' ){var d = GLOBAL.createElement('div');d.innerHTML=objs[i].options[objs[i].selectedIndex].text;			d.style.display='inline'; d.style.width=objs[i].clientWidth; d.style.padding='2px'; d.style.border='1px solid #999999'; d.style.backgroundColor='white';			if(objs[i].style.fontSize='8pt') d.style.fontSize='8pt';else d.style.fontSize='9pt';objs[i].parentNode.insertBefore(d,objs[i]);			objs[i].style.display='none';}}}},
	showInputs: function(){if(navigator.appVersion.indexOf('MSIE')>-1){var objs = document.getElementsByTagName('select');for( var i = 0; i < objs.length; i++ ){objs[i].style.display='';if( objs[i].previousSibling ) if( objs[i].previousSibling.tagName.toLowerCase()=='div' ) objs[i].parentNode.removeChild(objs[i].previousSibling);}}},

	hideMenu: function(cid){
		clearTimeout(GLOBAL.hideHdl);
		var o = GLOBAL.getElementById(cid);
		if(o){
			GLOBAL.hideHdl = setTimeout('GLOBAL.hideMenu2("' + cid + '");', 200);
			GLOBAL.hideMnu = o;
		}
	},
	createElement: function(w) {
		var d = document.createElement(w);
		return d;
	},
	hideVisibleMenus: function(){
		if( GLOBAL.hideMnu ) GLOBAL.hideMnu.style.display='none';
		if( GLOBAL.hideMnu2 ) GLOBAL.hideMnu2.style.display='none';
		if( GLOBAL.hideMnu3 ) GLOBAL.hideMnu3.style.display='none';
		if( GLOBAL.curMenu ) GLOBAL.curMenu.style.display='none';
		if( GLOBAL.curMenu2 ) GLOBAL.curMenu2.style.display='none';
		if( GLOBAL.curMenu3 ) GLOBAL.curMenu3.style.display='none';
	},
	showMenu: function(cid, pid){
		var o = GLOBAL.getElementById(cid);
		var op = GLOBAL.getElementById(pid);
		if( o.style.display != '' ){
			if(o&&op){
				GLOBAL.hideVisibleMenus();
				//var dim = getDim(op);
				//var dim = findPosition(op);
				//var dim2 = findPosition(o);
				//var clientHeight = op.clientHeight == 0 ? 20 : op.clientHeight;
				//var clientWidth = op.clientWidth == 0 ? 20 : op.clientWidth;
				//o.style.top=parseInt(clientHeight)+'px';
				//o.style.left=parseInt(clientWidth)+'px';
				o.style.display='';
				GLOBAL.curMenu = o;
			}
		}
		clearTimeout(GLOBAL.hideHdl);
		clearTimeout(GLOBAL.hideHdl2);
	},

  setTimeout: function(a, t) { this.tmId = window.setTimeout(a, t); },
  clearTimeout: function() { if (this.tmId!=null) { window.clearTimeout(this.tmId); this.tmId=null;}},
  newMenu: function(i,o) { // id, config options, 
  	if (i) {
  		this.menus[i] = this.menuObject(o);
  	}
  },
  menuObject: function(c) {
  	return {
  		orient: ((c.orient) ? c.orient: 'h'),
  		container: ((c.container) ? c.container: null),
  		showIcon: ((c.showIcon) ? c.showIcon: null),
  		showSubIcon: ((c.showSubIcon) ? c.showSubIcon: null),
  		count: 0,
  		ready: true,
  		position: [0,0],
  		maxColWidth: 100,
  		menuH: 25,
  		menuW: 100
  	};
  },
  menuItemObject: function(c) {
  	return {
  		id: null,
  		menuH: null,
  		menuW: null,
  		onClick: null,
  		clss: null,
  		style: null,
  		icon: null,
  		url: null
  	};
  },
  newSubMenu: function(i,p,o) {
  	
  },
  openMenu: function(i) {
  	
  },
  closeMenu: function() {
  	
  },
  renderMenu: function(i) {
  	if (!this.menus[i]) return false;
  	
  },
  addMenuItems: function(i, itms) {
  	
  	
  },
  disableFormFields: function(f, fld, val, rev, clr, fields) {
  	/*
  		@usage: GLOBAL.disableFormFields(form, form.element.name, value, true, true, ['form.field1', 'form.field2']);
  		rev: reverse the condition...ie, if theVal == val, then disable
  	*/
  	if (!f[fld]) { return false; }
  	var theVal = this.getFormValue(f[fld]);
  	if (fields.length > 0) {
			for (i=0; i < fields.length; i++) {
				if (f[fields[i]]) {
					f[fields[i]].disabled = (rev) ? (theVal == val) : (theVal != val);
					if (((theVal != val && !rev) || (theVal == val && rev)) && clr) {
						this.emptyFormValue(f[fields[i]]);
					}
					
				}
			}
		}
  },
  checkLength: function(f, e, maxchars, str) {
  	if (!e) return false;
  	if (str) {
  		return (str.length <= maxchars);
  	}
  	if (typeof e == 'string') {
  		if (typeof f == 'string') {
  			if (document.forms[f]) { f = document.forms[f]; } else { return false; }
  		}
  		if (f[e]) {
  			e = f[e];
  		} else { return false; }
  	}
  	var theVal = this.getFormValue(e);
		return (theVal <= maxchars);
	},
	getSelectedAds: function(db, t) {
		var old_ads = this.getCookie('SELECTED_ADS');
		if (old_ads == null || old_ads == '' || old_ads == 'empty') {
			old_ads = [];
		} else {
			old_ads = old_ads.split("|");
		}
		var ads = [];
		if (old_ads.length > 0) {
			for (var i in old_ads) {
				var item = old_ads[i].split('=');
				if (item[0] == db) {
					ads.push(item[1]);
				}
			}
		}
		if (ads.length > 0) {
			if (t == 1) {
				return ads.join('|');
			} else {
				return ads;
			}
		} else {
			return 0;
		}
	},
	setSelectedAds: function(e, db, db_id) {
		var old_ads = new Array();
		var cookie_string = this.getCookie('SELECTED_ADS');
		if (cookie_string == null || cookie_string == '') {
			
		} else {
			if (cookie_string != 'empty') {
				old_ads = cookie_string.split("|");
			}
		}
		var ads = new Array();
		var ad = db + '=' + db_id;
		var del = false;
		var ad_count = 0;
		if (old_ads.length > 0) {
			for (var i=0; i < old_ads.length; i++) {
				if (old_ads[i] != ad) {
					ads.push(old_ads[i]);
					var str = old_ads[i];
					var item = str.split("=");
					if (item[0] == db) {
						ad_count++;
					}
				} else {
					del = true;
				}
			}
		}
		if (!del) {
			ads.push(ad);
			ad_count++;
		}
		if (ads.length < 1) {
			ads.push('empty');
		}
		this.setCookie('SELECTED_ADS', ads.join("|"), 30, 'd', '/');
		var counter = this.getElementById('selected_ad_count_Top');
		if (counter) {
			counter.innerHTML = ad_count;
		}
		var counter = this.getElementById('selected_ad_count_Bottom');
		if (counter) {
			counter.innerHTML = ad_count;
		}
		var str = ad_count + ' of 4';
		if (ad_count > 4) {
			str = '<font color="#FF0000">too many</font>';
		}
		var counter = this.getElementById('compare_ad_count_Top');
		if (counter) {
			counter.innerHTML = str;
		}
		var counter = this.getElementById('compare_ad_count_Bottom');
		if (counter) {
			counter.innerHTML = str;
		}
	},
	inArray: function( elem, array ) {
		for ( var i = 0, length = array.length; i < length; i++ )
		// Use === because on IE, window == document
			if ( array[ i ] === elem )
				return i;

		return -1;
	},
	addSelectedToFavourites: function(db, db_id, img, src) {
		var old_ads = this.getCookie('FAVOURITE_ADS');
		if (old_ads == null || old_ads == '') {
			old_ads = [];
		} else {
			if (old_ads == 'empty') {
				old_ads = new Array();
			} else {
				old_ads = old_ads.split("|");
			}
		}
		var ads = [];
		var selectedAds = [];
		if (old_ads.length > 0) {
			for (var i in old_ads) {
				var item = old_ads[i].split('=');
				if (item[0] == db) { //ignore the selected ads from other sections
					ads.push(item[1]);
				}
				selectedAds.push(old_ads[i]);
			}
		}
		
		for (i=0; i < db_id.length; i++) {
			if (this.inArray(db_id[i], ads) == -1) {
				var ad = db + '=' + db_id[i];
				selectedAds.push(ad);
			}
		}
		
		this.setCookie('FAVOURITE_ADS', selectedAds.join("|"), 30, 'd', '/');
	},
	clearSelectedAds: function(db) {
		var old_ads = new Array();
		var cookie_string = this.getCookie('SELECTED_ADS');
		if (cookie_string == null || cookie_string == '') {
			return false;
		} else {
			old_ads = cookie_string.split("|");
		}
		var ads = new Array();
		var selectedAds = new Array();
		if (old_ads.length > 0) {
			for (i=0; i < old_ads.length; i++) {
				
				var item = old_ads[i].split('=');
				if (item[0] != db) { //ignore the selected ads from other sections
					ads.push(old_ads[i]);
				} else {
					if (item[1] && item[1] != '') { 
						var cb = item[1].replace(/\s/, '_');
						cb = 'fav_chkbox_' + cb;
						cb = this.getElementById(cb);
						if (cb && cb.checked) {
							cb.checked = false;
						}
					}
				}
			}
		} else {
			return false;
		}
		if (ads.length < 1) {
			ads.push('empty');
		}
		this.setCookie('SELECTED_ADS', ads.join("|"), 30, 'd', '/');
		var ad_count = 0;
		var counter = this.getElementById('selected_ad_count_Top');
		if (counter) {
			counter.innerHTML = ad_count;
		}
		var counter = this.getElementById('selected_ad_count_Bottom');
		if (counter) {
			counter.innerHTML = ad_count;
		}
		var str = ad_count + ' of 4';
		if (ad_count > 5) {
			str = '<font color="#FF0000">too many</font>';
		}
		var counter = this.getElementById('compare_ad_count_Top');
		if (counter) {
			counter.innerHTML = str;
		}
		var counter = this.getElementById('compare_ad_count_Bottom');
		if (counter) {
			counter.innerHTML = str;
		}
		
	},
	addSelectedToCompare: function(limit, db, gotourl) {
		var old_ads = this.getCookie('SELECTED_ADS');
		if (old_ads == null || old_ads == '' || old_ads == 'empty') {
			//alert(this.lang['no_items_selected_compare']);
			return false;
		} else {
			if (old_ads == 'empty') {
				old_ads = new Array();
			} else {
				old_ads = old_ads.split("|");
			}
		}
		var ads = [];
		if (old_ads.length > 0) {
			for (var i in old_ads) {
				var item = old_ads[i].split('=');
				if (item[0] == db) { //ignore the selected ads from other sections
					ads.push(old_ads[i]);
				}
			}
		}
		// alert if there are more than 5 ads selected for compare
		if (ads.length > limit) {
			alert('You have selected more then ' + limit + ' items.');
			return false;
		} else {
			
			this.setCookie('COMPARE_ADS', ads.join("|"), 30, 'd', '/');
			if (gotourl) {
				this.loadUrl({ url: gotourl });
			}
		}
	},
	setFavourite: function(add_or_del, db, db_id, img, src, standalone) {
		var old_ads = this.getCookie('FAVOURITE_ADS');
		if (old_ads == null || old_ads == '') {
			old_ads = [];
		} else {
			old_ads = old_ads.split("|");
		}
		var ads = [];
		var ad = db + '=' + db_id;
		var del = false;
		
		if (old_ads.length > 0) {
			for (var i in old_ads) {
				if (old_ads[i] != ad) {
					ads.push(old_ads[i]);
				} else {
					del = true;
				}
			}
		}
		if (!del) {
			ads.push(ad);
		}
		this.setCookie('FAVOURITE_ADS', ads.join("|"), 30, 'd', '/');

		if (img) {
			if (src != 1) {
				var imgsrc = this.getElementById(img);
				if(imgsrc && imgsrc.src) {
					imgsrc.src = imgsrc.src.replace(/_(on|off)/, ((!del) ? '_on' : '_off'));
				}
			} else {
				var imgsrc = this.getElementById(img);
				if(imgsrc && imgsrc.src) {
					imgsrc.src = imgsrc.src.replace(/-(on|off)/, ((!del) ? '-on' : '-off'));
				}
			}
			if (!standalone || standalone != 1) {
				var imgsrc = this.getElementById(img+'_side');
				if (imgsrc && imgsrc.src) {
					imgsrc.src = imgsrc.src.replace(/-(on|off)/, ((!del) ? '-on' : '-off'));
				}
				var imgtxt = this.getElementById('favourite_text');
				if (imgtxt) {
					imgtxt.innerHTML = (!del) ? this.lang.favoriteDel : this.lang.favoriteAd;
				} else {
					imgtxt = this.getElementById(img+'_text');
					if (imgtxt) {
						imgtxt.innerHTML = (!del) ? this.lang.favoriteDel : this.lang.favoriteAd;
					}
				}
			}
		}
	},
	// TODO remove this function removeFavouriteItem when using new headlines throughout
	removeFavouriteItem: function(id, num, ad, section, type) {
		var tbl = this.getElementById(id);
		
		var section_count = document.cookie_counters[section+'_cookies'];
		if (!section_count) { return false; }
		var total_count = document.cookie_counters.total_cookie_count;
		if (!total_count) { return false; }
		var section_counter = this.getElementById( section + '_item_count');
		if (!section_counter) { return false; }
		
		var row = this.getElementById(num);
		row.parentNode.removeChild(row);
		this.setFavourite('del', section, ad);
		
		section_count.value = parseInt(section_count.value - 1);
		total_count.value = parseInt(total_count.value - 1);
		
		section_counter.innerHTML = section_count.value;
		
		if (section_count.value < 1) {
			section_div = section + '_results';
			var myReference = this.getElementById(section_div);
			if( !myReference ) { return; }
			if( myReference.display ) {
				myReference.display = 'none';
			} else {
				if( myReference.style ) {
					myReference.style.display = 'none';
				} else {
					return;
				}
			}
		}
		
		if (total_count.value < 1) {
			var myReference = this.getElementById('total_ads_results');
			var myAltReference = this.getElementById('total_ads_no_results');
			if( !myReference ) { return; }
			if( myReference.display ) {
				myReference.display = 'none';
				myAltReference.display = 'block';
			} else {
				if( myReference.style ) {
					myReference.style.display = 'none';
					myAltReference.style.display = 'block';
				} else {
					return;
				}
			}
		}
	},
	comboBoxes: [],
	addComboGroup: function(g, f, c, s) {
		if (this.comboBoxes[g]) { return false; }
		
		if (!f) return false;
		
		this.comboBoxes[g] = new Array();
		this.comboBoxes[g]['formName'] = f;
		if (s) {
			this.comboBoxes[g]['storeCookie'] = false;
		} else {
			this.comboBoxes[g]['storeCookie'] = true;
		}
		if (c) {
			if (c.length) {
				for (i=0; i < c.length; i++) {
					if (this.comboBoxes[g][c[i].name]) {
						
					} else {
						this.comboBoxes[g][c[i].name] = this.comboObject(c[i]);
					}
					if (c[i].parent && this.comboBoxes[g][c[i].parent]) {
						this.comboBoxes[g][c[i].parent].children.push(c[i].name);
					}
				}
			}
		}
	},
	comboObject: function(c) {
		return {
			name: ((c.name) ? c.name : null),
			parent: ((c.parent) ? c.parent : null),
			children: new Array(),
			data: ((c.data) ? c.data : null),
			currentValue: ((c.currentValue) ? c.currentValue : null),
			childText: ((c.childText) ? c.childText : '')
		};
	},
	updateComboCookie: function() {
		if (!this.comboBoxes) return false;
		
		var cData = new Array();
		for (i in this.comboBoxes) {
			var cookData = new Array();
			for (j in this.comboBoxes[i]) {
				if (j == 'formName') { continue; }
				thisValue = this.comboBoxes[i][j].currentValue;
				if (j == 'storeCookie') {
					if (this.comboBoxes[i][j] == true) {
						thisValue = 'true';
					} else {
						thisValue = 'false';
					}
				}
				var tstr = '{' + j + ':' + thisValue + '}';
				cookData.push(tstr);
			}
			if (cookData.length > 0) {
				var str = i + ':[' + cookData.join(',') + ']';
				cData.push(str);
			}
		}
		if (cData.length > 0) {
			this.setCookie('multiselects', cData.join(','), null, null, '/', false);
		}
	},
	regex: function(reg, str) {
		m = new Array;
		try {
			m = reg.exec(str);
		} catch(e) {
			alert(e.description);
		}
		return m;
	},
  initComboBoxes: function(){
  	var cook = this.getCookie('multiselects');
  	thisForm = null;
  	if (cook) {
  		var reg = /([^:]+):\[([^\]]+)\](,)?/gi;
  		var reg2 = /\{([^\:]+):([^\}]+)\}/gi;
  		while (m = reg.exec(cook)) {
  			if (!m) { continue; }
  			var combo = m[1];
  			var lists = m[2];
  			if (this.comboBoxes[combo]) {
  				if (this.comboBoxes[combo]['formName']) {
  					thisForm = this.comboBoxes[combo]['formName'];
  					thisForm = document.forms[thisForm];
  				}
  				var sCookie = true;
					while (c = reg2.exec(lists)) {
						if (!c) { continue; }
						var f = c[1];
						var v = c[2];
						if (f) {
  						if (this.comboBoxes[combo][f]) {
  							if (f == 'storeCookie') {
  								sCookie = (v == 'true') ? true : false;
  								this.comboBoxes[combo][f] = sCookie;
  							} else {
  								this.comboBoxes[combo][f].currentValue = v;
						  		if (thisForm) {
						  			if (this.comboBoxes[combo][f].parent != null) {
						  				theParent = this.comboBoxes[combo][f].parent;
						  				var e = thisForm[theParent];
						  				if (this.comboBoxes[combo][theParent].childText != '') {
						  					this.updateComboSelectBox(e, combo, thisForm, true, false, v);
						  				} else {
						  					this.updateComboValue(e,combo,true, v);
						  				}
						  			}
						  		}
  							}
  						}
  					}
					}
  			}
  		}
  	} else {
  		if (!this.comboBoxes) return false;
  		for (combo in this.comboBoxes) {
				if (this.comboBoxes[combo]) {
					if (this.comboBoxes[combo]['formName']) {
  					thisForm = this.comboBoxes[combo]['formName'];
  					thisForm = document.forms[thisForm];
  				}
  				if (!thisForm) continue;
					for (f in this.comboBoxes[combo]) {
						if (f == 'formName') continue;
						if (f == '') continue;
						if (f == 'storeCookie') continue;
						if (this.comboBoxes[combo][f].parent != null) {
		  				theParent = this.comboBoxes[combo][f].parent;
		  				var e = thisForm[theParent];
		  				if (this.comboBoxes[combo][theParent].childText != '') {
		  					this.updateComboSelectBox(e, combo, thisForm, true, false, this.comboBoxes[combo][f].currentValue);
		  				} else {
		  					this.updateComboValue(e,combo,true, this.comboBoxes[combo][f].currentValue);
		  				}
		  			}
					}
				}
  		}
  	}
  },
	updateComboValue: function(e,g,s, v) {
		if (!g) { return false; }
		if (!this.comboBoxes[g]) return false;
		if (!this.comboBoxes[g][e.name]) return false;
		f = e.form;
		if (!f) return false;
		if (!this.comboBoxes[g]['formName'] || f.name != this.comboBoxes[g]['formName']) return false;
		this.comboBoxes[g][e.name].currentValue = this.getFormValue(e);
		if (s) {
			this.updateComboCookie();
		}
	},
	updateComboItemValue: [],
	updateComboSelectBox: function(e, g, f, s, c, v) { // e = element, g = group, f = form, s = set cookie, c = clear children, currentValue
		if (!g) { return false; }
		if (!this.comboBoxes[g]) return false;
		if (!this.comboBoxes[g][e.name]) return false;
		if (!f) return false;
		if (!this.comboBoxes[g]['formName'] || f.name != this.comboBoxes[g]['formName']) return false;
		//debugger;
		this.comboBoxes[g][e.name].currentValue = this.getFormValue(e);
		if (this.comboBoxes[g][e.name].children && this.comboBoxes[g][e.name].children.length > 0) {
			for (var lo=0; lo < this.comboBoxes[g][e.name].children.length; lo++) {
				var o = this.comboBoxes[g][e.name].children[lo];
				var el = null;
				try {
					el = f[o];
				} catch(err) {
					continue;
				}
				if (!el) continue;
				
				if (c) {
					if (this.comboBoxes[g][o]) {
						if (this.comboBoxes[g][o].children && this.comboBoxes[g][o].children.length > 0) {
							this.updateComboSelectBox(el, g, f, s, true);
						}
						this.comboBoxes[g][o].currentValue = null;
						el.length = 1;
						el.options[0].value = "";
						el.options[0].text = this.comboBoxes[g][this.comboBoxes[g][o].parent].childText;
						el.selectedIndex = 0;
						el.disabled = true;
					}
				} else {
					if (this.comboBoxes[g][o]) {
						if (this.comboBoxes[g][o].children && this.comboBoxes[g][o].children.length > 0) {
							this.updateComboSelectBox(el, g, f, s, true);
						}
						if (this.comboBoxes[g][e.name].currentValue == '') {
							el.length = 1;
							el.options[0].value = "";
							el.options[0].text = this.comboBoxes[g][e.name].childText;
							el.selectedIndex = 0;
							el.disabled = true;
						} else {
							this.comboBoxes[g][o].currentValue = (v != undefined) ? v : null;
							if (this.comboBoxes[g][o].data) {
								var theData = null;
								if (this.isArray(this.comboBoxes[g][o].data)) {
									theData = this.comboBoxes[g][o].data[this.comboBoxes[g][e.name].currentValue];
									if (theData && theData.length > 0) {
										this.initMenu(el, theData, '', v);
									}
								} else if (typeof this.comboBoxes[g][o].data === 'function') {
									this.updateComboItemValue[g] = new Array();
									this.updateComboItemValue[g][o] = this.comboBoxes[g][o].currentValue;
									theData = this.comboBoxes[g][o].data(this, this.comboBoxes[g][e.name].currentValue, g, e);
								}
							}
						}
						if (this.comboBoxes[g]['storeCookie']) {
							this.updateComboCookie();
						}
					}
				}
			}
		}
		
		
	},
	isArray: function(obj) { // frames lose type, so test constructor string
		if (obj.constructor && obj.constructor.toString().indexOf('Array') > -1) {
		    return true;
		} else {
		    return this.isObject(obj) && obj.constructor == Array;
		}
  },
	isBoolean: function(obj) {
    return typeof obj == 'boolean';
  },
	isFunction: function(obj) {
		return typeof obj == 'function';
  },
  isNull: function(obj) {
		return obj === null;
  },
  isNumber: function(obj) {
		return typeof obj == 'number' && isFinite(obj);
	},
	isObject: function(obj) {
		return typeof obj == 'object' || this.isFunction(obj);
	},
	isString: function(obj) {
		return typeof obj == 'string';
	},
	isUndefined: function(obj) {
		return typeof obj == 'undefined';
	},
	initMenu: function(fName, tFields, fText, value) {
		fName.options.length = 0;
		fName.disabled = true;
		fName.options[0] = new Option(((fText) ? fText: ''), '', false, '');
		i = 1;
		for (var j=0; j < tFields.length; j++) {
			var theVal = new Array();
			if (this.isArray(tFields[j])) {
				if (tFields[j][0] == value) {
					var selected = true;
					var seltext = 'selected="selected"';
				} else {
					var selected = false;
					var seltext = "";
				}
				fName.options[i] = new Option(tFields[j][1], tFields[j][0], selected, seltext);
			} else {
				if (tFields[j] == value) {
					var selected = true;
					var seltext = 'selected="selected"';
				} else {
					var selected = false;
					var seltext = "";
				}
				fName.options[i] = new Option(tFields[j], tFields[j], selected, seltext);
			}
			i++;
		}
		if (fName.options.length > 0) {
			fName.disabled = false;
		}
	},
	Pause: function(d) {
		if ( (d == null) || (d <= 0)) {return;}
		var duration = d * 1000;
		var later = (new Date()).getTime() + duration;
		while(true){
			if ((new Date()).getTime() > later) {
				break;
			}
		}
	},
	updateFormValue: function(e, v) {
		if (typeof e == 'string') {
			e = this.getElementById(e);
		}
		if (e) {
			e.value = v;
		}
	},
  emptyFormValue: function(e) {
  	var val=type='';
		if (e.length) {
			for (r=0; r<e.length;r++) {
				type = e[r].type;
				break;
			}
		} else {
			type = e.type;
		}
		if (type=='') { return 'error: no type'; }
		switch (type) {
			case 'radio':
				if (e.length) {
					for (r=0; r<e.length;r++) {
						if (e[r].checked == true) { e[r].checked = false; }
					}
				} else {
					if (e.checked) { e.checked = false; }
				}
				break;
			case 'checkbox':
				if (e.checked) { e.checked = false; }
				break;
			case 'select':
				e.selectedIndex = -1;
				break;
			default:
				e.value = ''; break;
		}
  },
  vForms: [],
  validateForm: function(f) { // form, submit(true/false)
  	if (typeof f == 'string') { 
  		f = document.forms[f];
  	}
  	if (!f || !f.name) return false;
  	if (typeof f != 'object') { return false; }
		if (this.vForms[f.name] && this.vForms[f.name].fields.length > 0) {
			var vt = this.vtypes;
			for (i=0; i < this.vForms[f.name].fields.length; i++) {
				var obj = this.vForms[f.name].fields[i];
				var e = obj.name;
				var vtype = obj.vtype;
				if (!f[e]) { continue; }
				var val = this.getFormValue(f[e]);
				try {
					if (obj.required) {
						if(!vt['required'](val, this)){
							if (obj.invalidText != '') {
								alert(obj.invalidText);
							} else {
								alert(this.lang.invalidError);
							}
							return false;
          	}
					}
					if (!obj.allowHTML) {
						if(!vt['html'](val, this)){
							alert(this.lang.invalidHTMLError);
							return false;
          	}
					}
					if (vtype) {
						if (val != '') {
							if (vtype == 'compare') {
								if (obj.compare && f[obj.compare]) {
									var theCompVal = this.getFormValue(f[obj.compare]);
									if(!vt['compare'](val, theCompVal, this)){
										if (obj.invalidCompareText != '') {
											alert(obj.invalidCompareText);
										} else {
											alert(this.lang.invalidError);
										}
			      	      return false;
			          	}
								} else {
									alert(this.lang.invalidError);
									return false;
								}
							} else {
								if(!vt[vtype](val, this)){
									if (obj.invalidText != '') {
										alert(obj.invalidText);
									} else {
										alert(this.lang.invalidError);
									}
		      	      return false;
		          	}
							}
						}
          }
				} catch(e) {
				}
			}
			this.vForms[f.name].submit(f, this);
		}
  	return false;
  },
	newFormValidation: function(f, c) {
		if (this.vForms && this.vForms.length > 0) {
			if (this.vForms[f]) {
				return false;
			}
		}
		
		var vfields = new Array();
		if (c.fields && c.fields.length > 0) {
			for (i=0; i < c.fields.length; i++) {
				if (!c.fields[i].name || !c.fields[i].type) { continue; } 
				vfields[i] = this.validationFieldObject({
					name: c.fields[i].name,
					type: c.fields[i].type,
					required: c.fields[i].required,
					vtype: ((c.fields[i].vtype) ? c.fields[i].vtype : false ),
					compare: ((c.fields[i].compare) ? c.fields[i].compare : false ),
					allowHTML: ((c.fields[i].allowHTML) ? c.fields[i].allowHTML : false ),
					invalidText: ((c.fields[i].invalidText) ? c.fields[i].invalidText : ''),
					invalidCompareText: ((c.fields[i].invalidCompareText) ? c.fields[i].invalidCompareText : '')
				});
			}
			var sf = function(f, o) { f.submit(); };
			sf = (c.submit) ? c.submit:sf;
			var flash = (c.flash) ? true : false;
			this.vForms[f] = this.validationFormObject({
				fields: vfields,
				form: f,
				submit: sf,
				flashfield: flash
			});
			
		}
		return false;
	},
	validationFormObject: function(c) {
		return {
			fields: ((c.fields) ? c.fields: []),
			form: ((c.form) ? c.form: null),
			submit: ((c.submit) ? c.submit: true),
			flashfield: false
		};
	},
	validationFieldObject: function(c) {
		var vtype = (c.vtype) ? c.vtype: false;
		var compare = (c.compare) ? c.compare: false;
		var allowHTML = (c.allowHTML) ? true: false;
		return {
			name: ((c.name) ? c.name: null),
			type: ((c.type) ? c.type: null),
			required: (c.required),
			vtype: vtype,
			compare: compare,
			allowHTML: allowHTML,
			invalidText: ((c.invalidText) ? c.invalidText: ''),
			invalidCompareText: ((c.invalidCompareText) ? c.invalidCompareText: '')
		};
	},
	swapValidateImage: function(f, id) {
		var img = this.getElementById(id);
		if (img) {
			if (typeof f == 'string') {
				f = this.getElementById(f);
			}
			if (f) {
				if (f.value != "") {
					var url = 'doimage.cgi?do=3&imagevalidatefile=' + f.value + '&rand=' + Math.random();
					img.src = url;
				}
			}
		}
	},
	matchFieldSelect: function(field, select, value) {
		if (select.disabled == true) return false;
		var property = value ? 'value' : 'text';
		var found = false;
		var elems = field.value.split(',');
		var le = elems.length - 1;
		var reg = /^\s/i;
		nval = elems[le].replace(reg, '');
		for (var i = 0; i < select.options.length; i++) {
			var val = select.options[i][property].toLowerCase();
			if ((found = val.indexOf(nval.toLowerCase()) == 0)) break;
		}
		if (found)
		select.selectedIndex = i;
		else
		select.selectedIndex = -1;
	},
	addItemToText: function(field, text, sep) {
		var sp = sep ? sep : ',';
		var nt = field.options[field.selectedIndex].value;
		if (nt == '') return false;
		var reg = /^\s/i;
		var elems = text.value.split(',');
		var found = false;
		for (var i=0; i < elems.length; i++) {
			var val = elems[i].replace(reg, '');
			if (val.toLowerCase() == nt.toLowerCase()) {
				found = true;
				break;
			}
		}
		if (!found) {
			var le = elems.length - 1;
			elems[le] = ' ' + nt;
			text.value = elems.join(sp) + sp + ' ';
		}
	},
	keyUPList: [],
	keyUpStart: [],
	currentListDiv: null,
	keyUpLoading: false,
	autoLoadList: function(g, v, d, e) {
		if (this.hidingDiv == 1) {
			this.hidingDiv = 0;
			return false;
		}
		if (v.length > 1) {
			this.currentListDiv = d;
			if (v.indexOf(',') > -1) {
				var elms = v.split(',');
				v = elms[0];
			}
			
			if (v.length == 2 || (v.length > 1 && !this.keyUPList[g])) {
				var el = this.getElementById(d);
				if (el) {
					el.style.display = 'block';
				} else {
					return false;
				}
				if (!this.keyUpStart[g] || this.keyUpStart[g].toLowerCase() != v.toLowerCase()) {
					this.keyUPList[g] = new Array();
					if (!this.keyUpLoading) {
						el.style.display = 'block';
						el.innerHTML = 'Loading...';
						this.keyUpLoading = true;
						this.keyUpStart[g] = v.substr(0, 2);
						this.loadListValues(d, this.siteUrl + '/xml.cgi?do=3&v='+v.substr(0, 2), e, g, this.getElementById(e));
					}
				}
			}
			if (this.keyUPList[g] && this.keyUPList[g].length > 0) {
				var v_l = 0;
				for (i=0; i < this.keyUPList[g].length; i++) {
					var val = this.keyUPList[g][i].toLowerCase();
					if (val.indexOf(v.toLowerCase()) == 0) {
						var el = this.getElementById(g+'_drop_'+i);
						if (el) {
							el.style.display = 'block';
						}
						v_l++;
					} else {
						var el = this.getElementById(g+'_drop_'+i);
						if (el) {
							el.style.display = 'none';
						}
					}
				}
				var el = this.getElementById(d);
				var n_h = v_l * 20;
				if (n_h > 200) {
					el.style.height = '200px';
				} else {
					el.style.height = n_h + 'px';
				}
				el.style.display = 'block';
			}
		} else {
			var el = this.getElementById(d);
			if (el) {
				el.style.display = 'none';
			}
		}
	},
	toggleElement: function(d, i) {
		if (typeof d == 'string') {
			d = this.getElementById(d);
		}
		var setIcon = '_on';
		if (d && d.style) {
			d.style.display = (d.style.display != 'block') ? 'block' : 'none';
			setIcon = (d.style.display != 'block') ? '_on' : '_off';
		}
		if (i) {
			i = this.getElementById(i);
			if (i && i.src) {
				i.src= i.src.replace(/_(on|off)/, setIcon);
			}
		}
	},
	hideElement: function(d) {
		if (typeof d == 'string') {
			d = this.getElementById(d);
		}
		if (d && d.style) {
			d.style.display = 'none';
		}
	},
	showElement: function(d) {
		if (typeof d == 'string') {
			d = this.getElementById(d);
		}
		if (d && d.style) {
			d.style.display = 'block';
		}
	},
	hideListElement: function(d) {
		this.setTimeout('GLOBAL.hideListDiv()', 500);
	},
	hideListDiv: function() {
		if (this.currentListDiv) {
			d = this.currentListDiv;
			if (typeof d == 'string') {
				d = this.getElementById(d);
			}
			if (d && d.style) {
				d.style.display = 'none';
			}
		}
		this.clearTimeout();
	},
	hidingDiv: 0,
	selectedListValue: '',
	loadListValues: function(d, u, e, g, el) {
		var page_request = false;
		page_request = this.GetHttpRequest();
		if (!page_request) { return false; }
		var a = true;
		page_request.open( 'GET', u, a );
		
		page_request.onreadystatechange = function() {
			switch (page_request.readyState) {
				case 4:
					if ( page_request.status == 200 ) {
						if (page_request.responseText) {
							var json = GLOBAL.jsonParse(page_request.responseText);
							if (json.list && json.list.length > 0) {
								GLOBAL.keyUPList[g] = json.list;
								if (json.data && json.data.length > 0) {
									var str = '';
									var reg = /\s/i;
									var div = GLOBAL.getElementById(d);
									if (div) {
										for (i=0; i< json.data.length; i++) {
											var d_id = g+'_drop_'+i;
											var d_str = ((json.data[i].town != '') ? json.data[i].town +', ':'') + json.data[i].state +((json.data[i].postcode != '') ? ', '+json.data[i].postcode : '');
											var j_str = ((json.data[i].town != '') ? json.data[i].town +', ':'') + json.data[i].state;
											j_str = j_str.replace("'", "\\'");
											
											str = str + '<div id="' + d_id + '" class="maintext" style="display: block; height: 20px; padding-left: 4px; padding-right: 4px; font-size: 13px; line-height: 20px;" onclick="GLOBAL.updateFormValue(\'' + e + '\', \'' + j_str + '\'); GLOBAL.getElementById(\'' + d + '\').style.display=\'none\'; GLOBAL.hidingDiv = 1; return false;" onmouseover="GLOBAL.clearTimeout();"><a href="#" onclick="GLOBAL.updateFormValue(\'' + e + '\', \'' + j_str + '\'); GLOBAL.getElementById(\'' + d + '\').style.display=\'none\'; GLOBAL.selectedListValue = \'' + j_str + '\'; return false;" onmouseover="GLOBAL.clearTimeout();">' + d_str +'</a></div>';
										}
										div.innerHTML = str;
									}
								} else {
									var div = GLOBAL.getElementById(d);
									if (div) {
										div.style.display = 'none';
									}
								}
							} else {
								var div = GLOBAL.getElementById(d);
								if (div) {
									div.style.display = 'none';
								}
							}
						} else {
							var div = GLOBAL.getElementById(d);
							if (div) {
								div.style.display = 'none';
							}
						}
						
					} else {
						var div = GLOBAL.getElementById(d);
						if (div) {
							div.style.display = 'none';
						}
					}
					GLOBAL.keyUpLoading = false;
					GLOBAL.autoLoadList(g, el.value, d, e);
				default:
					break;
			}
		}
		
		page_request.send(null);
		return;
		
	},
	checkLoginMemory: function(what, name, path, domain) {
		if (!what.checked) {
			this.deleteCookie(name);
		}
	},
	deleteCookie: function( name, path, domain ) {
		if (  this.getCookie(name)  ) {
			document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
	},
	getCookie: function(name) {
		var cookies = document.cookie.split( ';' );
		var atc = ''; var cn = ''; var cv = ''; var cf = false;
		if (cookies.length > 0) {
			for ( i = 0; i < cookies.length; i++ ) {
				atc = cookies[i].match(/^([^=]*)=(.*)/);
				cn = atc[1].replace(/^\s+|\s+$/g, '');
				if ( cn == name ) {
					cf = true;
					if ( atc.length == 3 ){ cv = unescape( atc[2].replace(/^\s+|\s+$/g, '') ); }
					return cv; break;
				}
				atc = null; cn = '';
			}
		}
		if ( !cf ){ return null; }

	},
	setCookie: function( name, value, expires, exp_type, path, esc, domain, secure ) {
		// set time, it's in milliseconds
		today = new Date();
		this.fixCookieDate(today);
		exp_type = (exp_type || exp_type != 'd') ? exp_type : 'd';
		/*
		if the expires variable is set, make the correct 
		expires time, the current script below will set 
		it for x number of days, to make it for hours, 
		delete * 24, for minutes, delete * 60 * 24
		*/
		var expires_date = null;
		if ( expires ) {
			if (exp_type == 'y') {
				expires = expires * 1000 * 60 * 60 * 24 * 356;
			} else if (exp_type == 'd') {
				expires = expires * 1000 * 60 * 60 * 24;
			} else if (exp_type == 'h') {
				expires = expires * 1000 * 60 * 60;
			} else if (exp_type == 'm') {
				expires = expires * 1000 * 60;
			} else {
				expires = expires * 1000 * 60 * 60 * 24;
			}
			expires_date = new Date( today.getTime() + (expires) );
		} else {
			expires_date = new Date();
		}
		
		document.cookie = name + "=" +((esc) ? escape( value ) : value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
//		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
	},
	fixCookieDate: function(date) {
	  var base = new Date(0);var skew = base.getTime(); // dawn of (Unix) time - should be 0
	  if (skew > 0)  // Except on the Mac - ahead of its time
	    date.setTime (date.getTime() - skew);
	},
	destroyMask: function(destroy) {
		var d = this.getElementById('globalmask');
		if (d) {
			if (destroy && d.parentNode) {
				d.parentNode.removeChild(d);
			} else {
				if (d.style) {
					d.style.display = 'none';
				} else {
					
				}
			}
		}
	},
	createMask: function() {
		var d = this.getElementById('globalmask');
		if (d) {
			if (d.style) {
				d.style.display = 'block';
			} else {
				
			}
		} else {
			div = this.createElement('DIV');
			if (div) {
				div.setAttribute('id', 'globalmask');
				div.style.position = 'absolute';
				div.style.top = 0;
				div.style.left = 0;	
				div.style.backgroundColor = '#000000';
				div.style.filter = 'alpha(style=0, opacity=80, finishOpacity=0)';
				div.style.opacity = 0.8;
				var winH = this.getWinH();
				var h = 
		  (window.innerHeight && window.scrollMaxY) ? window.innerHeight + window.scrollMaxY
		: (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight
		: document.body.offsetHeight;
				div.style.height = (winH < h) ? h + 'px' : '100%';
				div.style.width = '100%';
				div.style.display = 'block';
				document.body.appendChild(div);
			}
		}
	},
	swapLayers: function(d, o) {
		var div = this.getElementById(d);
		if (div.style) {
			div.style.display = 'none';
		} else {
			if (div.display) {
				div.display = 'none';
			}
		}
		var logO = this.getElementById(o);
		if (logO.style) {
			logO.style.display = 'block';
		} else {
			if (logO.display) {
				logO.display = 'block';
			}
		}
	},
	doubleDigit: function(n) {    // Format integers to have at least two digits.
      return n < 10 ? '0' + n : n;
  },
  quote: function(string) {
  	var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g,
            gap,
            indent,
            meta = {    // table of character substitutions
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"' : '\\"',
                '\\': '\\\\'
            },
            rep;
    return escapeable.test(string) ?
        '"' + string.replace(escapeable, function (a) {
            var c = meta[a];
            if (typeof c === 'string') {
                return c;
            }
            c = a.charCodeAt();
            return '\\u00' + Math.floor(c / 16).toString(16) +
                                       (c % 16).toString(16);
        }) + '"' :
        '"' + string + '"';
  },
  jsonStr: function(key, holder) {
		var i,          // The loop counter.
        k,          // The member key.
        v,          // The member value.
        length,
        mind = gap,
        partial,
        value = holder[key];
		if (value && typeof value === 'object' &&
            typeof value.toJSON === 'function') {
        value = value.toJSON(key);
    }

    if (typeof rep === 'function') {
        value = rep.call(holder, key, value);
    }

    switch (typeof value) {
    	case 'string':
        return this.quote(value);

    	case 'number':
        return isFinite(value) ? String(value) : 'null';

    	case 'boolean':
   		case 'null':
        return String(value);
    	case 'object':
        if (!value) {
            return 'null';
        }
        gap += indent;
        partial = [];
        if (typeof value.length === 'number' &&
                !(value.propertyIsEnumerable('length'))) {
            length = value.length;
            for (i = 0; i < length; i += 1) {
                partial[i] = this.jsonStr(i, value) || 'null';
            }
            v = partial.length === 0 ? '[]' :
                gap ? '[\n' + gap + partial.join(',\n' + gap) +
                          '\n' + mind + ']' :
                      '[' + partial.join(',') + ']';
            gap = mind;
            return v;
        }
        if (typeof rep === 'object') {
            length = rep.length;
            for (i = 0; i < length; i += 1) {
                k = rep[i];
                if (typeof k === 'string') {
                    v = this.jsonStr(k, value, rep);
                    if (v) {
                        partial.push(this.quote(k) + (gap ? ': ' : ':') + v);
                    }
                }
            }
        } else {
            for (k in value) {
                v = this.jsonStr(k, value, rep);
                if (v) {
                    partial.push(this.quote(k) + (gap ? ': ' : ':') + v);
                }
            }
        }
        v = partial.length === 0 ? '{}' :
            gap ? '{\n' + gap + partial.join(',\n' + gap) +
                      '\n' + mind + '}' :
                  '{' + partial.join(',') + '}';
        gap = mind;
        return v;
    }
	},
	jsonStringify: function (value, replacer, space) {
      var i;
      gap = '';
      indent = '';
      if (space) {
          if (typeof space === 'number') {
              for (i = 0; i < space; i += 1) {
                  indent += ' ';
              }
          } else if (typeof space === 'string') {
              indent = space;
          }
      }
      if (!replacer) {
          rep = function (key, value) {
              if (!Object.hasOwnProperty.call(this, key)) {
                  return undefined;
              }
              return value;
          };
      } else if (typeof replacer === 'function' ||
              (typeof replacer === 'object' &&
               typeof replacer.length === 'number')) {
          rep = replacer;
      } else {
          throw new Error('GLOBAL.JSON.stringify');
      }
      return this.jsonStr('', {'': value});
  },
  jsonParse: function (text, reviver) {
      var j;
     
      j = eval('(' + text + ')');
      return typeof reviver === 'function' ?  this.jsonWalk({'': j}, '') : j;
      
      
      throw new SyntaxError('this.jsonParse');
  },
  jsonWalk: function(holder, key) {
      var k, v, value = holder[key];
      if (value && typeof value === 'object') {
          for (k in value) {
              if (Object.hasOwnProperty.call(value, k)) {
                  v = this.jsonWalk(value, k);
                  if (v !== undefined) {
                      value[k] = v;
                  } else {
                      delete value[k];
                  }
              }
          }
      }
      return reviver.call(holder, key, value);
  },
  browser: null,
  version: null,
  OS: null,
	init: function () {
		this.browser = this.browserSearchString(this.dataBrowser) || "An unknown browser";
		this.version = this.browserSearchVersion(navigator.userAgent)
			|| this.browserSearchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.browserSearchString(this.dataOS) || "an unknown OS";
	}
};

Date.prototype.toJSON = function () {
            return this.getUTCFullYear()   + '-' +
                 GLOBAL.doubleDigit(this.getUTCMonth() + 1) + '-' +
                 GLOBAL.doubleDigit(this.getUTCDate())      + 'T' +
                 GLOBAL.doubleDigit(this.getUTCHours())     + ':' +
                 GLOBAL.doubleDigit(this.getUTCMinutes())   + ':' +
                 GLOBAL.doubleDigit(this.getUTCSeconds())   + 'Z';
        };

GLOBAL.init();
