/*********************************************************************************************
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;
		}

	}

	function BO_JS_Process_FLASH(LabelFieldTag,Tag_Name){
		var FormName = 'document.ContentEdit';
		var HiddenField = eval(FormName+'.HIDDEN_'+Tag_Name);
		var HeightFlashField = eval(FormName+'.HEIGHT_'+Tag_Name);
		var WidthFlashField = eval(FormName+'.WIDTH_'+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='';
			HeightFlashField .value = '';
			WidthFlashField.value = '';
		}
	}

	//Check Field with tag FLASH
	function BO_JS_Process_FLASH2(LabelFieldTag,Tag_Name){
		var FormName = 'document.ContentEdit';
		//alert('Tag_Name'+Tag_Name);
		
		var HeightFlashField = eval(FormName+'.HEIGHT_'+Tag_Name);
		var WidthFlashField = eval(FormName+'.WIDTH_'+Tag_Name);
		var Msg = '';
		if (HeightFlashField.value == '')
			Msg += '  le champ Hauteur\n';
		if (WidthFlashField.value == '')
			Msg += '  le champ Largeur\n';
		
		if (Msg != '')
		{
			alert ('Vous devez remplir :\n'+Msg);
			return false;
		}
		else
		{
			if (!HeightFlashField.value.match(/[0-9]+/))
			{
				alert ('Le champs Hauteur n\'est pas au bon format');
				return false;
			}
			if (!WidthFlashField.value.match(/[0-9]+/))
			{
				alert ('Le champs Largeur n\'est pas au bon format');
				return false;
			}
		}
		return true;
	}

	//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 OpenWindowForInternalLink(winName, winTarget, width, height)
			   {
				   var myWindow = window.open(winName, winTarget,
				   'height='+height+',width='+width+',status=no,scrollbars=no,toolbar=no,menubar=no,location=no, resizable=yes');
					if(window.focus){
						myWindow.focus();
					}
		}


	//fonction permettant d'ouvrir une nouvelle fenetre du navigateur
	//function OpenWindow(winName, winTarget, width, height,left='0',top='0',statusbar='yes',scrollbars='yes',toolbar='yes',menubar='yes', location='yes', resize='yes')
	function OpenWindow(winName, winTarget, width, height, params)
  {
		if (params != null)
		{
			//alert("height="+height+",width="+width+","+params);
			var myWindow = window.open(winName, winTarget, 
			"height="+height+",width="+width+","+params);
		}
		else
		{
			var myWindow = window.open(winName, winTarget, 
			"height="+height+",width="+width+",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='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='BOContentEdit.php4?TypeAction=preview&coe_i_id='+document.ContentEdit.coe_i_id.value;
					document.ContentEdit.target=BOPreview;
				break;
				default:
					document.ContentEdit.action='BOContentAction.php4';
					document.ContentEdit.target=BOPreview;
			}
			return true;
		}
		else{
			alert('Vous devez sélectionner un gabarit');
			return false;
		}


	}

	//Remplace un chaine par une autre chaine
	function replace(expr,a)
		{

           var i=0;
           while (i!=-1) {
              i=expr.indexOf(a,i);
              if (i>=0) {
                 expr=expr.substring(0,i)+expr.substring(i+a.length);
              }
           }
           return expr;
        }

//Alimente la liste des templates
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('Selectionner une Template','');
			for (i=0;i<TemplateID.length;i++) {
				
				if (TemplateTypeID[i]==num){
					boxlength++;
					if (TemplateID[i]==IdTemplate){
						index = boxlength;
					}
					oForm.tpl_i_id_coe.options[boxlength] = new Option(replace(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='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;
	   }

	   
	function ChangeSelect(url, id)
	{
		if (OW_status == 1)	
		{
			OW_status = 2;
			OpenWindow(url + "?coe_i_id=" + id, "Parameters", "280", "280", "left=0,top=0,status=yes,scrollbars=no,toolbar=no,menubar=no,location=no,resizable=no");
		}
		else
			OW_status = 1;
	}		

document.write('<script language="Javascript" src="/commun/scripts/open.js"></script>');
