// Javascript ...

// +----------------------------------------------------------------------+
// | PHYSIO EXTRA                                                         |
// | Common Javascript Functions - scripts/physioextra.js                 |
// +----------------------------------------------------------------------+
// | Copyright (c) REVOLVER 3                                             |
// +----------------------------------------------------------------------+
// | DESCRIPTION                                                          |
// | -----------                                                          |
// | All common Javascript functions used in the project. Included        |
// | as an external file in <head>.                                       |
// |                                                                      |
// | FUNCTIONS                                                            |
// | -----------                                                          |
// | preload_image()                                                      |
// | change_image()                                                       |
// | change_image_layer()                                                 |
// | open_window()                                                        |
// |                                                                      |
// +----------------------------------------------------------------------+
// | Authors: Guillaume Lambert <mastercloud@hotmail.com>                 |
// +----------------------------------------------------------------------+

<!-- | Google analytique | -->
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21201692-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

/**************************************************************************
 * FUNCTION preload_image(image_name, image_src)
 *
 * Paramaters:
 *   var image_name  - Name of image
 *   var image_src   - Source of image file
 *
 * Description:
 *   Preloads image object for faster rollover action. Make a function on
 *   head of page like the following and body onLoad it:
 *
 *     var preload_done = false;    // images not preloaded
 *
 *     function preload()
 *     {
 *         preload_image('image_name', '../_images/image_src.gif');
 *         ...
 *         preload_done = true;    // all images are preloaded.
 *     }
 *
 *************************************************************************/

function preload_image(image_name, image_src)
{

    if (document.images)
    {
        eval(image_name + ' = new Image()');
        eval(image_name + '.src = "' + image_src + '"');
    }

}


/* ************************************************************************
 * FUNCTION change_image(image_name, image_src)
 *
 * Paramaters:
 *   var image_name  - Name of image
 *   var image_src   - Source of image file
 *
 * Description:
 *   Basic rollover (swap-image action) function.
 *
 *************************************************************************/

function change_image(image_name, image_src)
{

    if (document.images)
    {
        document.images[image_name].src = image_src;
    }

}


/* ************************************************************************
 * FUNCTION change_image_layer(image_name, image_src, layer_name)
 *
 * Paramaters:
 *   var image_name  - Name of image
 *   var image_src   - Source of image file
 *   var layer_name  - Name of the layer where the image is nested
 *
 * Description:
 *   Basic rollover (swap-image action) function for image contained within
 *   layers (DIVs)
 *
 *************************************************************************/

function change_image_layer(image_name, image_src, layer_name)
{

    // Can the browser handle rollovers?
    if (document.images)
    {
        // Is is a DOM-compatible browser?? (Netscape4.x below are NOT)
        if (document.layers)
        {
            // MUST FIX N4.x ... Trouver le moyen de targeter un image dans un layer
            document.layers[layer_name].document.images[image_name].src = image_src;
        }
        else
        {
            document.images[image_name].src = image_src;
        }
    }

}


/**************************************************************************
 * FUNCTION open_window(page_url, page_name, window_width, window_height,
 *                      scrollbar_value, is_center)
 *
 * Paramaters:
 *   var page_url         - Url to the page
 *   var page_name        - Page name (target)
 *   var window_width     - Width of the new window
 *   var window_height    - Height of the new window
 *   var scrollbar_value  - Scrollbar? 'yes', 'no' or 'auto'.
 *   var is_center        - Center new window? 'yes' or 'no'.
 *
 * Description:
 *   Opens a pop-up window calculated placed upon the width and height
 *   the user sends as a paramater. Calculates center position of the window
 *   if is_center is set to 'yes'. Works in Netscape and Internet Explorer.
 *
 *************************************************************************/

function open_window(page_url, page_name, window_width, window_height, scrollbar_value, is_center)
{

    // Set the position of window - default values
    var window_pos_x = 20;
    var window_pos_y = 20;

    // If centered, calculate center position
    if (is_center == 'yes')
    {
        window_pos_x = (screen.width / 2) - (window_width / 2);
        window_pos_y = (screen.height / 2) - (window_height / 2);
    }

    // Open new window
    // NOTE: - new window name must be DIFFERENT than function name or ERROR!
    //       - don't put space between windowFeatures and commas - equal ERROR in N4.7
    popup_window = this.open(page_url, page_name, "toolbar=no,status=no,menubar=no,location=no,scrollbars=" + scrollbar_value + ",resizable=no,width=" + window_width + ",height=" + window_height + ",screenX=" + window_pos_x + ",screenY=" + window_pos_y + ",left=" + window_pos_x + ",top=" + window_pos_y);
    popup_window.focus();

}


/**************************************************************************
 * FUNCTION valide_newsletter_form()
 *
 * Paramaters:
 *   - none -
 *
 * Description:
 *   Valide le formulaire pour s'inscrire à la liste de diffusion.
 *
 * Returns:
 *   false or true depending on the result.
 *
 *************************************************************************/

function valide_newsletter_form()
{

    // Expression reguliere pour la verification de email
    var at = /^(.+)@(.+)\.(.+)$/;

    if (document.newsletter.nom.value == "" || document.newsletter.nom.value == "votre nom")
    {
        alert('Veuillez entrer votre nom');
        document.newsletter.nom.focus();
        return false;
    }

    if (!at.test(document.newsletter.email.value) || document.newsletter.email.value == "" || document.newsletter.email.value == "email@domaine.com")
    {
        alert('Votre courriel semble invalide, veuillez le corriger');
        document.newsletter.email.focus();
        return false;
    }

    // If no errors submit!
    //document.newsletter.submit();

}

/**************************************************************************
 * FUNCTION validateRDVDate (day, month, year)
 *
 * Paramaters:
 *   var day
 *	 var month
 *   var year
 *
 * Description:
 *   Valide le formulaire pour s'inscrire à la liste de diffusion.
 *
 * Returns:
 *   -none-
 *
 *************************************************************************/

function validateRDVDate (day, month, year) {
	var month = month - 1;
   	var objDate=new Date();
	objDate.setFullYear(year,month,day);
	var today = new Date();

   if (month != objDate.getMonth() || day != objDate.getDate() || year != objDate.getFullYear()) 
   {
	   return false;
   }
   else if(objDate < today)
   {
	   alert("Le rendez-vous doit être plus tard");
	   return false;
   }
   
   return true;
} 

/**************************************************************************
 * FUNCTION AcceptDigits(objtextbox)
 *
 * Paramaters:
 *   var objtextbox		- The objectbox that should contain only digits
 *
 * Description:
 *   Valide un objet qui doit contenir seulement des chiffres
 *
 * Returns:
 *   - none -
 *
 *************************************************************************/
function AcceptDigits(objtextbox)
{
	var exp = /[^\d]/g;
	objtextbox.value = objtextbox.value.replace(exp,'');
}

/**************************************************************************
 * FUNCTION ChangeFocusCheck(currObj, nextObj)
 *
 * Paramaters:
 *   var currObj		- The objectbox that currently has focus
 *   var nextObj		- The objectbox that should get next focus
 *
 * Description:
 *   Unefois l'objet courrant completer on donne le focus au prochain
 *
 * Returns:
 *   - none -
 *
 *************************************************************************/
function ChangeFocusCheck(currObj, nextObj)
{
	if(currObj.value.length == currObj.getAttribute('maxlength'))
		nextObj.focus();
}

// ... End of file.
