//-----------------------------------------------------------------------------------------------//
// Fonctions
//-----------------------------------------------------------------------------------------------//

function GetId(Ctl) {
	return document.getElementById(Ctl)
}

//-----------------------------------------------------------------------------------------------//
// Notice légale
//-----------------------------------------------------------------------------------------------//

function GetWidth() { return (document.all) ? document.body.clientWidth : window.innerWidth - 19; }
function GetHeight() { return (document.all) ? document.body.clientHeight : window.innerHeight - 19; }

function GetPos(Ctrl, Axis)
{
	var Pos = 0;
	while (Ctrl) { if (Ctrl.tagName == 'BODY') { break; } Pos += (Axis=='X') ? Ctrl.offsetLeft: Ctrl.offsetTop; Ctrl = Ctrl.offsetParent; }
	return Pos;
}

function SwapNotice() {
	//GetId('Notice').style.display = (GetId('Notice').style.display=='' ? 'none' : '');
	if (GetId('Notice').style.display=='') {
	 GetId('Notice').style.display = 'none';
	 if (GetId('flash_ads')) showFlashAds("flash_ads",true);
	} else {
	 GetId('Notice').style.display = '';
	 if (GetId('flash_ads')) showFlashAds("flash_ads",false);
	}

	X = (GetWidth()-450)/2;
	Y = GetPos(GetId('Container'),'Y') - GetId('Notice').offsetHeight;
	H = GetId('Container').offsetHeight;
	
	GetId('Notice').style.left = parseInt(X) + 'px';
	GetId('Notice').style.top = parseInt(Y+H)+10 + 'px';
}


//-----------------------------------------------------------------------------------------------//
// Gestion des formulaires
//-----------------------------------------------------------------------------------------------//

function Command(Action, Param1, Param2)
{	
	Form = document.WoopamiForm;
	Form.Action.value = Action;
	Form.Param1.value = Param1;
	Form.Param2.value = Param2;

	switch (Action.toUpperCase()) {
		case 'FIND': 
			if (Form.Query.value=='' || Form.Query.value=='Mots clés...') return false;
			Form.action = '/1/recherche.html';
			doNotShowPopupOnExit();
			Form.submit();
			break;
			
		case 'UPLOAD':
			if (Form.MSG_File.value=='')   { alert('Le fichier de votre carte est obligatoire.');   return false; }
			if (!Form.CGU.checked) {
				alert('Vous devez confirmer les conditions générales d\'utilisation\navant de pouvoir valider votre inscription');
				return false;
			}
			Form.action = '/Upload.html';
			Form.encoding = "multipart/form-data";

			doNotShowPopupOnExit();
			Form.submit();
			break;
		
		case 'PREVIEW':
			if (Form.MSG_Sujet.value=='')   { alert('Le sujet est obligatoire.');   return false; }
			if (Form.MSG_Message.value=='') { alert('Le message est obligatoire.'); return false; }

			if ((Form.DST_Nom.value=='') || (Form.DST_Prenom.value=='') || (Form.DST_Email.value=='')) {
			   alert('Les informations sur le destinataire sont manquantes.');
			   return false;
			}
			if (!isEmail(Form.DST_Email)) {
			   alert('L\'adresse e-mail du destinataire est invalide !');
			   return false;
			}
			if ((Form.SRC_Nom.value=='') || (Form.SRC_Prenom.value=='') || (Form.SRC_Email.value=='')) {
			   alert('Les informations sur votre identité.');
			   return false;
			}
			if (!isEmail(Form.SRC_Email)) {
			   alert('Votre adresse e-mail est invalide !');
			   return false;
			}

			if (!Form.CGU.checked) {
				alert('Vous devez confirmer les conditions générales d\'utilisation\navant de pouvoir valider votre inscription');
				return false;
			}
		
			// Si c'est l'écriture personnalisé
			// On exporte les données vers le input
			if (Param1==1) exportDraw(); 

			Form.action = '/Apercu.html';
			doNotShowPopupOnExit();
			Form.submit();
			break;
		case 'COMPOSE':
			
		case 'MODIFY':
			Form.action = '/' + Param1 + '/formulaire.html';
			doNotShowPopupOnExit();
			Form.submit();
			break;
		case 'SEND':
			Form.action = '/envoi.html';
			doNotShowPopupOnExit();
			Form.submit();
			break;
	}
}

function OnFocus(Ctl, Txt) 		{ if (Ctl.value == Txt) Ctl.value = ''; CurrentCtl = Ctl.name; }
function OnBlur(Ctl, Txt)  		{ if (Ctl.value == '') Ctl.value = Txt; }

//-----------------------------------------------------------------------------------------------//
// Blocage du clic droit
//-----------------------------------------------------------------------------------------------//

function DisableRClic() {
	alert('Désolé l\'accès au menu contextuel est désactivé.');
	return false;
}

//-----------------------------------------------------------------------------------------------//
// Gestion des champs de formulaires
//-----------------------------------------------------------------------------------------------//

function isEmail(obj) { // vérif validité email par REGEXP
      var reg = /^[A-Za-z0-9._-]+@[A-Za-z0-9.-]{2,}[.][A-Za-z]{2,4}$/
      return((reg.exec(obj.value)!=null))
}

function showFlashAds(id,b) {
   if (document.images) {
    tobj = document.all(id);
    if (b) tobj.style.display = "block";
     else tobj.style.display = "none";   
   } else {
    tobj = document.getElementById(id);
    if (b) tobj.style.display = "block";
	 else tobj.style.display = "none";   
   }
}

function GetMail(Ctrl, Address, Domain, Tld) {
	window.location = "mailto:" + Address + '@' + Domain + '.' + Tld;
}

//-----------------------------------------------------------------------------------------------//
// Scripts carte virtuelle
//-----------------------------------------------------------------------------------------------//

function resizeFlash(w, h)
{
 	document.getElementById("Virt").width  = w;
	document.getElementById("Virt").height = h;
}

function importDraw()
{
	return document.WoopamiForm.MSG_VirtData.value;
}

function exportDraw()
{
	var f = document.getElementById("Virt");
	if (typeof f.exportData!='undefined')
		document.WoopamiForm.MSG_VirtData.value = f.exportData();
}

function fixFlash(s) { document.write(s); }
