function fSelectItem(vQuelSelect,vQuelActif){
	window.location = '?vItemActif=VisuelItem&vItemRef=' + vQuelActif + '&vOMagItemId=' + vQuelSelect.value;
}

function fSelectAdmin(vQuelSelect,vQuelOperation,vQuelCat){
	window.location = '?vAdminActif='+vQuelOperation+'&vOpId=' + vQuelSelect.value + '&vChoixCat=' + vQuelCat;
}

function fMailSetUp(tryNumb){
	//** 'tryNumb' sert à savoir si le champs est corrigé dans le php... 0 -> non, 1 -> oui; **//
	//** 'vSendInsertMail' fait que l'inscription dans 'index.php' ne s'affiche pas; **//
	var courriel = fGetObj('mailInscrip').value != "courriel" ? fGetObj('mailInscrip').value : "";	
	var nom = fGetObj('mailUser').value != "votre nom" ? fGetObj('mailUser').value : "";
	// Toujours afficher plus de détail, donc "mailPlus" toujours égale à true -> 18/11/2011;
	//var mailPlus = fGetObj('mailPlus') == null ? fScanPath("vInsertPlus") : fGetObj('mailPlus').checked;
	var mailPlus = true;
	var loadStr = '?vItemActif=InscriptionDetail&vItemRef=0&vSendInsertMail=1&vInsertMail=' + courriel + '&vInsertUser=' + nom + '&vInsertPlus=' + mailPlus;	
	
	if(tryNumb){
		//if(mailPlus == "true"){
		if(mailPlus){	
			loadStr += '&vInsertEntreprise=' + fGetObj('mailEntreprise').value;
			loadStr += '&vInsertSecteur=' + fGetObj('mailSecteur').value;
			loadStr += '&vInsertVille=' + fGetObj('mailVille').value;
			loadStr += '&vInsertAcheteur=' + fGetObj('mailAcheteur').value;
		}
		
		loadStr += '&vTryNumb=' + 1;
	}else{
		loadStr += '&vTryNumb=' + 0;
	}

	window.location = loadStr;
}

function fCheckStr(expression, str){
	var vErrorFlag;
	var vRegExpObj = new RegExp(expression);
	
	vErrorFlag = vRegExpObj.test(str);
	
	return vErrorFlag;
}

function fNewWin(vQuelPath,vQuelAttribut){																// ?? :-);
	vWinName = new Date();
	window.open(vQuelPath,'OMag' + vWinName.getTime(),vQuelAttribut);
}

function fCheckSearch(vQuelSearch, vQuelType){															// Vérifie et construit le 'path' (variable), si une recherche est demandée, pour la page de produit;
	if(vQuelSearch.value != '' && vQuelSearch.value != 'recherche'){
		window.location = '?vItemActif=Produit&vType=' + vQuelType + '&vItemSKey=' + vQuelSearch.value;
	}else{
		document.all.inscRouge.className = 'omagAsterRouge';
	}
}

function fCheckSoum(vQuelSoum){																			// Vérifie le formulaire de demande de soumission;
	
	var vErrorFlag = 1;																					// 'Flag', quand = 1, tout est OK et on peut envoyer le mail, quand = 0 erreur;
		
	var vRegExpPattern = new Array();																	// 1er niveaux -> pattern de l'expression régulière, 2e niveaux -> action ou message d'erreur;
	vRegExpPattern[0] = new Array(/[a-z]+/i,'Ce champs ne peut être vide.');
	vRegExpPattern[1] = new Array(/[a-z]+/i,'Vous devez inscrire un nom de contact.');
	vRegExpPattern[2] = new Array(/[\w]+@[\w]+\.[\w]+/i,'Ce courriel ne semble pas valide.');
	vRegExpPattern[3] = new Array(/\b\d{3}-\d{3}-\d{4}\b/,'XXX-XXX-XXXX');
	vRegExpPattern[4] = new Array(/[a-z]+/i,'Une description est nécessaire pour votre soumission.');
	
	for(var i = 0; i < vRegExpPattern.length; i ++){													// Vérifie les champs selon le pattern de 'vRegExpPattern';
		var vRegExpObj = new RegExp(vRegExpPattern[i][0]);
		if(!vRegExpObj.test(vQuelSoum[i].value) || vQuelSoum[i].value == vRegExpPattern[i][1]){
			document.infoSoum[i].className = 'omagFormInputSoumRouge';
			document.infoSoum[i].value = vRegExpPattern[i][1];
			vErrorFlag = 0;
		}else{
			document.infoSoum[i].className = 'omagFormInputSoum';
		}
	}
	
	if(vErrorFlag){
		fBuildPath(vQuelSoum,'includes/OMagSendSoum.php?');
	}
	
}

function fBuildPath(vQuelForm,vQuelPageSend){																// Construit un path selon l'objet du formulaire demandé (vQuelForm) et l'envoit à la page demandée (vQuelPageSend);
		var vNextPagePath = '';																				// Contient le 'path'; 
		vNextPagePath += vQuelPageSend;

		for(var i = 0; i < vQuelForm.length; i ++){
			vNextPagePath += vQuelForm[i].name + '=' + (vQuelForm[i].type == "checkbox" ? (vQuelForm[i].checked ? 1 : 0) : escape(vQuelForm[i].value));

			if(i != (vQuelForm.length - 1)){
				vNextPagePath += '&';
			}
		}
				
		window.location = vNextPagePath;
}

function fCheckBoxPath(vQuelForm,vQuelPageSend){															// Construit un path selon le checkBox demandé (vQuelForm) et l'envoit à la page demandée (vQuelPageSend);
		var vNextPagePath = '';																				// Contient le 'path'; 
		vNextPagePath += vQuelPageSend;
		
		for(var i = 0; i < vQuelForm.length; i ++){
			if(vQuelForm[i].checked){
				vNextPagePath += vQuelForm[i].value;
				vNextPagePath += ',';
			}
			
		}
		window.location = vNextPagePath;
}

function fBuildNews(vQuelNews,vQuelOp,vQuelId){																		// Construit le path pour l'envoi de la 'newsletter' à la page '.php' pour la visualisation;
		var vNextPagePath = '';																				// Contient le 'path';

		for(var i = 0; i < vQuelNews.length; i++){
			if(vQuelNews[i].type != 'select-multiple'){
				vNextPagePath += vQuelNews[i].name + '=';
				vNextPagePath += vQuelNews[i].value;
			}else{
				var vSelectedTemp = '';
				for(var e = 0; e < vQuelNews[i].length; e++){
					if(vQuelNews[i].options[e].selected){
						vSelectedTemp += vQuelNews[i].options[e].value + ',';
					}
				}
				vNextPagePath += vQuelNews[i].name + '=';
				vNextPagePath += vSelectedTemp;
			}
			
			if(i != (vQuelNews.length - 1)){
				vNextPagePath += '&';
			}
		}
		
		vNextPagePath += '&vOperation=' + vQuelOp;
		vNextPagePath += (vQuelId != undefined ? '&vNoId=' + vQuelId : '&vNoIdEtape=1');
		//fNewWin('includes/OMagNewsVis.php?' + vNextPagePath,'status,width=550,scrollbars=yes');

		fNewWin('OMagNewsVis.php?' + vNextPagePath,'status,width=550,scrollbars=yes');
}

function fScanPath(vQuelVariable){																			// Cherche dans le 'URL' de la page la variable 'vQuelVariable' et retourne sa valeur;
	
	var vOption;
	var vVarTarget = vQuelVariable + '=';
	var vPathToScan = document.location.href;
	
	vLocation = vPathToScan.indexOf(vVarTarget);
	
	if(vLocation != -1){
		var vIndexA = vLocation + (vVarTarget.length);
		var vIndexB;
		
		vPathToScan.indexOf('&',vIndexA) != -1 ? vIndexB = vPathToScan.indexOf('&',vIndexA) : vIndexB = vPathToScan.length;
		vOption = vPathToScan.substring(vIndexA,vIndexB);
	}else{
		vOption = '';
	}
	
	return(vOption);	
}

function fGetObj(id){ 
    if(document.getElementById){
      	return document.getElementById(id);
    	
	}else if(document.all){
     	 return document.all[id];
    
	}else if(document.layers){
      	return document.layers[id];
    	
	}else{ 
		return null;
	}
}

function fCreate_element(type){
	var element_temp = document.createElement(type);
	var len = arguments.length;
	
	
	for(var i = 1; i < len; i ++){
		if(arguments[i][0] == "style"){
			element_temp.style.cssText = arguments[i][1];
		}else{
			element_temp.setAttribute(arguments[i][0], arguments[i][1]);
		}
	}
	
	return element_temp;
}

function fWindowResize(){																					// Redimension la fenêtre après que la photo zoom soit 'loadé', utile pour le bouton zoom de chaque catégorie; 
	window.resizeTo(fGetObj('imageZoom').width + 30, fGetObj('imageZoom').height + 80);
}
