/* +--------------------------------------------------------------------------+
// | Orginial Code Care Of:                                                   |
// +--------------------------------------------------------------------------+
// | Copyright (c) 2004 Bitflux GmbH                                          |
// +--------------------------------------------------------------------------+
// | Licensed under the Apache License, Version 2.0 (the "License");          |
// | you may not use this file except in compliance with the License.         |
// | You may obtain a copy of the License at                                  |
// | http://www.apache.org/licenses/LICENSE-2.0                               |
// | Unless required by applicable law or agreed to in writing, software      |
// | distributed under the License is distributed on an "AS IS" BASIS,        |
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or          |
// | implied. See the License for the specific language governing             |
// | permissions and limitations under the License.                           |
// +--------------------------------------------------------------------------+
// | Author: Bitflux GmbH <devel@bitflux.ch>                                  |
// |         http://blog.bitflux.ch/p1735.html                                |
// | Modified by: Jeff Minard <jeff-js@creatimation.net>                      |
// |         http://jrm.cc/archives/blog/programming/how-to-use-liverequestjs/|                               |
// +-------------------------------------------------------------------------*/
								
var pURL = './main.php?module=report&function=rfqsearch';
var lsReq = false; var t = null; var lsLast1 = ""; var lsLast2 = ""; var isIE = false; var inID1; var outID1; var inID2; var outID2; var test;

if (window.XMLHttpRequest) {
	lsReq = new XMLHttpRequest();
}

function lsInit() {
	inID1 = document.getElementById('rfqnumber');
	inID2 = document.getElementById('rfqreference');
	outID1 = document.getElementById('rfqresults');
	outID2 = document.getElementById('rfqrefresults');
	if (navigator.userAgent.indexOf("Safari") > 0) {
		inID1.addEventListener("keydown",lsKeyPress1,false);
		inID2.addEventListener("keydown",lsKeyPress2,false);
	} else if (navigator.product == "Gecko") {
		document.getElementById('rfqnumber').addEventListener("keypress",lsKeyPress1,false);
		document.getElementById('rfqreference').addEventListener("keypress",lsKeyPress2,false);
	} else {
		inID1.attachEvent("onkeydown",lsKeyPress1);
		inID2.attachEvent("onkeydown",lsKeyPress2);
		isIE = true;
	}
	inID1.setAttribute("autocomplete","off");
	inID2.setAttribute("autocomplete","off");
}
	
function lsHide1() {
	outID1.style.display = "none";	
}

function lsHide2() {
	outID2.style.display = "none";	
}

function lsKeyPress1(event) {
	if (event.keyCode == 27) { // ESC
		lsHide1();
	} else if (event.keyCode == 13) { // ENTER
		var fillValue = highlight.id.value;
		document.report.rfqnumber.value=fillValue;
		lsHide1();
		event.keyCode = 9;
	}	
}

function lsKeyPress2(event) {
	if (event.keyCode == 27) { // ESC
		lsHide2();
	} else if (event.keyCode == 13) { // ENTER
		var fillValue = highlight.id.value;
		document.report.rfqreference.value=fillValue;
		lsHide2();
		event.keyCode = 9;
	}	
}

function lsStart(value) {
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("lsDoSearch"+value+"()",400);
}

function lsDoSearch1() {
	if (lsLast1 != inID1.value || inID1.value == "") {
		if (lsReq && lsReq.readyState < 4) {
			lsReq.abort();
		}
		if (window.ActiveXObject) {
			lsReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		lsReq.onreadystatechange= lsProcessReqChange1;
		lsReq.open("GET", pURL + "&rfqnumber=" + encodeURI(inID1.value));
		lsLast1 = inID1.value;
		lsReq.send(null);
	} else {
		return false;
	}
}

function lsDoSearch2() {
	if (lsLast2 != inID2.value || inID2.value == "") {
		if (lsReq && lsReq.readyState < 4) {
			lsReq.abort();
		}
		if (window.ActiveXObject) {
			lsReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		lsReq.onreadystatechange= lsProcessReqChange2;
		lsReq.open("GET", pURL + "&rfqreference=" + encodeURI(inID2.value));
		lsLast2 = inID2.value;
		lsReq.send(null);
	} else {
		return false;
	}
}

function lsProcessReqChange1() {
	if (lsReq.readyState == 4) {
		var  res = outID1;
		res.style.display = "block";
		var  sh = document.getElementById("lsShadow1");
		sh.innerHTML = lsReq.responseText;
	}
}

function lsProcessReqChange2() {
	if (lsReq.readyState == 4) {
		var  res = outID2;
		res.style.display = "block";
		var  sh = document.getElementById("lsShadow2");
		sh.innerHTML = lsReq.responseText;
	}
}

function lsFill(fillValue1, fillValue2, number) {
	var fillValue1, fillValue2;
	if (number) {
		document.report.rfqnumber.value=fillValue1;
	} else {
		document.report.rfqreference.value=fillValue2;
	}
	document.report.stateid.focus();
	if (number) {
		outID1.style.display = "none";
	} else {
		outID2.style.display = "none";
	}
}
