/***********************************************
* BENDAHMANE Abderrahmane code source pour(http://www.taseek.com)
* Pour tout usage de ce code, veuillez ne pas supprimer cette entête
* Veuillez respecter les droit d'auteur de ce code source
* Toute modification du code d'origine doit être signalée en bas de cette banière  
* create by BENDAHMANE Abderrahmane 18/07/2008 
* Merci
***********************************************/

var xhr1,xhr2,xhradd,xhrdel,xhredit,xhrpage;
var myiface;
var myifacesave;
var origindiv;
var origincib;
var maform;
var macib;

var curlink;
var curid=-1;
var cur_enab;
var cur_new;
var cur_formation;

var curlink_safe;
var curid_safe;
var look_safe;

var urle='%22edit.php?id=LogoCont&amp;cid='; 
var cibe='%22EditLogoCont%22';
		
/////////////////////////////////////////////////////////////
function new_ajax()
{	     
	var xhr;
	try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e) 
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  xhr = new XMLHttpRequest();   }
          catch (e3) {  xhr = false;   }
        }
     }
	 return(xhr);
}

function ajax_post(adr, params,rep,xhr)
{	     
     xhr.onreadystatechange  =rep;
     xhr.open("POST", adr,  true); 
     xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");   
     xhr.send(params); 
}


function write_html(htmltext,bal_id,add_e)
{
   var my_bal=document.getElementById(bal_id);
   if(add_e) my_bal.innerHTML+=htmltext; else my_bal.innerHTML=htmltext;
}

function ajax_msg(xhr,mycib,mafunc)
{
     if(xhr.readyState  == 4)
     {
         if(xhr.status  == 200)
		 { 
			var rep=xhr.responseText;
			write_html(rep,mycib,false);
			if(mafunc) mafunc();
		 }else write_html("Erreur lors du chargement... veuillez reactualiser la page(F5)",mycib,false);	 
     }
}

function ajax_loading(mycib)
{
	origindiv=document.getElementById(mycib).innerHTML;
	origincib=mycib;
	write_html("<img src='images/chargement.gif' alt='chargement' >",mycib,false);
}

function ajax_restore()
{
	write_html(origindiv,origincib,false);
}

function add_param(param,param_name,param_val)
{
	if(param!="")
		param+="&";
	
	param+=param_name;
	param+="=";
	if(param_val==true) param_val=1; 
	if(param_val==false) param_val=0; 
	param+=escape(param_val);
	//param+=param_val;
	
	return(param);
}
//////////////////////////////////////////////
function look_return(cib)
{
	document.getElementById(cib).innerHTML=looksafe;	
}

function look_page(url,cib)
{
	macib=cib;
	looksafe=document.getElementById(macib).innerHTML;
	
	ajax_loading(macib);
	xhrpage=new_ajax();
	ajax_post(url, "",page_msg,xhrpage);
}

function page_msg()
{
	ajax_msg(xhrpage,macib);
}

////////////////////////////////////////////
function look_edit(monurl)
{
	
	xhredit=new_ajax();
	var moncib="./script/canedit.php";
	var param="macible="+encodeURIComponent(monurl);
	//var moncib="script/canedit.php";
	//alert(moncib);
	
	ajax_post(moncib, param,wrkedit_msg,xhredit);
}

function wrkedit_msg()
{
	ajax_msg(xhredit,"canedit");
}
/////////////////////////////////////////////
function look_connected()
{
	xhr1=new_ajax();
	ajax_post("./script/conected.php", "",look_msg,xhr1);
}

function look_msg()
{
	ajax_msg(xhr1,"connected");
}

/////////////////////////////////////////////
function look_logos()
{
	ajax_loading("contlogostoedit");
	xhr2=new_ajax();
	ajax_post("./script/logos.php", "",logos_msg,xhr2);
}

function logos_msg()
{
	ajax_msg(xhr2,"contlogostoedit");
}

function loadinglogo()
{
	var maban=document.getElementById("itface");
	myiface=maban.innerHTML;
	maban.innerHTML="";
	look_logos();
}
////////////////////////////////////////////////////////////////////////
function del_logo(idt)
{
	var param="";
	xhrdel=new_ajax();
	
	param=add_param(param,"id",idt);
	ajax_loading("itface");
	ajax_post("script/del_logo.php", param,del_msg,xhrdel);
}

function del_msg()
{
	ajax_msg(xhrdel,"itface",look_logos());
}
///////////////////////////////////////////////////////////////////////
function insert_logo()
{
	var param="";
	xhradd=new_ajax();
	
	mylink=document.getElementById("inslink").value;
	myalt=document.getElementById("insalt").value;
	mysrc=document.getElementById("Elogo").src;
	myextlink=document.getElementById("ext_link").checked;
	mynew=document.getElementById("ext_new").checked;
	myformation=document.getElementById("ext_formation").checked;
	
	param=add_param(param,"link",mylink);
	param=add_param(param,"alt",myalt);
	param=add_param(param,"src",mysrc);
	param=add_param(param,"extlink",myextlink);
	param=add_param(param,"extnew",mynew);
	param=add_param(param,"extformation",myformation);
	
	ajax_loading("itface");
	ajax_post("script/add_logo.php", param,insert_msg,xhradd);
}

function insert_msg()
{
	ajax_msg(xhradd,"itface",look_logos());
}
///////////////////////////////////////////////////////////////////////
function edit_logo(idt)
{
	var param="";
	xhredit=new_ajax();
	
	mylink=document.getElementById("inslink").value;
	myalt=document.getElementById("insalt").value;
	mysrc=document.getElementById("Elogo").src;
	myextlink=document.getElementById("ext_link").checked;
	mynew=document.getElementById("ext_new").checked;
	myformation=document.getElementById("ext_formation").checked;
	
	param=add_param(param,"link",mylink);
	param=add_param(param,"alt",myalt);
	param=add_param(param,"src",mysrc);
	param=add_param(param,"id",idt);
	param=add_param(param,"extlink",myextlink);
	param=add_param(param,"extnew",mynew);
	param=add_param(param,"extformation",myformation);

	ajax_loading("itface");
	ajax_post("script/edit_logo.php", param,edit_msg,xhredit);
}

function edit_msg()
{
	ajax_msg(xhredit,"itface",look_logos());
}
////////////////////////////////////////////////////////////////////////
function UploadPicture()
{  
   maform=document.getElementById("kk").innerHTML;
   
   ajax_loading("ElogoCont");
   document.getElementById("formx1").submit();
}

function img_upload_msg(myerr)
{
	document.getElementById("kk").innerHTML=maform;
	
	if(myerr==""){
		write_html('<img id="Elogo" src="pub/uptemp.jpg?num='+new Date().getTime()+'" alt="" border="1" height="60"><br><br>',"ElogoCont",false);   
		document.getElementById("errmsg").innerHTML="";
	}else{
		document.getElementById("errmsg").innerHTML=myerr;
		ajax_restore();
	}
}
//////////////////////////////////////////////////////////////
function IfaceSave()
{
	myifacesave=document.getElementById("itface").innerHTML;
	document.getElementById("addelt").style.visibility="hidden";
	curlink_safe=curlink;
	curid_safe=curid;
}

function IfaceRestore()
{
	write_html(myifacesave,"itface",false);
	document.getElementById("addelt").style.visibility="visible";
	curlink=curlink_safe;
	curid=curid_safe;
}

function getInf(myid, mylink, IsExtLink, IsNew, IsFormation)
{
   curlink=mylink;
   document.getElementById("addelt").style.visibility="visible";
   write_html(myiface,"itface",false);
   var my_bal=document.getElementById("logo"+myid);   
   write_html(my_bal.alt,"logodescription",false);
   write_html(mylink,"logolink",false);
   
   SetExtLink(IsExtLink,'disabled');
   SetNewLink(IsNew,'disabled');
   SetFormationLink(IsFormation,'disabled');
   document.getElementById("Elogo").src=my_bal.src;
   curid=myid;
}

function SetExtLink(val,is_enab)
{
	if(val==1)
	{
		if(is_enab==''){
		  write_html('<input name="ext_link" type="checkbox" id="ext_link" onclick="SetExtLink(this.checked,\'\')" checked="true">','my_ext_link',false);
		  write_html("<input  id='inslink' class='text_11' type='text' size='50' value='"+curlink+"' id='img_link'>","logolink",false);
		}else{
		  write_html('<input name="ext_link" type="checkbox" id="ext_link" onclick="SetExtLink(this.checked,\'\')" checked="true" disabled="disabled">','my_ext_link',false);
	      write_html(curlink,"logolink",false);
		}
		
		write_html('<b>Lien:</b>','mlink',false);	
		
	}else{
		if(is_enab=='')
		{
		  write_html('<input name="ext_link" type="checkbox" id="ext_link" onclick="SetExtLink(this.checked,\'\')">','my_ext_link',false);			
		}else{
		  write_html('<input name="ext_link" type="checkbox" id="ext_link" onclick="SetExtLink(this.checked,\'\')" disabled="disabled">','my_ext_link',false);
		}
		

		if((curid>=0)&&(is_enab=='')){ 
			write_html('<a href="javascript:look_page('+urle+curid+'%22,'+cibe+')"><img src="images/b_edit.png" alt="&eacute;diter" width="16" height="16" border="0"></a>','logolink',false); 
			write_html('<b>Contenu:</b>','mlink',false);
		}else{ 
			write_html('','logolink',false); 
			write_html('','mlink',false);
		}
		
		write_html("<input  id='inslink' class='text_11' type='text' size='50' value='"+curlink+"' id='img_link' style='visibility:hidden'>","logolink",true);
	}
	
	cur_enab=val;
}

function SetNewLink(val,is_enab)
{
	if(val==1)
	{
		if(is_enab==''){
		  write_html('<input name="ext_new" type="checkbox" id="ext_new" onclick="SetNewLink(this.checked,\'\')" checked="true">','my_new',false);
		}else{
		  write_html('<input name="ext_new" type="checkbox" id="ext_new" onclick="SetNewLink(this.checked,\'\')" checked="true" disabled="disabled">','my_new',false);
		}
				
	}else{
		if(is_enab=='')
		{
		  write_html('<input name="ext_new" type="checkbox" id="ext_new" onclick="SetNewLink(this.checked,\'\')">','my_new',false);			
		}else{
		  write_html('<input name="ext_new" type="checkbox" id="ext_new" onclick="SetNewLink(this.checked,\'\')" disabled="disabled">','my_new',false);
		}
	}
	
	cur_new=val;
}

function SetFormationLink(val,is_enab)
{
	if(val==1)
	{
		if(is_enab==''){
		  write_html('<input name="ext_formation" type="checkbox" id="ext_formation" onclick="SetFormationLin(this.checked,\'\')" checked="true">','my_formation',false);
		}else{
		  write_html('<input name="ext_formation" type="checkbox" id="ext_formation" onclick="SetFormationLin(this.checked,\'\')" checked="true" disabled="disabled">','my_formation',false);
		}
				
	}else{
		if(is_enab=='')
		{
		  write_html('<input name="ext_formation" type="checkbox" id="ext_formation" onclick="SetFormationLin(this.checked,\'\')">','my_formation',false);			
		}else{
		  write_html('<input name="ext_formation" type="checkbox" id="ext_formation" onclick="SetFormationLin(this.checked,\'\')" disabled="disabled">','my_formation',false);
		}
	}
	
	cur_formation=val;
}


function showedit(myid)
{ 
	IfaceSave();
    var imgdesc=document.getElementById("logodescription").innerHTML;
	var imglink=document.getElementById("logolink").innerHTML;
	
    write_html("<input id='insalt' class='text_11' type='text' size='50' value='"+imgdesc+"' id='img_alt'>","logodescription",false);
    if(cur_enab) write_html("<input  id='inslink' class='text_11' type='text' size='50' value='"+imglink+"' id='img_link'>","logolink",false);	 
	SetExtLink(cur_enab,'');
	SetNewLink(cur_new,'');
	SetFormationLink(cur_formation,'');
			   
	write_html('<input type="button" value="Annuler" onclick="IfaceRestore()"><input type="button" value="Valider"  onclick="edit_logo('+curid+')">',"logoact",false);	 

	write_html('<input  class="text_11" name="fichier" size="25" type="file" onchange="UploadPicture()">',"logoimg",false);	
	write_html('<b>Image:Ax60</b> ',"logoimg_c",false);	
}

function logoinsert()
{
   IfaceSave();
   curlink='http://'; curid=-1;
   write_html(myiface,"itface",false); 
   document.getElementById("Elogo").src="pub/temp.jpg";	
	
   write_html("<input  id='insalt' class='text_11' type='text' size='50' value='' id='img_alt'>","logodescription",false);
   write_html("<input  id='inslink' class='text_11' type='text' size='50' value='http://' id='img_link'>","logolink",false);	 
   write_html('<input type="button" value="Annuler" onclick="IfaceRestore()"><input type="button" value="Valider"  onclick="insert_logo()">',"logoact",false);	   SetExtLink(false,'');
   SetNewLink(true,'');
   SetFormationLink(false,'');
			  
   write_html('<input class="text_11" name="fichier" size="25" type="file" onchange="UploadPicture()">',"logoimg",false);	
   write_html('<b>Image:Ax60</b> ',"logoimg_c",false);	
}

function showdel(myid)
{ 
	IfaceSave();
    write_html('<input type="button" value="Valider"  onclick="del_logo('+curid+')"><input type="button" value="Annuler" onclick="IfaceRestore()">',"logoact",false);	
    write_html('<div class="redalert">Voulez vous vraiment supprimer ce logo?</div>',"logoimg",false);	
}

////////////////////////////////////////////////////////////////////////////////////////


