// JavaScript Document
var preloadFlag = false;
function preloadImages() {
if(document.images) {
  p_accueil = newImage('boutons/accueil-2.jpg');
  p_catalogue = newImage('boutons/catalogue-2.jpg');
  p_associations = newImage('boutons/associations-2.jpg');
  p_impression = newImage('boutons/impression-1.jpg');
  p_cdv = newImage('boutons/cdv-1.jpg');
  p_contact = newImage('boutons/contact-1.jpg');
  preloadFlag = true;
  }
}
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}
function changeImages() {
	changeImagesArray(changeImages.arguments);
}
function isEmpty(s) {
	if(s.length==0) return true; else return false;
}
function AlertEmpty(champ) {
	var a = "Le champ ("+champ+") ne peut pas etre vide";
	alert(a);
}
function isEmail(s) {

}
function VEmail() {
	if(isEmpty(document.contact.vemail.value)) {
		AlertEmpty("Adresse email");
		document.contact.vemail.focus();
		return false;
	}
	if(isEmpty(document.contact.vsujet.value)) {
		AlertEmpty("Sujet");
		document.contact.vsujet.focus();
		return false;
	}
	if(isEmpty(document.contact.vtexte.value)) {
		AlertEmpty("Texte");
		document.contact.vtexte.focus();
		return false;
	}
	return true;
}
function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}
function ChArt(ind) {
	var DHTML = (document.getElementById || document.all || document.layers);
	if(!DHTML) return;
	var a = eval('art'+ind);
	var x = new getObj('image_grande');
	//x.obj.src = "http://www.cartes-de-voeux-entreprise.fr/"+a[0];
	x.obj.innerHTML = "<a style=\"cursor: pointer; cursor: hand;\"><img src=\"http://www.cartes-de-voeux-entreprise.fr/"+a[0]+"\" onclick=\"window.open('http://www.cartes-de-voeux-entreprise.fr/photo.php?pid="+a[11]+"','Details','toolbar=no,menubar=no,status=no,height="+a[12]+",width="+a[13]+"')\" border=\"0\" ></a>"; 

	// onclick="window.open(\'photo.php?pid='+a[11]+'\')">'; 
	var x = new getObj('titre');
	x.obj.innerHTML = a[1];
	var x = new getObj('desc1');
	x.obj.innerHTML = a[2];
	var x = new getObj('desc2');
	var nprix = a[4]*(100-a[9])/100;
	nprix= nprix.toFixed(2);
	if (a[3] == 1)
	{
		var b = "A partir de "+a[3]+" pack<br>Prix unitaire : <b>"+a[4]+"</b> &euro; HT<br>Avec enveloppe "+a[5];
	}else{
		if (a[9]>0)
		var b = "A partir de "+a[3]+" cartes<br>Prix unitaire :<font color='red'><s>"+a[4]+"</s></font> <b>"+nprix+"</b> &euro; HT<br>Avec enveloppe "+a[5];
		else
		var b = "A partir de "+a[3]+" cartes<br>Prix unitaire : <b>"+a[4]+"</b> &euro; HT<br>Avec enveloppe "+a[5];
	}
	x.obj.innerHTML = b;
	var x = new getObj('format');
	x.obj.innerHTML = a[6];
	
	var x = new getObj('logo_assoc');
	x.obj.innerHTML = "<img src='photos/associations/"+a[16]+"/"+a[15]+"' alt='"+a[15]+"' style='border: 1px solid #993399;width:57px;' />";

	
	var x = new getObj('echantillon');
	if (a[14]>0)
	x.obj.innerHTML = "<a href=\"javascript:AjPanierE('5')\" class=\"ajouter_panier1\" valign=\"middle\">Commander un échantillon</a>";
	else
	x.obj.innerHTML = "";
	
	var x = new getObj('ref');
	x.obj.innerHTML = "Réf.  "+a[10]+"";
	document.art5.article.value=a[8];
	
	var x = new getObj('poids');
	if (a[7]>0) {
	x.obj.innerHTML = "Poids : "+a[7]+" grs";
	}
	else {
	x.obj.innerHTML = "";
	}
	
	
}
function AjPanier(ind) {
	eval('document.art'+ind+'.submit()');
}
function AjPanierE(ind) {
	document.art5.esantillon.value = 1;
	eval('document.art'+ind+'.submit()');
}
function NCompte() {
	if(isEmpty(document.compte.societe.value)) {
		AlertEmpty("Societe");
		document.compte.societe.focus();
		return false;
	}
	if(isEmpty(document.compte.tva.value)) {
		AlertEmpty("Numero Tva");
		document.compte.tva.focus();
		return false;
	}
	if(isEmpty(document.compte.ape.value)) {
		AlertEmpty("Code Ape");
		document.compte.ape.focus();
		return false;
	}
	if(isEmpty(document.compte.telephone.value)) {
		AlertEmpty("Telephone");
		document.compte.telephone.focus();
		return false;
	}
	if(isEmpty(document.compte.adresse.value)) {
		AlertEmpty("Adresse");
		document.compte.adresse.focus();
		return false;
	}
	if(isEmpty(document.compte.cp.value)) {
		AlertEmpty("Code Postal");
		document.compte.cp.focus();
		return false;
	}
	if(isEmpty(document.compte.ville.value)) {
		AlertEmpty("Ville");
		document.compte.ville.focus();
		return false;
	}
	var value = '';
  for(var i=0;i<document.compte.pol.length;i++) {
    if(document.compte.pol[i].checked) {
      value = document.compte.pol[i].value;   
	  break;
      }
    }
  if(value == '') {
    alert('Merci de choisir votre civilité');
    return false;
    }
	
	if(isEmpty(document.compte.responsable.value)) {
		AlertEmpty("Nom de responsable");
		document.compte.responsable.focus();
		return false;
	}
	if(isEmpty(document.compte.email.value)) {
		AlertEmpty("Email");
		document.compte.email.focus();
		return false;
	}
	if(isEmpty(document.compte.passe.value)) {
		AlertEmpty("Mot de passe");
		document.compte.passe.focus();
		return false;
	}
	

	if(document.compte.cgv.checked===false) {
		alert("Vous devez être d'accord avec les conditions generales de vente");
		//document.compte.passe.focus();
		return false;
	}
	return true;
}
