// JavaScript Document
var obiekt;
var newdiv = 0;
var nazwaprod;

var xmlHttp;

var emailanswer='';

var colorok = '#DDFFA0';
var colorbad = '#FFFFFF';

var colormailok='#11FF33';
var colormailbad='#FF1133';

var dupa=false;
var ostatniadres='!';
var ostatniblad='';
var adresemailjest='';
var searchtrigger=0;

var zawnam='';








function getAbsoluteLeft(o) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects

	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(o) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects

	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}

function creatediv(id, html, width, height, left, top) {


   newdiv = document.createElement('div');
   newdiv.setAttribute('id', id);
   
//       newdiv.style.width = width+'px';
//       newdiv.style.height = height+'px';

//newdiv.setAttribute('style','position: absolute; left: '+left+'px; top: '+top+'px; border:1px solid #000; background-color: #000;  filter:alpha(opacity=75);  -moz-opacity: 0.75;  opacity: 0.75; font-size: 10px;  color:#FFFFFF;  text-decoration:none; z-index:100;');
   
//   		newdiv.setAttribute('class','przezroczysty');
newdiv.className = 'przezroczysty';
       newdiv.style.position = "absolute";
       
           newdiv.style.left = left+'px';
           newdiv.style.top = top+'px';
   
   newdiv.style.backgroundColor = "#AA0000";
   newdiv.style.border = "1px solid #000";
   
       newdiv.innerHTML = html;
//	   newdiv.style = "position:absolute; top: 100px;";
   
   document.body.appendChild(newdiv);

} 

function wyniki(zawartosc)
{
//alert('aaa');
//if (newdiv==null){
//newdiv=document.createElement("div");
//}
nazwaprod="";
var podzielone = zawartosc.split(",");
var podz="";
var zaw="";



if (podzielone.length > 1) { 
for (i=0;i<podzielone.length;i++)
{
podz=podzielone[i].split("|");
zaw=zaw+'<a href=#blank onmouseover="changeIt(\''+podz[0]+'\')" class="bialy_link">'+podz[0]+'</a><br />';
}
} else {zaw = '';}



if (newdiv == 0 ){creatediv('divek', zaw, 250, 200, getAbsoluteLeft(obiekt), getAbsoluteTop(obiekt)+20);




}
else {newdiv.style.border = "1px solid #000"; newdiv.innerHTML = zaw;}


}

function changeIt(jakanazwa)
{
nazwaprod=jakanazwa;
//newdiv.innerHTML="";
}

function blurIt()
{
if ((nazwaprod!="")&&(nazwaprod!="undefined")){
obiekt.value=nazwaprod;
nazwaprod='';
obiekt.form.submit();
}

if (newdiv!=0) {newdiv.innerHTML="";newdiv.style.border = "0px solid #000";}
}

function searchTop(obiekto)
{ 

searchtrigger=1;




if (obiekto.value != ""){
obiekt=obiekto;
str=obiekto.value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Brak obslugi AJAX");
  return;
  } 
var url="searchProduct.php";
url=url+"?nazwa="+encodeURI(str);
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
else {
if (newdiv!=0) {newdiv.innerHTML="";}
}



}

function stateChanged() 
{ 

if (xmlHttp.readyState==4)
{ 

if (searchtrigger==1){
productsearch=xmlHttp.responseText;
wyniki(productsearch);
searchtrigger=0;
}
else
{
emailtemp = xmlHttp.responseText;
emailtempa = emailtemp.split('|');
emailanswer= emailtempa[0];
sprawdzpola();
}


}

}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



