// tooltip init
$j(document).ready(function() {
	
	$j("form").each(
		function(i,el){
			$j(el).validate({ignoreTitles:false});
		}
	);	
		/*
       $j("[title]").each(
	   		function(i, el){									
				$j(el).simpletooltip();
			}
	   );*/
	   
  		$j(".select").selectbox();
	  
	  
	   $j(".temporary").each(
	   		function(i,el){
				$j(el).oneTime(10000, function() {					
				    $j(this).hide();
				  });
			}
	   );
	  
	   $j(".popup").each(function(i,el){
	   		$j(el).click(
				function()
				{
					p_id="#"+$j(this).attr("window");															
					p_width=parseInt(($j(this).attr("window_width")?$j(this).attr("window_width"):100));
					p_height=parseInt($j(this).attr("window_height")?$j(this).attr("window_height"):100);
					p_resizeable=($j(this).attr("window_resizeable")?$j(this).attr("window_resizeable")=="true":true);
					p_draggable=($j(this).attr("window_draggable")?$j(this).attr("window_draggable")=="true":true);
					p_modal=($j(this).attr("window_modal")?$j(this).attr("window_modal")=="true":true);
					p_title=($j(this).attr("window_title")?$j(this).attr("window_title"):100);
					 
					this.dialog=$j(p_id).dialog({width:p_width, height: p_height, title:p_title, modal: p_modal, draggable:p_draggable,   resizable:p_resizeable });
					this.dialog.dialog( 'open' );
				}
			);				   		
	   });
	  
	   $j("button").each(function(i, el){
	   		$j(el)
				.addClass("ui-corner-all")
				.addClass("ui-state-default")
				.mouseover(function(){$j(this).toggleClass("ui-state-hover");})
				.mouseout(function(){$j(this).toggleClass("ui-state-hover");});
	   });
	   
	   $j("input.calendar").each(function(i,el){
	   		$j(el).datepicker({ dateFormat: 'yy-mm-dd' });
	   });
	   
	   $j("input.spinner").each(function(i,el){
	   		new Spinner(el.id);
	   });
	   
	   $j("div.ddsmoothmenu").each(function(i,el){
	   		ddsmoothmenu.init({
				mainmenuid: el.id,				
				contentsource: "markup" 
			})
	   });
	  
	   
	   $j(".tabs_view").each(function(i,el){
	   		
			if($j(el).attr("select"))
			{		
				$j(el).tabs({ selected: $j(el).attr("select") });
			}
			else
				$j(el).tabs();
			$j(el).show();
	   });
	
	   $j(".slideshow").each(function(i,el){
	   		$j(el).carousel({
		      hide: 'fadeOut', 
		      show: 'fadeIn', 
		      duration: 500, 
		      speed: 2000, 
		      seed: 5 
		              
		    });
			$j(el).show();
		});
	   
	  
	   $j(".expander").each(function(i,el){	   		
	   		$j(el).click(
				function(){	 						
					if ( $j(this).attr("expand")!="") {						
						if ($j("#"+$j(this).attr("expand")).is(':visible'))
							$j("#"+$j(this).attr("expand")).slideUp();
						else 
							$j("#"+$j(this).attr("expand")).slideDown();
					}
					else {
						if ($j(this).next().is(':visible')) 
							$j($j(this)).next().slideUp();
						else 
							$j($j(this)).next().slideDown();
					}
				}
			);	   		
	   });
	  
});

function ajax_load(url, pars, where, evalonsuccess) 
{
	$j.ajax({
			url: url,
			data: pars,
			cache: true,
			success: function(response){
				if(where!="")
					$j(where).html(response);
				eval(evalonsuccess);
			}
		});
}


function go_to(url)
{
	location.href=url;
	return false;
}

function edit(url,id)
{
	go_to(url+"?a=edit:"+id);
}

function del(url)
{
	if(confirm("Sunteti sigur ca doriti sa stergeti?"))
	{
		go_to(url);
	}
}

function cnf(message)
{
	return confirm(message);
}

function ajax_del(url,id,evalonsuccess)
{
	if (confirm("Sunteti sigur ca doriti sa stergeti?")) {
		ajax_load(url + "?a=delete:" + id, "", "", evalonsuccess);
	}
}

function ajax_order(url,id,order,evalonsuccess)
{
	ajax_load(url+"?a=order:"+id+":"+order,"","",evalonsuccess);
}

function ajax_active(url,id,value,evalonsuccess)
{
	ajax_load(url+"?a=active:"+id+":"+value,"","",evalonsuccess);
}

function ajax_action(url,action,evalonsuccess)
{
	ajax_load(url+"?a="+action,"","",evalonsuccess);
}

function cart_add(product_id,quantity)
{
	if(product_id && quantity)
		go_to(root+"companii/cart?a=add&product_id="+product_id+"&quantity="+quantity);
}

function cart_save(product_id,quantity)
{
	if(product_id && quantity)
		go_to(root+"companii/cart?a=save&product_id="+product_id+"&quantity="+quantity);
}

function cart_delete(product_id,quantity)
{
	if(product_id)
		go_to(root+"companii/cart?a=delete&product_id="+product_id+"&quantity="+quantity);
}

function cart_empty()
{
	go_to(root+"companii/cart?a=empty");
}

function form_check_all(id, elem){
	$j("*:checkbox").each(		
		function(i,el){
			el.checked=elem.checked;
		}
	);	
}

function start_editor(id,baseurl)
{
	oFCKeditor = new FCKeditor( id ) ;
	oFCKeditor.BasePath = baseurl ;
	oFCKeditor.ReplaceTextarea() ;
}


