// $Id: util.php,v 1.23 2002/11/19 14:20:03 xylome Exp $

var random_number="ord="+(Math.round(Math.random()*10000000000))+"?";

base_url = 'http://bao.orange.fr/Service/' ;

var pop_width    = "690";
var pop_height   = "440";
var url_article  = "envoyer_article.php";
var url_image    = "envoyer_image.php"; 
var url_imprimer = "imprimer_page.php";
var url_voter    = "vote.php";

function envoyer_article( id_chaine, titre_article, estat_page, estat_class, image_file, abo  ){
  var myUrl = base_url + url_article + "?id_chaine=" + id_chaine + "&titre_article=" + escape( titre_article, 1 ) + "&estat_class=" + estat_class + "&estat_page=" + estat_page + "&image_file=" + escape(image_file,1 )+ "&url=" + escape(document.location,1) + "&abo=" + abo ;
  Open_Window( myUrl );
}

function envoyer_image( id_chaine, titre_article, estat_page, estat_class, image_file, abo, nocache  ){
  var myUrl = base_url + url_image + "?id_chaine=" + id_chaine + "&titre_article=" + escape( titre_article, 1 ) + "&estat_class=" + estat_class + "&estat_page=" + estat_page + "&image_file=" + escape(image_file,1 )+ "&url=" + escape(document.location,1) + "&abo=" + abo + "&nocache=" + nocache ;
  Open_Window( myUrl );
}

function imprimer( id_chaine, id_texte, estat_page, estat_class, titre_article ){
  var myUrl = base_url + url_imprimer + "?id_chaine=" + id_chaine + "&estat_class=" + estat_class + "&estat_page=" + estat_page + "&url=" + escape(document.location,1) + "&id_texte=" + id_texte + "&titre_article=" + titre_article;
  Open_Window( myUrl );
}

function voter( id_chaine, article_id, titre_article, estat_page, estat_class, image_file ){
  var myUrl = base_url + url_voter + "?id_chaine=" + id_chaine + "&estat_class=" + escape(estat_class,1) + "&estat_page=" + escape(estat_page, 1) + "&url_article=" + escape(document.location,1) + "&article_id=" + article_id + "&titre_article=" + escape(titre_article, 1)+ "&image_file=" + escape(image_file,1 );
  // alert( myUrl ) ;
   document.write('<IFRAME SRC="'+myUrl+'" WIDTH=470 HEIGHT="50" MARGINWIDTH="0" MARGINHEIGHT="0" HSPACE="0" VSPACE="0" FRAMEBORDER="0" SCROLLING="no" BORDERCOLOR="#000000"></IFRAME>');
}


function NewWin(theURL,winName,features){
	window.open(theURL,winName,features);
}

function Open_Window(File){
	window.open(File,'_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width='+ pop_width +',height='+pop_height);
}

function ouvre(theURL,winName,features){
	window.open(theURL,winName,features);
}

function validmail(){
	if (document.myform.emails.value == '' || document.myform.emails.value == 'adresse@destinataire.fr'){
		alert('Remplissez les adresses mails de vos destinataires SVP');
 		return false; 
	}
	var ok4parsing = false;
	var myArray = new Array();
	//default
	myArray[0] = document.myform.emails.value;
	if( document.myform.emails.value.lastIndexOf(",") != -1 ){
		myArray = document.myform.emails.value.split(",");
		ok4parsing = true;
	}
	if( document.myform.emails.value.lastIndexOf(";") != -1 ){
		myArray = document.myform.emails.value.split(";");
		ok4parsing = true;
	}
	for( k = 0; k < myArray.length; k++){
		if (  ! EmailOk( myArray[k] ) ){	
			alert("L'email " + myArray[k] + " n'est pas valide..." );
			return false;
		}
	}

	if (document.myform.mail.value == '' || document.myform.mail.value == 'votre-adresse@destinataire.fr' || !EmailOk(document.myform.mail.value )){
		alert('Remplissez/corrigez votre adresse mail SVP');
		return false;
	}
	if (document.myform.nom.value == '' || document.myform.nom.value == 'votre_nom'){
        	alert('Remplissez votre nom SVP');
        	return false;
	}
	if (document.myform.prenom.value == '' || document.myform.prenom.value == 'votre_prenom'){
        	alert('Remplissez votre prénom SVP');
        	return false;
	}

	return true;
}


function EmailOk(value)
{
	var pos_aro = 0;
    	var pos_pt = 0;
	if (value.length == 0) return false;
    	// On vérifie que l'adresse E-Mail semble correcte
    	for (i = 1; i < value.length && pos_aro == 0; i++){
        	if (value.charAt(i) == '@')  pos_aro = i;
    	}
	for (i = value.length - 3; i > 2 && pos_pt == 0; i--){
        	if (value.charAt(i) == '.') pos_pt = i;
    	}
    	if (pos_aro == 0 || pos_pt == 0 || pos_pt <= pos_aro + 1){
                return false;
    	}
	else return true ;
} // fin EmailOk

function check(val)
{
  // check radios button quand click sur lien associé
 	if (val == 1)
	document.form.CHOIX[0].checked = true ;
	if (val == 2)
        document.form.CHOIX[1].checked = true ;
	if (val == 3)
        document.form.CHOIX[2].checked = true ;
}

function verif_vote()
{
    if ( ( document.form.CHOIX[0].checked == false ) && (  document.form.CHOIX[1].checked == false ) && ( document.form.CHOIX[2].checked == false ) )
	{
		alert("Veuillez faire un choix SVP");
		return false ;
	}
	return true ;
}
