/* ****************************************** *//* *** DEFINITION OF GENERAL UN FUNCTIONS *** *//* ****************************************** */var winConfig = "'toolbar=no,location=no,scrollbars=yes,resizable=yes,width=600,height=600'"var canEdit = true; /* ------------------------------------------------------------------------- * * ----------------------------------------------------------------------- */function preventEditing () {	var selpopupLangIndex 	= document.mainForm.popupLang.options.selectedIndex; // the index presently selected	var selLangName 		= document.mainForm.popupLang.options[selpopupLangIndex].text;	var actualLangName 		= document.mainForm.popupLang.options[popupLangIndex].text; //popupLangIndex is initialized in the page when it load	var msg					= "You are presently editing " + actualLangName  + ".\n";	msg						= msg + "Please press the Go button first to edit " + selLangName + ".";if (canEdit == false) {		if (popupLangIndex != selpopupLangIndex) {			alert (msg);			return false;		}	} 	return true;} /* ------------------------------------------------------------ * don't want empty fields * ------------------------------------------------------------*/function noEmptyField(thisField) {	if (thisField.value == "") {			thisField.value = 0;	}}/* -------------------------------------------------------------- * alert when there is an empty field and return false * ------------------------------------------------------------*/function alertEmptyField (thisField, msg) {	if (thisField.value == "") { 		alert (msg); 		thisField.focus (); 		return false; 	} 	return true}/* -------------------------------------------------------------- * check if the value is an integer * ------------------------------------------------------------*/function isInt (s) {	 if (s == "") {	 	return false	 }  else {	 	for (i=0; i < s.length; i++) {	 		if ( (s.charAt (i) < "0") || (s.charAt (i) > "9")) {	 			return false	 		}	 	}	 }	 return true}/* -------------------------------------------------------------- * check if the value if the string is empty and if its  an integer * ------------------------------------------------------------*/function isInteger (s, msgEmpty, msgNotNumber) {	 if (s == "") {	 	alert (msgEmpty)	 	return false	 }  else {	 	for (i=0; i < s.length; i++) {	 		if ( (s.charAt (i) < "0") || (s.charAt (i) > "9")) {	 			alert (msgNotNumber)	 			return false	 		}	 	}	 }	 return true}/* ----------------------------------------------------------------------- * check if the value is either a valid number (either integer or float) * ----------------------------------------------------------------------*/function isFloatOrInt (s) {	var ix = "";	ix = s.indexOf(".");	if (ix == -1) {		return isInt (s);	} else if (isNaN(s)) {		return false;	}	return true}/* ----------------------------------------------------------------------- * check if the value is either a valid number (either integer or float) * ----------------------------------------------------------------------*/function isFloatOrInteger (s) {	var ix = "";	ix = s.indexOf(".");	if (ix == -1) {		return isInteger (s, msgEmpty, msgNotFloat);	} else if (isNaN(s)) {		alert (msgNotFloat)		return false;	}	return true}/* -------------------------------------------------------------- * check if the dateTo is not before the dateFrom * work only from the year 2000 and not before * ------------------------------------------------------------*/function makeDateObjectFromPopUpMenu (dayArg, monthArg, yearArg) {		var dateDay 	= dayArg.options[dayArg.selectedIndex].value;	var dateMonth 	= monthArg.options[monthArg.selectedIndex].value - 1;	var dateYear 	= yearArg.options[yearArg.selectedIndex].value;		if (dateYear.length != 4) {dateYear = "20" + dateYear}			return new Date (dateYear, dateMonth, dateDay);}	/* -------------------------------------------------------------- * compare 2 dates objects. If the dateFrom is < than dateTo * return true, otherwise, return false. * ------------------------------------------------------------*/function compareDates (dateTo, dateFrom) {	dateTo 		= dateTo.getTime ();	dateFrom 	= dateFrom.getTime ();	if (dateTo > dateFrom) {		return false;	}	return true}/* -------------------------------------------------------------- * Part of: * 	http://javascript.internet.com/calendars/date-menu.html * 	Original:  Ben McFarlin (mcfarlin@netscape.net) * 	Web Site:  http://sites.netscape.net/mcfarlin * This script find the last day of the month. * ------------------------------------------------------------*/function getLastDayOfMonth (thisMonth, thisYear) {	var timeA = new Date (thisYear, thisMonth, 1);	var timeDifference = timeA - 86400000;	var timeB = new Date (timeDifference);	var daysInMonth = timeB.getDate ();	return parseInt (daysInMonth);}/* -------------------------------------------------------------- * Inspired by the Hilton reservation page (http://www.hilton.com/). * Take the name of each popUpMenu displaying a date, and oblige in * the popUpMenuDay to display only a valid date * ------------------------------------------------------------*/function obligeValidDay (popUpMenuDay, popUpMenuMonth, popUpMenuYear) {	var dateDay		= parseInt (popUpMenuDay.options[popUpMenuDay.selectedIndex].value);	var dateMonth	= popUpMenuMonth.options[popUpMenuMonth.selectedIndex].value;	var dateYear	= popUpMenuYear.options[popUpMenuYear.selectedIndex].value;	if (dateYear.length != 4) {dateYear = "20" + dateYear}	var lastDayOfMonth 	= getLastDayOfMonth (dateMonth, dateYear)	if ( dateDay > lastDayOfMonth ) {		popUpMenuDay.options.selectedIndex = lastDayOfMonth - 1;		return true;	}}/* -------------------------------------------------------------- * Check if the difference between now and thisDate is less than one year. * One year = 366 days to allow bisextiles years. * ------------------------------------------------------------*/function isLessThanOneYear (thisDate) {	thisDate = thisDate.getTime ();	var now = new Date;	now = now.getTime ();	var oneYear = (1000 * 60 * 60 * 24) * 366;	var nowPlusOneYear = now + oneYear;	if (thisDate <= nowPlusOneYear) {		return true	}	return false;}/* -------------------------------------------------------------- * Simplistic function to check email * ------------------------------------------------------------*/function checkEmail (s) {	var badChar = " /:;,"	var ctAt = 0;	var ctDot = 0;	var posAt = s.indexOf('@');		s = trimWhiteSpace (s);		// check first if we have at least an '@' and dot	if ( s.indexOf('@') == -1 || s.indexOf('.') == -1) {		return false	}		//don't want more than one '@'	for (i = 0; i < s.length; i++) {		if (s[i] == '@') {			ctAt++		}		if (ctAt > 1) {			return false		}				//check now for bad chars		for (j = 0; j < badChar.length; j++) {			if (s.charAt(i) == badChar.charAt(j)) {				return false			}		}	}	//don't want '@' at the beginning of the string	if (posAt == 0) {		return false	}		// find the substring starting at posAt	var stringAfterAt = s.substring (posAt, s.length)	var posDot = stringAfterAt.indexOf ('.')		//check if we have a dot after the @	if (posDot == -1) {return false}		//make sure that at least there is 2 chars between '@' and the dot	if (posDot < 3) { 		return false	}	//make sure that at least there is 2 chars after the dot in the substring starting at '@'	if ( posDot + 2 >= stringAfterAt.length ) { 		return false	}	return true}		/* -------------------------------------------------------------- * Trim white spaces at the beginning and end of a string and * return the trimmed string. * ------------------------------------------------------------*/function trimWhiteSpace (s) {	var whiteSpaceItems = "\t\r\n\f ";	var sStart = s.charAt (0);	var sEnd = s.charAt (s.length - 1)		function hasWhiteSpace (thisChar){		if (whiteSpaceItems.indexOf (thisChar) != -1) {			return true		} else {			return false		}	}	while (hasWhiteSpace (sStart)) {		s = s.substring (1, s.length)		sStart = s.charAt (0)	}		while (hasWhiteSpace (sEnd)) {		s = s.substring (0, s.length - 1);		sEnd = s.charAt (s.length - 1);	}		return s;}/* -------------------------------------------------------------- * Round a float to unit. Return a float. * For example roundThis (100.1299, 0.01) will return 100.13 * But there is somewhere a bug in Javascript and its on different browsers: * sometimes the number returned will be correctly rounded for the first 2 * numbers after the decimal but will be followed by a bunch of zeros and one unit; *  roundThis (100.239, 0.01) == 100.24000000000001. * I made some tests and its different from browser to browser, so the best thing is * to use popDecimals () (below) on the returned number to sure of the result. * ------------------------------------------------------------*/function roundThis (x, unit) {	// adapted a Frontier script by Brian Andersen called "round"	var y = x / unit;	y = parseInt (y + 0.5);	return y * unit;}/* -------------------------------------------------------------- * Pop n number in the numbers after a decimal. * Return a string or the original number (coerced to a string) if there is nothing to pop. * ------------------------------------------------------------*/function popDecimals (keepDecimalNum, num) {	numString = num.toString ()	numSplitted = numString.split ('.')	if (numSplitted.length == 2) {		prefix = numSplitted[0]		suffix = numSplitted[1]		suffix = suffix.slice (0, keepDecimalNum)		numString = prefix + "." + suffix		return numString	} else {		return num.toString ()	}}/* ------------------------------------------------------------ * Open a new window * win_url = url to open * win_name = name of the window * win_params = javascript params for the window * ------------------------------------------------------------*/function open_url(win_url, win_name, win_params) {	var newWin = window.open (win_url, win_name, win_params);	newWin.focus ();}