﻿var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

//Fix the partial transparency with PNG24 on IE
function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
     var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='image');\"></span>"
	   myImage.outerHTML = strNewHTML
    }
}

//Return the main Form name
function GetMainFormName()
{
	var i;
	for (i=0;i<document.forms.length;i++)
	{
		// Framework v1.0.3705
		if (document.forms[i].name.indexOf("_ServerForm") != -1)
			return document.forms[i].name;
		// Framework v1.1.4322
		if (document.forms[i].name.indexOf("__aspnetForm") != -1)
			return document.forms[i].name;
		// Framework v2
		if (document.forms[i].name.indexOf("aspnetForm") != -1)
			return document.forms[i].name;
	}
	return null;
}

//Return the reel ID of a control
function GetUniqueID(id)
{
	var mf = GetMainFormName();
	if (id==null || id=="") return null;
	id = id.toLowerCase();
	var i;
	for (i=0;i<document.forms[mf].elements.length;i++)
	{
		if (document.forms[mf].elements[i].id.toLowerCase().lastIndexOf(id) != -1)
		{
			var strform = document.forms[mf].elements[i].id.toLowerCase();
			var strformname = strform.substr(strform.lastIndexOf(id));
			if (strformname == id)
				return document.forms[mf].elements[i].id;
		}	
	}
	return id;
}

//Return the reel IDs of controls
function GetUniqueIDs(id)
{
  var IDs = new Array();
	var mf = GetMainFormName();
	if (id==null || id=="") return null;
	id = id.toLowerCase();
	var i;
	for (i=0;i<document.forms[mf].elements.length;i++)
	{
		if(document.forms[mf].elements[i].id.toLowerCase().lastIndexOf(id) != -1)
		{
			var strform = document.forms[mf].elements[i].id.toLowerCase();
			var strformname = strform.substr(strform.lastIndexOf(id));
			if (strformname == id)
				IDs.push(document.forms[mf].elements[i].id);
		}
	}
	return IDs;
}

//Return the element by reel ID
function GetElementUniqueID(id)
{
	return document.getElementById(GetUniqueID(id));
}

//Return child element with reel ID which are in an element
function GetElementUniqueIDInChild(id,element)
{
  id = id.toLowerCase();
  for(var i=0;i<element.childNodes.length;i++)
  {
    var child = element.childNodes[i];
    if(child.nodeType==1)
    {
      var childID = child.id.toLowerCase();
	    childID = childID.substr(childID.lastIndexOf(id));
	    if(childID == id)
	      return element.childNodes[i];
	  }
	  var el = GetElementUniqueIDInChild(id,child);
	  if(el) return el;
  }
  return null;
}


//Return child element with reel ID which are in an element, the reel ID only have to contain the id, ca end by others characters
function GetElementUniqueIDInChild2(id,element)
{
  id = id.toLowerCase();
  for(var i=0;i<element.childNodes.length;i++)
  {
    var child = element.childNodes[i];
    if(child.nodeType==1)
    {
      var childID = child.id.toLowerCase();
	    if ((childID.substr(childID.lastIndexOf(id)) != -1)&&(childID.length>40))
	      return element.childNodes[i];
	  }
	  var el = GetElementUniqueIDInChild2(id,child);
	  if(el) return el;
  }
  return null;
}


//Search service
function Search(visual,sitename)
{
  var search = $get('InputSearch');
  GoTo(sitename + '/_fr/_fr/'+visual+'/catalog/searchresults.aspx?search='+search.value);
}

//Put into an array the url parameters
function PrmUrl()
{
 var prm = new Array();
 var tmp = unescape(window.location.search).substr(1).split("&");
 var inter;
 for ( i=0; i<tmp.length; i++)
 {
  inter=tmp[i].indexOf("=");
  if ( inter>=0 )
    {
     prm[tmp[i].substr(0,inter)]=tmp[i].substr(inter+1)
    }
  else {
     prm[tmp[i]]="";
    }
 }
 return prm;
}

//Validate forms with the enter touch
function ValidWithEnter(form) {
if ((event.which && event.which == 13)||(event.keyCode && event.keyCode == 13)) {
form.submit();
}
}

//Check if a chain contains special characters
function CheckAlphanumeric(textToCheck){
    regex=new RegExp('^[_a-z0-9]+$', 'gi'); 
    return (textToCheck.match(regex)!=textToCheck)
}

/**********************************
 *            AJAX                *
 **********************************/

//Return the reel ID of an AJAX object
function GetObjectUniqueID(id)
{
  /// <param name="id" type="String"></param>
  /// <returns type="Sys.Component" mayBeNull="true"></returns>
  var e = Function._validateParams(arguments, [{name: "id", type: String}]);
  if (e) throw e;
  if (id==null || id=="") return null;
  id = id.toLowerCase();
  for (i=0;i<Sys.Application._disposableObjects.length;i++)
  {
    var objectID = Sys.Application._disposableObjects[i]._id;
		if (objectID && objectID.toLowerCase().lastIndexOf(id) != -1)
		{
			var strObject = objectID.toLowerCase();
			var strObjectName = strObject.substr(strObject.lastIndexOf(id));
			if (strObjectName == id)
				return Sys.Application._disposableObjects[i]._id;
		}
		objectID = Sys.Application._disposableObjects[i]._element;
		if(objectID != null && objectID != 'undefined')
		{
		  objectID = objectID.id;
		  if (objectID && objectID.toLowerCase().lastIndexOf(id) != -1)
		  {
			  var strObject = objectID.toLowerCase();
			  var strObjectName = strObject.substr(strObject.lastIndexOf(id));
			  if (strObjectName == id)
				  return Sys.Application._disposableObjects[i]._element.id;
		  }
		}
  }
  return null;
}

//Return the AJAX object
function GetObject(id)
{
  id = GetObjectUniqueID(id);
  if(id == null) return null;
  return $find(id);
}

//Show a ModalPopup by ID
function ShowModalPopup(id)
{
  var modal = GetObject(id);
  if (modal)
  {
    modal.show();
  }
}

//Hide a ModalPopup by ID
function HideModalPopup(id)
{
  var modal = GetObject(id);
  if (modal)
  {
    modal.hide();
  }
}

//Show an HoverMenu by ID
function ShowHoverMenu(id)
{
  var hover = GetObject(id);
  if (hover)
  {
    hover._onHover();
  }
}

//Get the post back element id
var postBackElementID = null;
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(GetPostBackElementID);
function GetPostBackElementID(sender, args)
{
  postBackElementID = args.get_postBackElement().id;
  postBackElementID = postBackElementID.toLowerCase();
}

//If the id is the same that the postback element return true.
function IsPostBackElement(id)
{
  if(postBackElementID)
  {
    id = id.toLowerCase();
	  var pbElem = postBackElementID.substr(postBackElementID.lastIndexOf(id));
	  return (pbElem == id);
	}
	return false;
}

//IsPostBack
function IsPostBack()
{
  return (postBackElementID != null);
}


//Refresh an update panel with an hiddenfield
function RefreshUpdatePanel(hiddenFieldID)
{
  hiddenFieldID = GetUniqueID(hiddenFieldID);
  var hiddenField = $get(hiddenFieldID);
  if (hiddenField)
  {
    __doPostBack(hiddenFieldID,'');
  }
}

//Show the first rows of the table
function ShowFirstRows(id)
{
  var table = $get(id);
  if(table == null) return;
  for(var i=0;i<table.rows.length-1&&i<5;i++)
  {
    table.rows[i].style.display='block';
  }
  if(table.rows.length>6)
    table.rows[table.rows.length-1].style.display='block';
}

//Show/Hide the rows of the table
function ToggleRows(visual,css,id)
{
  var table = $get(id);
  var img = $get(id+'_img');
  var back = $get(id+'_back');
  var hide = $get(id+'_hide');
  var more_or_close_input = $get(id+'_more_or_close_input');
  var more = $get(id+'_more');
  var close = $get(id+'_close');
  if(back && hide)
  { 
    if(back.style.position != 'absolute')
    {
      hide.style.width = back.offsetWidth+'px';
      hide.style.height = back.offsetHeight+'px';
      back.style.width = back.offsetWidth+'px';
      back.style.position = 'absolute';
      if(visual.toLowerCase() == 'men')
      {
        back.style.backgroundColor = '#f2f2f2';
      }
      else
      {
        back.style.backgroundColor = '#e1f0fb';
      }
      table.className='browse_open';
      hide.style.display = 'block';
    }
    else
    {
      table.className='browse_' + css;
      back.style.backgroundColor = '';
      hide.style.display = 'none';
      back.style.position = '';
    }
  }
  if(table)
  {
    for(var i=5;i<table.rows.length-1;i++)
    {
      if(table.rows[i].style.display=='none')
        table.rows[i].style.display='block';
      else
        table.rows[i].style.display='none';
    }
  }
  if(img)
  {
    if(img.src.lastIndexOf('roundplus.gif')>0)
      img.src='/img/_ww/_ww/' + visual + '/catalog/roundminus.gif';
    else
      img.src='/img/_ww/_ww/' + visual + '/catalog/roundplus.gif';
  }
  if(more_or_close_input.value=='more')
  {
    more_or_close_input.value='close';
    more.style.display='none';
    close.style.display='inline';
  }
  else
  {
    more_or_close_input.value='more';
    more.style.display='inline';
    close.style.display='none';
  }
}

//Set the text of the element
function SetInputText(element,text)
{
  if(element.value == '')
    element.value = text;
}

function ShowPassword(element)
{
  var pass = GetElementUniqueIDInChild('Password',element.parentNode);
  if(pass)
  {
    element.style.display = 'none';
    pass.style.display = 'block';
    pass.focus();
  }
}

function HidePassword(element)
{
  var pass = $get('PasswordFake',element.parentNode);
  if(pass && element.value == '')
  {
    pass.style.display = 'block';
    element.style.display = 'none';
  }
}

//Set the current page
function SetPage(page)
{
  var element = $get('page');
  if (element)
  {
    element.value = page;
  }
}

//Set the current page
function GoPage(page)
{
  SetPage(page);
  RefreshUpdatePanel('RefreshList');
}

//Go To the URL
function GoTo(url)
{
  window.location.href=url;
}

//Open a popup
function OpenPopup(src,name,width,height,scrollbars)
{
  var newWin = window.open(src,name,'width='+width+',height='+height+',resizable=0,toolbar=0,scrollbars='+scrollbars+',status=0,menubar=0');
}

//To upper a string for coremetrics
function ToUpperCM(input)
{
  if(input)
  {
	  input = input.replace(/([àáâãäåāăæ])/, 'a');
	  input = input.replace(/([çćĉċ])/, 'c');
	  input = input.replace(/([èéêë])/, 'e');
	  input = input.replace(/([ìíîï])/, 'i');
	  input = input.replace(/([ñ])/, 'n');
	  input = input.replace(/([òóôõö])/, 'o');
	  input = input.replace(/([ùúûü])/, 'u');
	  input = input.replace(/([ýÿ])/, 'y');
    input = input.toUpperCase();
  }
  return input;
}

function Variant(value)
{
	this.varcode='';
	this.varprice='';
	this.prdcode='';
	this.bi_rupture='';
	this.bi_stopped='';
	var array = value.split("#");
	if(array.length == 5)
	{
		this.varcode=array[0];
		this.varprice=array[1];
		this.prdcode=array[2];
		this.bi_rupture=array[3];
		this.bi_stopped=array[4];
	}
	this.SetPrice = SetPrice;
	this.CheckBIStopped = CheckBIStopped;
	this.CheckBIRupture = CheckBIRupture;
	this.SetProductCode = SetProductCode;
	this.SetVariantCode = SetVariantCode;
	this.SetVariantCodeBag = SetVariantCodeBag;
	this.SetQuantity = SetQuantity;
	this.CheckZeroPrice = CheckZeroPrice;
}

function SetPrice()
{
	var priceElement = $get('VarPrice_'+this.prdcode);
	if(priceElement)
	{
		priceElement.innerHTML = this.varprice;
	}
}

function CheckZeroPrice()
{
	var visibility = true;
	var price = this.varprice.replace(' ','');
	var index = price.lastIndexOf(',');
	if(index <= 0)
	{
    visibility = false;
  }
  else
  {
    price = price.substring(0,index);
    if(price=='0')
    {
      visibility = false;
    }
  }
	var addToBagElement = $get('AddToBag_'+this.prdcode);
	if(addToBagElement && !visibility)
	{
    addToBagElement.style.visibility = 'hidden';
	}
}

function CheckBIStopped()
{
	var addToBagElement = $get('AddToBag_'+this.prdcode);
	if(addToBagElement)
	{
		if(this.bi_stopped=='1')
		{
			addToBagElement.style.visibility = 'hidden';
		}
		else
		{
			addToBagElement.style.visibility = '';
		}
	}
}

function CheckBIRupture()
{
  this.SetProductCode();
	this.SetVariantCode();
	if(this.bi_rupture=='1')
	{
		RefreshUpdatePanel('RefreshQuickDetailsNoStock');
		RefreshUpdatePanel('RefreshComparatorNoStock');
		RefreshUpdatePanel('RefreshProductNoStock');
		RefreshUpdatePanel('RefreshShopStep1NoStock');
		return;
	}
	this.SetVariantCodeBag();
	this.SetQuantity();
	RefreshUpdatePanel('SubmitPurchase');
}

function SetProductCode()
{
	var hiddenProductCode = $get('hiddenProductCode');
	if(hiddenProductCode)
	{
		hiddenProductCode.value = this.prdcode;
	}
}

function SetVariantCode()
{
	var hiddenVariantCode = $get('hiddenVariantCode');
	if(hiddenVariantCode)
	{
		hiddenVariantCode.value = this.varcode;
	}
}

function SetVariantCodeBag()
{
	var hiddenVariantCodeBag = $get('hiddenVariantCodeBag');
	if(hiddenVariantCodeBag)
	{
		hiddenVariantCodeBag.value = this.varcode;
	}
}

function SetQuantity()
{
	var quantity = $get('QtyList_'+this.prdcode);
	var hiddenQuantity = $get('hiddenQuantity');
	if(hiddenQuantity)
	{
		if(quantity)
		{
			hiddenQuantity.value = quantity.options[quantity.selectedIndex].value;
		}
		else
		{
			hiddenQuantity.value = '1';
		}
	}
}

function SelectVar(value)
{
  var variant = new Variant(value);
  variant.SetPrice();
  variant.CheckBIStopped();
  variant.CheckZeroPrice();
}

function SetVar(prdcode,varname)
{
  var select = $get('VarList_'+prdcode);
  if(select)
  {
    for(var i=0;i<select.length;i++)
    {
      if(select[i].text==varname)
      {
        select.selectedIndex=i;
        SelectVar(select.options[i].value);
        return;
      }
    }
  }
}

function InitVar()
{
  var IDs = document.getElementsByTagName("select");
  for(var i=0;i<IDs.length;i++)
  {
		var select = IDs[i];
		if(select.id != null && select.id.indexOf('VarList_') == 0)
		{
			SelectVar(select.options[select.selectedIndex].value);
    }
  }
}

function AddToBagVar(element)
{
  while(element.id.indexOf('Container_') != 0)
  {
    element = element.parentNode;
  }
  var prdcode = element.id.substr(10);
  var varlist = $get('VarList_'+prdcode);
  var variant = new Variant(varlist.options[varlist.selectedIndex].value);
  variant.CheckBIRupture();
  return false;
}

function AddVar2Favorites(element)
{
  while(element.id.indexOf('Container_') != 0)
  {
    element = element.parentNode;
  }
  var prdcode = element.id.substr(10);
  var varlist = $get('VarList_'+prdcode);
  var variant = new Variant(varlist.options[varlist.selectedIndex].value);
  variant.SetProductCode();
  variant.SetVariantCode();
  return true;
}

function newsletter(sexe){
	window.location.href = "/_fr/_fr/"+sexe+"/club/register_newsletter.aspx?valeur_email="+document.getElementById("newsletter_email_01").value;
}