
function fktValidateForm(form)
{
	var isOK = true;
	var checkSelected = false;
	var maxID = document.getElementById("txtMaxID").value;
	var requestID = document.getElementById("txtRequestId").value;
	var cat51Sel = false;
	var txtCatSelect = "";
	
	if(document.getElementById("chkCat36") || document.getElementById("chkCat37") || document.getElementById("chkCat38"))
	{
		if(document.getElementById("chkCat36").checked || document.getElementById("chkCat37").checked || document.getElementById("chkCat38").checked)
		{
			checkSelected = true;
		}
		else
		{
			for(i=1; i < maxID+1; i++)
			{	
				txtCatSelect = document.getElementById("idCatSelState_" + i);
				
				if(txtCatSelect)
				{
					if(txtCatSelect.value == 1)
					{
						checkSelected = true;
						
						if (i == 51)
						{
							cat51Sel = true;
						}
						
					}
				}
			}
		}
	}
	else
	{	
		for(i=1; i < maxID+1; i++)
		{	
			txtCatSelect = document.getElementById("idCatSelState_" + i);
			
			if(txtCatSelect)
			{
				if(txtCatSelect.value == 1)
				{
					checkSelected = true;
					
					if (i == 51)
						{
							cat51Sel = true;
						}
				}
			}
		}
	}

	if(!checkSelected)
	{
		alert("To proceed with your request, please tick at least one Information Pack to request.");
		isOK = false;
	}
	
	if(isOK && form.txtAccNo && form.txtAccNo.value == "")
	{
		alert("Please provide your Hafele Account No. so we can retrieve your company details.");
		form.txtAccNo.focus();
		isOK = false;
	}
	
	if(isOK && form.txtCompanyName && form.txtCompanyName.value == "")
	{
		alert("A company name is required for the selected Information Pack.\nPlease enter your company's name.");
	    form.txtCompanyName.focus();
	    isOK = false;
	}else if((requestID="51" || cat51Sel) && form.txtCompanyName && form.txtCompanyName.value == "")
	{
		alert("A company name is required for the selected Information Pack.\nPlease enter your company's name.");
	    form.txtCompanyName.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtABN && form.txtABN.value == "")
	{
		alert("Our Information Packs are available to registered Australian companies only.\nIf you are a registered Australian company, please enter your A.B.N.");
	    form.txtABN.focus();
	    isOK = false;
	}else if((requestID="51" || cat51Sel) && form.txtABN && form.txtABN.value == "")
	{
		alert("Our Information Packs are available to registered Australian companies only.\nIf you are a registered Australian company, please enter your A.B.N.");
	    form.txtABN.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtStreet.value == "")
	{
		alert("Please enter a Street or P.O. box so the Information Pack can be delivered.");
	    form.txtStreet.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtTown.value == "")
	{
		alert("Please enter a Suburb / Town so the Information Pack can be delivered.");
	    form.txtTown.focus();
	    isOK = false;
	}
	
	if(isOK && form.selStates.selectedIndex == 0)
	{
		alert("Please select a State so the Information Pack can be delivered.");
	    form.selStates.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtPostcode.value == "")
	{
		alert("Please enter a Postcode so the Information Pack can be delivered.");
	    form.txtPostcode.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtCountry.value == "")
	{
		alert("Please enter a country so the Information Pack can be delivered.");
	    form.txtCountry.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtTitle.selectedIndex == 0)
	{
		alert("Please enter your Title.");
	    form.txtTitle.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtFName.value == "")
	{
		alert("Your name is required to order the selected Information Pack.\nPlease enter your full name.");
	    form.txtFName.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtLName.value == "")
	{
		alert("Your name is required to order the selected Information Pack.\nPlease enter your full name.");
	    form.txtLName.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtTeleAreaCode.value == "")
	{
		alert("Please enter your telephone area code.  If you are entering a mobile number\nplease enter 04 as the area code, followed by the rest of the number.");
	    form.txtTeleAreaCode.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtTelephone1.value == "")
	{
		alert("A valid telephone number is required for the selected Information Pack.\nPlease enter your telephone number.");
	    form.txtTelephone1.focus();
	    isOK = false;
	}
	
	if(isOK && form.txtTelephone2.value == "")
	{
		alert("A valid telephone number is required for the selected Information Pack.\nPlease enter your telephone number.");
	    form.txtTelephone2.focus();
	    isOK = false;
	}

	if(isOK && form.txtEmployees && form.txtEmployees.value == "")
	{
		alert("Please enter the number of employees in your company.");
	    form.txtEmployees.focus();
	    isOK = false;
	}
	
	if(isOK && form.bclass && form.bclass.selectedIndex == 0)
	{
		alert("The Information Pack you have selected requires you to select a main business class.\nPlease select a main business class.");
	    form.bclass.focus();
	    isOK = false;
	}

	return isOK;
}

var divOverlay, divCustType;
var divSelectCustType, divAuthAccount;
var frm, frmAuth, trAuthFailed;


function fktStartRequest(id)
{
	divOverlay = document.getElementById("divOverlay");
	divCustType = document.getElementById("divCustType");
	divSelectCustType = document.getElementById("divSelectCustType");
	divAuthAccount = document.getElementById("divAuthAccount");
	frm = document.getElementById("frmCustomerType");
	frmAuth = document.getElementById("frmAuthAccount");
	
	if(divSelectCustType)
	{
		divSelectCustType.style.display = "";
	}
	
	if(frm)
	{
		if(frm.chkCustType[0] && frm.chkCustType[1])
		{
			frm.chkCustType[0].checked = false;
			frm.chkCustType[1].checked = false;
		}
	}
	
	if(divOverlay)
	{
		divOverlay.style.display = "";
	}
	
	if(divCustType)
	{
		divCustType.style.display = "";
	}
	
	if(divAuthAccount)
	{
		divAuthAccount.style.display = "none";
	}
	
	// assign the ID value to the txtID of form frmAuthAccount
	var txtID = document.getElementById("txtID");
	if(txtID)
	{
		txtID.value = id;
	}
	
	frm.action = "request_info_packs.asp?id=" + id
	
}

function fktStartTradeRequest(id, acc, type)
{
	var url = "http://www.hafele.com.au/isapi/online/catalogues/request_info_packs_trade.asp?id=" + id + "&acc=" + acc + "&t=" + type;
	
	document.location.href = url;
}

function fktCancelRequest()
{	
	trAuthFailed = document.getElementById("trAuthFailed");
	
	frmAuth.scustomerid.value = "";
	frmAuth.spassword.value = "";
	trAuthFailed.style.display = "none";
	divSelectCustType.style.display = "none";
	divAuthAccount.style.display = "none";
	divOverlay.style.display = "none";
	divCustType.style.display = "none";
}

function fktCheckCustomerType()
{
	if(!frm.chkCustType[0].checked && !frm.chkCustType[1].checked)
	{
		alert("Please indicate whether you are an existing Häfele trade customer by ticking 'Yes' or 'No'.");
		return;
	}
	else if(frm.chkCustType[1].checked)
	{
		frm.submit();
	}
	else
	{
		frmAuth.hdnGoto.value = "http://www.hafele.com.au/isapi/online/catalogues/request_info_packs_trade.asp?id=" + frmAuth.txtID.value;
		frmAuth.chkCustType.value = "Customer";
		
		divSelectCustType.style.display = "none";
		divAuthAccount.style.display = "";
		frmAuth.action = "../checklogin.asp"
		frmAuth.scustomerid.focus();
	}
}

function fktStartAuthentication()
{	
	fktDisabledLoginBtns();
	
	trAuthFailed = document.getElementById("trAuthFailed");
	
	if(trAuthFailed)
	{
		trAuthFailed.style.display = "none";
	}
	
	fktStartWaitMsg();
	
	xmlHttpAuth = GetXmlHttpObject();
		
	if(xmlHttpAuth == null)
	{
		alert("Your browser does not support AJAX!.\nPlease advise your Administrator.");
		return; 
	}
	
	var frmAuth = document.getElementById("frmAuthAccount");
	var trAuthFailed = document.getElementById("trAuthFailed");
	
	var url = "authenticate.asp";
	url += "?acctno=" + frmAuth.scustomerid.value;
	url += "&pwd=" + frmAuth.spassword.value;
	url += "&sid=" + Math.random();

	xmlHttpAuth.onreadystatechange = function()
	{	
		if(xmlHttpAuth.readyState == 4)
		{
			if(xmlHttpAuth.responseText == "ok")
			{	
				frmAuth.hdnGoto.value = "http://www.hafele.com.au/isapi/online/catalogues/request_info_packs_trade.asp?id=" + frmAuth.txtID.value + "&acc=" + frmAuth.scustomerid.value + "&t=" + frmAuth.chkCustType.value;
				frmAuth.submit();
			}
			else
			{
				// login failure
				trAuthFailed.style.display = "";
				fktEndWaitMsg();
				fktEnableLoginBtns();
				return false;
			}
		}
	}

	xmlHttpAuth.open("GET", url, true);
	xmlHttpAuth.send(null);
}

function fktSumbitKey(e)
{
	var keycode = e.keyCode ? e.keyCode : e.charCode;
	
	if(keycode == 13)
	{
		event.returnValue = false;
		fktStartAuthentication();
	}
}

var ajaxLoading
var ajax_loader;
var ajx;

function fktStartWaitMsg()
{
	ajaxLoading = document.getElementById("divWaitOverlay");
	ajax_loader = document.getElementById("ajax_loader");
	
	if(ajaxLoading)
	{		
		ajaxLoading.style.display = "";
		ajx = setTimeout("ajax_loader.src = ajax_loader.src", 100);
	}
}

function fktEndWaitMsg()
{	
	if(ajaxLoading)
	{
		if(ajx)
		{
			clearTimeout(ajx);
			ajx = null;
		}
		ajaxLoading.style.display = "none";
	}
}

var btnAuthAccount, btnAuthCancel;

function fktDisabledLoginBtns()
{
	btnAuthAccount = document.getElementById("btnAuthAccount");
	btnAuthCancel = document.getElementById("btnAuthCancel");
	
	if(btnAuthAccount)
	{
		btnAuthAccount.disabled = true;
	}
	
	if(btnAuthCancel)
	{
		btnAuthCancel.disabled = true;
	}
}

function fktEnableLoginBtns()
{
	if(btnAuthAccount)
	{
		btnAuthAccount.disabled = false;
	}
	
	if(btnAuthCancel)
	{
		btnAuthCancel.disabled = false;
	}
}

function fktGetCustDetails(no)
{
	var acctno = no.replace(/^\s+|\s+$/g,"");	//trimming
	var form = document.forms["frmRequest"];
	var ajaxLoading = document.getElementById("divWaitOverlay");
	
	//var txtCustType = document.getElementById("txtCustType");

	if(acctno != "")
	{	
		xmlHttpDetails = GetXmlHttpObject();
		
		if(xmlHttpDetails == null)
		{
			alert("Your browser does not support AJAX!.\nPlease advise your Administrator.");
			return; 
		}
		
		var url = "get_customer_details.asp";
		url += "?acctno=" + acctno;
		url += "&sid=" + Math.random();

		xmlHttpDetails.onreadystatechange = function()
		{	
			if(xmlHttpDetails.readyState == 1)
			{
				// display wait message
				ajaxLoading.style.display = "";
			}
			else if(xmlHttpDetails.readyState == 4)
			{	
				ajaxLoading.style.display = "none";
				
				if(xmlHttpDetails.responseText != "")
				{	
					var arrValues = xmlHttpDetails.responseText.split("][");
					var objState = form.selStates;
					var objBClass = form.bclass;
					var strBClass = "";
					
					form.txtAccNo.value = no;
					form.txtCompanyName.value = arrValues[0];
					form.txtABN.value = arrValues[1];
					form.txtStreet.value = arrValues[2];
					form.txtTown.value = arrValues[3];
					form.txtPostcode.value = arrValues[5];
					form.txtFName.value = arrValues[6];
					form.txtLName.value = arrValues[7];
					
					for(i=0; i<objState.length; i++)
					{
						if(objState.options[i].value == arrValues[4])
						{
							objState.selectedIndex = i;
							break;
						}
					}
					
					for(i=0; i<objBClass.length; i++)
					{
						strBClass = objBClass.options[i].value.substr(0, 2);
						
						if(strBClass == arrValues[8])
						{
							objBClass.selectedIndex = i;
							break;
						}
					}
				}
			}
		}
		
		xmlHttpDetails.open("GET", url, true);
		xmlHttpDetails.send(null);
	}
	
	/*if(value != "")
	{	
		if(value.charAt(0) < 8)
		{
			txtCustType.value = "Customer";
		}
		else
		{
			txtCustType.value = "Prospect";
		}
	}else
	{
		txtCustType.value = "Retail";
	}*/
}		


function fktTCHSelect(id)
{
	if(id == 36 || id == 37)
	{
		if(document.getElementById("chkCat36").checked && document.getElementById("chkCat37").checked)
		{
			document.getElementById("chkCat36").checked = false;
			document.getElementById("chkCat37").checked = false;
			document.getElementById("chkCat38").checked = true;
		}
		else
		{
			document.getElementById("chkCat38").checked = false;
		}
	}
	else
	{
		document.getElementById("chkCat36").checked = false;
		document.getElementById("chkCat37").checked = false;
	}
}

function fktCatSelect(ele, id, type)
{	
	var divCatSelect = document.getElementById(ele.id);
	var divCatText = document.getElementById("divCatText_" + id);
	var idCatSelect = document.getElementById("idCatSelState_" + id);
	var strHTML = "";

	if(idCatSelect.value == 1)
	{
		strHTML = "<img src='images/not_selected.png' border='0' style='vertical-align:middle;' /> Click to add this " + type + " to your request.";
		
		divCatText.innerHTML = strHTML;
		divCatSelect.title = "Click to request this " + type + ".";
		document.getElementById("idCatSelState_" + id).value = 0;
	}
	else
	{
		//strHTML =  "<img src='images/selected.png' border='0' style='vertical-align:middle;' /> This Information Pack has been added to your request.";
		strHTML = "<div style='width:8%; float:left;'><img src='images/selected.png' border='0' /></div>";
		strHTML += "<div style='line-height:15px;'>This " + type + " has been added to you request.<br /> <i class='catToggle_note'>&nbsp&nbsp;[ Click again to remove from request. ]</i></div>";
		
		divCatText.innerHTML = strHTML
		divCatSelect.title = "Click to remove this " + type + " from your request.";
		document.getElementById("idCatSelState_" + id).value = 1;
	}
}
	

function fktToggle(id)
{
	var div = document.getElementById("divCatContents_" + id);
	var divHeader = document.getElementById("divCatHeader_" + id);
	var divToggle = document.getElementById("catToggle_" + id);
	var divCatSelect = document.getElementById("idCatSelState_" + id);
	var imgToggle = document.getElementById("imgToggle_" + id);
	var txtToggle = document.getElementById("txtToggle_" + id);
	var maxID = document.getElementById("txtMaxID").value;
	var frm = document.forms[0];
	var showAll = false;
	
	var strToggleAll = document.getElementById("imgToggle_All").src;
	var indexToggleAll = strToggleAll.lastIndexOf("/");
	strToggleAll = strToggleAll.substr(indexToggleAll+1, strToggleAll.length);
	

	if(id == "all")
	{	
		if(strToggleAll == "collapse.png")
		{
			showAll = true
		}

		for(i=1; i < parseInt(maxID)+1; i++)
		{	
			div = document.getElementById("divCatContents_" + i);
			divHeader = document.getElementById("divCatHeader_" + i);
			divToggle = document.getElementById("catToggle_" + i);
			divCatSelect = document.getElementById("idCatSelState_" + i);
			imgToggle = document.getElementById("imgToggle_" + i);
			txtToggle = document.getElementById("txtToggle_" + i);
			
			if(div)
			{
				if(divToggle)
				{	
					if(showAll)
					{
						document.getElementById("catToggle_All").innerHTML = "<img id='imgToggle_All' src='images/expand.png' border='0' /> EXPAND ALL"
						
						if(i == 38)
						{
							if(!frm.chkCat36.checked && !frm.chkCat37.checked && !frm.chkCat38.checked)
							{
								divHeader.style.backgroundColor = "#E2EBF2";
								divHeader.style.color = "#7697b3";
								divHeader.style.borderBottom = "solid 1px #7697b3";
							}	
						}
						else if(divCatSelect.value != "1")
						{
							divHeader.style.backgroundColor = "#E2EBF2";
							divHeader.style.color = "#7697b3";
							divHeader.style.borderBottom = "solid 1px #7697b3";
						}
						
						if(imgToggle)
						{
							imgToggle.src = "images/expand.png";
						}
						if(txtToggle)
						{
							txtToggle.innerHTML = "EXPAND";
						}
						div.style.display = "none";
						div.style.backgroundColor = "#FFFFFF";
					}
					else
					{
						document.getElementById("catToggle_All").innerHTML = "<img id='imgToggle_All' src='images/collapse.png' border='0' /> HIDE ALL"
						
						if(i == 38)
						{
							if(!frm.chkCat36.checked && !frm.chkCat37.checked && !frm.chkCat38.checked)
							{
								divHeader.style.backgroundColor = "#FFEADF";
								divHeader.style.color = "#DD4800";
								divHeader.style.borderBottom = "solid 1px #DD4800";
							}
						}
						else if(divCatSelect.value != "1")
						{
							divHeader.style.backgroundColor = "#FFEADF";
							divHeader.style.color = "#DD4800";
							divHeader.style.borderBottom = "solid 1px #DD4800";
						}
						
						if(imgToggle)
						{
							imgToggle.src = "images/collapse.png";
						}
						if(txtToggle)
						{
							txtToggle.innerHTML = "HIDE";
						}
						div.style.display = "";
						div.style.backgroundColor = "#FFFFF2";
					}
				}
			}
		}
		
	}
	else
	{
		document.getElementById("catToggle_All").innerHTML = "<img id='imgToggle_All' src='images/expand.png' border='0' /> EXPAND ALL"
		
		if(div.style.display == "none")
		{
			if(id == 38)
			{
				if(!frm.chkCat36.checked && !frm.chkCat37.checked && !frm.chkCat38.checked)
				{
					divHeader.style.backgroundColor = "#FFEADF";
					divHeader.style.color = "#DD4800";
					divHeader.style.borderBottom = "solid 1px #DD4800";
				}
			}
			else if(divCatSelect.value != "1")
			{
				divHeader.style.backgroundColor = "#FFEADF";
				divHeader.style.color = "#DD4800";
				divHeader.style.borderBottom = "solid 1px #DD4800";
			}
			imgToggle.src = "images/collapse.png";
			txtToggle.innerHTML = "HIDE";
			div.style.display = "";
			div.style.backgroundColor = "#FFFFF2";
		}
		else
		{	
			if(id == 38)
			{
				if(!frm.chkCat36.checked && !frm.chkCat37.checked && !frm.chkCat38.checked)
				{
					divHeader.style.backgroundColor = "#E2EBF2";
					divHeader.style.color = "#7697b3";
					divHeader.style.borderBottom = "solid 1px #7697b3";
				}
			}
			else if(divCatSelect.value != "1")
			{
				divHeader.style.backgroundColor = "#E2EBF2";
				divHeader.style.color = "#7697b3";
				divHeader.style.borderBottom = "solid 1px #7697b3";
			}
			else if(id == 38)
			{
				if(!chkCat36.checked && !chkCat37.checked && !chkCat38.checked)
				{
					divHeader.style.backgroundColor = "#E2EBF2";
					divHeader.style.color = "#7697b3";
					divHeader.style.borderBottom = "solid 1px #7697b3";
				}
			}
			imgToggle.src = "images/expand.png";
			txtToggle.innerHTML = "EXPAND";
			div.style.display = "none";
			div.style.backgroundColor = "#FFFFFF";
		}
	}
}



var indexWordList = 0;
var startIndex = 0;
var lastSelectedWord = "";
var divY = 0;
var divX = 0;


function fktGetTownAxis()
{
	divY = findPosY('txtTown')+18;
	divX = findPosX('txtTown');
}

function fktMatchTownWords(strWord, e)
{
	var keycode = e.keyCode ? e.keyCode : e.charCode;
	var x;
	var selectTownSuggestion = document.getElementById("divTownSuggestion");
	var objTown = document.getElementById("txtTown");


	if(keycode)
	{
		/*if(window.event)
		{
			keycode = window.event.keyCode;
		}
		else if(event)
		{
			keycode = event.which;
		}*/
	
		// ________________________
		
		// 38 = arrow up key
		// 40 = arrow down key
		if((keycode == 38 || keycode == 40) && document.getElementsByName("spanWordList").length > 0)
		{	
			//x = document.getElementsByTagName("span");
			x = document.getElementsByName("spanWordList");
			
			if(x) 
			{
				//alert(indexWordList);
				if(startIndex == 0)
				{
					x[indexWordList].className='wordMouseOver';
					startIndex = 1;
				}
				else
				{
					if(keycode == 38)
					{
						if(x[indexWordList-1])
						{
							x[indexWordList].className='wordMouseOut';
							indexWordList -= 1;
							x[indexWordList].className='wordMouseOver';
						}
					}
					else if(keycode == 40)
					{
						if(x[indexWordList+1])
						{
							x[indexWordList].className='wordMouseOut';
							indexWordList += 1;
							x[indexWordList].className='wordMouseOver';
						}
					}
				}
				
				objTown.value = x[indexWordList].innerHTML;
				lastSelectedWord = x[indexWordList].innerHTML;
			}
		}
		else if(keycode == 27) // Esc key
		{
			selectTownSuggestion.innerHTML = "";
			selectTownSuggestion.style.display = "none";
		}
		else
		{
			if(strWord != '' && strWord != lastSelectedWord)
			{	
				xmlHttpSuggest = GetXmlHttpObject();
				
				if(xmlHttpSuggest == null)
				{
					alert("Your browser does not support AJAX!.\nPlease advise your Administrator.");
					return; 
				}
				
				var url = "check_town.asp";
				url += "?town=" + strWord;
				url += "&sid=" + Math.random();
		
				xmlHttpSuggest.onreadystatechange = function()
				{	
					if(xmlHttpSuggest.readyState == 4)
					{
						if(xmlHttpSuggest.responseText != "None")
						{	
							if(selectTownSuggestion)
							{
								fktGetTownAxis();
								
								selectTownSuggestion.style.display = "";
								selectTownSuggestion.style.position = "absolute";
								selectTownSuggestion.style.top = divY;
								selectTownSuggestion.style.left = divX;
								selectTownSuggestion.innerHTML = xmlHttpSuggest.responseText;
							}
						}
					}
				}
				
				xmlHttpSuggest.open("GET", url, true);
				xmlHttpSuggest.send(null);
			}
			else
			{
				selectTownSuggestion.innerHTML = "";
				selectTownSuggestion.style.display = "none";
			}
		}
	}
}


function fktSelectSuggestedWord()
{

	var objTown = document.getElementById("txtTown");
	var objState = document.getElementById("selStates");
	var objPostcode = document.getElementById("txtPostcode");
	var selectTownSuggestion = document.getElementById("divTownSuggestion");
	var spanWords = document.getElementsByName("spanWordList");
	var spanPostcodes = document.getElementsByName("spanWordListState");
	var tmpValue = "";
	var tmpString, stateStart;
	var tmpPostcode = "", tmpState = "";
	//var indexSuggestedWord = indexWordList;
	var arrWordList = document.getElementsByName("spanWordList");
	var index = null;
	
	if(objTown.value != "")
	{
		for(i=0; i<arrWordList.length; i++)
		{
			if(arrWordList[i].className == "wordMouseOver")
			{
				index = i;
			}
		}
		
		if(index == null)
		{
			index = 0;
		}
		
		if(spanWords.length > 0 && index != null)
		{
			tmpValue = spanWords[index].innerHTML;
			
			tmpString = spanPostcodes[index].innerHTML;
			tmpPostcode = tmpString.substr(0, 4);
			
			tmpState = tmpString.substr(7, 3);
			tmpState = tmpState.replace(/^\s+|\s+$/g,"");
	
		}
		else
		{
			selectTownSuggestion.style.display = "none";
			objTown.focus();
		}
		
		if(tmpValue != "")
		{	
			objTown.value = tmpValue;
			
			for(i=0; i<objState.length; i++)
			{
				if(objState.options[i].value == tmpState)
				{
					objState.selectedIndex = i;
				}
			}
			
			objPostcode.value = tmpPostcode;
			selectTownSuggestion.style.display = "none";
		}
		
		indexWordList = 0;
	}
}
	


var xmlHttp

function GetXmlHttpObject()
{
	var xmlHttp = null;
	
	try
	{
		// for firefox, opera 8+, safari browsers
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		//IE
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}


function findPosY(ele)
{
	var obj = document.getElementById(ele);
	var curTop = 0;

    if(obj.offsetParent)
		while(1)
        {
          curTop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          	obj = obj.offsetParent;
        }
    else if(obj.y)
		curTop += obj.y;
	
    return curTop;
}

function findPosX(ele)
{
	var obj = document.getElementById(ele);
	var curLeft = 0;
	
    if(obj.offsetParent)
        while(1) 
        {
          curLeft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curLeft += obj.x;
		
    return curLeft;
}

function fktTapAtEnd(obj, nextField, e)
{
	var keycode = e.keyCode ? e.keyCode : e.charCode;
	var maxLength = obj.maxLength;
	var strLength = obj.value.length;
	var nextFld = document.getElementById(nextField);
	
	if(keycode)
	{
		if(keycode != 9)
		{
			if(strLength == maxLength)
			{
				if(nextFld.value != "")
				{
					nextFld.focus();
					nextFld.select();
				}
				else
				{
					nextFld.focus();
				}
			}
			else
			{
				return;
			}
		}
	}
	else
	{
		return;
	}
}