function login(f){
	//document.forms[f].submit();
	document.getElementById(f).submit();
}
function overImg(img){
	var id=img;
	img = document.getElementById(img).src;
	var ind = img.indexOf('.gif');
	img = img.substring(0,ind) + '_over.gif';
	document.getElementById(id).src =img;
return(true);
}
function outImg(img){
	var id = img ;
	img = document.getElementById(img).src;
	var ind = img.indexOf('_over.gif');
	img = img.substring(0,ind) + '.gif';
	document.getElementById(id).src =img;
	return(true);
}

function addFav(){
	if(document.all){
		window.external.AddFavorite(location.href, document.title);
	}
	else {
		alert('Ctrl + D pour ajouter le site à vos favoris.');
	}
	return(true);
}

function addHomePage(t){
	if(document.all){
		t.style.behavior='url(#default#homepage)';
		t.setHomePage(location.href);
	}
	else {
		alert('menu :outils > options ');
	}
	return(true);
}

// inscription newsletter
function inscriptionNews(e,d,t){
	e = document.getElementById(e).value ;
	if(t.length<2) {t='all';}
	if(verifmail(e)){
		url = 'incV2/inscriptionNews.asp?e='+ e + '&t=' + t ;
		httpRequest(url,d);
	}
	else {
		alert('adresse mail incorrecte.');
	}
return(true);
}

function clearInput(i){
	if(document.getElementById(i)){
		s =document.getElementById(i).style;
		if(s.readOnly =='true' || s.disabled=='true'){
		}
		else {
			document.getElementById(i).value='';
		}
	}
}

function verifmail(email)
	{
	var isNav = (navigator.appName.indexOf("Netscape") !=-1);
		if (isNav){
		
			// vérif validité email par STRING
            var arobase = email.indexOf("@")
            var point = email.lastIndexOf(".")
            if((arobase < 3)||(point + 2 > email.length) ||(point < arobase+4)) { 
              return false;}
            else {                                 	
              return true;}
			}
		else{
			var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/
			return (reg.exec(email)!=null)
		}
}

function httpRequest(url,div){

	var xhr_object = getHTTPObject();

	xhr_object.open("GET", url, true);
	
	xhr_object.onreadystatechange = function() {
	   if(xhr_object.readyState == 4) 
	   {
	   	document.getElementById(div).innerHTML = xhr_object.responseText ;
	   }
	}
	
	xhr_object.send(null);
}




function getHTTPObject() {
	var httpObj = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			httpObj = new XMLHttpRequest();
        } catch(e) {
			httpObj = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	httpObj = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		httpObj = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		httpObj = false;
        	}
		}
    }
    if(!httpObj){
    	alert('httpRequest n\'est pas supporté par votre navigateur');
    }
	return httpObj;
} 

/* convertisseur euro */
function euroConvert(c,s){
	s = s.replace(',','.');
	if(isNaN(s)){
		alert('je ne peux convertir que des nombres');
	}
	if(c=='ef'){
		doc = 'sFrancs'
		s = s*100*6.55957;
	}
	else {
		doc = 'sEuros'
		s = s*100/6.55957;
	}
	s = Math.round(s)/100;
	document.getElementById (doc).value = s;
}

function showDiv(d){
	var st = document.getElementById(d).style.display;
	
		if (document.getElementById(d).style.display != 'block') {document.getElementById(d).style.display = 'block';}
		else {document.getElementById(d).style.display = 'none';}
		return(true);
}

function openDemo(u,w,h){
	if (!w){w=790;}
	if(!h){h=540;}
	var tabUrlDemo = new Array('http://www.toutapprendre.com/demo/demo_bureautique.html','http://www.toutapprendre.com/demonstration/harry/harry.asp','http://cours.toutapprendre.com/demo/assimil/eaz0a/IntroDemoAssimilV2.html','http://www.toutapprendre.com/demonstration/internet/tuto.asp','http://www.toutapprendre.com/tol/demo/demo_learnorama.html','http://www.toutapprendre.com/demonstration/actiononline/gestion.html','http://www.toutapprendre.com/demonstration/actiononline/finance.html','http://cours.toutapprendre.com/demo/assimil/eazDrop/demoDragDrop.asp','http://leofrance.reward-net.com/data/Reflex_Flash/Business/les_a01/les_a01.flo','http://cours.toutapprendre.com/demo/commest/demo.html','http://www.toutapprendre.com/demonstration/bridge/launchDemo.asp','http://www.toutapprendre.com/bridge/quiz.html')
	//u = url 0=bureautique, 1=harry, 2=assimil, 3=internet, 4=vente, 5=gestion, 6 = finance, 7=assimil drag-drop
	url = tabUrlDemo[u];
	
	options = 'toolbar=no, menubar=no, directories=no, location=no, width=' + w + ', height=' + h ;
	var wDemo = window.open (url,'demonstration',options);
	if (!wDemo){
		alert('un logiciel anti-popup empêche l\'ouverture de la fenêtre de démonstration');
	}
	
}

function demo(url){
	
	options = 'toolbar=no, menubar=no, directories=no, location=no, width=790, height=540';
	if(url.indexOf('cnpmusic.com')>0){
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=780, height=600';
	}
	else if (url.indexOf('eduV2')>0){
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=880, height=650';
	}
	else if (url.indexOf('www.elephorm.com')>0){
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=880, height=650';
	}
	else if (url.indexOf('demo-multimedia.asp?video=')>0){
	//elephorm new
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=880, height=650';
	}	
	else if (url.indexOf('netpro')>0){
	//commest
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=880, height=650';
	}	
	
	else if (url.indexOf('demo-vie-pro')>0){
	// smart canal
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=1020, height=790';
	}		
	
	else if (url.indexOf('chinois')>0){
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=1020, height=620';
	}	
	else if (url.indexOf('video2brain.net')>0){
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=1024, height=768';
	}	
	else if (url.indexOf('demo-multimedia.asp?id=')>0){
		// video2brain
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=1024, height=768';
	}				
	var wDemo = window.open (url,'demonstration',options);
	if (!wDemo){
		alert('un logiciel anti-popup empêche l\'ouverture de la fenêtre de démonstration');
	}	
}

function launchCours(u,n){
/* rep,  num, */
/*	url = 'http://cours.toutapprendre.com/' + c + '/common/V2/launch.asp?c=' + u + '&n=' + n; */
url = u + '&n=' + n; 
	var options = 'top=0,left=0,resizable=yes, toolbar=no, scrollbars=yes, menubar=no, location=no, statusbar=no';
	options = options + ' , width=' + screen.width + ', height=' + screen.height ;
	var LancementCoursTA = window.open(url,'assimil',options);
}

function openW(u,w,h){
	options = 'toolbar=no, menubar=no, directories=no, location=no, scrollbars=yes, width=' + w +', height=' + h;
	window.open (u,'toutapprendre',options);
}
function renouveler(n,p, div){
	// n =num user, p = pk cours, div destination
	data = 'n=' + n + '&p=' + p ;
	httpRequestPost('/incV2/divRenouveler.asp',div,data);
}

function httpRequestPost(url,div,data){

	var xhr_object = getHTTPObject();

	xhr_object.open("POST", url, true);
    xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr_object.onreadystatechange = function() {
	   if(xhr_object.readyState == 4) 
	   {
	   	document.getElementById(div).innerHTML = xhr_object.responseText ;
	   }
	}
	xhr_object.send(data);
}

function fenetreCours(n,c,pk,lien){

		var options = 'top=0,left=0,resizable=yes, toolbar=no, scrollbars=yes, menubar=no, location=no, statusbar=no';
	//	options = options + ' , width=' + screen.width + ', height=' + screen.height ;
		
		if(c.indexOf('nformit')>0 ||c.indexOf('harry')>0) {
		  options = options + ' , width=810, height=650' ;
    }
		else{
	 	options = options + ' , width=' + screen.width + ', height=' + screen.height ;
    }
		
		if ( c.charAt(4)==':'){ url = c  ;	}
		else { url = 'http://www.toutapprendre.com/' + c;}
		if(c.indexOf('taptouche')>0) {
			// tapTouche
			options = '';
			//url = url + 'connect2.asp?ID_partner=TOUTAPPRENDRE&ID_School_Name=&ID_Group_Name=&ID_Prof=&Prof_First_Name=&Prof_Last_Name=&User_First_Name=&User_Last_Name=&ADDR_HTTP=http://www.toutapprendre.com/formation.asp@5053';
			url = url + '&Id_User=' + n + '&User_Name=' + jsNom + ' ' + jsPrenom;
			
		}
		else if (c.indexOf('vod.elephorm')>0){
			url = url ;
		}
/*
		else if (pk=5057){
			options = '';
			url = url + '&num=' + n + '&pkc=' + pk;
			window.location.href = url;
			return(false);
		}
		*/

		else {
			if (url.indexOf('?') > 0) { url = url + '&num=' + n + '&pkc=' + pk;}
			else {url = url + '?num=' + n  + '&pkc=' + pk;}
		}
		try{
	 	var oWin = window.open (url, 'cours',options);
		 	if(oWin==null || typeof(oWin)=="undefined") {
		 	alert(' la fenêtre du cours ne peut s\'ouvrir \n Vérifier la configuration de vos logiciels "anti-popup"');
		 	}
	 	}
	 	catch(e){
	 		e = null;
	 		alert(' la fenêtre du cours ne peut s\'ouvrir \n Vérifier la configuration de vos logiciels "anti-popup"');
	 	}
}


function toLogBox(){
		window.scrollTo (0,0);
		document.getElementById ('email').style.background = '#FFFF00';
		document.getElementById ('email').style.color = 'red';
		document.getElementById ('email').value = 'identifiant (email)';
		document.getElementById ('password').style.background = '#FFFF00';
		document.getElementById ('formLogin').focus;
}

function mailContact(p1, p2, ext, texte){
	var tg="<";     
	var arob="@";
	document.write(tg+"a hr"+"ef=mai"+"lto:"+p1);
	document.write(arob+p2+ext+">"+texte+tg+"/a>");

}
function goUrl(u){
	    window.open(u);
}


function conseillerTel(){
	var nom = document.getElementById('ctN').value;
	var email = document.getElementById('ctM').value;
	var tel = document.getElementById('ctT').value;
	//var h = document.getElementById('ctH').value;
	var h = document.getElementById('ctH').options[document.getElementById('ctH').selectedIndex].value;
	
	var obj  = document.getElementById('ctObjet').value;
	var pays = document.getElementById('ctPays').value;
	var autre = document.getElementById('ctAutre').value;
	var page = document.location.href;
	
	var m = '';
	if(nom.length<2 || tel.length<8){
		m = m + 'Merci de complèter le formulaire.';
	}
	if(!verifmail(email)){
		m = m + '\n Adresse email incorrecte' ;
	}
	if (m!=''){
		alert(m);
	}
	else {
		url = 'incV2/mailConseiller.asp?e='+ email + '&t=' + tel + '&n=' + nom + '&h=' + h + '&obj=' + obj + '&pays=' + pays + '&autre=' + autre + '&page=' + page;
		httpRequest(url,'conseiller');
	}
	return(true);
}
function selCtObjet(){

	if (document.getElementById('ctObjet').selectedIndex == 3){
		document.getElementById('divCtAutre').style.display = 'block';
	}
	else if(document.getElementById('ctObjet').selectedIndex == 2){
		document.getElementById('infosPaiement').style.display = 'block';
		document.getElementById('divCtAutre').style.display = 'none';
	}
	else {
		document.getElementById('divCtAutre').style.display = 'none';
	}

}

function printFact(pka){
	var u = 'http://www.toutapprendre.com/facture/facture_client.asp?pka=' + pka;
	window.open (u,'Facture');
}
function afficheTimer(div, t){
try{
	//var aff = setTimeout("showDiv('"+ div + "');",t);
	
	var aff = setTimeout(function(){document.getElementById(div).style.display='block';},t);
	}catch(e){alert(e);e=null;}
}