// Global script
var ad_cap = false;
// Retrieve element by id (croos-browser function)
function $E(id){if (typeof id == 'string'){var d=document; if (d.getElementById){return d.getElementById(id);}else if (d.all){return d.all[id];}else if (d.layers){return d.layers[id];}}return null;}
// Add parameter to embed object
function ad_params(c,p) {var res="",a=arguments;for (var i = 1; i < a.length; i++) {if (c=='object') {res += '<param name='+a[i][0]+' value="'+a[i][1]+'">';} else if (c=='embed') {res += a[i][0]+'="'+a[i][1]+'"';if (i < (a.length-1)) {res += ' ';}} else {return;}}return [c,res];}
// Add object in page like swf etc.
function ad_embedObj(t,pos,did,w,h,q) {var o="";switch (t) {case "swf":var clsid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';break;default:return;}var oid=t+pos;if (q[0]=='object') {o='<object classid="'+clsid+'" id="'+oid+'" width="'+w+'" height="'+h+'">'+q[1]+'</object>';} else if (q[0]=='embed') {o='<embed name="'+oid+'" '+q[1]+'></embed>';} else {return;}if (did!=='') {var d = $E(did);d.innerHTML=o;} else {document.write(o);}}ad_jsl=1;

function ShowDIV(oItem){
	var e = document.getElementById(oItem);
	if (e) {
		e.style.display = 'block';
	}
}

function HideDIV(oItem){
	var e = document.getElementById(oItem);
	if (e) {
		e.style.display = 'none';
	}
}

function AutoDIV(oItems, Largeur, Hauteur){
    if ((document.getElementById(oItems).style.display == "") || (document.getElementById(oItems).style.display == "none")) {
         document.getElementById(oItems).style.display = "block";
    }     else {
         document.getElementById(oItems).style.display = "none";
    }
}

function PopUpZoom(url, Largeur, Hauteur) {
		PopUpZoom = window.open(url,"Zoom","width="+Largeur+",height="+Hauteur+", scrollbars=yes, resizable=no, toolbar=no, status=no, menubar=no, location=no, directories=no");
}

function fenetreCenter(url) {
	var haut=(screen.height-300)/2;
	var Gauche=(screen.width-300)/2;
		fenetreCenter = window.location=(url,'Broderie',"top="+haut+",left="+Gauche+",width="+300+",height="+300+",'scrollbars=no,resizable=no,toolbar=no,status=no,menubar=no,location=no,directories=no'");
}

function BtnEnabled(o) {
	var e = document.getElementById(o);
	if (e) {
		e.disabled = false;
	}
}
function BtnDisabled(o) {
	var e = document.getElementById(o);
	if (e) {
		e.disabled = true;
	}
}

function UnCheckBox(o,oItem){
	if (document.getElementById(o).checked) {
		document.getElementById(oItem).checked = false;
	}
}

function ChekBox(iTem,o,c) {
	var e = document.getElementById(iTem+o)
	if(e.checked) {
		document.getElementById("Container"+o).style.backgroundColor = c;
		document.getElementById("Container"+o).style.filter = "alpha(opacity=80)";
		document.getElementById("Container"+o).style.opacity = "0.80";
	}
	if(!e.checked) {
		document.getElementById("Container"+o).style.backgroundColor = "";
		document.getElementById("Container"+o).style.filter = "alpha(opacity=100)";
		document.getElementById("Container"+o).style.opacity = "1.00";
	}
}

function afficheVignette(cheminVignette, cheminImg, i){
	document.write('<A HREF="javascript:afficheMaxi(\''+cheminImg+'\')"><IMG SRC="'+cheminVignette+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="Cliquez ici pour voir l\'image en grand"><span class="Texte_Produit_white">Zoom</span></A>');
}
function afficheMaxi(chemin){
	i1 = new Image;
	i1.src = chemin;
	var LoadWidth = parseInt(i1.clientWidth);
	var LoadHeight = parseInt(i1.clientHeight);
	var haut=(screen.height-LoadHeight)/2;
	var Gauche=(screen.width-LoadWidth)/2;
	
	html = '<HTML><HEAD><TITLE>Image</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+14,document.imageTest.height+52)"></CENTER></BODY></HTML>';
	popupImage = window.open('','_blank','top='+haut+',left='+Gauche+',width='+LoadHeight+',height='+LoadWidth+',"toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close()
}

function jumpMenu(targ,page,selObj,restore){
  eval(targ + ".location='" + page + selObj.value + "'");
  if (restore) selObj.selectedIndex=0;
}

function formatTel(theField){
     var oLen = theField.value.length; 
     if(oLen == 2 || oLen == 5 || oLen == 8 || oLen == 11){theField.value += ".";}
}

function LimteCaractMini(theField, nb, DIV){
	var oLen = theField.value.length; 
	if(oLen < nb){
		ShowDIV(DIV);
		theField.focus();
		return false;
	}
}

function checkExtension(file, extList){
	var e = file.substr(file.lastIndexOf('.')).toLowerCase();
	var eList = extList+',';
	return eList.indexOf(e+',')>=0;
}

function getNumerique(e) {
	e = (e) ? e : (window.event) ? window.event : null;
	if (e) {
		var object = null;
		if (e.target) {
			object = (e.target.nodeType == 3) ? e.target.parentNode : e.target;
		} else {
			object = e.scrElement;
		}
		var keycode = (window.event) ? window.event.keyCode : e.which;
		var s = object.value;
		if(keycode == 8 || keycode == 127) {
			return true;
		} else if(keycode == 44 || keycode == 46){
			if(s.indexOf(",")!=-1 || s.indexOf(".")!=-1){
				return false;
			}
			return true;
		} else if(keycode < 48 || keycode > 57) {
			return false;
		}	
	}
}

function Reset(o) {
	var e = document.getElementById(o)
	if (e) {
		e.style.border = "#e841ac solid 1px";
		e.style.backgroundColor = "#FEFEFE";
		//e.style.filter = "alpha(opacity=90)";
		//e.style.opacity = "0.90";
	}
}
function ShowBorder(o) {
	var e = document.getElementById(o);
	if (e) {
		e.style.border = "#038cb5 solid 1px";
		e.style.backgroundColor = "#FFFFFF";
		//e.style.filter = "alpha(opacity=100)";
		//e.style.opacity = "1.00";
	}
}
function checkMaxInput(mytextarea, maxLen, Bouton) {
	var e = document.getElementById(Bouton);
	if (mytextarea.value.length > 0) {
		if (e) {
			e.disabled = false;
		}
	} else {
		if (e) {
			e.disabled = true;
		}
	}
	if (mytextarea.value.length > maxLen) { // if too long.... trim it!
		mytextarea.value = mytextarea.value.substring(0, maxLen);
		ShowDIV('Limite');
		return 0;
	}
	// otherwise, return 'characters left' counter
	return (maxLen - mytextarea.value.length);
}
function checkLength(name, field, length) {
	if (field.value.length > length) {
		alert('Le champ \'' + name + '\' est limité à ' + length + ' caractères ' + '(il en contient ' + field.value.length + ').');
		field.focus();
		return false;
	}
	return true;
}
function CheckMail(Oinput, Odiv) {
	var s = document.getElementById(Oinput).value;
	var reg = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/;
	var re = new RegExp(reg);
	if (s.match(re)) {
		HideDIV(Odiv);
		return true;
	} else {
		ShowDIV(Odiv);
		return false;
	}
}