function xmlhttpPost(strURL) {
	updatepage1("Searching, please wait<br><br><img src=images/loading.gif><br><br>");
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
       self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
   self.xmlHttpReq.send(getquerystring());
}

function xmlhttpPost2(strURL) 
{
	//alert(strURL);
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
       self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			//alert(self.xmlHttpReq.responseText);
            updatepage2(self.xmlHttpReq.responseText);
        }
    }
	
   self.xmlHttpReq.send(getquerystring2());
}

function getquerystring2() 
{
	var form = document.forms['form13'];
	var qstr = 'ajax2=1&lapict=' + form.lapict.value;
	if(form.loption1)
	{
		if(form.loption1.checked)
		{
			qstr += '&loption1=' + form.loption1.value;
		}
	}
	if(form.loption2)
	{
		if(form.loption2.checked)
		{
			qstr += '&loption2=' + form.loption2.value;
		}
	}
	if(form.lelse)
	{
		if(form.lelse.value)
		{
			qstr += '&lelse=' + form.lelse.value;
		}
	}
	//alert(qstr);
	return qstr;
}

function getquerystring() {
    var form     = document.forms['form12'];
    var lquery = form.lquery.value;
	if(!lquery)
	{
		lquery = parent.location.hash.replace(/#/i, "");
	}
    qstr = 'lquery=' + escape(lquery);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage2(str){
    document.getElementById("loggin").innerHTML = str;
}


function updatepage1(str){
    document.getElementById("result").innerHTML = str;
}
function updatepage(str){
    document.getElementById("result").innerHTML = str;
    var reg = /for<i> (.+)<\/i>/i;
    var ar = reg.exec(str); 
	if(ar!=null)
	{
		document.title = "UTYP results for "+ar[1];
		parent.location.hash = ar[1];
		document.forms['form12'].lquery.focus();
		var currentTime = new Date();
		googlead.location = "adsense.php?lquery="+getquerystring()+"&s=" + currentTime.getTime();
		 metatags = document.getElementsByTagName("link");
		 for (cnt = 0; cnt < metatags.length; cnt++)
		 {
			var name = metatags[cnt].getAttribute("name");
			 var content = metatags[cnt].getAttribute("href");
			 if (metatags[cnt].getAttribute("href") == "rss.php?query="){metatags[cnt].setAttribute("href", "rss.php?query="+ar[1]);content = metatags[cnt].getAttribute("href");}
		 }
	}
}

function placeFocus() 
{
	if (document.forms.length > 0) 
	{
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) 
		{
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) 
			{
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

