// ------- fonctions pour allopass -------	
// fonction addEvent (http://www.scottandrew.com/weblog/jsjunk)

function clearField(quelchamps, mValue){
	actValue=document.getElementById(quelchamps).value;

	if (actValue==mValue){
		document.getElementById(quelchamps).value='';
	}
}
function initOnFocus(){
	var j_field = document.getElementById('input_code');
	var j_field2 = document.getElementById('input_code_access');
	var j_field3 = document.getElementById('input_code_access2');
	//addEvent(j_select, 'change', setHiddenFields);
	/* If the element exists, we can assign the onchange event to call the swap function using the same type test we used before. */
	if(j_field) {
		if(j_field.addEventListener) {
			j_field.addEventListener('focus',  function(){clearField('input_code', 'votre code allopass')}, false);
		} else if(j_field.attachEvent) {
			j_field.attachEvent('onfocus', function(){clearField('input_code', 'votre code allopass')});
		}
	}
	if(j_field2) {
		if(j_field2.addEventListener) {
			j_field2.addEventListener('focus',  function(){clearField('input_code_access', "votre code allopass")}, false);
		} else if(j_field2.attachEvent) {
			j_field2.attachEvent('onfocus', function(){clearField('input_code_access', "votre code allopass")});
		}
	}
	if(j_field3) {
		if(j_field3.addEventListener) {
			j_field3.addEventListener('focus',  function(){clearField('input_code_access2', "votre code allopass")}, false);
		} else if(j_field3.attachEvent) {
			j_field3.attachEvent('onfocus', function(){clearField('input_code_access2', "votre code allopass")});
		}
	}

}
function setHiddenFields(quelChamps, myDiv){
		//tableau des champs cachés ALLOPASS
		//1
		myFields=new Array();
		myFields[1]=new Array();
		myFields[1]['ids']='191948';
		myFields[1]['idd']='523124';
		myFields[1]['lang']='fr';
		//5
		myFields[2]=new Array();
		myFields[2]['ids']='191948';
		myFields[2]['idd']='519309';
		myFields[2]['lang']='fr';
		//10
		myFields[3]=new Array();
		myFields[3]['ids']='191948';
		myFields[3]['idd']='519303';
		myFields[3]['lang']='fr';
		//20
		myFields[4]=new Array();
		myFields[4]['ids']='191948';
		myFields[4]['idd']='519303';
		myFields[4]['lang']='fr';
		//set la valeur des champs cachés
		myValue=quelChamps;
		//
		
		var selectFields='<input type="hidden" name="ids" value="'+myFields[myValue]['ids']+'" /><input type="hidden" name="idd" value="'+myFields[myValue]['idd']+'" /><input type="hidden" name="lang" value="'+myFields[myValue]['lang']+'" />';

	
		document.getElementById(myDiv).innerHTML = selectFields;
	
}	
function initOnChange() {

/* NOT USED ATM --- Get the select element you want the onchange to be applied to. I use the j_ prefix because sometimes errors happen when variables are named the same thing as IDs in the HTML. */
	var j_select = document.getElementById('select_num');
	//addEvent(j_select, 'change', setHiddenFields);
	/* If the element exists, we can assign the onchange event to call the swap function using the same type test we used before. */
	if(j_select) {
		if(j_select.addEventListener) {
			j_select.addEventListener('change', setHiddenFields, false);
		} else if(j_select.attachEvent) {
			j_select.attachEvent('onchange', setHiddenFields);
		} else {
			j_select.onload = setHiddenFields;
		}
		/* Now, we need to fire the event to get the default. */
		if(document.createEvent) {
			//The W3C method. 
			var j_event = document.createEvent('HTMLEvents');
			j_event.initEvent("change", true, true);
			j_select.dispatchEvent(j_event);
		} else if(document.createEventObject) {
			//The IE method.
			j_select.fireEvent("onchange");
		}
	}
}

function getCodePack(myDiv,myFormId){
	if (document.forms[myFormId].nb_articles[0].checked==true){
		setHiddenFields(2,myDiv);
	}else{
		setHiddenFields(3,myDiv);
	}
	window.open('','DisplaySub','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=570');
}

function getArticlePack(myForm,myFormId,myDiv){
	/*alert(myForm);*/	
	if (document.forms[myFormId].nb_articles[0].checked==true){		
		setHiddenFields(2,myDiv);
	}else{
		setHiddenFields(3,myDiv);
	}
	myForm.submit();
	myForm.APsub.disabled=true;
}
addEvent(window, 'load', initOnFocus);


