function switch_class(el, old_class, new_class){
		var a, clasa=""; 
		a = el.className.split(" ");
    for (i = 0;i<a.length;i++){
      if (a[i] != old_class){
        clasa=clasa+" "+a[i];
      }
    }
    clasa=clasa+" "+new_class;
		el.className=clasa;
}

function show_hide(el, sw){
	var myel=document.getElementById(el);
	if (sw){
		myel.style.display='block';
	}else{
		myel.style.display='none';
	}
}	

function OpenCameraWindow(cam, speed) {
  var a;
  var light;
  var dim = getPageSize();
  var scr = getPageScroll();
  var cam_height = 400;
  var cam_width = 400;
  if (a = document.getElementById("overlay")){
     a.style.height = dim[1]+"px";
     a.style.display = "";
  }
  if (light = document.getElementById("lightbox")){
     light.style.display = "";
     light.style.top = scr[1]+"px";

     var ifr;

     if (a = document.getElementById("video_iframe")){
        ifr = a;
     }else{
            light.innerHTML = "xxx";

            var vd = document.createElement("div");
            vd.className = "video_container";
            light.appendChild(vd);

            ifr = document.createElement("iframe");
            ifr.name = "video_iframe";
            ifr.id = "video_iframe";
            ifr.setAttribute("frameborder","0");
            ifr.setAttribute("scrolling","no");
            ifr.className = "video_iframe";
            vd.appendChild(ifr);

            var cl = document.createElement("a");
            cl.href = "javascript:void(0);";
            cl.onclick = closeCamera;
            cl.className = "video_close";

            vd.appendChild(cl);
     }
     ifr.src = "http://www.bigbrother.ro/live.php?camera=" + cam + "&speed=" + speed;
  }
}

function ShowPicture(img_src) {
  var a;
  var light;
  var dim = getPageSize();
  var scr = getPageScroll();
  if (a = document.getElementById("overlay")){
     a.style.height = dim[1]+"px";
     a.style.display = "";
  }
  if (light = document.getElementById("lightbox")){
     light.style.display = "";

     var img;
     var imgwidth;
     var imgheight;

     if (a = document.getElementById("light_picture")){
        img = a;
        img.src = img_src;
        
        imgwidth = parseInt(img.offsetWidth);
        imgheight = parseInt(img.offsetHeight);
     }else{
            light.innerHTML = "";

            var vd = document.createElement("div");
            vd.className = "video_container picture_container";
            light.appendChild(vd);

            img = document.createElement("img");
            img.className = "light_picture";
            img.src = img_src;
			img.title = "Click pentru a Inchide";
            img.onclick = closeCamera;
            vd.appendChild(img);

            var cl = document.createElement("a");
            cl.href = "javascript:void(0);";
            cl.onclick = closeCamera;
            cl.className = "video_close";

            vd.appendChild(cl);
     }
     light.style.top = scr[1]+"px";
  }
}

function closeCamera(){
  if (a = document.getElementById("overlay")){
     a.style.display = "none";
  }
  if (light = document.getElementById("lightbox")){
     light.style.display = "none";
  }
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	xScr = xScroll;
	yScr = yScroll;
		
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScr,yScr)
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function livrare(){
	if (parseInt(document.getElementById('qt_update').value) == 1)	{
		document.getElementById('send_cmd').value = 1;
		document.forms.comanda_form.submit();
	}else{
		location.href="/comanda_trimite.html";
	}
}

var hidden=0; // Daca a fost sau nu ascunse zonele
function select_zona_livrare() {
		$("#zone_livrare div").addClass("hover");

		$("#zone_livrare div").hover(function(){$(this).removeClass("hover");},function(){$(this).addClass("hover");});

		
		$("#zona_livrare a").click(function(event) { // functie afisat zonele (cand e deja selectata zona)
			event.preventDefault();
			$.post("/set_zone.php", // Ajax POST function
			{ zona: $(this).attr("id") },
			function(data){ 
				$.each(data.preturi_vechi, function(i,item){
									$("#"+i).html('');
									$("#prod"+i).html('Pentru pre&#355;, selecteaz&atilde; zona de livrare');
					});

				$("#zone_livrare").slideDown('slow',function(){ hidden=0 /* zone vizibile*/});
				$("#zone_livrare div").removeClass("opaque");
				$("#zona_livrare").slideUp('fast',function(){
				$("#zona_livrare").html('<span class="red">Alege zona</span><span> de livrare pentru comanda online sau suna la 037BROTHER.</span>');
				});
				$("#prog_comenzi").html('Pentru a afla programul selecteaza zona de livrare');
				$("#prog_livrari").html('Pentru a afla programul selecteaza zona de livrare');
				$("#form_comanda").hide();
				$("#zona_livrare").slideDown('fast');
			},
			"json");// end POST function
		});

		$("#zone_livrare div").click(function() {// la click pe o zona

			if (!($('#zone_livrare div').hasClass('opaque'))){ // daca nu este vreo zona setata
				if (hidden==0)	{ // si zonele sunt vizibile    
					var zona_id = '#'+$(this).attr("id") 
					$.post("/set_zone.php", // Ajax POST function
					{ zona: $(this).attr("id") },
					function(data){ 
						$.each(data.preturi_noi, function(i,item){
							$("#"+i).html('<span style="color:white;"><span style="text-decoration: line-through;">'+ data.preturi_vechi[i]+'</span> / </span>'+item);
							$("#prod"+i).html('<span style="text-decoration: line-through;">'+data.preturi_vechi[i]+' Lei</span><BR>'+item+' Lei');
						});
						$("#prog_comenzi").html(data.prog_comenzi);
						$("#prog_livrari").html(data.prog_livrari);
						if(data.show_cmd == 1 ) $("#form_comanda").show();
						$("#zone_livrare div").addClass("opaque");
						$(zona_id).removeClass("opaque");
						$(zona_id).removeClass("opaque");
						oDv.style.visibility='hidden';

						$("#zone_livrare").delay(500).slideUp('slow',function(){hidden=1 /* zone ascunse*/});
						var title=data.descriere_zona;
						$("#zona_livrare").html(' ');
						$("#zona_livrare").html('<span> Ai selectat zona de livrare </span><span class="red">'+title+'</span> <span> Apasa <a  href="#">aici</a>  pentru a modifica zona de livrare. </span> ');

						$("#zona_livrare a").click(function(event) {
						event.preventDefault();

						if (hidden==1){
							$.post("/set_zone.php", // Ajax POST function
							{ zona: $(this).attr("id") },
							function(data){ 
								$.each(data.preturi_vechi, function(i,item){
									$("#"+i).html('');
									$("#prod"+i).html('Pentru pre&#355;, selecteaz&atilde; zona de livrare');
									});// restore preturi fara discount

								$("#zone_livrare").slideDown('slow',function(){ hidden=0 /* zone vizibile*/});
								$("#zone_livrare div").removeClass("opaque");
								$("#zona_livrare").slideUp('fast',function(){
								$("#zona_livrare").html('<span class="red">Alege zona</span><span> de livrare pentru comanda online sau suna la 037BROTHER.</span>');
								});
								$("#prog_comenzi").html('Pentru a afla programul selecteaza zona de livrare');
								$("#prog_livrari").html('Pentru a afla programul selecteaza zona de livrare');
								$("#form_comanda").hide();
								$("#zona_livrare").slideDown('fast');
							},
							"json");// end POST function
						}
				});

					},
					"json");
				}
			}
		});

$("#zona_livrare").ajaxError(function() {
$(this).html('<span class="red">Eroare: zona de livrare nu a putut fi setata.</span> ');
});
				
}
// Functii zone in paginile comanda
var text_z_neselectata = '<span class="red">Selecteaza</span> <span>zona de livrare pentru definitivarea comenzii</span>';

function reset_zone(event) { // functie afisat zonele (cand e deja selectata zona)
		$.post("/set_zone.php", // Ajax POST function
		{ zona: $(this).attr("id") },
		function(){ 
		
			$("#zone_livrare").slideDown('slow', function(){$("#comanda").hide();});
			$("#zone_livrare div").removeClass("opaque");
			$("#zona_livrare").slideUp('fast',function(){
			$("#zona_livrare").html(text_z_neselectata);
			
			});
			
			$("#zona_livrare").slideDown('fast');
		},
		"json");// end POST function
	}

function select_zona_livrare_comanda() {
	$("#locatie").change(
		function () {
			$.post("/verify_zone_comanda.php", // Ajax POST function
				{ zona_select: $("select option:selected").val() },
				function(data){ 
					if (data.interval_ok!='ok'){
					$('.trimite_comanda').attr('disabled', "disabled");
					locatie = $("select option:selected").val();
					
					alert("Programul de preluat comenzi pentru "+locatie+ " este "+data.program);
					}else{
					$('.trimite_comanda').removeAttr('disabled');
					}
				},
				"json");
        }
	
	);
	// Hover zone
	$("#zone_livrare div").addClass("hover");
	$("#zone_livrare div").hover(function(){$(this).removeClass("hover");},function(){$(this).addClass("hover");});

	if ($('#zone_livrare').is(':visible')) { 
		$("#zona_livrare").html(text_z_neselectata); // Rescrie textul default
		}
	else $("#zona_livrare a").click(function(event){event.preventDefault();reset_zone(event);});

	$("#zone_livrare div").click(function() {// la click pe o zona

		if (!($('#zone_livrare div').hasClass('opaque'))){ // daca nu este vreo zona setata
			if ($('#zone_livrare').is(':visible')) 	{ // si zonele sunt vizibile    
				var zona_id = '#'+$(this).attr("id") 
				$.post("/set_zone.php", // Ajax POST function
				{ zona: $(this).attr("id") },
				function(data){ 
					
					$("#zone_livrare div").addClass("opaque");
					$(zona_id).removeClass("opaque");
					$(zona_id).removeClass("opaque");
					oDv.style.visibility='hidden'; // Kill tooltip

					$("#zone_livrare").delay(500).slideUp('slow', function(){document.location=document.location;});
					var title=data.descriere_zona;
					$("#zona_livrare").html(' ');
					$("#zona_livrare").html('<span> Ai selectat zona de livrare </span><span class="red">'+title+'</span> <span> Apasa <a  href="#">aici</a>  pentru a modifica zona de livrare. </span> ');

					$("#zona_livrare a").click(function(event) {
					event.preventDefault();

					if ($('#zone_livrare').is(':hidden')) {
						reset_zone();
					}
			});

				},
				"json");
			}
		}
	});

//error
$("#zona_livrare").ajaxError(function() {$(this).html('<span class="red">Eroare: zona de livrare nu a putut fi setata.</span> ');});
			
}
