var friendContact = 0;

function onoffFriendContact() {
  if(friendContact == 0) {
    friendContact = 1;
    show('contactfriend');
  } else {
    friendContact = 0;
    hide('contactfriend');
  }
 }
 
function openPopup(my_url,win_name,x,y)
{
  open_editwin(my_url,win_name,x,y,50,50,'no');
}

function open_editwin(my_url,win_name,width_x,height_y,top_pos,left_pos,scrollbars)
{
  var editwin = "";
  editwin = editwin + "width=" + width_x;
  editwin = editwin + ",height=" + height_y;
  editwin = editwin + ",resizable=yes";
  editwin = editwin + ",scrollbars=yes";
  editwin = editwin + ",menubar=no";
  editwin = editwin + ",toolbar=no";
  editwin = editwin + ",directories=no";
  editwin = editwin + ",location=no";
  editwin = editwin + ",status=no";
  editwin = editwin + ",top=" + top_pos;
  editwin = editwin + ",left=" + left_pos;
  editwin_win = window.open(my_url,win_name,editwin);
  editwin_win.focus();
  editwin_win.opener = self;
}

function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()
//With nested layers for netscape, this function hides the layer if it's visible and visa versa
function showHide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	if(obj.visibility=='visible' || obj.visibility=='show') obj.visibility='hidden'
	else obj.visibility='visible'
}
//Shows the div
function show(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.visibility='visible'
}
//Hides the div
function hide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.visibility='hidden'
}


function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"block";
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display? "":"block";
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display? "":"block";
}
}

/***************************************************/
/* Particulier, outils pratiques, calculer tarif : */
/* inhibe les options selon la selection           */
/* Construit à partir de www.laposte.fr (cgarriga) */
/***************************************************/


function initCalculTarif() {
	if (document.getElementById('cal')) {
		document.getElementById('cal').onsubmit=calculer_tarif_verifForm;
	}
}


/* destination */
function calculer_tarif_inhibiteur_dest() {
	var myform = document.formulaire;
	var france = myform.destination[0];
	var domtom = myform.destination[1];
	var etranger = myform.destination[2];

	if (france.checked == true) {
		myform.country[0].disabled = true;
		myform.country[1].disabled = true;
		myform.nature[3].disabled = true;
		myform.nature[2].disabled = true;
		myform.nature[1].disabled = false;
		myform.nature[0].disabled = false;
		myform.nature[0].checked = true;
		myform.recommendation.checked = false;
		myform.recommendation.disabled = true;
		myform.ack.checked = false;
		myform.ack.disabled = true;
		myform.type[0].checked = true;
		myform.type[1].disabled = false;
		myform.type[2].disabled = false;
		myform.type[3].disabled = false;
	}
	else if (domtom.checked == true) {
		myform.country[0].disabled = false;
		myform.country[1].disabled = true;
		myform.nature[3].disabled = true;
		myform.nature[2].disabled = true;
		myform.nature[1].disabled = false;
		myform.nature[0].disabled = false;
		myform.nature[0].checked = true;
		myform.recommendation.checked = false;
		myform.recommendation.disabled = true;
		myform.ack.checked = false;
		myform.ack.disabled = true;
		myform.type[0].checked = true;
		myform.type[1].disabled = false;
		myform.type[2].disabled = false;
		myform.type[3].disabled = false;
	}
	else if (etranger.checked == true) {
		myform.country[0].disabled = true;
		myform.country[1].disabled = false;
		myform.nature[3].disabled = false;
		myform.nature[2].disabled = false;
		myform.nature[1].disabled = true;
		myform.nature[0].disabled = true;
		myform.nature[2].checked = true;
		myform.type[0].checked = true;
		myform.type[1].disabled = true;
		myform.type[2].disabled = true;
		myform.type[3].disabled = true;
		myform.recommendation.checked = false;
		myform.recommendation.disabled = true;
		myform.ack.checked = false;
		myform.ack.disabled = true;
	}
}

/* nature de l'envoi */
function	calculer_tarif_inhibiteur_nature()
{
	var myform = document.formulaire;
	var france = myform.destination[0];
	var domtom = myform.destination[1];

	if (myform.nature[1].checked == true && (france.checked == true || domtom.checked == true)) {
		myform.type[0].checked = true;
		myform.type[1].disabled = true;
		myform.type[2].disabled = true;
		myform.type[3].disabled = true;
		myform.recommendation.checked = false;
		myform.recommendation.disabled = true;
		myform.ack.checked = false;
		myform.ack.disabled = true;
	}
	else if (myform.nature[0].checked == true && (france.checked == true || domtom.checked == true)) {
		myform.type[0].checked = true;
		myform.type[1].disabled = false;
		myform.type[2].disabled = false;
		myform.type[3].disabled = false;
	}
}

/* recommandes */
function	calculer_tarif_inhibiteur_reco()
{
	var myform = document.formulaire;
	var france = myform.destination[0];
	var domtom = myform.destination[1];
	
	if (myform.type[0].checked == true) {
		myform.recommendation.checked = false;
		myform.recommendation.disabled = true;
		myform.ack.checked = false;
		myform.ack.disabled = true;
	}
	else if (	(myform.type[1].checked == true || myform.type[2].checked == true || myform.type[3].checked == true) &&
				(france.checked == true || domtom.checked == true)	) {
		myform.recommendation.disabled = false;
		myform.recommendation.checked = true;
		myform.ack.disabled = false;
	}
	return;
}

function calculer_tarif_verifForm()
{
	if (this.destination[1].checked==1) {
		if (this.dom_tom.value=="") {
			alert("Veuillez sélectionner un DOM/TOM dans la liste");
			return false;
		}
	}
	if (this.destination[2].checked==1) {
		if (this.etranger.value=="") {
			alert("Veuillez sélectionner un pays dans la liste");
			return false;
		}
	}	
	if ((this.gr.value=="") || (this.gr.value=="0") || (!IsNumeric(this.gr.value)) ) {
			alert("Veuillez saisir un poids en grammes");
			return false;
	}
	if (this.gr.value > 3000) {
			alert("Votre envoi dépasse les 3000 grammes, contactez votre interlocuteur commercial");
			return false;
	}
	if ((this.gr.value > 250) && (this.nature[1].checked==1)) {
			alert("Le tarif Ecopli ne s'applique pas au delà de 250gr");
			return false;
	}	
	// On averti l'utilisateur si l'envoi est à destination de l'étranger, en économique et pèse moins de 51 grammes.
	if ((this.gr.value < 51) && (this.destination[2].checked==1) && (this.nature[3].checked==1)) {
		alert ('Le tarif économique est un tarif unique de 0 à 100 grammes. Nous vous conseillons de choisir le tarif prioritaire pour vos envois de 0 à 50 g pour bénéficier d\'un tarif plus avantageux et d\'un délai de distribution plus rapide. Cela vous évitera de payer le tarif d\'une tranche de poids plus élevée.');
		/*this.destination[2].checked=0;*/
		this.nature[3].checked=0;
		/*this.gr.value = '';*/
		return false;
	}
	return true;
}