//--- removed : <script type="text/javascript">

//------------ validation parameters ---------------------

var	genCondCheckBoxID = 'genCondCB';
var	numberDaysTotalID = 'numberDaysTotal';
var	numberWeekEndsID = 'numberWeekEnds';
var	exceptionAcceptedID = 'exceptionAccepted';

//------>30.01.2007 : 3->2 --- dans webapp / js / commonFunctions 
//          26.03.2008  ---> reprise des commonFunctions de tools, modif non transmise :-(
//------- 15.04.2008 : 3->2
var	minimumStay = 2;

// 18.07.2011
var  ratesReferenceDateID = '00000000'; 


//--------- TEST-----------

function postCommonVersion()
{	alert ('common functions - version : 0.1');
}

//----------------- fonctions communes gestion des images (OCIR initial)-------------------

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// ---------------- fonctions communes multiPages ------------------

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_openBrWindow(theURL,winName,features) {
  oneWIndow = window.open(theURL,winName,features);
  oneWIndow.focus();
  
  return oneWIndow;
}

function goBack(){
	history.go(-1);
}

function closeWin(){
	window.close();
}

// 08.08.2009 : allows for variable features
// 18.04.2008 : pb with small screeens (laptops)
// must control available space
// also allow for resizing window
function openNewFullWindow(urlString,winName,oneWidth,oneHeight, windowTitle, variableWinFeatures) 
{
	var  height = oneHeight;
	var  width = oneWidth;
	if	( height > screen.availHeight) height = screen.availHeight;
	if	( width > screen.availWidth) width = screen.availWidth;

	var  posx = (screen.width/2) - (width/2)
	var  posy = (screen.height/2) - (height/2)
	if(posx < 0) { posx = 0; }
	if(posy < 0) { posy = 0; }
	
	var  winFeatures   =  '';
	winFeatures += '  width=' + width;
	winFeatures += ', height=' + height;
	if	( variableWinFeatures != null ) 
		{ 
		winFeatures += ', ' + variableWinFeatures;
		}
	winFeatures += ', left=' + posx;
	winFeatures += ', top=' + posy;
	
	var  newWindow = MM_openBrWindow(urlString, winName, winFeatures);
	
	if	( windowTitle != null ) 
		{ newWindow.document.title = windowTitle;
		}
}

// 08.08.2009 : standard new window
function openNewWindow(urlString,winName,oneWidth,oneHeight, resizeFlag, windowTitle) 
{
	
	var  variableWinFeatures   =  '';
	variableWinFeatures += ' scrollbars=yes, status=no, toolbar=no, ';
	variableWinFeatures += ', resizable=' + resizeFlag;
	
	openNewFullWindow(urlString,winName,oneWidth,oneHeight, windowTitle, variableWinFeatures);
}

function openFAQWindow(urlString,winName,width,height) 
{
	   openNewWindow(urlString,winName,width,height, 'no', null);
}

// popUp is common to FAQ & Help
function openPopUp(urlString, popupTitle) 
{	   openFAQWindow(urlString, popupTitle, 530, 700);
} 
function openVariablePopUp(urlString, popupTitle, width, height) 
{	   openFAQWindow(urlString, popupTitle, width, height);
} 

// variable Help popUp with window Title 
function openVariableHelpWithTitlePopUp(urlString, windowTitle, width, height) 
{	   
	var  variableWinFeatures  = ' scrollbars=yes, status=no, toolbar=no, resizable=yes, locationbar=no ';
	openNewFullWindow(urlString, 'helpWIN', width, height, windowTitle, variableWinFeatures);
} 

//-------------  08.08.2009 : test features --------------

function openTestPopUp(urlString, windowTitle, width, height) 
{	   
	var  variableWinFeatures   =  '';
	variableWinFeatures += '  scrollbars=no, status=no, toolbar=no, resizable=no, locationbar=no';
	variableWinFeatures += ', width=' + width;
	variableWinFeatures += ', height=' + height;
	variableWinFeatures += ', left=100';
	variableWinFeatures += ', top=100';

	newWindow = window.open('', 'testWIN', variableWinFeatures);
	if	( windowTitle != null ) 
		{ newWindow.document.title = windowTitle;
		}
} 

//------------------------------------------------


// details popUp
function openDetailsPopUp(urlString) 
{	   openFAQWindow(urlString, '', 530, 700);
} 

// variabledetails popUp
function openVariableDetailsPopUp(urlString, width, height) 
{	   openNewWindow(urlString, 'flowerDetailsWIN', width, height, 'yes', null);
} 

// variabledetails popUp with window Title
function openVariableDetailsWithTitlePopUp(urlString, windowTitle, width, height) 
{	   openNewWindow(urlString, 'flowerDetailsWIN', width, height, 'yes', windowTitle);
} 

// variabledetails popUp with window Title called from parent PopUp
function openNewVariableDetailsWithTitlePopUp(urlString, windowName, windowTitle, width, height) 
{	   openNewWindow(urlString, windowName, width, height, 'yes', windowTitle);
} 

// variabledetails popUp with window Title for SHOP MANAGER
function openShopVariableDetailsWithTitlePopUp(urlString, windowTitle, width, height) 
{	   openNewWindow(urlString, 'shopDetailsWIN', width, height, 'yes', windowTitle);
} 


//----------------------------------- PopUp pour fenêtre spPlus --------------------------------------

function Ouvrir_Spplus()
{
	// 19.04.2010 : vérification de la faisabilité de l'appel
	var	requestIsOK = true;
	var	errorMessage = '';
	
	if	( paymentRequestHasBeenSent )
		{
		errorMessage += "Vous avez déjà contacté le serveur de paiement pour cette commande. \n\n";
		errorMessage += "Si votre demande n'a pas abouti, vous pouvez la renouveler à condition que votre commande porte un autre numéro. \n\n";
		errorMessage += "Il vous suffit de RECHARGER (rafraichir) LA PRÉSENTE PAGE de demande de paiement, et votre commande sera automatiquement renumérotée.\n\n";
		errorMessage += "N'hésitez pas à nous contacter si les problèmes persistent. \n";
		errorMessage += "Merci de votre confiance. \n";
		errorMessage += "Maïaflor. \n";
		
		alert ( errorMessage);
		requestIsOK = false;
		}
	else	{
		paymentRequestHasBeenSent = true;

		// Largeur et hauteur préconisées de la fenêtre SPPLUS
		var PopupSpplus_largeur	= 750;
		var PopupSpplus_hauteur	= 560;

		// Position haut et gauche de la fenêtre SPPLUS pour affichage centré dans l'écran
		var PopupSpplus_top	=((screen.height-PopupSpplus_hauteur)/2);
		var PopupSpplus_left	=((screen.width-PopupSpplus_largeur)/2);

		// Ouverture du popup SPLUS avec barre état uniquement et focus sur la fenêtre
		var win = window.open('', "SPPLUS","status=yes,top="+PopupSpplus_top+",left="+PopupSpplus_left+",width="+PopupSpplus_largeur+",height="+PopupSpplus_hauteur);
		win.focus();
		}
	return requestIsOK;
}

//-------------------------------------------------------------------------------------------------------------

function  submitForm (oneFormID) 
{
	var thisForm = document.getElementById(oneFormID);
	if   ( thisForm == null ) return;

//alert (thisForm.action);

	thisForm.submit();
}

// 17.01.2010
function submitFormWithRBAction(oneFormID, oneRBID)
{
	var thisForm =  document.getElementById(oneFormID);

	// ATTENTION : il semble que la recherche par ID ne donne que le premier élément du RB
	// var thisRB =  document.getElementById(oneRBID);
	
	var  selectedTarget =  'not found';
	
	for	( var j=0; j < thisForm.length; j++ )
		{
		if	( thisForm.elements[j].id != oneRBID ) continue;
		if	( ! thisForm.elements[j].checked ) continue;
		selectedTarget =  thisForm.elements[j].value;
		break;
		}

	thisForm.action = selectedTarget;
	thisForm.submit();
}

// 18.07.2011
function setFormElementValueWithVariable(oneFormID, oneFormElementID, oneVariable)
{
	var thisForm =  document.getElementById(oneFormID);
	
	for	( var j=0; j < thisForm.length; j++ )
		{
		if	( thisForm.elements[j].id != oneFormElementID ) continue;
		thisForm.elements[j].value = oneVariable;
		break;
		}
}



// 17.01.2010 (HTML action is form target, not PHL action !!)
function setFormAction(oneFormID, oneFormAction)
{
	var thisForm =  document.getElementById(oneFormID);
	thisForm.action = oneFormAction;
}

// 17.01.2010
function postRBValue(oneRBID)
{
	var thisRB =  document.getElementById(oneRBID);
	alert (oneRBID + '<br>' + thisRB.id + '<br>' + thisRB.value);
}

// 11.02.2011
function getRBInFormWithID(oneFormID, oneRBID)
{
	var thisForm =  document.getElementById(oneFormID);

	// ATTENTION : il semble que la recherche par ID ne donne que le premier élément du RB
	// var thisRB =  document.getElementById(oneRBID);
	
	var thisRB =  null;
	for	( var j=0; j < thisForm.length; j++ )
		{
		if	( thisForm.elements[j].id != oneRBID ) continue;
		thisRB =  thisForm.elements[j];
		break;
		}
	return thisRB;
}
// 08.02.2011
function getRBValueInForm(oneFormID, oneRBID)
{
	var thisForm =  document.getElementById(oneFormID);

	// ATTENTION : il semble que la recherche par ID ne donne que le premier élément du RB
	// var thisRB =  document.getElementById(oneRBID);
	
	var thisRBValue =  null;
	for	( var j=0; j < thisForm.length; j++ )
		{
		if	( thisForm.elements[j].id != oneRBID ) continue;
		if	( ! thisForm.elements[j].checked ) continue;
		thisRBValue =  thisForm.elements[j].value;
		break;
		}
	return thisRBValue;
}

// 11.02.2011
function setAsCheckedRBWithValueInForm(oneFormID, oneRBID, oneRBValue)
{
	var thisForm =  document.getElementById(oneFormID);

	// ATTENTION : il semble que la recherche par ID ne donne que le premier élément du RB
	// var thisRB =  document.getElementById(oneRBID);
	
	for	( var j=0; j < thisForm.length; j++ )
		{
		if	( thisForm.elements[j].id != oneRBID ) continue;
		if	( thisForm.elements[j].value != oneRBValue ) continue;
		thisForm.elements[j].checked = true;
		break;
		}
}

// 08.02.2011
function postRBValueInForm(oneFormID, oneRBID)
{
	var thisRBValue =  getRBValueInForm(oneFormID, oneRBID);
	alert (oneRBID + '<br>' + oneRBID + '<br>' + thisRBValue);
}



//---------------------------------  search DB --------------------------------

function linkToDBSearch( oneLinkURL, oneSearchAction, oneSource)
{
	searchParam = '';
	
	// 11 : search keyID (see DBHandler)
	if   ( oneSearchAction == 11 )
		 { searchParam = document.getElementById('keyID').value;
		 }
	// 12 : search eMail (see DBHandler)
	if   ( oneSearchAction == 12 )
		 { searchParam = document.getElementById('EMAIL').value;
		 }

	// 32 : search DiscountReference (see DBHandler)
	if   ( oneSearchAction == 32 )
		 { searchParam = document.getElementById('reference').value;
		 }
	
	//ne pas mettre les quotes autour de l'URL	
	myLinkURL  = '';	
	myLinkURL += oneLinkURL;	
	myLinkURL += '?action=' + oneSearchAction;	
	myLinkURL += '&search=' + searchParam;	
	myLinkURL += '&source=' + oneSource;	
	// link to target location
	
	//alert('myLinkURL : ' + myLinkURL);
	
	window.location = myLinkURL;
	//alert('après : window.location ');

	//Location.replace(myLinkURL);
	//window.location.replace(myLinkURL);
	//alert('après : window.location.replace ');
}

//----------------------------------- Validations --------------------------------------


function  confirmOrderDelete() 
{
	return confirm ('Etes-vous sûr de vouloir supprimer cette commande ?');
}

function  isCheckBoxIDChecked (oneCBID) 
{
	var thisCheckBox = document.getElementById(oneCBID);
	if   ( thisCheckBox.checked == true ) return true;
	return false;
}



function  validatePersonalInput () 
{

	// test
	var  initials = document.getElementById('initials').value;
	if ( initials == '%') return true;

	// name
	var  firstName = document.getElementById('firstName');
	var  firstNameValue = firstName.value;
	if   ( ( firstNameValue  == null  ) || ( firstNameValue == '' )) 
		 { alert ( ERR_MES_PERSONAL_FIRST_NAME );
		   firstName.focus();
		   return false;
		 }
	var  lastName = document.getElementById('lastName');
	var  lastNameValue = lastName.value;
	if   ( ( lastNameValue  == null  ) || ( lastNameValue == '' )) 
		 { alert ( ERR_MES_PERSONAL_LAST_NAME );
		   lastName.focus();
		   return false;
		 }

	// address
	var  street1 = document.getElementById('street1');
	var  street1Value = street1.value;
	if   ( ( street1Value  == null  ) || ( street1Value == '' )) 
		 { alert ( ERR_MES_PERSONAL_ADDRESS );
		   street1.focus();
		   return false;
		 }
	var  zipCode = document.getElementById('zipcode');
	var  zipCodeValue = zipCode.value;
	if   ( ( zipCodeValue  == null  ) || ( zipCodeValue == '' )) 
		 { alert ( ERR_MES_PERSONAL_ZIP );
		   zipCode.focus();
		   return false;
		 }
	var  city = document.getElementById('city');
	var  cityValue = city.value;
	if   ( ( cityValue  == null  ) || ( cityValue == '' )) 
		 { alert ( ERR_MES_PERSONAL_CITY );
		   city.focus();
		   return false;
		 }
	var  country = document.getElementById('country');
	var  countryValue = country.value;
	if   ( ( countryValue  == null  ) || ( countryValue == '' )) 
		 { alert ( ERR_MES_PERSONAL_COUNTRY );
		   country.focus();
		   return false;
		 }

	// contacts
	var  phone = document.getElementById('phone');
	var  phoneValue = phone.value;
	if   ( ( phoneValue  == null  ) || ( phoneValue == '' )) 
		 { alert ( ERR_MES_PERSONAL_PHONE );
		   phone.focus();
		   return false;
		 }
	var  email = document.getElementById('email');
	var  emailValue = email.value;
	if   ( ( emailValue  == null  ) || ( emailValue == '' )) 
		 { alert ( ERR_MES_PERSONAL_EMAIL );
		   email.focus();
		   return false;
		 }
	var  emailCheck = document.getElementById('emailCheck');
	var  emailCheckValue = emailCheck.value;
	if   ( ( emailCheckValue  == null  ) || ( emailCheckValue == '' )) 
		 { alert ( ERR_MES_PERSONAL_EMAIL_CHECK );
		   emailCheck.focus();
		   return false;
		 }
	if   ( emailCheckValue  != emailValue ) 
		 { alert ( ERR_MES_PERSONAL_EMAIL_NO_MATCH );
		   email.focus();
		   return false;
		 }

	return true;
}

//---------------------------- contract final validation ----------------
function  validateContract () 
{
	if   (( ( currentStartDateID == null ) || ( currentEndDateID == null ) )
	||   ( ( currentStartDateID == '' ) || ( currentEndDateID == '' ) ))
		 { // no dates selected
		   alert ( ERR_MES_CONTRACT_NO_STAY_DATES );
		   return false;
		 }

	// get days in stay hidden fields
	daysInStay = document.getElementById(numberDaysTotalID).value;
	weInStay = document.getElementById(numberWeekEndsID).value;
	exceptionAccepted = document.getElementById(exceptionAcceptedID).value;
	
	if   ( ( daysInStay < minimumStay ) && ( weInStay < 1) && (exceptionAccepted == 0)) 
		 { // stay less than minimum (W.E.excepted)
		   alert ( ERR_MES_CONTRACT_MINIMUM_STAY );
		   return false;
		 }
	
	// general conditions checkBox
	if   ( isCheckBoxIDChecked (genCondCheckBoxID) == false )
		 { // box is not checked
		   alert ( ERR_MES_CONTRACT_GEN_CONDITIONS );
		   return false;
		 }
}


//----------------------------------- fonctions Javascript XSLT (source : W3Schools, xslt_client) --------------------------------------


function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation 
&& document.implementation.createDocument)
  {
  xmlDoc=document.implementation.createDocument("","",null);
  }
else
  {
  alert('Your browser cannot handle this script');
  }
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}

function displayResult()
{
xml=loadXMLDoc("cdcatalog.xml");
xsl=loadXMLDoc("cdcatalog.xsl");
// code for IE
if (window.ActiveXObject)
  {
  ex=xml.transformNode(xsl);
  document.getElementById("example").innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation 
&& document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  document.getElementById("example").appendChild(resultDocument);
  }
}


//-----------------------------------------------  scrolling ----------------------------------------------------------

function scrollToElementWithID(oneElementID) 
{
	if	( oneElementID == null ) return;
	var  myElement = document.getElementById(oneElementID);
	scrollToElement(myElement);
}


// pour MSIE, MSIEHeaderOffset doit être positionné dans la page HTML
function scrollToElement(oneElement) 
{
	var __isExplorer = navigator.userAgent.match(/MSIE/i);

	if	( oneElement == null ) return;
	var  myElementPosition = getElementAbsolutePos(oneElement);
	var  scroll_X = myElementPosition.x;
	var  scroll_Y = myElementPosition.y;

//alert  ('initial ( x, y ) : ' + scroll_X + ' , ' + scroll_Y );
	
	// essai de résoudre les bugs Explorer :-(
	if	( __isExplorer )
		{ 
		    if	( MSIEHeaderOffset == null ) MSIEHeaderOffset = 0;
		    scroll_Y = scroll_Y + MSIEHeaderOffset;
		}
	 
//alert (navigator.userAgent +"\n\n" + '( x, y ) : ' + scroll_X + ' , ' + scroll_Y + '   offset : ' + MSIEHeaderOffset);

	scrollTo(scroll_X, scroll_Y);
}

//----- returns the absolute position of some element within document ---
function getElementAbsolutePos(element) 
{
	var __isFireFox = navigator.userAgent.match(/gecko/i);
	var res = new Object();

	res.x = 0; res.y = 0;
	if (element !== null) {
		res.x = element.offsetLeft; 
		res.y = element.offsetTop; 
    	
		var offsetParent = element.offsetParent;
		var parentNode = element.parentNode;

		while (offsetParent !== null) {
			res.x += offsetParent.offsetLeft;
			res.y += offsetParent.offsetTop;

			if (offsetParent != document.body && offsetParent != document.documentElement) {
				res.x -= offsetParent.scrollLeft;
				res.y -= offsetParent.scrollTop;
			}
			//next lines are necessary to support FireFox problem with offsetParent
			if (__isFireFox) {
				while (offsetParent != parentNode && parentNode !== null) {
					res.x -= parentNode.scrollLeft;
					res.y -= parentNode.scrollTop;
					
					parentNode = parentNode.parentNode;
				}    
			}
			parentNode = offsetParent.parentNode;
			offsetParent = offsetParent.offsetParent;
		}
	}
    return res;
}

//-------------------------- Dates -----------------------

function  getFrenchDateFromID ( oneDateID, separ)
{
	if   ( separ == null ) separ = '.';
	
	frenchDate  = '';
	frenchDate += oneDateID.substr(6,2) + separ;
	frenchDate += oneDateID.substr(4,2) + separ;
	frenchDate += oneDateID.substr(0,4);
	
	return 	frenchDate;
}

//------------------  tests and Utilities ----------------------


function  testParentWindow()
{
	alert ("WindowName : " + window.self.name);
	alert ("ParentWindowName : " + window.opener.name);
}


//</script>
