// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

Effect.Highlightborder = Class.create();
Object.extend(Object.extend(Effect.Highlightborder.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    if(!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {});
    this.start(options);
  },
  setup: function() {
    // Prevent executing on elements not in the layout flow
    if(this.element.getStyle('display')=='none') { this.cancel(); return; }
    if(!this.options.endcolor)
      this.options.endcolor = this.element.getStyle('border-color').parseColor('#ffffff');
    if(!this.options.restorecolor)
      this.options.restorecolor = this.element.getStyle('border-color');
    // init color calculations
    this._base  = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
    this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
  },
  update: function(position) {
    this.element.setStyle({borderColor: $R(0,2).inject('#',function(m,v,i){
      return m+(Math.round(this._base[i]+(this._delta[i]*position)).toColorPart()); }.bind(this)) });
  },
  finish: function() {
    this.element.setStyle(Object.extend(this.oldStyle, {
      borderColor: this.options.restorecolor
    }));
  }
});
function videoChecked() {
	[$$('#infosDVDV input'),$$('#infosDVDV select'),$$('#voDVDV input'),$$('#stDVDV input')].each(
			function() {
			this.Form.Element.enable;
			}
			);  
	Element.setOpacity('voDVDV',1.0); 
	Element.setOpacity('stDVDV',1.0); 
	Element.setOpacity('infosDVDV',1.0);
}
function videoUnChecked() {
	[$$('#infosDVDV input'),$$('#infosDVDV select'),$$('#voDVDV input'),$$('#stDVDV input')].each(
			function() {
			this.Form.Element.disable;
			}
			);  
	Element.setOpacity('voDVDV',0.5); 
	Element.setOpacity('stDVDV',0.5); 
	Element.setOpacity('infosDVDV',0.5);
}

function forSaleUnChecked() {
	[$$('product_allow_sale')].each(function() {this.Form.Element.disable;})
	Element.setOpacity('sale_dt',0.5);
	[$$('product_public_sale_price'), $$('producer_marge_for_sale'), $$('marge_36pulp_for_sale')].each(function() {this.Form.Element.disable;})
	Element.setOpacity('product_public_sale_price', 0.5); 
	Element.setOpacity('marge_36pulp_for_sale', 0.5); 
	Element.setOpacity('producer_marge_for_sale', 0.5)
}
function forSaleChecked(value) {
	if (value == false) {
		forSaleUnChecked();
		return;
	}
	[$$('product_allow_sale')].each(function() {this.Form.Element.enable;})
	Element.setOpacity('sale_dt',1.0);
	[$$('product_public_sale_price'), $$('producer_marge_for_sale'), $$('marge_36pulp_for_sale')].each(function() {this.Form.Element.enable;})
	Element.setOpacity('product_public_sale_price', 1.0); 
	Element.setOpacity('marge_36pulp_for_sale', 1.0); 
	Element.setOpacity('producer_marge_for_sale', 1.0)
}
function forDownloadUnChecked() {
	[$$('product_allow_download')].each(function() {this.Form.Element.disable;})
	Element.setOpacity('download_dt',0.5);
	[$$('product_public_download_price'), $$('producer_marge_for_download'), $$('marge_36pulp_for_download')].each(function() {this.Form.Element.disable;})
	Element.setOpacity('product_public_download_price', 0.5); 
	Element.setOpacity('marge_36pulp_for_download', 0.5); 
	Element.setOpacity('producer_marge_for_download', 0.5)
}
function forDownloadChecked(value) {
	if (value == false) {
		forDownloadUnChecked();
		return;
	}
	[$$('product_allow_download')].each(function() {this.Form.Element.enable;})
	Element.setOpacity('download_dt',1.0);
	[$$('product_public_download_price'), $$('producer_marge_for_download'), $$('marge_36pulp_for_download')].each(function() {this.Form.Element.enable;})
	Element.setOpacity('product_public_download_price', 1.0); 
	Element.setOpacity('marge_36pulp_for_download', 1.0); 
	Element.setOpacity('producer_marge_for_download', 1.0)
}


function checkAll(value) {
  if (value == false) {
    uncheckAll();
    return false;
  }
  var form = document.getElementById('listing'); var sel = form.elements; var l = sel.length;
  for (i = 0; i < l; i++) {  
    if (sel[i].id.substr(0,12) == "listing_row_") {
      sel[i].checked = true; 
    }
  }
}
function uncheckAll() {
  var form = document.getElementById('listing'); var sel = form.elements; var l = sel.length;
  for (i = 0; i < l; i++) {  
    if (sel[i].id.substr(0,12) == "listing_row_") {
      sel[i].checked = false; 
    }
  }
}
function uncheckCheckAll(value) {
  if (value == false) {
    document.getElementById('checkall_checkbox').checked = false;
  } else {
    var form = document.getElementById('listing'); var sel = form.elements; var l = sel.length;
    for (i = 0; i < l; i++) {  
      if (sel[i].id.substr(0,12) == "listing_row_" && sel[i].checked == false) {
        return;
      }
    }
    document.getElementById('checkall_checkbox').checked = true;
  }
}
function checkCGV(form) {
	var checked = document.getElementById('CGV');
  if (checked.checked) {
    return true;
  }
  alert("Vous devez accepter les conditions générales de vente pour continuer.");
  return false;
}

function scrollItem() {
	if($('contenuProduitsListe')) {
		var anchor = $('contenuProduitsListe').getElementsByClassName('courant');
		$('contenuProduitsListe').scrollTop = anchor[0].offsetTop - $('contenuProduitsListe').offsetTop - 140;
	}
}

function modalboxShow(el,tab) {
	Modalbox.show(el.href, {title: el.title, width: 882, height: 457, transitions: false});
	var copyTabs = $('MB_tabs').cloneNode(true);
	$('MB_window').appendChild(copyTabs); 
	copyTabs.setStyle({visibility: 'visible'});
	$(tab).addClassName('current');
	return false;
}
function modalboxUpdate(el) {
	el.blur();
	Modalbox.show(el.href, {title: el.title, width: 882, height: 457, transitions: false});
	var tabsEls = $('MB_tabs').getElementsByClassName('current');
	for(var i=0;i<tabsEls.length;i++) tabsEls[i].removeClassName('current');
	el.addClassName('current');
	return false;
}
/* For cookie */
function EcrireCookie(nom, valeur) {
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	var CookieVal = document.cookie.substring(offset, endstr);
	CookieVal = CookieVal.replace(/\+/g, "%20");
	return unescape(CookieVal);
}
function LireCookie(nom) {
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;

	}
	return null;
}

/* Footer functions */
function MaximizeFooter() {
	Element.hide('footerOn'); Element.show('footerOff'); Element.hide('footerMin'); Element.show('footerMax'); 
	EcrireCookie('footerminimized', 0);
	return false;
}

function MinimizeFooter() {
	Element.hide('footerOff'); Element.show('footerOn'); Element.hide('footerMax'); Element.show('footerMin');
	EcrireCookie('footerminimized', 1);
	return false;
}

function MinimizeFooterIfNeeded() {
	if (LireCookie("footerminimized") == '1') {
		Element.hide('footerOff'); Element.show('footerOn'); Element.hide('footerMax'); Element.show('footerMin');
	}
}
/****/

/** Gestion des adresses */
function copy_billing_address(val, name) {
	var fieldList = new Array('name','city','company_name','street','zipcode','phone_1');
	var tempObj;
	for (count=0;count<fieldList.length;count++) {
		if (val.checked) {
			command = "old_facturation_A_"+ fieldList[count] +" = $('address_facturation_A_" + fieldList[count] +"').value;";
			eval(command);
			command = "$('address_facturation_A_"+ fieldList[count] +"').value = $('"+ name +"_"+ fieldList[count] +"').value;";
			eval(command);
		} else {
			command = "$('address_facturation_A_" + fieldList[count] +"').value = old_facturation_A_"+ fieldList[count] +";";
			eval(command);
		}
	}
}
