var baseURL = "http://seku.ro/";

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

function applyFilterProd(x) {
   var ka = 0;
   var fv = ""
   var xx = x+2;
   for (i=1; i<=xx; i=i+1) {
       fv = document.getElementById("fopt"+i).value;
       document.getElementById("foptval"+i).value =fv;
       if (fv!="" && fv!=null) {
           ka=ka+1;
       }
   }

   if (ka==0) {
      alert("Selectati cel putin un criteriu de filtrare");
   } else {
       document.activeForm.filteraction.value="applyfilter";
       document.activeForm.submit();
   }
}

function removeFilterProd(x) {
   var ka = 0;
   var xx = x+2;
   for (i=1; i<=xx; i=i+1) {
       document.getElementById("foptval"+i).value = "";
   }
   document.activeForm.filteraction.value="removefilter";
   document.activeForm.submit();
}

function newsf() {
  var newse = document.getElementById("newsemail").value;
  if (newse=="adresa ta de mail") {
     document.getElementById("newsemail").value = "";
  }
}

function newsb() {
  var newse = document.getElementById("newsemail").value;
  if (newse=="") {
     document.getElementById("newsemail").value = "adresa ta de mail";
  }
}

function finishOrder() {
   if (confirm("Sigur doriti sa finalizati si sa trimiteti comanda ?")) {
       document.cartForm.submit();
   }
}

function sendOrder(x) {
   if (x==0) {
       document.location = baseURL+"user-login/?backurl=cos-produse";
   } else {
       document.location = baseURL+"trimite-comanda";
   }
}

function refreshCart() {
    document.cartForm.submit();
}

function delFromCart(id) {
   if (confirm("Sigur doriti sa stergeti produsul din cos ?")) {
       document.location = baseURL+"cos-produse/?action=delete&id="+id;
   }
}

function add2cart(codp) {
   var txt = "<br><font class='sk_txt3'>Buc.</font> <input type='text' name='qty' id='qty' value=1 class='inputTxt5'>&nbsp;";
   txt = txt + "<a href=\"javascript:add2cartfin('"+codp+"')\" border=0 onMouseout='swapBtnAdd2CartOff()' onMouseover='swapBtnAdd2CartOn()'><img src='"+baseURL+"images/button_add_to_cart2.jpg' border=0 alt='Adauga' title='Adauga' align='absmiddle' id='btnadd2cartfin'></a>";
   document.getElementById("adaugaincos").innerHTML = txt;
}

function editUserFirma(idf) {
        window.scrollTo(0,0);
	var objBody = document.getElementsByTagName("body").item(0);
        var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

        new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
        document.getElementById("div-compara-produse").style.display = "block";
        loadFirmaInfo(idf);

}

function editUserLivrare(idf) {
        window.scrollTo(0,0);
	var objBody = document.getElementsByTagName("body").item(0);
        var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

        new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
        document.getElementById("div-compara-produse").style.display = "block";
        loadLivrareInfo(idf);

}

function addLivrareUser() {
        window.scrollTo(0,0);
	var objBody = document.getElementsByTagName("body").item(0);
        var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

        new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
        document.getElementById("div-compara-produse").style.display = "block";
        loadAddLivrare();

}

function addFirmaUser() {
        window.scrollTo(0,0);
	var objBody = document.getElementsByTagName("body").item(0);
        var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

        new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
        document.getElementById("div-compara-produse").style.display = "block";
        loadAddFirma();

}

function comparaProdusele() {
  
	var objBody = document.getElementsByTagName("body").item(0);
        var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

        new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
        document.getElementById("div-compara-produse").style.display = "block";
        loadProduseComparate();

}

function showOrderDetails(ido) {
  
	var objBody = document.getElementsByTagName("body").item(0);
        var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { myLightbox.end(); }
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
	if (!e) var e = window.event;
	   var clickObj = Event.element(e).id;
		if ( clickObj == 'lightbox') {
			myLightbox.end();
		}
	};
	objBody.appendChild(objLightbox);

	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

        new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: 0.8 });
        document.getElementById("div-compara-produse").style.display = "block";
        loadOrderDetails(ido);

}

function userProfileSave()
{

var nume = document.getElementById("nume").value;
var parola = document.getElementById("parola").value;
var parola2 = document.getElementById("parola2").value;
var oras = document.getElementById("oras").value;
var judet = document.getElementById("judet").value;
var adresa = document.getElementById("adresa").value;
var codp = document.getElementById("codp").value;
var telefon = document.getElementById("telefon").value;

if (nume=="" || nume==null || telefon=="" || telefon==null || oras=="" || oras==null || judet=="" || judet==null || adresa=="" || adresa==null) {
    alert("Completati toate campurile marcate cu *");
} else if (parola!=parola2 && parola!="" && parola !=null) {
    alert("Parola si confirmarea ei nu corespund");
} else if (parola.length<5 && parola!="" && parola !=null) {
    alert("Parola trebuie sa fie de minim 5 caractere");
} else {
   document.activeForm.action.value="saveuserprofile";
   document.activeForm.submit();
}
}

function userLogin()
{

var email = document.getElementById("login_email").value;
var parola = document.getElementById("login_parola").value;

if (email=="" || email==null || parola=="" || parola==null) {
    alert("Completati adresa de e-mail si parola");
    return;
} else if (email!="" && email!=null && !validEmail(email)) {
    alert("Adresa de email introdusa nu este intr-un format valid");
    return;
} else {
  document.activeForm.action.value="userlogin";
  document.activeForm.submit();
}
}


function checkEnter(e){
var characterCode;// literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e;
characterCode = e.which; //character code is contained in NN4's which property
}
else{
e = event;
characterCode = e.keyCode; //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
userLogin(); //submit the form
}
else{
return false;
}

}

function strrpos (haystack, needle, offset) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // *     example 1: strrpos('Kevin van Zonneveld', 'e');
    // *     returns 1: 16
 
    var i = (haystack+'').lastIndexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
}

function swapBtn1Off(idprod) {
   document.getElementById("img-prod-"+idprod).src=baseURL+"images/button_goto_prod_details.gif";
}

function swapBtn1On(idprod) {
   document.getElementById("img-prod-"+idprod).src=baseURL+"images/button_goto_prod_details_on.gif";
}

function swapBtn2Off(idprod) {
   document.getElementById("img-prod-"+idprod).src=baseURL+"images/button_add_to_cart.gif";
}

function swapBtn2On(idprod) {
   document.getElementById("img-prod-"+idprod).src=baseURL+"images/button_add_to_cart_on.gif";
}

function swapBtnComparaOff() {
   document.getElementById("img-comparaprod").src=baseURL+"images/btn_compara.gif";
}

function swapBtnComparaOn() {
   document.getElementById("img-comparaprod").src=baseURL+"images/btn_compara_on.gif";
}

function swapBtnAdd2CartOff() {
   document.getElementById("btnadd2cartfin").src=baseURL+"images/button_add_to_cart2.jpg";
}

function swapBtnAdd2CartOn() {
   document.getElementById("btnadd2cartfin").src=baseURL+"images/button_add_to_cart2on.jpg";
}

function swapBtnSendOrderOff() {
   document.getElementById("img-send-order").src=baseURL+"images/btn_trimite_comanda.gif";
}

function swapBtnSendOrderOn() {
   document.getElementById("img-send-order").src=baseURL+"images/btn_trimite_comanda_on.gif";
}

function swapBtnFinishOrderOff() {
   document.getElementById("img-finish-order").src=baseURL+"images/btn_finalizare.gif";
}

function swapBtnFinishOrderOn() {
   document.getElementById("img-finish-order").src=baseURL+"images/btn_finalizare_on.gif";
}

function showHideChild(divid) {
    var state = document.getElementById(divid).style.display;
    if (state=="block") {
       document.getElementById(divid).style.display = "none";
       document.getElementById("img-"+divid).src = baseURL+"images/plus.jpg";
    } else {
       document.getElementById(divid).style.display = "block";
       document.getElementById("img-"+divid).src = baseURL+"images/minus.jpg";
    }
}

function siteLoad(undesuntem) {
  
  var prodcomp = document.getElementById("compProdTotal").value;
  if (prodcomp>0) {
     document.getElementById("compara-produse").style.display="block";
  }
  if (undesuntem!="produs_subgrupa") {
     setInterval("slideRecomandari()", 5000);
  }
}

function slideRecomandari() {
   var recProdPos = document.getElementById('recProdPos').value*1;
   var recProdTotal = document.getElementById('recProdTotal').value*1;
   var recProdDir = document.getElementById('recProdDir').value*1;

   if (recProdPos>0 && recProdPos<=recProdTotal) {
       if (recProdDir>0) {
          // spre dreapta
          nextRec(recProdTotal);
       } else {
         // spre stanga
         prevRec(recProdTotal)
       }
   }
}

function showPage(x) {
    document.activeForm.crntPage.value=x;
    document.activeForm.submit();
}

function validEmail(address) {

if (address.length==0) {
  return (true);
}
else
{
if (address.length>=6) {
if (address.indexOf("@")>0) {
if ((address.indexOf("@")+1)<address.lastIndexOf(".")) {
if (address.lastIndexOf(".")<(address.length-2)) {
return (true);
}
}
}
}
}
return (false);
}

function nextRec(x) {

  var recProdPos = document.getElementById('recProdPos').value*1;
  var divxPX = document.getElementById('recImgDivInner').style.left;
  var divx = 0;
  var newx = 0;

  if (divxPX=="" || divxPX==null) {
      divx=0;
  } else {
      divx = divxPX.substring(0,divxPX.length-2)*1;
  }

  newx = divx-138;

  if (recProdPos==1) {
     document.getElementById("recArrLeft").src = baseURL+"images/arr_left.jpg";
  }

  if (recProdPos<x) {
    document.getElementById('recProdPos').value = recProdPos+1;
    document.getElementById('recProdDir').value = 1;
    var t1 = new Tween(document.getElementById('recImgDivInner').style,'left',Tween.strongEaseOut,divx,newx,1,'px');
    t1.start();
  }
  if (recProdPos==(x-1)) {
    document.getElementById("recArrRight").src = baseURL+"images/arr_right_off.jpg";
    document.getElementById('recProdDir').value = -1;
  }

}

function prevRec(x) {

  var recProdPos = document.getElementById('recProdPos').value*1;
  var divxPX = document.getElementById('recImgDivInner').style.left;
  var divx = 0;
  var newx = 0;

  if (divxPX=="" || divxPX==null) {
      divx=0;
  } else {
      divx = divxPX.substring(0,divxPX.length-2)*1;
  }

  newx = divx+138;

  if (recProdPos>1) {
    document.getElementById('recProdPos').value = recProdPos-1;
    document.getElementById('recProdDir').value = -1;
    var t1 = new Tween(document.getElementById('recImgDivInner').style,'left',Tween.strongEaseOut,divx,newx,1,'px');
    t1.start();
  }
  
  if (recProdPos<=x) {
     document.getElementById("recArrRight").src = baseURL+"images/arr_right.jpg";
  }
  
  if (recProdPos==2) {
     document.getElementById("recArrLeft").src = baseURL+"images/arr_left_off.jpg";
     document.getElementById('recProdDir').value = 1;
  }

}