function is_array( mixed_var ) {
 
    var key = '';
    var getFuncName = function (fn) {
        var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
        if(!name) {
            return '(Anonymous)';
        }
        return name[1];
    };
 
    if (!mixed_var) {
        return false;
    }
 
    // BEGIN REDUNDANT
    this.php_js = this.php_js || {};
    this.php_js.ini = this.php_js.ini || {};
    // END REDUNDANT
 
    if (typeof mixed_var === 'object') {
 
        if (this.php_js.ini['phpjs.objectsAsArrays'] &&  // Strict checking for being a JavaScript array (only check this way if call ini_set('phpjs.objectsAsArrays', 0) to disallow objects as arrays)
            (
            (this.php_js.ini['phpjs.objectsAsArrays'].local_value.toLowerCase &&
                    this.php_js.ini['phpjs.objectsAsArrays'].local_value.toLowerCase() === 'off') ||
                parseInt(this.php_js.ini['phpjs.objectsAsArrays'].local_value, 10) === 0)
            ) {
            return mixed_var.hasOwnProperty('length') && // Not non-enumerable because of being on parent class
                            !mixed_var.propertyIsEnumerable('length') && // Since is own property, if not enumerable, it must be a built-in function
                                getFuncName(mixed_var.constructor) !== 'String'; // exclude String()
        }
 
        if (mixed_var.hasOwnProperty) {
            for (key in mixed_var) {
                // Checks whether the object has the specified property
                // if not, we figure it's not an object in the sense of a php-associative-array.
                if (false === mixed_var.hasOwnProperty(key)) {
                    return false;
                }
            }
        }
 
        // Read discussion at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_is_array/
        return true;
    }
 
    return false;
}

function in_array(needle, haystack, argStrict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
 
    var key = '', strict = !!argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}

function trim(aString) 
{
	var regExpBeginning = /^\s+/;
	var regExpEnd       = /\s+$/;
    return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}

function verif_date(date)
{
	var e = new RegExp("^[0-9]{2}\/[0-9]{2}\/([0-9]{4})$");
	var e2 = new RegExp("^00\/00\/([0-9]{4})$");
	if (!e.test(date) && !e2.test(date)) // On teste l'expression régulière pour valider la forme de la date
	{
		return false;
	}	
	return true;
}

function get_date(chaine)
{
	var reg		=	new RegExp("[/]", "g");
	var param	=	chaine.split(reg);
	var date	=	new Date(param[2], param[1]-1, param[0]);
	return date;
}

function affiche_div(nom_el)
{
	monElement = $(nom_el);
	if (monElement.style.display == 'none')
		monElement.style.display = 'block';
	else
		monElement.style.display = 'none';
}

var old_div	=	null;
function switch_div(nom_el)
{
	var monElement = $(nom_el);

	if(old_div != null)
		old_div.style.display = 'none';
	
	if (monElement && monElement != old_div && monElement)
	{
		monElement.style.display = 'block';
		old_div	=	monElement;
	}
	else
	{
		old_div	=	null;
	}
}

function formcheck_date(el)
{
    if (!verif_date(el.value))
	{
        el.errors.push("La date n'est pas au format JJ/MM/AAAA");
        return false;
    }
	else
	{
        return true;
    }
}

function formcheck_sup_zero(el)
{
    if (el.value == 0)
	{
        el.errors.push("Ce nombre ne doit pas valoir 0");
        return false;
    }
	else
	{
        return true;
    }
}

function formcheck_password(el)
{
	if($('confirm_password').value != '' && $('confirm_password').value != $('password').value)
	{
		el.errors.push("La confirmation ne correspond pas au mot de passe.");
		return false;
	}
	else
	{
		return true;
	}
}

function formcheck_img(el)
{
	var ext	=	el.value.substr(el.value.lastIndexOf(".")+1);
	ext		=	ext.toLowerCase();
	if(ext != 'gif' && ext != 'jpg' && ext != 'jpeg')
	{
		el.errors.push("Votre fichier n'est pas une image valide (JPG et GIF uniquement)");
		return false;
	}
	else
	{
		return true;
	}	
}

function formcheck_png_gif(el)
{
	var ext	=	el.value.substr(el.value.lastIndexOf(".")+1);
	ext		=	ext.toLowerCase();
	if(ext != 'gif' && ext != 'png')
	{
		el.errors.push("Votre fichier n'est pas une image valide (PNG et GIF uniquement)");
		return false;
	}
	else
	{
		return true;
	}	
}

function formcheck_png(el)
{
	var ext	=	el.value.substr(el.value.lastIndexOf(".")+1);
	ext		=	ext.toLowerCase();
	if(ext != 'png')
	{
		el.errors.push("Votre fichier n'est pas une image valide (PNG uniquement)");
		return false;
	}
	else
	{
		return true;
	}	
}

function formcheck_date_abo(el)
{
	// on vérifie déjà que la date est valide
	if (!verif_date(el.value))
	{
        el.errors.push("La date n'est pas au format JJ/MM/AAAA");
        return false;
    }
	else
	{
		var now		=	new Date();
		var date	=	get_date(el.value);
		if(date.diff(now) > 0)
		{
			el.errors.push("La date est antérieure à aujourd'hui.");
			return false;
		}
		else
		{
			var abo			=	$('abonnement_id').value;
			//alert(abo+"ici");
			if(abo != '')
			{
				var date_min	=	tab_abo[abo][1];
				var date_max	=	tab_abo[abo][2];
				var date	=	get_date(el.value);
				//alert(date.diff(date_min)+" "+date_min+" "+date)
				//alert(date.diff(date_max)+" "+date_max+" "+date)
				if(date.diff(date_min) > 0)
				{
					
					el.errors.push("La date est antérieure à la date de début de l'abonnement choisi. ("+date_min.get('date')+"/"+(date_min.get('month')+1)+"/"+date_min.get('year')+")");
					return false;
				}
				else if(date.diff(date_max) < 0)
				{
					
					el.errors.push("La date est postérieure à la date de fin de l'abonnement choisi.("+date_max.get('date')+"/"+(date_max.get('month')+1)+"/"+date_max.get('year')+")");
					return false;
				}
				else
				{
					return true;
				}
			}
		}
    }
}

function minchecked(el)
{
	// block the default validates
	el.errors = [];
	el.isOk = true;
	var nb_check	=	$$("input[name^="+el.name+"[]]:checked").length;
	
	// confirm the length of the checked elements array
	if(nb_check > 0 )
	{
		
		if($(el.id+'_limit') && nb_check > $(el.id+'_limit').value)
		{
			var limit	=	$(el.id+'_limit').value;
			el.errors.push("Vous devez choisir au maximum "+limit+" valeur"+(limit > 1 ? 's' : ''));
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		el.errors.push("Merci de choisir au moins une valeur");
		return false;
	}
} 


function chargement(num)
{
	//Affiche un image de chargement
	$('img_chargement'+num).style.display='inline';	
}

function stop_chargement(num)
{
	//Stoppe l'image de chargement
	$('img_chargement'+num).style.display='none';		
}

function check_boxes(type, name)
{
	i	=	0;
	var boxes	=	$$('input.'+name).each(function(el)
	{
		if(type)
			el.checked	=	true;
		else
			el.checked	=	false;
	});
	
}
