function $y(element){
	return new YAHOO.util.Element(element);
}
function $e(element){
	if (typeof element == 'string')
	    element=document.getElementById(element);
	return element;
}

function $f(name){
	return document.forms[name];
}
function ee(){
	return;
}
function show(id){
	var arr=[];
	if (arguments.length > 1) {
		for (var i = 0; i < arguments.length; i++)
			arr.push(arguments[i]);
  	}else
		arr[0]=id;
	for(var e=0;e<arr.length;e++)
		$e(arr[e]).style.display='';
}
function hide(id){
	var arr=[];
	if (arguments.length > 1) {
		for (var i = 0; i < arguments.length; i++)
			arr.push(arguments[i]);
  	}else
		arr[0]=id;
	for(var e=0;e<arr.length;e++)
		$e(arr[e]).style.display='none';
}
function setStyle(el,styleName,value){
	$e(el).style[styleName]=value;
}
//
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
String.prototype.padRight = function(tL,fC) {
	var str=this;
	while(str.length < tL)
		str=str.concat(fC);
	return str;
}
String.prototype.padLeft = function(tL,fC) {
	var str=this;
	while(str.length < tL)
		str=fC.concat(str);
	return str;
}
String.prototype.stripTags=function(){
	if(typeof this=='string')
		return this.replace(/(<([^>]+)>)/ig,"");
	else return '';
}
Array.prototype.inArray=function(str){
	for(var i in this){
		if(this[i]==str)
			return true;
	}
	return false;
}
function insertImage(tag,src,alt){
	var el=document.createElement('img');
	el.setAttribute('src',src);
	el.setAttribute('alt',alt);
	$e(tag).innerHTML='';
	$e(tag).appendChild(el);
}
function checkAll(el,ma){
	if(typeof el=='string') el=$e(el);
	var e=el.getElementsByTagName('input');
	for(var i=0;i<e.length;i++)
		if(e[i].type=='checkbox')
			e[i].checked=(ma==undefined)?true:(e[i].name.indexOf(ma)==0?true:e[i].checked);
}
function uncheckAll(el,ma){
	if(typeof el=='string') el=$e(el);
	var e=el.getElementsByTagName('input');
	for(var i=0;i<e.length;i++)
		if(e[i].type=='checkbox')
			e[i].checked=(ma==undefined)?false:(e[i].name.indexOf(ma)==0?false:e[i].checked);
}

function checkOne(el,xi){
  	if(typeof el=='string') el=$e(el);
  	var e=el.getElementsByTagName('input');
  	var chbx = new Array();
  	var j=1;
  	for(var i=0;i<e.length;i++){
  		if(e[i].type=='checkbox')
  			{chbx[j]=e[i];j++;}
	}
	chbx[xi].checked=true;
}	
//
function evalResponse(o){
	if(o){
		return eval("("+o.responseText+")");
	}else{
		return 'empty';
	}
}
function logout(){
	var frm=$f('logout_frm');
	frm.submit();
}
function removeElement(id){
	var el=$e(id);
	var pa=el.parentNode;
	pa.removeChild(el);
}
function disableElements(f,aE){
	if(typeof f=='string')
		f=document.forms[f];
	for(i in aE){
		if(typeof f[aE[i]]!='object') continue;
		f[aE[i]].disabled=true;
	}
}
function enableElements(f,aE){
	if(typeof f=='string')
		f=document.forms[f];
	for(i in aE){
		if(typeof f[aE[i]]!='object') continue;
		f[aE[i]].disabled=false;
	}
}
function logout(){
	var callback={
		success:function(o){
			pvalert('ati fost deconectat de la contul dumneavoastra','info');
			//setTimeout("location.href=Site_URL+'/login.htm'",3000);
			setTimeout("window.location.reload();",500);

		}
	};
	var yuc=YAHOO.util.Connect;
	yuc.asyncRequest('POST',Site_URL+'/login.htm',callback,'action=logout');
}
function loadPanel(hd, bd, w){
	var W=YAHOO.util.Dom.getViewportWidth();
	var WMic=(w!=undefined?w:700);
	Panel = new YAHOO.widget.Panel("popup_panel", {
					width:WMic+'px',
					fixedcenter: false,
					y:75,
					x:(W-WMic)/2,
					visible: false,
					constraintoviewport:true,
					draggable:true
			} );
	Panel.render();
	Panel.setHeader(hd);
	Panel.setBody(bd);
	Panel.show();
}
function closePanel(){
	Panel.setHeader('');
	Panel.setBody('');
	Panel.hide();
}
function updateCart(produse,total){
	if(produse==0){
		/*show('cart-empty');$/
		/*hide('cart-fill');*/
		$e('cart-produse').innerHTML=produse+' produse';
		$e('cart-pret').innerHTML=total+' Lei';
		
	}else{
		/*hide('cart-empty');*/
		$e('cart-produse').innerHTML=produse+(produse>1?' produse':' produs');
		$e('cart-pret').innerHTML=total+' Lei';
		/*show('cart-fill');*/
	}
}
function getSProducatori(){
	var frm=$f('search_site_frm');
	var callback={
		success:function(o){
			var obj=evalResponse(o);
			SelectUtil.clear(frm.producator_id);
			SelectUtil.addSorted(frm.producator_id,'-- producator --','0');
			for(var i in obj){
				SelectUtil.addSorted(frm.producator_id,obj[i],i);
			}
			frm.producator_id.options[0].className='info';
		}
	};
	var yuc=YAHOO.util.Connect;
	yuc.asyncRequest('POST',Site_URL+'/index.htm',callback,'action=producatori&grupa='+frm.grupa_id.value);
}
function cautare(){
	var frm=$f('search_site_frm');
	var url=Site_URL+'/'+frm.grupa_id.value+'/'+frm.producator_id.value+'/0/'+(frm.chei.value.length>0?encodeURIComponent(frm.chei.value).replace(/%2F/gi,"***"):0)+'/cautare.htm';
	//alert(url);
	location.href=url;
}
function pvalert(text,theme,container,gotop){
	var a=new PAlert;
	a.setContainer((container!=undefined?container:'palert'));
	a.setImagesDir(Site_URL+'/images/');
	a.setGoTop(gotop==undefined?true:gotop);
	a.show(text,theme);
}
function checkAll(el,ma){
	if(typeof el=='string') el=$e(el);
	var e=el.getElementsByTagName('input');
	for(var i=0;i<e.length;i++)
		if(e[i].type=='checkbox')
			e[i].checked=(ma==undefined)?true:(e[i].name.indexOf(ma)==0?true:e[i].checked);
		//if(e[i].type=='radio')
			//e[i].checked=(ma==undefined)?true:(e[i].value.indexOf(ma)==0?true:e[i].checked);
}
function uncheckAll(el,ma){
	if(typeof el=='string') el=$e(el);
	var e=el.getElementsByTagName('input');
	for(var i=0;i<e.length;i++)
		if(e[i].type=='checkbox')
			e[i].checked=(ma==undefined)?false:(e[i].name.indexOf(ma)==0?false:e[i].checked);
			//if(e[i].type=='radio')
			//e[i].checked=(ma==undefined)?false:(e[i].value.indexOf(ma)==0?false:e[i].checked);
}
function printPage(Url){
	var printed=window.open(Url,"_blank","channelmode=yes,directories=no,left=50,top=50,location=no,menubar=no,resizable=no,status=yes,toolbar=no,width=670,height=600,scrollbars=yes");
	printed.focus();
}
// INIT

function CatShowMore(id)
{
	var mel = document.getElementById('categ_c_'+id+'_more');
	if(!mel) return;
	mel.parentNode.removeChild(mel);
	var el = document.getElementById('categ_c_'+id);
	for(var i=0;i<el.childNodes.length;i++)
	{
		if(el.childNodes[i].nodeName=='DIV' && el.childNodes[i].style.display=='none') el.childNodes[i].style.display='';
	}
}

function CatToggle(id)
{
	if(document.getElementById('categ_c_'+id+'_more')){
		CatShowMore(id);
		return;
	}
	var el = document.getElementById('categ_'+id);
	if(!el) return;
	if(el.className=='categorie'){
		el.className='categorie_collapsed';
	}else{
		el.className='categorie';
	}
	
}
