function pushSearch(){
	search   = document.getElementById('search_input').value;
	if(search != '')
	{
		selector = document.getElementById('selector').value;
		
			pageTracker._trackPageview('?searchstring=' + escape(search) + '&searchcateg=' + escape(selector));
		
		search   = search.replace(" ", "-"); 
		
		window.location = web_root+"search/"+selector+"/"+search+".html";
	}
	else
	{ 
		alert("Va rugam completati campul de cautare");
	}
}
//+++++++++++++++++++++++++++++ adaugare fct ajax  +++++++++++++++++++++++++++++++++++++++++++//
var xmlhttp = new Array();
var idreq = -1;
var web_root = "http://www.laredoute.ro/";
var lr_root  = "http://www.laredoute.ro/";
function asyncrequest (url, call, target, type )
{
    idreq++;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
     try {
      xmlhttp[idreq] = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xmlhttp[idreq] = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp[idreq] = false;
      }
     }
    @end @*/
	
	
	
    if (!xmlhttp[idreq] && typeof XMLHttpRequest!='undefined') {
	    try {
		    xmlhttp[idreq] = new XMLHttpRequest();
	    } catch (e) {
		    xmlhttp[idreq] =false;
	    }
    }
    if (!xmlhttp[idreq] && window.createRequest) {
	    try {
		    xmlhttp[idreq] = window.createRequest();
	    } catch (e) {
		    xmlhttp[idreq] =false;
	    }
    }
    
    if (!xmlhttp[idreq])
    {
        if (form)
        {
            document.forms[form].submit();
        }
        else
            return false;
    }
    
    procesor = 'processRequest';        
    if (document.getElementById(target))
        callbackid = target;
    else
    	return false;
        
    url = url + '/' + call;
    
    xmlhttp[idreq].onreadystatechange = new Function(procesor + '(' + idreq + ', \'' + callbackid + '\', \'' + type + '\', \'' + call + '\');');
    xmlhttp[idreq].open('GET',url, true);
    xmlhttp[idreq].send(null);
    
    return true;
}


function getResponse ( idreq, xml )
{                         
    if (xmlhttp[idreq].readyState == 4) {
        if (xmlhttp[idreq].status == 200) {
           if (xml) {  
              return xmlhttp[idreq].responseXML;
           } else {
              return xmlhttp[idreq].responseText;
           }
        } else {
            return false;
        }
    } else {
        return false;
    }
}

function changeSelect(select, opts) {
    var selObj = document.getElementById(select);
    if (!selObj)
        return false;   
    if (!opts)
        return false;
        
    selObj.length=0;
    opts = opts.split(";");
	var i = 0; var j = 0;
    while ( i < opts.length )
    {
        val = opts[i++];
        txt = opts[i++];
        selObj[j++] = new Option(txt,val);
    }
    return true;
}

function changeDiv(div, content) {
    var divtag = document.getElementById(div);
    if (!divtag)
        return false;
    if (!content)
        content = '';
    divtag.innerHTML=content;
    return true;
}

function changeFields ( unimportant, response )
{
    response = response.split(";");
	var i = 0; var j = 0;
	var str = ''; 
    while ( i < response.length )
    {
        idf = response[i++];
        val = response[i++];
        if (document.getElementById(idf))
        {
			if (document.getElementById(idf).type)
			{
	        	if (val.split('#').length-1 > 0)
	        	{
					val = val.split('#');
					str = '';
					for (j=0; j<val.length; j++)
						str = str + val[j] + ";";
					
					str = str.substring(0, str.length-1);
					changeSelect(idf, str);
				}
				else
		        if (val == 'checked')
		        	document.getElementById(idf).checked = 1;
		        else
		        if (val == 'unchecked')
		        	document.getElementById(idf).checked = 0;
		        else
		        	document.getElementById(idf).value = val;
		    }
		    else
		    {
		    	document.getElementById(idf).innerHTML = val;
		    }
	    }
        else
        {
            if (idf == 'function-callback')
            {
                func = new Function(val+'()');
                func();
            }
        }
    }
    return true;	
}

function changeFunctie(callbackid, response)
{
	response = response.split(";");
	functie = response[0]+'(';
	for(var i=1; i<response.length; i++ ) 
		functie = functie+"'"+response[i]+"', ";
	functie = functie.substring(0, (functie.length-2)); 
	functie = functie+")";
	eval(functie);
}

function changeCall(callbackid, response, call)
{
//	response = response.split(";");
//	callback = callback.split(";");
	functie = callbackid+'(';
	functie = functie+"'" + call + "', "; 
	functie = functie+"'"+ response +"'"; 
	functie = functie+")";
	eval(functie);
}


function processRequest ( idreq, callbackid, type, call )
{
    var response = getResponse(idreq, false);
    if (!response)
        return false; 
    alert
    if (type == 'div')
        changeDiv(callbackid, response);
    else
    if (type == 'options')
    	changeSelect(callbackid, response);
    else
    if (type == 'fields')
    	changeFields (callbackid, response);
    else
    if (type == 'functie')
    	changeFunctie (callbackid, response);
    else
	if (type == 'call')
    	changeCall (callbackid, response, call);
	
    return true;
}

var tracking = new Array();
var timers   = new Array();
var nTrack = 0;
function pushAjax ( url, call, target, type )
{
	var i = 0;
	var sw = 0;
	var str = url + ' / ' + target + ' / ' + type;
	for (i = 0; i<nTrack; i++)
	if (tracking[i] == str)
	{
		clearTimeout(timers[i]);
		sw = i;
	}

	if (!sw)
		sw = nTrack;
	tracking[sw] = str;
	timers[sw] = setTimeout("asyncrequest('" + url + "', '" + call + "', '" + target + "', '" + type + "')", 500);
	nTrack = nTrack + 1;
	return true;
}



/***************************************** Proprietary software **********************************
    File: ajax.js
    Developed by: Marian Fechete <dtk_ro@yahoo.com>
    
    USE IS SUBJECT TO LICENSE. 
*************************************************************************************************/

//+++++++++++++++++++++++++++++++++++++ END +++++++++++++++++++++++++++++++++++++++++++++++++//

var object = null;
var cererePreferata; 
var cerereDetaliiComanda;
var last_order_request = 0;
var cerereVot;
var voturi_timeout = 200;
var voturi_close_timer = null;
var root = "http://www.laredoute.ro";

var cerereUpdateCantitate;
var idCantitateInput = 0;
var cantitateProdusCos = 0;

function updatePret(object,id){
	cantitate = object.value;
	if(cantitate.length < 1)
		cantitate = '0';
	pret = document.getElementById('pret_'+id).value;
	pret_cant = document.getElementById('pret_cant_'+id).childNodes[0];
	pretOriCantInput = document.getElementById('pret_cant_input_'+id)
	pretOriCant = parseFloat(pret.replace(',','')) * parseFloat(cantitate.replace(',',''));
	
	num = new Number(pretOriCant);
	num = num.toFixed(2);
	pret_cant.innerHTML = num+' LEI'; 
	old_total = pretOriCantInput.value;
	pretOriCantInput.value = num;
	val_fin = document.getElementById("valoare_finala_input").value;
	val_fin = parseFloat(val_fin.replace(',','')) - parseFloat(old_total.replace(',','')) + parseFloat(num.replace(',',''));
	document.getElementById("valoare_finala_input").value = val_fin;
	document.getElementById('valoarea_finala').innerHTML = addCommas(val_fin.toFixed(2)) + 'LEI';
	document.getElementById('valoarea_totala').innerHTML = addCommas(val_fin.toFixed(2)) + 'LEI';
	//valoare_finala_input
	//valoarea_finala 
	//valoarea_totala
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function changeCantitate(id,cantitate){ 
	idCantitateInput = id;
	cantitateProdusCos = cantitate; 
	url = 'ajax/updateCantitate.php?id='+id+'&cant='+cantitate;
	sendChangeCantitateRequest(url,'updateCantitateInput');
}
/*
function verifica_datele(){
	form_produse.submit();
}
*/
function sendChangeCantitateRequest(url,fct){
	if(window.XMLHttpRequest){
		cerereUpdateCantitate = new XMLHttpRequest();
		cerereUpdateCantitate.onreadystatechange = eval(fct);
		cerereUpdateCantitate.open("GET", url, true);
		cerereUpdateCantitate.send(null);
	}
	else if(window.ActiveXObject)
	{
		cerereUpdateCantitate = new ActiveXObject("Microsoft.XMLHTTP");
		if(cerereUpdateCantitate){
			cerereUpdateCantitate.onreadystatechange = eval(fct);
			cerereUpdateCantitate.open("GET", url, true);
			cerereUpdateCantitate.send();
		}
	}
} 

function updateCantitateInput(){
	if(cerereUpdateCantitate.readyState == 4){	
		if(cerereUpdateCantitate.status == 200){	
			raspuns = cerereUpdateCantitate.responseText;
			if(raspuns.indexOf("ok") != -1 )
					document.getElementById("cantitate_"+idCantitateInput).value=cantitateProdusCos;
		}
		else{
			alert("Cererea de update a cantitatii a esuat..va rugam reintroduceti cantitatea");
		}	
	}
}

function validateCosCumparaturi(total){
	check = 'ok';
	if(total == '0.00'){
		check = 'not ok';
		alert('Cosul este gol');
	}
	if(check =='ok'){
		window.location='comanda_adresa_cumparator.html';
	}
} 
function validareCos(nrProduse){
	check = 'ok';
	if(nrProduse == '0'){
		check = 'not ok';
		alert('Cosul este gol');
	}
	if(check =='ok'){
		window.location='comanda_adresa_cumparator.html';
	}
}
function validareFinalaCosCumparaturi(){ 
	check = 'ok';
	if(document.getElementById('cheackbox_termeni').checked == false){
		check='not ok';
		alert('Va rugam sa confirmati acordul dvs. cu privire la termenii si conditiile La Redoute.'); 
	}
	if(check =='ok'){
		pageTracker._trackPageview('/goal/order/finalizare_comanda.html');
		document.getElementById('form_lista').submit(); 
	} 
}
//===================================JS PASI COMANDA===================================
function hideAdressBlocks(id,count, judet){
	if(judet == 50){
		document.getElementById('livrare_reprezentant').checked = true;
		document.getElementById('livrare_curiero').checked = false;
		document.getElementById('curiero').style.display = "none";
		document.getElementById('laredoute').style.display = "block";
	}
	else{
		document.getElementById('livrare_reprezentant').checked = false;
		document.getElementById('livrare_curiero').checked = true;
		document.getElementById('curiero').style.display = "block";
		document.getElementById('laredoute').style.display = "none";
	}
	for(i=1;i<=count;i=i+1){
		if(i==id){
			document.getElementById('detalii_'+i).style.display = 'block';
		}
		else{
			
			document.getElementById('detalii_'+i).style.display = 'none';
		}
	}
}

function confirmFormDelete(submitFormName){
var r=confirm("Doriti sa stergeti aceasta adresa?");
if (r==true)
  {
  document.getElementById(''+submitFormName+'').submit();
  }
else
  {
  	;
  }
}
//===================================END PASI COMANDA===================================
//===================================HELP TOOLTIP===================================
function showToolTipHelp(e,text){
	if(document.all)e = event;
	
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	obj2.innerHTML = text;
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX - 20;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
}	

function hideToolTipHelp()  
{
	document.getElementById('bubble_tooltip').style.display = 'none';
	
}
//=================================END HELP TOOLTIP=================================
//======================================JS COMENZILE MELE=======================================
var last_order_request = 0;
function getOrderProducts(oid){
div = 'div_'+last_order_request; 
if(last_order_request !=0){
document.getElementById(div).style.height='0px';
document.getElementById(div).innerHTML = "";
}
if ( last_order_request != oid ) {
last_order_request = oid;
asyncrequest(web_root+'client/ajax_produse_comanda', last_order_request, 'div_'+last_order_request, 'div');
} else {
document.getElementById('div_'+oid).style.height='0px';
document.getElementById('div_'+oid).innerHTML = "";
last_order_request = 0;
}
}
function getDetaliiComandaRequest(url,fct){
	if(window.XMLHttpRequest){
		cerereDetaliiComanda = new XMLHttpRequest("Microsoft.XMLHTTP");
		cerereDetaliiComanda.onreadystatechange = eval(fct);
		cerereDetaliiComanda.open("GET", url, true);
		cerereDetaliiComanda.send(null);
	}
	else if(window.ActiveXObject)
	{
		cerereDetaliiComanda = new ActiveXObject("Microsoft.XMLHTTP");
		if(cerereDetaliiComanda){
			cerereDetaliiComanda.onreadystatechange = eval(fct);
			cerereDetaliiComanda.open("GET", url, true);
			cerereDetaliiComanda.send();
		}
	}
}
function showDetaliiComandaMessage(){
	if(cerereDetaliiComanda.readyState == 4){	
		if(cerereDetaliiComanda.status == 200){		
			raspuns = cerereDetaliiComanda.responseText;
			if(raspuns.indexOf("a") != -1 ){
				div = 'div_'+last_order_request;
				document.getElementById(div).style.height='auto';
				document.getElementById(div).innerHTML = raspuns;
			}
		} 
		else{
			alert("A aparut o problema la transferul datelor.\n Incercati din nou mai tarziu");
		}	
	}
}
//===================================END JS COMENZILE MELE=====================================

//======================================JS PRODUSE PREFERATE=======================================
function SetAsPreferredProdus(bid,pid){
date = bid+";"+pid;
asyncrequest(web_root+'continut/ajax_set_produs_preferat', date, 'produs_preferat', 'functie');
}
function alert_client(mesaj){
	alert(mesaj);
}
//===================================END JS PRODUSE PREFERATE=====================================
//======================================JS VOTARE=======================================
function sendVotRequest(bid,pid,nota){
date = bid+";"+pid+";"+nota;
asyncrequest(web_root+'continut/ajax_votare_produs', date, 'continut_voturi', 'div');
}
function showBackgroundVot(nr){
	for(i=1;i<=nr;i++){
		document.getElementById("vot_"+i).style.background = "url("+lr_root+"images/green_star.gif) no-repeat";
	}
	for(j=nr+1;j<=5;j++){
		document.getElementById("vot_"+j).style.background = "url("+lr_root+"images/star_grey.gif) no-repeat"; 
	} 
}
function getInitialVotePictures(nr_vot,scor_vot){
	if(nr_vot == 0)
		a = 0; 
	else   
		a =scor_vot/nr_vot;
	nr = Math.round(a);
	for(i=1;i<=nr;i++){
		document.getElementById("vot_"+i).style.background = "url("+lr_root+"images/green_star.gif) no-repeat";
	}
	for(i=nr+1;i<=5;i++){
		document.getElementById("vot_"+i).style.background = "url("+lr_root+"images/star_grey.gif) no-repeat";
	}
}

function showPopupVotare(e,text){
	CancelCloseVoturi();
	if(document.all) e = event;
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_middle');
	obj2.innerHTML = text;
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0) st=0; 
	var leftPos = e.clientX - 20;
	if(leftPos<0) leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -5 + st + 'px';
	obj.style.display = 'block';
}	 

function hidePopupVotare(){
	document.getElementById('bubble_tooltip').style.display = 'none';
}

function setCloseTimeVoturi()
{
	voturi_close_timer = window.setTimeout(hidePopupVotare, voturi_timeout);
}
function CancelCloseVoturi(){
	if(voturi_close_timer)
	{
		window.clearTimeout(voturi_close_timer);
		voturi_close_timer = null;
	}
}


//====================================END JS VOTARE=====================================
//--------------------------- Review produse -----------------------------------//
var cerere_comentarii;
var cerere_add_comentariu;
function showReview(div){
	document.getElementById('detalii_produs').style.display = "none";
	document.getElementById('detalii_servicii').style.display = "none";
	document.getElementById('detalii_comentarii').style.display = "none";
	if(div == 'detalii_produs' || div == 'detalii_servicii'){
		if(div == 'detalii_produs'){
			document.getElementById("div_a_detalii_produs").className = "nav_cap_gri";
			document.getElementById("a_detalii_produs").className = "nav_bt";
			document.getElementById("div_a_detalii_servicii").className = "nav_cap_green";
			document.getElementById("a_detalii_servicii").className = "nav_bt_green";
			document.getElementById("div_a_detalii_comentarii").className = "nav_cap_green";
			document.getElementById("a_detalii_comentarii").className = "nav_bt_green";
		}
		else{
			document.getElementById("div_a_detalii_produs").className = "nav_cap_green";
			document.getElementById("a_detalii_produs").className = "nav_bt_green";
			document.getElementById("div_a_detalii_comentarii").className = "nav_cap_green";
			document.getElementById("a_detalii_comentarii").className = "nav_bt_green";
			document.getElementById("div_a_detalii_servicii").className = "nav_cap_gri";
			document.getElementById("a_detalii_servicii").className = "nav_bt";
		}
		document.getElementById(div).style.display = "block";
	}
	else{
		document.getElementById("div_a_detalii_produs").className = "nav_cap_green";
		document.getElementById("a_detalii_produs").className = "nav_bt_green";
		document.getElementById("div_a_detalii_servicii").className = "nav_cap_green";
		document.getElementById("a_detalii_servicii").className = "nav_bt_green";
		document.getElementById("div_a_detalii_comentarii").className = "nav_cap_gri";
		document.getElementById("a_detalii_comentarii").className = "nav_bt";
		//id  =  document.getElementById("produs_id").value;
		//url = "ajax/get_comentarii_produs.php?id="+div;
		
		asyncrequest(web_root+'continut/ajax_comentari_produs',div,'detalii_comentarii','div');
		document.getElementById("detalii_comentarii").style.display = "block";
		//getCommentContent(url,'showCommentContent'); 
		//ajax_comentari_produs
		//detalii_comentarii // de inlocuit si dat block
	}
}

function getCommentContent(url,fct){
	if(window.XMLHttpRequest){
		cerere_comentarii = new XMLHttpRequest();
		cerere_comentarii.onreadystatechange = eval(fct);
		cerere_comentarii.open("GET", url, true);
		cerere_comentarii.send(null);
	}
	else if(window.ActiveXObject)
	{
		cerere_comentarii = new ActiveXObject("Microsoft.XMLHTTP");
		if(cerere_comentarii){
			cerere_comentarii.onreadystatechange = eval(fct);
			cerere_comentarii.open("GET", url, true);
			cerere_comentarii.send();
		}
	}
}

function showCommentContent(){
	if(cerere_comentarii.readyState == 4){	
		if(cerere_comentarii.status == 200){	
			raspuns = cerere_comentarii.responseText;
			if(raspuns.indexOf("<div") != -1 ){
				document.getElementById('detalii_comentarii').innerHTML =raspuns;
				document.getElementById('detalii_comentarii').style.display = "block"; 
			}
		}
		else{
			alert("A aparut o problema la transferul datelor:\n" + cerere_adresa.statusText);
		}	
	}
}
function adaugaComentariu(text,pid){
	if(text.length > 5){
		url="ajax/addComentariu.php?text="+text+"&pid="+pid;
		sendAddCommentRequest(url);
		showReview('detalii_comentarii');
		alert("Comentariul dumneavoastra va fi afisat dupa ce este validat de unul dintre administratorii nostri");
	}
	else alert('Comentariul trebuie sa contina cel putin 5 caractere!');
}

function sendAddCommentRequest(url){
	if(window.XMLHttpRequest){
		cerere_add_comentariu = new XMLHttpRequest();
		//cerere_add_comentariu.onreadystatechange = eval(fct);
		cerere_add_comentariu.open("GET", url, true);
		cerere_add_comentariu.send(null);
	}
	else if(window.ActiveXObject)
	{
		cerere_add_comentariu = new ActiveXObject("Microsoft.XMLHTTP");
		if(cerere_add_comentariu){
			//cerere_add_comentariu.onreadystatechange = eval(fct);
			cerere_add_comentariu.open("GET", url, true);
			cerere_add_comentariu.send();
		}
	}
}

function showMsgAfterAdded(){
	if(cerere_add_comentariu.readyState == 4){	
		if(cerere_add_comentariu.status == 200){	
			raspuns = cerere_add_comentariu.responseText;
			if(raspuns.indexOf("a") != -1 ){
				document.getElementById('mesaje_cometarii').innerHTML =raspuns;
				document.getElementById('mesaje_cometarii').style.display = "block"; 
			}
		}
		else{
			//alert("A aparut o problema la transferul datelor:\n" + cerere_adresa.statusText);
		}	
	}
}

//====================================JS FIRME=====================================
var cerere_firma;  
var position_firme = 0;
function surfFirme(action){

	if(action == 'next'){
		position_firme = position_firme + 1;
		SendFirmeRequest(array_firme[position_firme]);  //variabila array_adrese este initializata in adrese.tpl
	}
	if(action == 'back'){
		position_firme = position_firme - 1;
		SendFirmeRequest(array_firme[position_firme]);  //variabila array_adrese este initializata in adrese.tpl
	}
	
	var aux1 = position_firme+1;
	if(!array_firme[aux1])
		document.getElementById('buton_next').style.visibility = 'hidden';
	else document.getElementById('buton_next').style.visibility = 'visible';
		
	var aux2 = position_firme-1;
	if(!array_firme[aux2])
		document.getElementById('buton_back').style.visibility = 'hidden';
	else document.getElementById('buton_back').style.visibility = 'visible';
	
}

function SendFirmeRequest(firmaId){
asyncrequest(web_root+'client/ajax_get_next_firma', firmaId, 'content_firme', 'div');
}
//==================================END JS FIRME===================================

//====================================JS ADRESE=====================================
var cerere_adresa;  
var position = 0;
function surfAdresses(action){

	if(action == 'next'){
		position = position + 1;
		SendAdressRequest(array_adrese[position]);		//variabila array_adrese este initializata in adrese.tpl
	}
	if(action == 'back'){
		position = position - 1;
		SendAdressRequest(array_adrese[position]);  //variabila array_adrese este initializata in adrese.tpl
	}
	
	var aux1 = position+1;
	if(!array_adrese[aux1])
		document.getElementById('buton_next').style.visibility = 'hidden';
	else document.getElementById('buton_next').style.visibility = 'visible'; 
		
	var aux2 = position-1;
	if(!array_adrese[aux2])
		document.getElementById('buton_back').style.visibility = 'hidden';
	else document.getElementById('buton_back').style.visibility = 'visible';
	 
}

function SendAdressRequest(adresaId){ 
asyncrequest(web_root+'client/ajax_get_next_adress', adresaId, 'content_adrese', 'div');
}
//==================================END JS ADRESE===================================

//==================================JS SEARCH===================================

var test = 1; 
var previousSearchId; 
var cerere_search;

function showToolTipSearch(e,id){
	if(id != previousSearchId){
		if(document.all)e = event;
		
		previousSearchId = id;
		var obj = document.getElementById('bubble_tooltip');
		document.getElementById('div_search_size_content').innerHTML ="Loading...";
		sendSearchRequest(id);
		obj.style.display = 'block';
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
		var leftPos = e.clientX - 20;
		if(leftPos<0)leftPos = 0;
		obj.style.left = leftPos + 'px';
		obj.style.top = e.clientY - obj.offsetHeight -4 + st + 'px';		
	}
	else recalculatePosition(e);
}	

function sendSearchRequest(id){
	if (tooltipsCache == undefined) var tooltipsCache = [];
	if ( tooltipsCache[id] != undefined  && tooltipsCache[id] != '' && tooltipsCache[id] != 'Loading...' ){
	document.getElementById('div_search_size_content').innerHTML = tooltipsCache[id];
	} else {
	
	asyncrequest(web_root+'continut/ajax_get_marimi_produs', id, 'div_search_size_content', 'div');
	
	
//	var SR = document.createElement("processSearchRequest");
//	SR.setAttribute("id",id);
//	asyncrequest(web_root+'continut/ajax_get_marimi_produs', id, 'processSearchRequest', 'call'); 
	
	if ( document.getElementById('div_search_size_content').innerHTML != 'Loading...' )
		tooltipsCache[id] = document.getElementById('div_search_size_content').innerHTML;
	}
	//urlSearch = 'ajax/getProductSize.php?pid='+id;
	//getSearchContent(urlSearch,"showSearchContent");
}

function processSearchRequest(id, content) {
	document.getElementById('div_search_size_content').innerHTML = content;
	menucache[id] = content;
}

function recalculatePosition(e){
	if(document.all)e = event;
	
	var obj = document.getElementById('bubble_tooltip');
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX - 20;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -4 + st + 'px';
}
function hideToolTipSearch()
{
	document.getElementById('bubble_tooltip').style.display = 'none';
	//document.getElementById('div_search_size_content').innerHTML ="Loading...";
	
}

//================================END JS SEARCH=================================
//================================ JS MARCI ======================================
var tooltip_timeout = 300;
var cerere_tooltip;
var previus_mid = '';
var tooltip_close_timer = null;
function CalculateMarciTooltipPosition(e){
		if(document.all)e = event;
		
		var obj = document.getElementById('bubble_tooltip');
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		
		if(navigator.userAgent.toLowerCase().indexOf('safari')>=0) st=0;
		var leftPos = e.clientX - 20;
		if(leftPos<0)leftPos = 0;
		obj.style.left = leftPos + 'px';
		obj.style.top = e.clientY - obj.offsetHeight -4 + st + 'px';
		obj.style.display = 'block';
}

/**
Ajax tooltips needs rewrite to cache ajax requests.
**/
function lkajsdssda(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);

		var bubble = document.getElementById('bubble_tooltip');
		bubble.style.left = curleft + 'px';
		bubble.style.top = curtop + 20 + 'px';
		bubble.style.display = 'block';
	}
}
function showToolTip(e,mid,content){
	CancelTooltipClose();
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_middle');
	if(previus_mid != mid){
		if(document.all)e = event;
		obj.style.display = 'none';
		obj.style.left = 0;
		obj.style.top  = 0;
		
		//This is where you call ajax to get tooltip contents
		obj2.innerHTML = "";
 		asyncrequest (web_root+'marci/ajax_getTooltipContent',mid, 'bubble_middle','div');
		//if(obj2.innerHTML.indexOf("<ul") != -1);
			//CalculateMarciTooltipPosition(e);
		//		alert(e); 
		//window.setTimeout("CalculateMarciTooltipPosition(e)", 200);
		lkajsdssda(content);
	 
		previus_mid = mid;
	}
	else{
		CancelTooltipClose();
		if(obj2.innerHTML.indexOf("<ul") != -1){
			//CalculateMarciTooltioPosition(e)
			CalculateMarciTooltipPosition(e);
			//window.setTimeout(CalculateMarciTooltipPosition, 250,e);	
		}
	}
}	


function hideToolTip()
{
	document.getElementById('bubble_tooltip').style.display = 'none';
	//document.getElementById('bubble_tooltip_content').innerHTML = 'Loading...';
	previus_mid = '';
	
}

function setCloseTime()
{
	tooltip_close_timer = window.setTimeout(hideToolTip, tooltip_timeout);
}
function CancelTooltipClose(){
	if(tooltip_close_timer)
	{
		window.clearTimeout(tooltip_close_timer);
		tooltip_close_timer = null;
	}
}
function SendTooltipRequest(marcaID){
urlTooltip = 'ajax/getTooltipContent.php?mid='+marcaID;
getTooltipContent(urlTooltip,"showTooltipContent");
}

function getTooltipContent(url,fct){
	if(window.XMLHttpRequest){
		cerere_tooltip = new XMLHttpRequest();
		cerere_tooltip.onreadystatechange = eval(fct);
		cerere_tooltip.open("GET", url, true);
		cerere_tooltip.send(null);
	}
	else if(window.ActiveXObject)
	{
		cerere_tooltip = new ActiveXObject("Microsoft.XMLHTTP");
		if(cerere_tooltip){
			cerere_tooltip.onreadystatechange = eval(fct);
			cerere_tooltip.open("GET", url, true);
			cerere_tooltip.send();
		}
	}
}

function showTooltipContent(){
	if(cerere_tooltip.readyState == 4){	
		if(cerere_tooltip.status == 200){					
			raspuns = cerere_tooltip.responseText;
			
			if(raspuns.indexOf("<div") != -1 ){
					document.getElementById('bubble_middle').innerHTML =raspuns;
			}

		}
		else{
			//alert("A aparut o problema la transferul datelor:\n" + cerere_tooltip.statusText);
		}	
	}
}


var cerereMarci;
var urlMarci;
function incarcaMarciContent(categorie,divMargin){
urlMarci = 'ajax/getMarciContent.php?grupa='+categorie+'&margin='+divMargin;
getMarciContent(urlMarci,"showMarciContent");
}

function getMarciContent(url,fct){
	if(window.XMLHttpRequest){
		cerereMarci = new XMLHttpRequest();
		cerereMarci.onreadystatechange = eval(fct);
		cerereMarci.open("GET", url, true);
		cerereMarci.send(null);
	}
	else if(window.ActiveXObject)
	{
		cerereMarci = new ActiveXObject("Microsoft.XMLHTTP");
		if(cerereMarci){
			cerereMarci.onreadystatechange = eval(fct);
			cerereMarci.open("GET", url, true);
			cerereMarci.send();
		}
	}
}
function showMarciContent(){
	if(cerereMarci.readyState == 4){	
		if(cerereMarci.status == 200){					
			raspuns = cerereMarci.responseText;
			
			if(raspuns.indexOf("<div") != -1 ){
					document.getElementById('wrap_marci').innerHTML =raspuns;
			} 
		}
		else{
			//alert("A aparut o problema la transferul datelor:\n" + cerere.statusText);
		}	
	}
}


//============================== END JS MARCI ======================================
//============================ JS CATEGORII=================================
var prevId = 0;
var raspuns = '';
var display_sub_categories = "off";
var timeout          = 1000;
var closetimer		 = 0;
var menuCache		 = [];

function showSubCategories(id, departament){
	mcancelclosetime();
	if( prevId != 0){
		document.getElementById("DD"+prevId).style.display = "none";	
	}
	
	if(prevId != id){
		prevId = id;
		if ( document.getElementById("DD"+prevId).innerHTML != '&nbsp;' ) { 
		menuCache[id] = document.getElementById("DD"+prevId).innerHTML;
		}
		if (menuCache[id] != undefined  && menuCache[id] != '&nbsp;') {
			document.getElementById("DD"+prevId).innerHTML = menuCache[id];
		} else {
		asyncrequest(web_root+'continut/ajax_show_subcat/'+departament, id, "DD"+id, 'div');
		menuCache[id] = document.getElementById("DD"+prevId).innerHTML;
		} 
	}
	document.getElementById("DD"+id).style.display = "block";
}

function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function mclosetime()
{
	closetimer = window.setTimeout(hideSubCategories, timeout);
}

function hideSubCategories(){
	if(prevId != 0){
		if(document.getElementById("DD"+prevId))
			{
				document.getElementById("DD"+prevId).style.display = "none";
			}
	}
}
//============================ END JS CATEGORII=================================
function loadMarime(stock_id){
	if(stock_id != "Alege" && stock_id){
		asyncrequest(web_root+'continut/ajax_stock_produs', stock_id, 'spatiu_pret', 'div');
	}
}
function loadCuloare(culoare, defDep, colectie){ 
	if(culoare != "Alege" && culoare){
		if(colectie != '2')
		document.getElementById('product_picture').src = lr_root+'shopImages/'+defDep+'/produse/'+culoare+'.jpg';
		asyncrequest(web_root+'continut/ajax_marimi_produs', culoare, 'product_size', 'options');	
	}
}

//====================== JS FILTRE STOC=========================\\
var filter_prevId = '';
var filter_timeout          = 1000;
var filter_closetimer		 = 0;

function filter_showFilter (id) {
	filter_mcancelclosetime();
	if( filter_prevId != ''){
		document.getElementById(filter_prevId).style.display = "none";	
	}
	
	if(prevId != id){
		filter_prevId = id;
		document.getElementById(id).style.display = "block";
}
}

function filter_mcancelclosetime()
{
	if(filter_closetimer)
	{
		window.clearTimeout(filter_closetimer);
		filter_closetimer = null;
	}
}

function filter_mclosetime()
{
	filter_closetimer = window.setTimeout(filter_hideFilter, timeout);
}

function filter_hideFilter(){
	if(filter_prevId != 0){
		if(document.getElementById(filter_prevId))
			{
				document.getElementById(filter_prevId).style.display = "none";
			}
	}
}

//====================== JS PRODUSE MARCA=========================\\
 
function getMarciForLetter(obj,letter,marca){
	if(!marca) marca = '------';
	if(obj){
  		object = obj;
  		url = web_root+"ajax/getMarciForLetter.php?litera="+letter+"&marca="+marca;
		incarcaURL(url, "setMarciForLetter");
  	}
}
//creaza submeniul categoriei active
function setMarciForLetter(){
	if(cerere.readyState == 4){	
		if(cerere.status == 200){					
			raspuns = cerere.responseText;
			if(raspuns.indexOf("<ul") != -1 ){
				if(object){
				object.className = "leftLi"; 
				//object.style.background = "url(images/flech_toutes.gif) #ffffff no-repeat 0px 5px;";
				object.style.listStyleType = "none";
				object.innerHTML =raspuns;
				}
			}
		}
		else{
			//alert("A aparut o problema la transferul datelor:\n" + cerere.statusText);
		}	
	}
}

var cerere;
//incarca URL-ul care raspunde pentru cerere
function incarcaURL(url, fct){
	if(window.XMLHttpRequest){
		cerere = new XMLHttpRequest();
		cerere.onreadystatechange = eval(fct);
		cerere.open("GET", url, true);
		cerere.send(null);
	}
	else if(window.ActiveXObject)
	{
		cerere = new ActiveXObject("Microsoft.XMLHTTP");
		if(cerere){
			cerere.onreadystatechange = eval(fct);
			cerere.open("GET", url, true);
			cerere.send();
		}
	}

} 
//====================== END JS PRODUSE MARCA=========================\\