var scripturl = "";

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

function calculateTimeOffset()
{
	d = new Date();
	document.getElementById("timeOffset").value = (d.getTimezoneOffset() / 60) * -1;
	updateTime(false);
}

var timeout;
var searchString = "";

function beginSICRetrieval()
{
	var sicSearch = document.getElementById('sicSearch');
	var sicResults = document.getElementById('sicResults');
	
	if((sicSearch.value.length < 4 && isNaN(sicSearch.value)) || (sicSearch.value == ""))
	{
		sicSearchValue = "";
		searchString = "";
		
		while(sicResults.childNodes.length > 0)
			sicResults.removeChild(sicResults.firstChild);
		
		isInSICResults = false;
		hideResults();
		return;
	}
	
	if(sicSearch.value.length > 0 && (isNaN(sicSearch.value) && searchString == "") || (!isNaN(sicSearch.value) && searchString == ""))
	{
		if(isNaN(sicSearch.value))
			searchString = sicSearch.value.substring(0, 4);
		else
			searchString = sicSearch.value.substring(0, 1);
		beginAjax();
	}
	else
	{
		var sicSearch = document.getElementById('sicSearch');
		var sicResults = document.getElementById('sicResults');
		
		var rA = sicResults.getElementsByTagName('a');
		
		sicSearchValue = sicSearch.value.replace(/^\s+|\s+$/g, '');
		
		while(sicResults.childNodes.length > 0)
			sicResults.removeChild(sicResults.firstChild);
		var show = false;
		for(i = 0; i < sicResultObjects.length; i++)
		{
			var str = sicResultObjects[i].SIC + " - " + sicResultObjects[i].name;
		
			var beginAt = str.toLowerCase().indexOf(sicSearchValue.toLowerCase());
			
			if(beginAt >= 0)
			{
				var begin = str.substring(0, beginAt);
				var middle = str.substring(beginAt, beginAt + sicSearchValue.length);
				var end = str.substring(beginAt + sicSearchValue.length);
				var rA = document.createElement('a');
				//rA.style.fontSize = "x-small";
				//rA.onmouseover = new Function("this.oldStyle = this.style; this.style.color = '#F00';");
				//rA.onmouseout = new Function("this.style = this.oldStyle;");
				rA.appendChild(document.createTextNode(begin));
				var rSpan = document.createElement('span');
				//rSpan.style.fontWeight = "bold";
				//rSpan.style.textDecoration = "underline";
				rSpan.appendChild(document.createTextNode(middle));
				rA.appendChild(rSpan);
				rA.appendChild(document.createTextNode(end));
				//rA.onclick = new Function("addToSICList(" + i + ")");
				rA.onclick = new Function("AddANZSICCode(" + i + ")");
				sicResults.appendChild(rA);
				sicResults.appendChild(document.createElement('br'));
				show = true;
			}
		}
		
		if(!show)
		{
			isInSICResults = false;
			hideResults();
		}
		else
		{
			isInSICResults = false;
			hideResults();
			showResults();
		}
	}
}

var ajaxObj;

function getElementPosition(object)
{
	var curleft = 0;
	var curtop = 0;

	if (object.offsetParent)
	{
		do
		{
			//if(object.style.position == "absolute")
			//	break;
			//alert(object.style.position + curleft + ', ' + curtop);
			curleft += object.offsetLeft;
			curtop += object.offsetTop;
		}
		while (object = object.offsetParent);
//alert(curleft + ', ' + curtop);
		return [curleft,curtop];
	}
}

var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

function showResults()
{
	var sicSearch = document.getElementById('sicSearch');
	var sicResults = document.getElementById('sicResults');
	if(sicResults)
	{
		var position = getElementPosition(sicSearch);
		sicResults.style.left = position[0] + "px";
		sicResults.style.top = (position[1] + sicSearch.offsetHeight) + "px";	

		if(IE6)
		{	
			//Increase default zIndex of div by 1, so that DIV appears before IFrame
			sicResults.style.zIndex=sicResults.style.zIndex+1;

			/*var iFrame = document.createElement("IFRAME");
			iFrame.setAttribute("src", "");

			//Match IFrame position with sicResults
			iFrame.style.position="absolute";
			iFrame.style.left =sicResults.offsetLeft + 'px';
			iFrame.style.top =sicResults.offsetTop + 'px';
			iFrame.style.width =sicResults.offsetWidth + 'px';
			iFrame.style.height =sicResults.offsetHeight + 'px';

			document.body.appendChild(iFrame);

			//Store iFrame in global variable, so it can get removed when sicResults is hidden g_PopupIFrame=iFrame;
			g_PopupIFrame=iFrame;*/
		}
		
		sicResults.style.visibility ="visible";
	}
}

var isInSICResults = false;

function inSICResults(value)
{
	isInSICResults = value;
}

var g_PopupIFrame;

function hideResults()
{
	if(isInSICResults)
		return;
	var sicResults = document.getElementById('sicResults');
	if(sicResults)
	{
		sicResults.style.visibility = "hidden";
		/*if(IE6 && g_PopupIFrame)
		{
			document.body.removeChild(g_PopupIFrame);
			g_PopupIFrame=null;
		}*/
	}
}

var sicSearchValue = "";
var sicResultObjects = new Array();

function beginAjax()
{
	if(document.getElementById('sicSearch').value.indexOf(sicSearchValue) < 0 || sicSearchValue == "" || !isNaN(document.getElementById('sicSearch').value))
	{
		var ajaxObj = null;
		
		if (window.XMLHttpRequest)
		{// code for all new browsers
			ajaxObj=new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{// code for IE5 and IE6
			ajaxObj=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if (ajaxObj != null)
		{
			ajaxObj.onreadystatechange = function() {
				if (ajaxObj.readyState==4)
				{// 4 = "loaded"
					if (ajaxObj.status==200)
					{// 200 = OK
					var sicSearch = document.getElementById('sicSearch');
					var sicResults = document.getElementById('sicResults');
					
					var position = getElementPosition(sicSearch);
					
					while(sicResults.childNodes.length > 0)
						sicResults.removeChild(sicResults.firstChild);
					
					sicResults.style.display = "block";
					sicResults.style.position = "fixed";
					sicResults.style.left = position[0] + "px";
					sicResults.style.top = (position[1] + sicSearch.offsetHeight) + "px";	
					sicResults.style.zIndex = 1002;
					sicResults.style.visibility = "visible";
					
					var results = ajaxObj.responseXML.getElementsByTagName('row');
					
					sicSearchValue = sicSearch.value.replace(/^\s+|\s+$/g, '');
					
					sicResultObjects.length = 0;
					for(i = 0; i < results.length; i++)
					{
						var obj = new Object();
						obj.SIC = results[i].firstChild.firstChild.nodeValue;
						obj.name = results[i].lastChild.firstChild.nodeValue;
						sicResultObjects[sicResultObjects.length] = obj;
					}
					
					for(i = 0; i < sicResultObjects.length; i++)
					{
						var str = sicResultObjects[i].SIC + " - " + sicResultObjects[i].name;
						var beginAt = str.toLowerCase().indexOf(sicSearchValue.toLowerCase());
						var begin = str.substring(0, beginAt);
						var middle = str.substring(beginAt, beginAt + sicSearchValue.length);
						var end = str.substring(beginAt + sicSearchValue.length);
						var rA = document.createElement('a');

						//rA.onmouseover = new Function("this.oldStyle = this.style; this.style.color = '#F00';");
						//rA.onmouseout = new Function("this.style = this.oldStyle;");
						
						//rA.style.fontSize = "x-small";
						rA.appendChild(document.createTextNode(begin));
						var rSpan = document.createElement('span');
						//rSpan.style.fontWeight = "bold";
						//rSpan.style.textDecoration = "underline";
						rSpan.appendChild(document.createTextNode(middle));
						rA.appendChild(rSpan);
						rA.appendChild(document.createTextNode(end));
						//rA.onclick = new Function("addToSICList(" + i + ")");
						rA.onclick = new Function("AddANZSICCode(" + i + ")");
						sicResults.appendChild(rA);
						sicResults.appendChild(document.createElement('br'));
					}

					if(IE6)
					{
						//Increase default zIndex of div by 1, so that DIV appears before IFrame
						/*sicResults.style.zIndex=sicResults.style.zIndex+1;

						var iFrame = document.createElement("IFRAME");
						iFrame.setAttribute("src", "");

						//Match IFrame position with sicResults
						iFrame.style.position="absolute";
						iFrame.style.left =sicResults.offsetLeft + 'px';
						iFrame.style.top =sicResults.offsetTop + 'px';
						iFrame.style.width =sicResults.offsetWidth + 'px';
						iFrame.style.height =sicResults.offsetHeight + 'px';

						document.body.appendChild(iFrame);

						//Store iFrame in global variable, so it can get removed when sicResults is hidden g_PopupIFrame=iFrame;
						g_PopupIFrame=iFrame;*/
					}
			      //var response = transport.responseText || "no response text";
			      //alert("Success! \n\n" + response);					
					}
					else
					{
						alert("Problem retrieving SIC Codes");
						alert(ajaxObj.status);
					}
				}
			};		
			//alert(scripturl + 'downloadSICList.php?search=' + escape(document.getElementById('sicSearch').value, true));
			ajaxObj.open("GET", scripturl + 'downloadSICList.php?search=' + escape(document.getElementById('sicSearch').value, true));
			ajaxObj.send(null);
		}
		else
		{
			alert("Your browser does not support XMLHTTP.");
		}
	
		/*ajaxObj = new Ajax.Request('downloadSICList.php?search=' + escape(document.getElementById('sicSearch').value),
			{
			    method:'get',
			    onSuccess: function(transport)
				{
					var sicSearch = document.getElementById('sicSearch');
					var sicResults = document.getElementById('sicResults');
					
					var position = getElementPosition(sicSearch);
					
					while(sicResults.childNodes.length > 0)
						sicResults.removeChild(sicResults.firstChild);
					
					sicResults.style.display = "block";
					sicResults.style.position = "absolute";
					sicResults.style.left = position[0] + "px";
					sicResults.style.top = (position[1] + sicSearch.offsetHeight) + "px";	
					sicResults.zIndex = 0;
					sicResults.style.visibility = "visible";
					
					var results = transport.responseXML.getElementsByTagName('row');
					
					sicSearchValue = sicSearch.value.replace(/^\s+|\s+$/g, '');
					
					sicResultObjects.length = 0;
					for(i = 0; i < results.length; i++)
					{
						var obj = new Object();
						obj.SIC = results[i].firstChild.firstChild.nodeValue;
						obj.name = results[i].lastChild.firstChild.nodeValue;
						sicResultObjects[sicResultObjects.length] = obj;
					}
					
					for(i = 0; i < sicResultObjects.length; i++)
					{
						var str = sicResultObjects[i].SIC + " - " + sicResultObjects[i].name;
						var beginAt = str.toLowerCase().indexOf(sicSearchValue.toLowerCase());
						var begin = str.substring(0, beginAt);
						var middle = str.substring(beginAt, beginAt + sicSearchValue.length);
						var end = str.substring(beginAt + sicSearchValue.length);
						var rA = document.createElement('a');

						rA.style.fontSize = "x-small";
						rA.appendChild(document.createTextNode(begin));
						var rSpan = document.createElement('span');
						rSpan.style.fontWeight = "bold";
						rSpan.style.textDecoration = "underline";
						rSpan.appendChild(document.createTextNode(middle));
						rA.appendChild(rSpan);
						rA.appendChild(document.createTextNode(end));
						rA.onclick = new Function("addToSICList(" + i + ")");
						sicResults.appendChild(rA);
						sicResults.appendChild(document.createElement('br'));
					}

					if(IE6)
					{
						//Increase default zIndex of div by 1, so that DIV appears before IFrame
						sicResults.style.zIndex=sicResults.style.zIndex+1;

						var iFrame = document.createElement("IFRAME");
						iFrame.setAttribute("src", "");

						//Match IFrame position with sicResults
						iFrame.style.position="absolute";
						iFrame.style.left =sicResults.offsetLeft + 'px';
						iFrame.style.top =sicResults.offsetTop + 'px';
						iFrame.style.width =sicResults.offsetWidth + 'px';
						iFrame.style.height =sicResults.offsetHeight + 'px';

						document.body.appendChild(iFrame);

						//Store iFrame in global variable, so it can get removed when sicResults is hidden g_PopupIFrame=iFrame;
						g_PopupIFrame=iFrame;
					}
			      //var response = transport.responseText || "no response text";
			      //alert("Success! \n\n" + response);
			    },
			    onFailure: function()
				{
					alert('Something went wrong...')
				}
			}
		);*/
	}
}



      function compareOptionText(a,b) {
      /*
        * return >0 if a>b
        * 0 if a=b
        * <0 if a<b
        */
      // textual comparison
      return a.text!=b.text ? a.text<b.text ? -1 : 1 : 0;
      // numerical comparison
      // return a.text - b.text;
       
      }
       
      function sortOptions(list) {
      var items = list.options.length;
      // create array and make copies of options in list
      var tmpArray = new Array(items);
      for ( i=0; i<items; i++ )
      tmpArray[i] = new
      Option(list.options[i].text,list.options[i].value);
      // sort options using given function
      tmpArray.sort(compareOptionText);
      // make copies of sorted options back to list
      for ( i=0; i<items; i++ )
      list.options[i] = new Option(tmpArray[i].text,tmpArray[i].value);
      }



function addToSICList(obj)
{
	var obj = sicResultObjects[obj];
	var sic_list = document.getElementById('sic_list');
	
	var found = false;
	
	for(i = 0; i < sic_list.options.length; i++)
	{
		if(sic_list.options[i].value == obj.SIC)
		{
			found = true;
			break;
		}
	}
	
	if(!found)
	{
		sic_list.options[sic_list.options.length] = new Option(obj.SIC + " - " + obj.name, obj.SIC);
		
		var element = document.createElement("input");
		
		element.name = "sic_codes[]";
		element.type = "hidden";
		element.value = obj.SIC;
		
		document.getElementById("sicCodeSubmission").appendChild(element);
		
		sortOptions(sic_list);
		
		/*$A(sic_list.options).sort(function(a,b){ return (a.text.toLowerCase() < b.text.toLowerCase() ) ?
-1 : 1; }).each(function(o,i){ sic_list.options[i] = o;});*/
	}
	
	isInSICResults = false;
	hideResults();
}

function removeSelectedFromSICList()
{
	var sic_list = document.getElementById('sic_list');

	if(sic_list.selectedIndex == -1)
		return;
	
	var sicCodeSubmission = document.getElementById("sicCodeSubmission");
	
	var sic_codes = sicCodeSubmission.getElementsByTagName('input');
	
	for(i = 0; i < sic_codes.length; i++)
	{
		if(sic_codes[i].value == sic_list.options[sic_list.selectedIndex].value)
			sicCodeSubmission.removeChild(sic_codes[i]);
	}
	
	sic_list.options[sic_list.selectedIndex] = null;
}

// make the specified div a windowed control in IE6
// this masks an iframe (which is a windowed control) onto the div,
// turning the div into a windowed control itself
function makeWindowed(p_div)
{
	var is_ie6 = document.all && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);

	if (is_ie6)
	{
		var html =
				"<iframe style=\"position: absolute; display: block; " +
				"z-index: -1; width: 100%; height: 100%; top: 0; left: 0;" +
				"filter: mask(); background-color: #ffffff; \"></iframe>";
		if (p_div) p_div.innerHTML += html;
		alert(p_div.innerHTML);
		// force refresh of div
		var olddisplay = p_div.style.display;
		p_div.style.display = 'none';
		p_div.style.display = olddisplay;
	};
}

 function generateReference(obj)
 {
	var str = "";
	for(i = 0; i < 8; i++)
	{
		str += Math.floor(Math.random() * 9);
	}
	obj.value = str;
 }
 
function validateEmail(str)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))
	{
		return true;
	}
	return false;
}

var timer = null;
var timeSecondsSince = 0;
var timeMinutesSince = 0;

function numberString(count, avg)
{
	var total = Math.round(avg * count);
	var minutes = Math.floor(total / 60.0);
	var seconds = total - (minutes * 60);
	return count + " Numbers - " + (minutes != 0 ? minutes + " minute(s) and " : "") + seconds + " second(s)<br />";
}

function waitTime(unknown)
{
	var div = document.createElement("div");
	div.style.position = "fixed";
	div.style.left = "0px";
	div.style.top = "0px";
	div.id = "blackbox";
	//div.onResize = new Function("if(window.innerWidth) this.style.width = window.innerWidth + \"px\"; else this.style.width = (document.body.offsetWidth - 21) + \"px\"; if(window.innerHeight) this.style.height = window.innerHeight + \"px\"; else this.style.height = (document.body.offsetHeight - 4) + \"px\";");
	if(window.innerWidth)
		div.style.width = window.innerWidth + "px";
	else
		div.style.width = (document.body.offsetWidth - 21) + "px";
		
	if(window.innerHeight)
		div.style.height = window.innerHeight + "px";
	else
		div.style.height = (document.body.offsetHeight - 4) + "px";
	div.style.backgroundColor = "#000000";
	div.style.opacity = "0.75";
	div.style.filter = "alpha(opacity=75)";
	
	var avg = document.getElementById("avg").value;
	
	var div2 = document.createElement("div");
	div2.innerHTML = "Please wait while your Number List is being processed." + (unknown != null ? " If this number list contains multiple columns, you will further be prompted to select the column containg the list of numbers." : "") + "<br /><img src=\"tiny_red.gif\" alt=\"Loading...\"><br /><center>";//<u>Average Submission Times</u><br />" + numberString(500, avg) + numberString(1000, avg) + numberString(2000, avg) + numberString(4000, avg) + numberString(8000, avg) + numberString(16000, avg) + "<br />Please note that these averages are based on previous number list submissions but may not necessarily represent the amount of time it would take to upload your number list.</center><br />";
	div2.style.position = "fixed";
	div2.style.width = "300px";
	div2.style.backgroundColor = "#FFFFFF";
	div2.style.color = "#000000";
	div2.style.padding = "5px";
	div2.id = "whitebox";
	if(window.innerWidth)
		div2.style.left = (window.innerWidth / 2 - 300 / 2) + "px";
	else
		div2.style.left = ((document.body.offsetWidth - 4) / 2 - 300 / 2) + "px";
		
	if(window.innerHeight)
		div2.style.top = (window.innerHeight / 2 - 200 / 2) + "px";
	else
		div2.style.top = ((document.body.offsetHeight - 4) / 2 - 200 / 2) + "px";
	div2.style.textAlign = "center";
	div2.style.border = "solid 1px #000000";
	div2.style.fontFamily = "Arial";
	div2.style.fontSize = "xx-small";

	document.body.appendChild(div);
	document.body.appendChild(div2);

	timer = document.createElement("div");
	timer.appendChild(document.createTextNode("It has been 0 minute(s) and 0 second(s) since your Number List was submitted."));
	div2.appendChild(timer);
	timeSecondsSince = 0;
	timeMinutesSince = 0;
	
	setTimeout("countUp()", 1000);
}

function countUp()
{
	if(timeSecondsSince == 60)
	{
		timeMinutesSince++;
		timeSecondsSince = 0;
	}
		
	while(timer.childNodes.length > 0)
		timer.removeChild(timer.firstChild);
		
	timer.appendChild(document.createTextNode("It has been " + timeMinutesSince + " minute(s) and " + timeSecondsSince + " second(s) since your Number List was submitted."));
			
	timeSecondsSince++;
	setTimeout("countUp()", 1000);
}

function boxResize()
{
	if(timer != null)
	{
		var div = document.getElementById("blackbox");
		if(window.innerWidth)
			div.style.width = window.innerWidth + "px";
		else
			div.style.width = (document.body.offsetWidth - 21) + "px";
		
		if(window.innerHeight)
			div.style.height = window.innerHeight + "px";
		else
			div.style.height = (document.body.offsetHeight - 4) + "px";
			
		var div2 = document.getElementById("whitebox");
			
		if(window.innerWidth)
			div2.style.left = (window.innerWidth / 2 - 300 / 2) + "px";
		else
			div2.style.left = ((document.body.offsetWidth - 4) / 2 - 300 / 2) + "px";
			
		if(window.innerHeight)
			div2.style.top = (window.innerHeight / 2 - 200 / 2) + "px";
		else
			div2.style.top = ((document.body.offsetHeight - 4) / 2 - 200 / 2) + "px";
	}
}

function getDateString(date)
{
	day = new Array();
	day.push("Sunday");
	day.push("Monday");
	day.push("Tuesday");
	day.push("Wednesday");
	day.push("Thursday");
	day.push("Friday");
	day.push("Saturday");
		
	month = new Array();
	month.push("January");
	month.push("February");
	month.push("March");
	month.push("April");
	month.push("May");
	month.push("June");
	month.push("July");
	month.push("August");
	month.push("September");
	month.push("October");
	month.push("November");
	month.push("December");
		
	return day[date.getDay()] + " " + date.getDate() + " " + month[date.getMonth()] + " " + date.getFullYear() + " " + ((date.getHours() <= 12 ? date.getHours() : date.getHours() - 12) < 10 ? "0" + (date.getHours() <= 12 ? date.getHours() : date.getHours() - 12) : (date.getHours() <= 12 ? date.getHours() : date.getHours() - 12)) + ":" + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":" + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()) + " " + (date.getHours() < 12 ? "am" : "pm");
}


function updateClientTime()
{
	d = new Date();
	d2 = new Date(d.getTime() - (d.getTimezoneOffset() / 60 * -1) * 3600000 + (clientTimeOffset * 3600000));

	while(document.getElementById("clientTime").childNodes.length > 0)
		document.getElementById("clientTime").removeChild(document.getElementById("clientTime").firstChild);

	document.getElementById("clientTime").appendChild(document.createTextNode(getDateString(d2)));
	setTimeout("updateClientTime()", 1000);
}

function ShowTimeOffsetThingy(id_client)
{
	var div = document.createElement("div");
	
	div.appendChild(document.createTextNode("Please Enter the time you wish to change it to:"));
	div.appendChild(document.createElement("br"));
	
	var d = new Date();
	
	var hours = document.createElement("select");
	hours.name = "hour";
	for(var i = 0; i < 12; i++)
	{
		hours.options[hours.options.length] = new Option((i < 9 ? "0" : "") + (i + 1), i);
		if((d.getHours() <= 12 ? d.getHours() : d.getHours() - 12) == i + 1)
			hours.selectedIndex = i;
	}
	div.appendChild(hours);
	
	div.appendChild(document.createTextNode(":"));
	
	var select = document.createElement("select");
	select.name = "minutes";
	for(var i = 0; i < 60; i++)
	{
		select.options[select.options.length] = new Option((i < 9 ? "0" : "") + i, i);
		if(d.getMinutes() == i)
			select.selectedIndex = i;
	}
	div.appendChild(select);
	
	div.appendChild(document.createTextNode(" "));
	
	var meridiem = document.createElement("select");
	meridiem.name = "meridiem";
	meridiem.options[meridiem.options.length] = new Option("AM", 0);
	meridiem.options[meridiem.options.length] = new Option("PM", 1);
	if(d.getHours() > 12)
		meridiem.selectedIndex = 1;
	div.appendChild(meridiem);
	
	var div2 = document.createElement("div");
	div2.align = "center";
	
	var input = document.createElement("input");
	input.type = "button";
	input.value = "OK";
	input.hours = hours;
	input.meridiem = meridiem;
	input.id_client = id_client;
	input.dialogBox = new DialogBox("Change the Time", div, "clientTimeOffset");
	input.onclick = function()
	{
		if(SubmitTimeChange(this.hours.options[this.hours.selectedIndex].value, this.meridiem.options[this.meridiem.selectedIndex].value, this.id_client))
		{
			this.dialogBox.Hide();
		}
	}
	div2.appendChild(input);
	
	div.appendChild(div2);
	
	input.dialogBox.Show();
}

function SubmitTimeChange(hours, meridiem, id_client)
{
	var ajax = null;
	if (window.XMLHttpRequest)
	{// code for all new browsers
		ajax = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{// code for IE5 and IE6
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (ajax != null)
	{
		ajax.open("GET", "index.php?action=SiteIndex&sa=SubmitTimeUpdate&xml&hour=" + escape(hours) + "&meridiem=" + escape(meridiem) + (id_client != null ? "&id_client=" + id_client : ""), false);
		ajax.send(null);
		
		var xmlDoc = null;
		
		var isIE = false;
		
		try //Internet Explorer
		{
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(ajax.responseText);
			isIE = true;
		}
		catch(e)
		{
			try //Firefox, Mozilla, Opera, etc.
			{
				parser = new DOMParser();
				xmlDoc = parser.parseFromString(ajax.responseText, "text/xml");
			}
			catch(e) {alert(e.message)}
		}
		
		var errors = xmlDoc.getElementsByTagName("errors");
		errors = errors[0];
		errors = errors.getElementsByTagName("error");
		
		if(errors.length > 0)
		{
			SetupErrorBox(errors, "change your time");
			return false;
		}
		
		var offset = xmlDoc.getElementsByTagName("offset");
		offset = parseInt(offset[0].firstChild.nodeValue);
		
		clientTimeOffset = offset;
		
		return true;
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
}
