Effect.FadeOut = function(element) {
 element = $(element);
 new Effect.Fade(element, arguments[1] || {});
}

function AddToCart(event,ProductId,num,msg,option) {
	//$('cart_summary').innerHTML = "<img src=\"image/ajax-loader.gif\" alt=\"Kérem várjon\" />";
  if(option == undefined) {
    option = 0;
  }
  else {
    option = parseInt(option);
    if(option < 1) {
      alert('Va rugam selectati o optiune din lista');
      return false;
    }
  }
	new Ajax.Updater('cart_summary', '/index.php?module=AjaxAddCart&pid='+ProductId+'&num='+num+'&option='+option+'&mod=ajax', {
  //new Ajax.Updater('cart_summary', '/Ajax/AddCart/?pid='+ProductId+'&num='+num+'&option='+option+'&mod=ajax', {
  		//parameters: { text: $F('text') }
	});
	//Effect.FadeOut('head','appear');
	
	var my_div = document.createElement('div');
	$(my_div).addClassName('addedcart');
    $(my_div).innerHTML = msg;
    pos = $(Event.element(event)).positionedOffset();

    $(my_div).style.top = pos[1]+16+'px';
    $(my_div).style.left = pos[0]+'px';
    document.body.appendChild(my_div);
    setTimeout(function() {Effect.FadeOut(my_div);},1500);    
    return false;
}

function ShippingClick(chkbox) {
	if(chkbox.checked) $('shipping_fields').hide();
	else $('shipping_fields').show();
}

function numericTest(e){
    var key = e.keyCode? e.keyCode : e.charCode
    if((key > 47 && key < 58) || key == 8 || key == 37 || key == 39 || key == 13 || key == 46) {
        return true;
    }
    else return false;
}

function toggleCategory(cat_id) {
    elems = $('sidebar_left').getElementsByClassName('sub_'+cat_id);
    for(i=0;i<elems.length;i++) {
        $(elems[i]).toggle();
    }
    
    if($(elems[0]).style.display == 'none') {
        createCookie('closepand'+cat_id,'true',20);    
    }
    else {
        eraseCookie('closepand'+cat_id);
    }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function showCont(cid) {
  //LightBB.initialize();
  LightBB.startText('/ecig/index.php?module=Content&id='+cid+'&mod=ajax');
}

function imgOver(img) {
  var src = img.src;
  myRe = new RegExp ("(.+).jpg", "g");
  myArray = myRe.exec(src);
  img.src = myArray[1]+"_ac.jpg";
}

function imgOut(img) {
  var src = img.src;
  myRe = new RegExp ("(.+)_ac.jpg", "g");
  myArray = myRe.exec(src);
  img.src = myArray[1]+".jpg";
}
