var basePicUrl = "http://img.fashionshopping.com/boutique/images_produits/";
var baseProductUrl = "http://www.fashionshopping.com/boutique/";

function isValidEmail(form) {
	var reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;

	if (form != "") {

		if (reg.test(form) == true) {
			return true;

		} else {

			alert("Veuillez entrer une adresse mail valide");
			return false;
		}
	} else {

		alert("Merci de saisir votre adresse électronique");
		return false;

	}
}
function displaypopup(url) {
	window.open(url, '', 'scrollbars=no,left=0,top=0,width=800px,height=800px');
}

function showdetail(temp, temp2) {
	curPic = temp2;
	if (document.images) {
		document.images['image_produit'].src = temp;
	}
	return;
}

function fillCurrentLocation() {
	document.getElementById('src_p').value = document.location.href;

}
function fillCurrentLocation3() {
	document.getElementById('src_p3').value = document.location.href;
	alert(document.getElementById('src_p3').value);
}

function getUrlAttribute(attribute) {

	var chaine2 = "";
	var pageLocation = window.document.location;

	var chaine = pageLocation.toString();
	var longueur = chaine.length;
	var index1 = Math.max(chaine.indexOf('&' + attribute + '='), chaine
			.indexOf('?' + attribute + '='));

	if (index1 != -1) {

		chaine2 = chaine.substring(index1 + 2 + attribute.length, longueur);

		var index2 = chaine2.indexOf('&');
		if (index2 != -1)
			chaine2 = chaine2.substring(0, index2);
	}
	return chaine2;
}

function getElementsById(sId) {
	var outArray = new Array();
	if (typeof (sId) != 'string' || !sId) {
		return outArray;
	}
	;

	if (document.evaluate) {

		var xpathString = "//*[@id='" + sId.toString() + "']"
		var xpathResult = document.evaluate(xpathString, document, null, 0,
				null);
		while ((outArray[outArray.length] = xpathResult.iterateNext())) {
		}
		outArray.pop();
	} else if (document.all) {
		var searchObj = document.all[sId];
		if (!searchObj)
			return outArray;
		if (!searchObj.length) {
			outArray[0] = searchObj;
		} else {
			for ( var i = 0; i < searchObj.length; i += 1) {
				outArray[i] = searchObj[i];
			}
		}

	} else if (document.getElementsByTagName) {

		var aEl = document.getElementsByTagName('*');
		for ( var i = 0, j = aEl.length; i < j; i += 1) {

			if (aEl[i].id == sId) {
				outArray.push(aEl[i]);
			}
			;
		}
		;

	}
	;

	return outArray;
}

function ouverture_css_modif(theURL, winName, features, dialogFeatures) {

	window.location.href = theURL
			+ "&url_referer=liste%5Fproduits%2Ecfm%3Ftype%3D2%26code%5Flg%3Dlg%5Ffr";
}

function maFonction( ) {
    var i = 0;
    var mySpans = document.getElementById("main_center").getElementsByTagName('span');
	var myCollections = new Array();
	var nbCollections = -1;
	var newCollection = false;
	for( var i = 0; i < mySpans.length ; i++ ) {
		if(mySpans[i].id == "prix_barre_devises_liste_produits" ) {
			//alert("newCollection");
			nbCollections++;
			newCollection = true;
			myCollections[nbCollections] = new Array();
		}
		if( nbCollections > -1 && newCollection == true) {
			if ( mySpans[i].id == "prix_barre" || mySpans[i].id == "prix_copie2" || mySpans[i].id == "prix_barre_devises_liste_produits" ) {
				myCollections[nbCollections][mySpans[i].id] = mySpans[i];
			}
		}
		if(mySpans[i].id == "prix_copie2") {
			newCollection = false;
		}
		//alert("test");
	}
	var tmpVar = "";
	for ( i = 0 ; i < myCollections.length ; i++ ) {
		if(myCollections[i]["prix_barre_devises_liste_produits"])
		{
			//alert(myCollections[i]["prix_barre"] + " - " + myCollections[i]["prix_copie2"].innerHTML + " - " + myCollections[i]["prix_barre_devises_liste_produits"].innerHTML);
			tmpVar = "";
			tmpVar = myCollections[i]["prix_copie2"].innerHTML.toString();
			//alert(tmpVar);
			myCollections[i]["prix_copie2"].innerHTML = "<span style='text-decoration:line-through'>" + myCollections[i]["prix_barre_devises_liste_produits"].innerHTML +"</span>&nbsp;&nbsp;" + "<span id=\"prix_solde\">Prix Soldé : <strong id=\"prix_copie2\">"+tmpVar+"</strong></span>";
		}
	}
}
	
function fix() {

	for (i = 0; i <= 98; i++) {
		if (document.getElementById("style_bo_cadrecms" + i)) {
			document.getElementById("style_bo_cadrecms" + i).style.border = "2px dotted #000000";
			document.getElementById("style_bo_cadrecms" + i).style.margin = "2px";
			document.getElementById("style_bo_boutoncms" + i).style.display = "";
		}
		if (document.getElementById("style_bo_cadre" + i)) {
			document.getElementById("style_bo_cadre" + i).style.border = "2px dotted #000000";
			document.getElementById("style_bo_cadre" + i).style.margin = "2px";
			document.getElementById("style_bo_bouton" + i).style.display = "";
		}
	}

//	var phone = document
//			.getElementById("champ_coordonnee_tel_formulaire_client");
//	if (phone != null)
//		phone.value = "0000000000";

	var commentaire = document
			.getElementById("info_textarea_commentaire_formulaire_client");
	if (commentaire != null) {
		commentaire.rows = "1";
	}

	var mytable = document.getElementById("encart_formulaire_client");
	if (mytable != null) {
		mytable.rows[4].height = "3";
		mytable.rows[11].height = "1";
		mytable.rows[12].height = "1";
		mytable.rows[14].height = "1";
	}

	var priceArray = getElementsById("prix_affiche_devises_promo_off_liste_produits");
	var priceArray2 = getElementsById("lien_plus_infos_liste_produits");
	var tauxSoldes = getElementsById("taux_soldes");
	
	var prixAffSolde = getElementsById("prixPromo");
	var prixBase = getElementsById('prixBase');
	var pourPromo = getElementsById('pourcentagePromo');
	
	
	
		
	var prixSOLDE = getElementsById('prix_copie2');
	var prixF = getElementsById('prix_barre_devises_liste_produits');

	for ( var i = 0; i < priceArray2.length; i++ ) {

		var newTR = document.createElement('TR');
		var newTD = document.createElement('TD');

		priceArray2[i].parentNode.parentNode.parentNode.appendChild(newTR);
		newTR.appendChild(newTD);

		if (tauxSoldes) {
			if (tauxSoldes[i] && tauxSoldes[i].innerHTML == "promotion") {
				newTD.innerHTML = "<span id=\"prix_copie_soldes\">Prix en promotion : <span id=\"prix_copie2_soldes_promotion\">"
						+ priceArray[i].innerHTML + "</span></span>";
			} else if (tauxSoldes[i] && tauxSoldes[i].innerHTML == "soldes") {
				newTD.innerHTML = "<span id=\"prix_copie_soldes\">Prix sold&eacute; : <span id=\"prix_copie2_soldes_promotion\">"
						+ priceArray[i].innerHTML + "</span></span>";
			} else if (tauxSoldes[i] && tauxSoldes[i].innerHTML != "") {
				newTD.innerHTML = "<span id=\"prix_copie_soldes\">Prix en promotion à <span id=\"affichage_taux_soldes\">"
						+ tauxSoldes[i].innerHTML
						+ "</span> : <span id=\"prix_copie2_soldes\">"
						+ priceArray[i].innerHTML + "</span></span>";
						
			} else if (prixAffSolde[i] && prixAffSolde[i].innerHTML != "") {
			
				newTD.innerHTML = "<p id=\"prix_copie\">Prix FashionShopping : <strong id=\"prix_copie2\" class='prixBarre'>"
					//+ prixBase[i].innerHTML + "</strong> "+ pourPromo[i].innerHTML +"</p><p id=\"prix_copie\">Prix Soldé : <strong id=\"prix_copie2\">"
					+ prixBase[i].innerHTML + "</strong></p><p id=\"prix_solde\">Prix Soldé : <strong id=\"prix_copie2\">"
					+ priceArray[i].innerHTML + "</strong><p></div>";
				
			}else
				newTD.innerHTML = "<span id=\"prix_copie\">Prix FashionShopping : <span id=\"prix_copie2\">"
						+ priceArray[i].innerHTML + "</span></span>";

		} else
			newTD.innerHTML = "<span id=\"prix_copie\">Prix FashionShopping : <span id=\"prix_copie2\">"
					+ priceArray[i].innerHTML + "</span></span>";

		priceArray[i].innerHTML = "";

	}

	var optionsNode = document.getElementById("menu_sous_ref1_fiche_produit");

	if (optionsNode) {
		for ( var i = 0; i < optionsNode.options.length; i++) {
			if (texteNonDispoArray[optionsNode.options[i].text])
				if (texteNonDispoArray[optionsNode.options[i].text].length > 0) {
					// alert(optionsNode.options[i].text);
					optionsNode.options[i].text = optionsNode.options[i].text
							+ " - article épuisé"; // +
													// texteNonDispoArray[optionsNode.options[i].text];
					// alert(optionsNode.options[i].text);

				}
		}
	}

	var product_ref = getElementsById("product_ref");
	var product_thumbnail = getElementsById("product_thumbnail");

	for ( var i = 0; i < product_ref.length; i += 1) {
		var node = product_ref[i].parentNode.parentNode.previousSibling;
		while (node.nodeName == "#text")
			node = node.previousSibling;

		var oldTcContent = node.innerHTML;
		node.innerHTML = "<a href=\""
				+ baseProductUrl
				+ "fiche_produit.cfm?ref="
				+ product_ref[i].innerHTML
				+ "&amp;code_lg=lg_fr\">"
				+ "<img src=\""
				+ basePicUrl
				+ product_thumbnail[i].innerHTML
				+ "\" class=\"bordure_image_defaut\" alt=\"\" border=\"0\" hspace=\"0\" vspace=\"0\"></a><br>"
				+ oldTcContent;
	}
	
	maFonction();
	
	var prixF_fiches = document.getElementById('prix_promotion_euro_fiche_produit');
	
	var valuePrixF_fiche = prixF_fiches.innerHTML;
	prixF_fiches.innerHTML = '<p id=\"prix_solde_fiche\">Prix Soldé : <strong id=\"prix_copie2\">'
								+ valuePrixF_fiche;
								+ '</strong></p>';
}
