function showBusy_login(){ $('#form_busy_login').show('slow');	}
function processForm_login(html){		
	$('#form_errors_login').hide('slow');			
	window.setTimeout( function(){			 	
		$('#form_busy_login').hide('slow');				
		if(parseFloat(html)){			 		
	 		$('.login_form').hide('slow');
	 		window.location='/admin/';
	 	}else{
	 		$('#form_errors_login').html(html).show('slow');
	 	}			 	
	}, 2000);	
}

function processForm_login_small(html){			
	window.setTimeout( function(){			 		
		if(parseFloat(html)){			 		
	 		$('.login_form_small').hide('slow');
	 		window.location='/admin/';
	 	}else{
	 		window.location='/contul_meu/';
	 	}			 	
	}, 1000);	
}

function showBusy(){ 	$('.form_busy').show('slow');	$('.form_added').hide('slow');	}
function showAdded(){	$('.form_added').show('slow'); }
function processForm(html){	
	$('.form_errors').hide('slow');		
	window.setTimeout( function(){			 	
				$('.form_busy').hide('slow');				
				if(parseFloat(html)){			 								
						showAdded();
			 	}else{
			 		$('.form_errors').html(html).show('slow');
			 	}			 	
	}, 2000);
}

jQuery(document).ready(function(){
	
	 function addMega(){
        $(this).addClass("hovering");
   }

   function removeMega(){
       $(this).removeClass("hovering");
   }

    var megaConfig = {
         interval: 0,
         sensitivity: 4,
         over: addMega,
         timeout: 100,
         out: removeMega
    };
    
   
		$("#over_bar_small").mouseover(function(){
			$("#over_bar").css("width","200px");
      $("#over_bar_big").show("slow");
      $("#over_bar_small").hide("slow");      
    }).mouseout(function(){
      setTimeout(function(){       	
    		 $("#over_bar_small").show("slow");
    		 $("#over_bar_big").hide("slow");
    		 $("#over_bar").css("width","25px"); 
  		}, 5000 ); 
    });													
									
	

   $("li.hover_li").hoverIntent(megaConfig);

	$("#top_news").easySlider({ auto: true, continuous: true, pause: 3200 });
	
	$("div.scrollable").scrollable();
	$("a[rel^='prettyPhoto']").prettyPhoto();			
	$("#tooltip_load").tooltip();  

	// $.LOGIN
	$('.login_form').submit(function(eve){
		eve.preventDefault();		
		$.ajax({
			url: "/admin/login",
			type: "POST",
			dataType: "html",
			data: $('.login_form').serialize(),
			beforeSend: function(){
				showBusy_login();
			},	
		  	success: function(html) {
		    	processForm_login(html);			    	
		 	}
		});
	});	
	
	// $.LOGIN_small
	$('.login_form_small').submit(function(eve){
		eve.preventDefault();		
		$.ajax({
			url: "/admin/login",
			type: "POST",
			dataType: "html",
			data: $('.login_form_small').serialize(),
			beforeSend: function(){				
			},	
		  	success: function(html) {
		    	processForm_login_small(html);			    	
		 	}
		});
	});	
	
	
	
	
	// $.REGISTER
	$('#standard_form_register').submit(function(eve){
		eve.preventDefault();		
		$.ajax({
			url: "/contul_meu/inregistrare",
			type: "POST",
			dataType: "html",
			data: $('#standard_form_register').serialize(),
			beforeSend: function(){
				showBusy();
			},	
		  	success: function(html) {		  		
		    	processForm(html);
		    	if(parseFloat(html)){
		    		$('#standard_form_register').hide('slow');
		    	}
		 	}
		});

	});	
	
	
	// $.CONTACT
	$('#standard_form_contact').submit(function(eve){
		eve.preventDefault();		
		$.ajax({
			url: "/contact/trimitere",
			type: "POST",
			dataType: "html",
			data: $('#standard_form_contact').serialize(),
			beforeSend: function(){
				showBusy();
			},	
		  	success: function(html) {		  		
		    	processForm(html);
		    	if(parseFloat(html)){
		    		$('#standard_form_contact').hide('slow');
		    	}
		 	}
		});

	});	
	
});

function filtrareUnitati()
{
	//$('#filtrareUnitati').submit();	
	//window.location.reload();
}



function doRezervare(unitateID)
{		
		var src = "/helper/rezervare/"+unitateID;		
		
		$.modal('<a href="#" class="simplemodal-close" onClick="$.modal.close();">&nbsp;</a><iframe name="testframe" src="' + src + '" height="500" width="830" style="border:0">', {
			closeHTML:"simplemodal-close",
			containerCss:{				
				height:502,
				width:830
			},
			overlayClose:true
		});				
}

function doContact(uID)
{		
		var src = "/helper/contact/"+uID;		
		
		$.modal('<a href="#" class="simplemodal-close" onClick="$.modal.close();">&nbsp;</a><iframe name="testframe" src="' + src + '" height="450" width="830" style="border:0">', {
			closeHTML:"simplemodal-close",
			containerCss:{				
				height:452,
				width:830
			},
			overlayClose:true
		});		
}

function doHarta(uID)
{		
		var src = "/helper/harta/"+uID;		
		
		$.modal('<a href="#" class="simplemodal-close" onClick="$.modal.close();">&nbsp;</a><iframe name="testframe" src="' + src + '" height="450" width="830" style="border:0">', {
			closeHTML:"simplemodal-close",
			containerCss:{				
				height:452,
				width:830
			},
			overlayClose:true
		});		
}

function doTur(htppsrc)
{		
		
		
		$.modal('<a href="#" class="simplemodal-close" onClick="$.modal.close();">&nbsp;</a><iframe name="testframe" src="' + htppsrc + '" height="700" width="830" style="border:0">', {
			closeHTML:"simplemodal-close",
			containerCss:{				
				height:702,
				width:830
			},
			overlayClose:true
		});		
}

function doComandaTur()
{		
		var src = "/helper/comanda_tur/";		
		
		$.modal('<a href="#" class="simplemodal-close" onClick="$.modal.close();">&nbsp;</a><iframe name="testframe" src="' + src + '" height="450" width="830" style="border:0">', {
			closeHTML:"simplemodal-close",
			containerCss:{				
				height:452,
				width:830
			},
			overlayClose:true
		});				
}


			function getIDhref()
			{			  
			  var regexS = "([^#]*)$";
			  var regex = new RegExp( regexS );
			  var results = regex.exec(document.location.href);			 	  
			  if( results == null )
			  {
			    return "";
			  }
			  else
			  {
			  	var return_msg = results[0].replace(new RegExp(/\//g),"");			  	
			    return return_msg;
			  }
			}
			
			
			function showElementsByClassName(findClass) 
			{
				var aElm=document.body.getElementsByTagName('*');
				for(var i=0; i<aElm.length; i++) {
				if(aElm[i].className==findClass) {
					aElm[i].style.display='block';
				}
				} 
			}
			
			function hideElementsByClassName(findClass) 
			{
				
				var aElm=document.body.getElementsByTagName('*');
				for(var i=0; i<aElm.length; i++) {
				if(aElm[i].className==findClass) {
					aElm[i].style.display='none';
				}
				} 
			}
			
			function hideElementssByClassName(node,classname) {
				if (node.getElementsByClassName)
					return node.getElementsByClassName(classname);
				else {
					// your custom function
				}
			}
			
			
									function getIDhref()
									{			  
									  var regexS = "([^#]*)$";
									  var regex = new RegExp( regexS );
									  var results = regex.exec(document.location.href);			 	  
									  if( results == null )
									  {
									    return "";
									  }
									  else
									  {
									  	var return_msg = results[0].replace(new RegExp(/\//g),"");			  	
									    return return_msg;
									  }
									}
									
									
									function show_hide_prices()
									{
											var hrefID = getIDhref();
											if(hrefID.length > 0) 
											{				
												
												if(hrefID.search(/speciala/i)> -1) { hideElementsByClassName("craciun_tr"); hideElementsByClassName("revelion_tr"); hideElementsByClassName("paste_tr");	hideElementsByClassName("1mai_tr");	hideElementsByClassName("sfvalentin_tr");	hideElementsByClassName("halloween_tr"); hideElementsByClassName("oferta_tr"); }
												else if(hrefID.search(/craciun/i)> -1) { hideElementsByClassName("speciala_tr");	hideElementsByClassName("revelion_tr"); hideElementsByClassName("paste_tr");	hideElementsByClassName("1mai_tr");	hideElementsByClassName("sfvalentin_tr");	hideElementsByClassName("halloween_tr"); hideElementsByClassName("oferta_tr"); }
												else if(hrefID.search(/revelion/i)> -1) { hideElementsByClassName("speciala_tr");	hideElementsByClassName("craciun_tr"); hideElementsByClassName("paste_tr");	hideElementsByClassName("1mai_tr");	hideElementsByClassName("sfvalentin_tr");	hideElementsByClassName("halloween_tr"); hideElementsByClassName("oferta_tr"); }
												else if(hrefID.search(/paste/i)> -1) { hideElementsByClassName("speciala_tr");	hideElementsByClassName("craciun_tr"); hideElementsByClassName("revelion_tr"); hideElementsByClassName("1mai_tr");	hideElementsByClassName("sfvalentin_tr");	hideElementsByClassName("halloween_tr"); hideElementsByClassName("oferta_tr"); }
												else if(hrefID.search(/1mai/i)> -1) { hideElementsByClassName("speciala_tr");	hideElementsByClassName("craciun_tr"); hideElementsByClassName("revelion_tr"); hideElementsByClassName("paste_tr"); hideElementsByClassName("sfvalentin_tr");	hideElementsByClassName("halloween_tr"); hideElementsByClassName("oferta_tr"); }
												else if(hrefID.search(/sfvalentin/i)> -1) { hideElementsByClassName("speciala_tr");	hideElementsByClassName("craciun_tr"); hideElementsByClassName("revelion_tr"); hideElementsByClassName("paste_tr"); hideElementsByClassName("1mai_tr");	hideElementsByClassName("halloween_tr"); hideElementsByClassName("oferta_tr"); }
												else if(hrefID.search(/halloween/i)> -1) { hideElementsByClassName("speciala_tr");	hideElementsByClassName("craciun_tr"); hideElementsByClassName("revelion_tr"); hideElementsByClassName("paste_tr");	hideElementsByClassName("1mai_tr");	hideElementsByClassName("sfvalentin_tr");	hideElementsByClassName("oferta_tr"); }										
											}				
									}		
	
									
			var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
			var startX = 10 //set x offset of bar in pixels
			var startY = 190 //set y offset of bar in pixels
			var verticalpos="frombottom" //enter "fromtop" or "frombottom"

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function closebar(){
if (persistclose)
document.cookie="remainclosed=1"
document.getElementById("over_bar").style.visibility="hidden"
}

function staticbar(){
	barheight=document.getElementById("over_bar").offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("over_bar");
	stayTopLeft();
}

if (window.addEventListener)
window.addEventListener("load", staticbar, false)
else if (window.attachEvent)
window.attachEvent("onload", staticbar)
else if (document.getElementById)
window.onload=staticbar			

		
