/*********************************************************************************************
FONCTION JAVASCRIPT POUR CHAQUE TYPE DE TAG
*********************************************************************************************/
	//Delete Contenu d'une Reference REF LINK
	function BO_JS_Process_REF_LINK(LabelFieldTag,Tag_Name){
		var FormName = 'document.ContentEdit';
		var Field = eval(FormName+'.'+Tag_Name);

		if (confirm('Etes vous sur de vouloir supprimer le contenur de cette reference '+LabelFieldTag)){
				eval("DIV_"+Tag_Name+".innerHTML='';");
				Field.value='';
		}


	}


	//Check  Fields DYNAMIC_IMAGE
	function BO_JS_Process_DYNAMIC_IMAGE(LabelFieldTag,Tag_Name){
		var FormName = 'document.ContentEdit';
		var HiddenField = eval(FormName+'.'+Tag_Name);

		if (confirm('Etes vous sur de vouloir supprimer le contenu de '+LabelFieldTag)){
			//Supprime le contenu du Tag
			eval("DIV_"+Tag_Name+".innerHTML='';");
			HiddenField.value='';
		}
	}


	//Check  Fields ATTACHMENT
	function BO_JS_Process_ATTACHMENT(LabelFieldTag,Tag_Name){
		var FormName = 'document.ContentEdit';
		var HiddenField = eval(FormName+'.HIDDEN_'+Tag_Name);
		var LabelField = eval(FormName+'.LABEL_'+Tag_Name);
		var UrlAttachmentField = eval(FormName+'.URLATTACHMENT_'+Tag_Name);

		if (confirm('Etes vous sur de vouloir supprimer le contenu de '+LabelFieldTag)){
			//Supprime le contenu du Tag
			eval("DIV_"+Tag_Name+".innerHTML='';");
			LabelField.value='';
			HiddenField.value='';
			UrlAttachmentField.value;
		}
	}

	//Check Field with tag INPUT
	function BO_JS_Process_INPUT(LabelFieldTag,Tag_Name){
		var FormName = 'document.ContentEdit';
		var Field = eval(FormName+'.'+Tag_Name);

		if (confirm('Etes vous sur de vouloir supprimer le contenu de '+LabelFieldTag)){
			//Supprime le contenu du Tag
			eval("DIV_"+Tag_Name+".innerHTML='';");
			Field.value='';
		}

	}

	//Check Field with tag FILE
	function BO_JS_Process_FILE(LabelFieldTag,Tag_Name){
		var FormName = 'document.ContentEdit';
		var HiddenField = eval(FormName+'.HIDDEN_'+Tag_Name);
		var AltImageField = eval(FormName+'.ALT_'+Tag_Name);

		if (confirm('Etes vous sur de vouloir supprimer le contenu de '+LabelFieldTag)){
			//Supprime le contenu du Tag
			eval("DIV_"+Tag_Name+".innerHTML='';");
			HiddenField.value='';
			AltImageField .value;
		}

	}

	//Check Field with tag HTML
	function BO_JS_Process_HTML(LabelFieldTag,Tag_Name){
		var FormName = 'document.ContentEdit';
		//Champ Hidden
		var HiddenField = eval(FormName+'.'+Tag_Name);;

		if (confirm('Etes vous sur de vouloir supprimer le contenu de '+LabelFieldTag)){
			eval("DIV_"+Tag_Name+".innerHTML=' ';");
			HiddenField.value=' ';
		}


	}

	//Check Field with tag SELECT
	function BO_JS_Process_SELECT(LabelFieldTag,Tag_Name){
		var FormName = 'ContentEdit';
		var MsgError = '';

		if ((eval('document.ContentEdit.'+Tag_Name+'.options[document.ContentEdit.'+Tag_Name+'.selectedIndex].value')=='')||(eval('document.ContentEdit.'+Tag_Name+'.options[document.ContentEdit.'+Tag_Name+'.selectedIndex].value')==0)) {
			alert('erreur '+LabelFieldTag);
			MsgError ='erreur '+LabelFieldTag;
			return MsgError;
		}

	}

/**************************************************************************************************************/

	//fonction permettant d'ouvrir une nouvelle fenetre du navigateur
	function OpenWindow(winName, winTarget, width, height)
		       {
		       var myWindow = window.open(winName, winTarget,
		       "height='+height+',width='+width+',left=0,top=0,screenX=0,screenY=0,status=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes, resizable=yes");
		       	if(window.focus){
		       		myWindow.focus();
		       	}
		       }


	//Fonction ActionWYSIWYG
	function ActionWYSIWYG(TargetName,FormTag,Tag_Name,AttributID){
		document.ContentEdit.action='http://www.icelec.com/BOWYSIWYGEdit.php4?coe_i_id='+document.ContentEdit.coe_i_id.value+'&FormTag='+FormTag+'&TagName='+Tag_Name+'&AttributID='+AttributID;
		document.ContentEdit.target=TargetName;
	}


	//Fonction qui la valeur du champ TypeAction
	function ActionValue(TypeAction,BOPreview){
		if ((document.ContentEdit.tpt_i_id.options[document.ContentEdit.tpt_i_id.selectedIndex].value!=0)&&(document.ContentEdit.tpl_i_id_coe.options[document.ContentEdit.tpl_i_id_coe.selectedIndex].value!=0)){
			document.ContentEdit.TypeAction.value=TypeAction;
			switch (TypeAction)
			{
				case 'preview':
					document.ContentEdit.action='http://www.icelec.com/BOContentEdit.php4?TypeAction=preview&amp;coe_i_id='+document.ContentEdit.coe_i_id.value;
					document.ContentEdit.target=BOPreview;
				break;
				default:
					document.ContentEdit.action='http://www.icelec.com/BOContentAction.php4';
					document.ContentEdit.target=BOPreview;
			}
			return true;
		}
		else{
			alert('Vous devez sélectionner un gabarit');
			return false;
		}


	}



	function FillList(TypeAction,IdTemplate,NewIDTemplate) {
		switch (TypeAction){
			case "Add":
				var oForm = document.BOContentEdit_add;
			break;
			case "Edit":
				var oForm = document.ContentEdit;
			break;
			default:
			var oForm = document.ContentEdit;
		}
		var index = 0;
		var num=oForm.tpt_i_id.options[oForm.tpt_i_id.selectedIndex].value;
		var boxlength = 0;

		oForm.tpl_i_id_coe.length = 0;

		if (num!=0){
			if (NewIDTemplate!=''){
				IdTemplate=NewIDTemplate;
			}
			oForm.tpl_i_id_coe.options[0] = new Option('Sélectionner une Template','');
			for (i=1;i<=TemplateID.length;i++) {
				if (TemplateTypeID[i]==num){
					boxlength++;
					if (TemplateID[i]==IdTemplate){
						index = boxlength;
					}
					oForm.tpl_i_id_coe.options[boxlength] = new Option(TemplateName[i],TemplateID[i]);
				}
			}
			oForm.tpl_i_id_coe.selectedIndex = index;
		}
		else{
			oForm.tpl_i_id_coe.length = 0;
			oForm.tpl_i_id_coe.options[0] = new Option('Aucun gabarit','');
		}
	}

//Fonction verifiant la validite de l'email
function ValidateEmail(Email)
{
	if (Email.indexOf('@')=='-1' || Email.indexOf('.')=='-1' || Email.indexOf('@')=='0' || Email.indexOf('.')=='0' || Email =='' || (Email.lastIndexOf('.') - Email.indexOf('@') <= 1) || (Email.length - Email.lastIndexOf('.') < 3) )
			{
				alert('Your sender email is not valid');
			return false;
			}
	else
	{

		for(var i=0;i<Email.length;i++)
		{
			var c = Email.charAt(i);
			if(c==' ' || c==','/* || c=='\''*/ || c=='"' || (c>=':' && c<='<') || c=='>' || (c>='[' && c<'^') || c>'z')
			{
				alert('Your email is not valid');
				return false;
			}
		}
	}

	return true;
}



	//Fonction CreateXmlJS
	function CreateXmlJS(){
		document.ContentEdit.TypeAction.value='edit';
		document.ContentEdit.action='http://www.icelec.com/BOContentAction.php4';
		document.ContentEdit.target='';
		document.ContentEdit.submit();
	}


	//	Fonction pour verifier la validiter d'une date
	//	Input
	//		v_d = jour (jj)
	//		v_m = mois (mm)
	//		v_y = annee (aaaa)
	//	output
	//		true si la date est valide
	//		false si la date n'est pas valide
	//
	function do_checkdate(v_d, v_m, v_y) {
	      var amin=1000; // annee mini
	      var j=v_d;
	      var m=v_m;
	      var a=v_y;
	      var ok=1;
	      if ( (isNaN(j)) || (j<1) || (j>31) )		ok=0;
	      if ( (isNaN(m)) || (m<1) || (m>12) )		ok=0;
	      if ( (isNaN(a)) || (a<amin) )	ok=0;

	      if (ok==1) {
		 var d2=new Date(a,m-1,j);
		 j2=d2.getDate();
		 m2=d2.getMonth()+1;
		 a2=d2.getYear();
		 if (a2<=100) {a2=1900+a2}
		 if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
		    ok=0;
		 }
	      }
	      if (ok==1)	return true;
	      if (ok!=1)	return false;
	   }




document.write('<script language="Javascript" src="commun/scripts/open.js"></script>');