/**
* @package mod_vm_ajax_search
*
* @license		http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
* VM Live Product Search is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*
*
* author: www.rupostel.com
*/

function search_vm_ajax_live(el, prods)
{
  str = ajop_escape(el.value); 
  
  if (prods == null) prods = 5;
  if (str.length==0)
  {
   hide_results_live();
   return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    var res = document.getElementById("vm_ajax_search_results2");
    res.style.border="1px solid #A5ACB2";
    
    //res.style.position = 'fixed';
    
	oh = document.getElementById("show_over_here");
	x=getX(oh); 
	y=getY(oh); 
	//res.style.left = oh.scrollLeft +'px';
	//res.style.top = oh.scrollTop +'px'; //y+'px';
	res.innerHTML=xmlhttp.responseText;
	res.style.display = 'block'; 
//    document.getElementById("vm_ajax_search_results2").style.visibility = 'visible';
    //alert(xmlhttp.responseText);
    }
  }

query = "keyword="+str+"&prods="+prods;

xmlhttp.open("POST","/modules/mod_vm_ajax_search/ajax/index.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", query.length);
xmlhttp.setRequestHeader("Connection", "close");

  //if (str.length > 10) alert(query); 

xmlhttp.send(query);
}

function hide_results_live()
{ 
 document.getElementById('vm_ajax_search_results2').style.display = 'none'; 
 return false; 
}

function search_setText(text, e)
{
 //return;
 //e.value = text; 
 setTimeout( "hide_results_live();", 1000);
 e.value = text;
 //hide_results_live();
 return true;
}

function getY( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;
}
return iReturnValue;
}

function getX( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetLeft;
oElement = oElement.offsetParent;
}
return iReturnValue;
} 


  function ajop_escape(str)
  {
   var x1 = document.getElementById('results_re_2');
   if (x1 == null || (typeof x1 == 'undefined')) str = '';
   if ((typeof(str) != 'undefined') && (str != null))
   {
     x = str.split("&").join("%26");
     x = str.split(" ").join("%20");
     return x;
   }
   else 
   return "";
  }

function aj_redirect(id)
{

  x = document.getElementById(id);
  if (x!=null)
  {
    if (x.href != null)
    {
      window.location = x.href;
     
    }
    else
    {
      
    }
  }
  
}
