function	autoUrl(name, dest)
{
	var loc;
	var id_list;

	id_list = document.getElementById(name);
	loc = id_list.options[id_list.selectedIndex].value;
	if (loc != 0)
		location.href = dest+loc;
	return ;
}

function	autoUrlNoList(name, dest)
{
	var loc;

	loc = document.getElementById(name).checked;
	location.href = dest + (loc == true ? 1 : 0);
	return ;
}


function GetWidth()
{
        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;
}


/*
** show or hide element e depending on condition show
*/
function toggle(e, show)
{
	e.style.display = show ? '' : 'none';
}

function toggleMultiple(tab)
{
    var len = tab.length;

    for (var i = 0; i < len; i++)
        if (tab[i].style)
            toggle(tab[i], tab[i].style.display == 'none');
}

/**
* Show dynamicaly an element by changing the sytle "display" property
* depending on the option selected in a select.
*
* @param string $select_id id of the select who controls the display
* @param string $elem_id prefix id of the elements controlled by the select
*   the real id must be : 'elem_id'+nb with nb the corresponding number in the
*   select (starting with 0).
*/
function showElemFromSelect(select_id, elem_id)
{
	var select = document.getElementById(select_id);
	for (var i = 0; i < select.length; ++i)
	{
	    var elem = document.getElementById(elem_id + select.options[i].value);
		if (elem != null)
			toggle(elem, i == select.selectedIndex);
	}
}

/**
* Get all div with specified name and for each one (by id), toggle their visibility
*/
function openCloseAllDiv(name, option)
{
	var tab = $('*[name='+name+']');
	for (var i = 0; i < tab.length; ++i)
		toggle(tab[i], option);
}

/**
* Toggle the value of the element id_button between text1 and text2
*/
function toggleElemValue(id_button, text1, text2)
{
	var obj = document.getElementById(id_button);
	if (obj)
		obj.value = ((!obj.value || obj.value == text2) ? text1 : text2);
}

function addBookmark(url, title)
{
	if (window.sidebar)
		return window.sidebar.addPanel(title, url, "");
	else if ( window.external )
		return window.external.AddFavorite( url, title);
	else if (window.opera && window.print)
		return true;
	return true;
}

function writeBookmarkLink(url, title, text, img)
{
	var insert = '';
	if (img)
		insert = writeBookmarkLinkObject(url, title, '<img src="' + img + '" alt="' + escape(text) + '" title="' + escape(text) + '" />') + '&nbsp';
	insert += writeBookmarkLinkObject(url, title, text);
	document.write(insert);
}

function writeBookmarkLinkObject(url, title, insert)
{
	if (window.sidebar || window.external)
		return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');
	else if (window.opera && window.print)
		return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');
	return ('');
}

function checkCustomizations()
{
	for (var i = 0; i < customizationFields.length; i++)
		/* If the field is required and empty then we abort */
		if (parseInt(customizationFields[i][1]) == 1 && $('#' + customizationFields[i][0]).val() == '')
			return false;
	return true;
}

//On over sur la liste de produits
function productListOn(id)
{
	if( $("#survolVisuelProduit"+id).length > 0) document.getElementById("survolVisuelProduit"+id).className  = "survolVisuelProduitVisible";
	if( $("#productListText"+id).length > 0) document.getElementById("productListText"+id).className  = "survolTextProduitOn";
	if( $("#imageListeProduit"+id).length > 0) document.getElementById("imageListeProduit"+id).style.borderBottom  = "none";
	if( $("#divProduitIndisponible"+id).length > 0) document.getElementById("divProduitIndisponible"+id).style.display  = "none";
}

function productListOff(id)
{
	if( $("#survolVisuelProduit"+id).length > 0) document.getElementById("survolVisuelProduit"+id).className  = "survolVisuelProduitInvisible";
	if( $("#productListText"+id).length > 0) document.getElementById("productListText"+id).className  = "survolTextProduitOff";
	if( $("#imageListeProduit"+id).length > 0) document.getElementById("imageListeProduit"+id).style.borderBottom  = "1px solid #CCCCCC";
	if( $("#divProduitIndisponible"+id).length > 0) document.getElementById("divProduitIndisponible"+id).style.display  = "block";
}

//================================== Fonction MM
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// ================================== Fonction MM

// ================================== ROLL BOUTON OK RECHERCHE
function btnOkOn(element)
{
	element.style.backgroundPosition = "0 -29px";
}

function btnOkOff(element)
{
	element.style.backgroundPosition = "0 0";
}
// ================================== ROLL BOUTON OK RECHERCHE

//CUSTOM FORM ELEMENTS
var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "68";

document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
				document.onmouseup = Custom.clear;
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.choose;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
		
		
		
		if(this.id == "mon_selec_taille_configuratuer"){
			$('#form_taille_listing').submit();
		}
		
		
		if(typeof(changeTaille5939)=='function') {
			changeTaille5939(this.value);
		}
		if(typeof(findCombination)=='function') {
			findCombination();
		}
	}
}
window.onload = Custom.init;


// =================  Survol bouton top du footer  ============

function survolOnGoToTop(){
	document.getElementById("GoToTopLeft").style.backgroundPosition  = "0 -29px";
	document.getElementById("GoToTop").style.backgroundPosition  = "0 -29px";
	document.getElementById("GoToTopRight").style.backgroundPosition  = "0 -29px";
}

function survolOffGoToTop(){
	document.getElementById("GoToTopLeft").style.backgroundPosition  = "0 0";
	document.getElementById("GoToTop").style.backgroundPosition  = "0 0";
	document.getElementById("GoToTopRight").style.backgroundPosition  = "0 0";
}

// =================  Survol bouton top du footer  ============




//=================  Changement de theme Corner  ============

function changeTheme(theme){
	//alert('nouveau theme:'+theme);
	document.getElementById('center_column').style.width='950px';
	if($('#pb-left-column').length > 0) document.getElementById('pb-left-column').style.marginRight='10px';
	if($('#pb-left-column').length > 0) document.getElementById('pb-left-column').style.styleFloat='right';
	if(theme == 'Kask' || theme == 'Urbanears'){
		url = document.getElementById('bigpic').src;
		ref = url.split('/');
		ref = ref[ref.length - 1].split('.');
		//alert(ref[0]);
		document.body.className  = theme+ref[0];
		document.getElementById('page').className = theme+ref[0];
		if(theme == 'Urbanears'){
			window_width = GetWidth();
			if(window_width > 950){
				left_margin = (window_width - 950)/2;
			}else{
				left_margin = 0;
			}
			
			document.getElementById('image-URBANEARS-leftimg').src = '/themes/headict/img/bg-urbanears/bg-URBANEARS-G-'+ref[0]+'.jpg';
			document.getElementById('image-URBANEARS-left').style.display = 'block';
			document.getElementById('image-URBANEARS-left').style.left = '-'+left_margin+'px';
			
			document.getElementById('image-URBANEARS-rightimg').src = '/themes/headict/img/bg-urbanears/bg-URBANEARS-D-'+ref[0]+'.jpg';
			document.getElementById('image-URBANEARS-right').style.display = 'block';
			
			//left_margin = Math.abs(left_margin - image_width);
			document.getElementById('image-URBANEARS-right').style.right = '-'+left_margin+'px';
			
			//image_width = document.getElementById('image-URBANEARS-right').offsetWidth;
			
		}
	}else{
		document.body.className  = theme;
		if($('#primary_block').length > 0) document.getElementById('primary_block').className = theme;
		document.getElementById('page').className = theme;
	}
}

//=================  Changement de theme Corner  ============


//=================  Verification des images produits  ============
function getImg(imgSrc)
{
	var newImg = new Image();
	newImg.src = imgSrc;
	if(newImg.height != 0){
		return true;
	}
	return false;
}


//=================  Verification des images produits  ============


//=================  Affichage image details du corner  ============

function displayImageDetailCorner(element,src){
	element.style.border = "1px solid #CCCCCC";
	element.style.cursor = "pointer";
	
	document.getElementById("bigDetail").src = src;
	document.getElementById("bigDetail").title = element.title;
	document.getElementById("bigDetail").alt = element.title;
	document.getElementById("detailCorner").className = 'visible';
}

function hideImageDetailCorner(element){
	element.style.border = "1px solid transparent";
	element.style.cursor = "pointer";
	
	document.getElementById("detailCorner").className = 'invisible';
}

//=================  Affichage image details du corner  ============

//=================  Affichage Slide Show Image corner sur la HOME  ============

function slideshowNext(currentSlide,nbSlide){
	if(currentSlide<nbSlide){
		nextSlide = currentSlide +1;
		document.getElementById('slide-'+currentSlide).className = 'hidden';
		document.getElementById('marque-'+currentSlide).className = 'hidden';
		document.getElementById('slide-'+nextSlide).className = 'visible';
		document.getElementById('marque-'+nextSlide).className = 'visible';
		return nextSlide;
	}else{
		return currentSlide;
	}
}

function slideshowPrevious(currentSlide,nbSlide){
	if(currentSlide>1){
		nextSlide = currentSlide -1;
		document.getElementById('slide-'+currentSlide).className = 'hidden';
		document.getElementById('marque-'+currentSlide).className = 'hidden';
		document.getElementById('slide-'+nextSlide).className = 'visible';
		document.getElementById('marque-'+nextSlide).className = 'visible';
		return nextSlide;
	}else{
		return currentSlide;
	}
}

//=================  Affichage Slide Show Image corner sur la HOME ============




/* ---------------------- Change la hauteur du Flash ---------------------------- */
function getHeightNavFlash(heightFlash){
	if( $('#ad_flash').length > 0 ){
		$('#ad_flash').attr('height', heightFlash);
	}
}



/* ----------------------------------------------------------------------------- */


