var xmlhttp;
var shim = 'x.gif';
var root = false;

function preloadImg(image)
{
    var img = new Image();
    img.src = image;
}

preloadImg('nyroModal-1.5.5/nyroModal-1.5.5/img/ajaxLoader.gif');
preloadImg('nyroModal-1.5.5/nyroModal-1.5.5/img/close.gif');
preloadImg('nyroModal-1.5.5/nyroModal-1.5.5/img/tab_fundal_activ.gif');

function LogOut(nume)
{
if(confirm(" "+nume+",\r"+" Sunteti sigur ca doriti sa va Deconectati?\n\n Atentie: in urma deconectarii toate produsele din cosul de cumparaturi vor fi trecute automat in Solicitare Oferta si nu veti mai avea posibilitatea sa vizualizati pretul pentru nici un produs.\nDaca va veti autentifica din nou, produsele vor reveni in starea initiala\n\n Confirmati Deconectarea?"))
{
 location.href="login_magazin.php?logout=1";
}
}

function Inchide()
{
  var ele = document.getElementById("ie6_error");
  ele.style.display = "none";
}

	var el_fnFixPng = function(img) {
		var src = img.src;
		img.style.width = img.width + "px";
		img.style.height = img.height + "px";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		img.src = shim;
	};

function ReparaPNG(id) {
   var elem=document.getElementById(id);
        //  .css('backgroundImage');
       var image=elem.currentStyle.backgroundImage;
                //element.style.background = "none";*/
       			if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
				image = RegExp.$1;

              elem.style.filter =  "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + image + "')";
                elem.style.backgroundImage = 'url('+shim+')';
                /*var position = element.style.position;
			   	if (position != 'absolute' && position != 'relative')
                    element.style.position="relative";  */
    //            alert(elem.style.filter);
             }
};


function ReparaToatePNG()
{
        root = document;

		for (var i = root.all.length - 1, obj = null; (obj = root.all[i]); i--) {
			// background pngs
			// image elements
			if (obj.tagName=='IMG' && obj.src.match(/\.png$/i) !== null){
				el_fnFixPng(obj);
			}
		}
};

//Pt newsletter
function Abonare()
{
location.href="abonare.php?email="+document.editare.newsletter.value;
}



function newsletter_curata()
{
if(document.editare.newsletter.value=="Adresa ta de email")
{document.editare.newsletter.value="";}
}



function newsletter_refa()
{
if(document.editare.newsletter.value=="")
{document.editare.newsletter.value="Adresa ta de email";}

}



function cautare_curata()
{
if(document.editare.cauta_produs.value=="Produsul Cautat")
{document.editare.cauta_produs.value="";}
}

function inchide_rez()
{
  document.getElementById("rez_rapid").style.display="none";
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (version < 7) && (document.body.filters))
{

 if(document.getElementById('evenimente_pagina'))
    {
        document.getElementById('evenimente_pagina').style.display="inline";
    }

if(document.getElementById('comanda_istoric'))
    {
        document.getElementById('comanda_istoric').style.display="inline";
    }


if(document.getElementById('perioada'))
    {
        document.getElementById('perioada').style.display="inline";
    }
if(document.getElementById('tip'))
    {
        document.getElementById('tip').style.display="inline";
    }
    if(document.getElementById('produse_pagina'))
    {
        document.getElementById('produse_pagina').style.display="inline";
    }
}
}


function cautare_executa()
{
var CP=document.getElementById("cauta_produs");
location.href='cautare.php?cuvinte_cheie='+CP.value;
//document.editare.cauta_produs.value;

}

function goHitReturn(evt) {
     var getEvent = (evt.which) ? evt.which : evt.keyCode;
     if (getEvent == "13")
     {cautare_executa();
     return false;}
     else
     {return true;}
}

function cautare_refa()
{
//document.getElementById("rez_rapid").style.display="none";

/*if(document.editare.cauta_produs.value=="")
{document.editare.cauta_produs.value="Produsul Cautat";}
*/
}


function showResult(str)
{
if (str.length>1)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
 // alert ("Browserul nu suporta cereri HTTP!");
  return;
  }

document.getElementById("rez_rapid").innerHTML='<table><tr><td style="height:12px;"><img src="css/images/loading19.gif" border="0" alt="" /></td><td><a title="Click aici pentru a inchide" href="javascript:inchide_rez();"><span style="color:#888;">Se cauta produsele..</span></a></td></tr></table>';
document.getElementById("rez_rapid").style.width="140px";
document.getElementById("rez_rapid").style.display="block";
document.getElementById("rez_rapid").style.height="18px";
document.getElementById("rez_rapid").style.left="745px";
document.getElementById("rez_rapid").style.padding="1px";

var url="cautare_rapida.php";
url=url+"?produs="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
    document.getElementById("rez_rapid").style.display="none";

}
}






function stateChanged()
{

if (xmlhttp.readyState==4)
{
var text_rasp=xmlhttp.responseText;


document.getElementById("rez_rapid").innerHTML=xmlhttp.responseText;
document.getElementById("rez_rapid").style.border="1px solid #A5ACB2";

document.getElementById("rez_rapid").style.width="500px";
document.getElementById("rez_rapid").style.left="450px";



if(text_rasp!='')
{document.getElementById("rez_rapid").style.display="block";
var lung=String(text_rasp).length;
//alert(lung);





//if(lung>10000)
if(lung>9000)
{
document.getElementById("rez_rapid").style.height="420px";
document.getElementById("rez_lista").style.height="375px";
document.getElementById("rez_lista").style.overflowY="scroll";

document.getElementById("umbra_sus").style.width="95%";
document.getElementById("umbra_jos").style.width="95%";


}
else
{
document.getElementById("rez_rapid").style.height="auto";
//document.getElementById("rez_rapid").style.overflowY="hidden";
document.getElementById("rez_lista").style.overflowY="hidden";
document.getElementById("rez_lista").style.height="auto";

document.getElementById("umbra_sus").style.width="98%";
document.getElementById("umbra_jos").style.width="98%";
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (version < 7) && (document.body.filters))
{

ReparaPNG('umbra_sus');
ReparaPNG('umbra_jos');
ReparaToatePNG();
if(document.getElementById('evenimente_pagina'))
    {
        document.getElementById('evenimente_pagina').style.display="none";
    }

if(document.getElementById('comanda_istoric'))
    {
        document.getElementById('comanda_istoric').style.display="none";
    }



if(document.getElementById('perioada'))
    {
        document.getElementById('perioada').style.display="none";
    }
if(document.getElementById('tip'))
    {
        document.getElementById('tip').style.display="none";
    }
    if(document.getElementById('produse_pagina'))
    {
        document.getElementById('produse_pagina').style.display="none";
    }

}
}
else
{
  document.getElementById("rez_rapid").style.display="none";

    document.getElementById("rez_rapid").innerHTML='<table><tr><td><img src="css/images/option_selected.gif" border="0" alt="" /></td><td><a title="Click aici pentru a inchide" href="javascript:inchide_rez();"><span style="color:#888;">&nbsp;Nici un rezultat gasit</span></a></td></tr></table>';
    document.getElementById("rez_rapid").style.width="125px";
    document.getElementById("rez_rapid").style.display="block";
    document.getElementById("rez_rapid").style.height="16px";
    document.getElementById("rez_rapid").style.left="743px";
    document.getElementById("rez_rapid").style.padding="1px";

}



 document.getElementById("rez_rapid").style.zIndex=1000;
 }

}

///////////////////////////////////////////////////////////////////////////////
// Functii Pentru COS Produse
///////////////////////////////////////////////////////////////////////////////
function Update_cart()
{
 //alert("Cosul a fost actualizat!");
 showCos();
}

function showCos()
{
xmlhttp1=GetXmlHttpObject();
if (xmlhttp1==null)
  {
 // alert ("Browserul nu suporta cereri HTTP!");
  return;
  }
  //document.getElementById("carut").innerHTML='<img src="../css/images/loading2.gif" width="32" height="32" border="0" alt="" />';

var url="actualizare_cos.php";
//url=url+"?produs="+str;
//url=url+"&sid="+Math.random();
xmlhttp1.onreadystatechange=AmPrimitRaspuns;
xmlhttp1.open("GET",url,true);
xmlhttp1.send(null);
}


function AmPrimitRaspuns()
{
    if (xmlhttp1.readyState==4)
    {
        var text_rasp=xmlhttp1.responseText;

        document.getElementById("carut").innerHTML=xmlhttp1.responseText;

    }
}


////////////////////////////////////////////////////////////////////////////////




function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
