/////////////////////////////////////////////////////////////////////////////////////////
// FADE IN //////////////////////////////////////////////////////////////////////////////
(function($) {
    $.fn.fadein = function(speedFade, animFade)
	{
		if (navigator.appName != "Microsoft Internet Explorer")
		{
			this.each(function()
			{
				$(this).fadeIn(speedFade);
			});
		}
		else
		{
			this.each(function()
			{
				if (animFade) { $(this).show(speedFade) } else { $(this).show(); }
			});
		}
		
        return $(this);
    };
})(jQuery);
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////
// FADE OUT /////////////////////////////////////////////////////////////////////////////
(function($) {
    $.fn.fadeout = function(speedFade, animFade)
	{
		if (navigator.appName != "Microsoft Internet Explorer")
		{
			this.each(function()
			{
				$(this).fadeOut(speedFade);
			});
		}
		else
		{
			this.each(function()
			{
				if (animFade) { $(this).hide(speedFade) } else { $(this).hide(); }
			});
		}
		
        return $(this);
    };
})(jQuery);
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

function verif_noempty(chaine)
{
	var reg = new RegExp("( )", "g");
	chaine = chaine.replace(reg, '');
	if (chaine.length > 0) { return true; } else { return false; }
}

function verif_email(chaine)
{
	return /^[a-z0-9]+([_|\.|-]{0,1}[a-z0-9_]+)*@[a-z0-9]+([_|\.|-]­{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$/i.test(chaine)
}

function verifChamps(mesChamps, suffixeError) // verifChamps("nom,prenom", "error_");
{
	var etatFormVerifC = 0;
	tabChamps = mesChamps.split(",");
	for (var i = 0; i < tabChamps.length; i++)
	{
		if (!verif_noempty($("#"+tabChamps[i]).val()))
		{
			$("#"+suffixeError+tabChamps[i]).html("Obligatoire");
			etatFormVerifC = 1;
		}
		else
		{
			if (tabChamps[i].search("email") != -1)
			{
				if (!verif_email($("#"+tabChamps[i]).val()))
				{
					$("#"+suffixeError+tabChamps[i]).html("Adresse \351lectronique incorrecte");
					etatFormVerifC = 1;
				}
				else
				{
					$("#"+suffixeError+tabChamps[i]).html("");
				}
			}
			else
			{
				$("#"+suffixeError+tabChamps[i]).html("");
			}
		}
	}
	
	if (etatFormVerifC == 0) { return true; } else { return false; }
}

function generate_string(numChar)
{
	var chars = '23456789abcdefghijkmnopqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
	var pass = '';
	while (pass.length < numChar)
	{
		pass += chars.charAt(Math.round(Math.random() * (chars.length)));
	}
	return pass;
}

function isInt(mixed_var)
{ 
    return !(mixed_var % 1);
}

function isPair(number)
{
	return isInt(number / 2);
}

function formatInt(fieldNum)
{
	fieldNum = fieldNum.replace(" ", "");
	var tab_field = fieldNum.split(",");
	var re = /\d*((\|)\d*)?/;
	for (var i = 0; i < tab_field.length; i++)
	{
		$(fieldNum).keyup(function(e)
		{
			var valNum = $(this).val();
			$(this).val(re.exec(valNum)[0]);
		});
	}
}

function strrpos(haystack, needle, offset)
{
	var i = -1;
	if (offset)
	{
		i = (haystack+'').slice(offset).lastIndexOf(needle);
		if (i !== -1)
		{
			i += offset;
		}
	}
	else
	{
		i = (haystack+'').lastIndexOf(needle);
	}
	return i >= 0 ? i : false;
}

function strrchr (haystack, needle)
{
    if (typeof needle !== 'string')
	{
        needle = String.fromCharCode(parseInt(needle, 10));
    }
	needle = needle.charAt(0);
    pos = haystack.lastIndexOf(needle);
    if (pos === -1)
	{
        return false;
    } 
    return haystack.substr(pos);
}

function parseFile(stringFile, restric)
{
	var nameFile = stringFile.substring(strrpos(stringFile, "/") + 1, stringFile.length);
	var nameFileNoExt = nameFile.substring(0, strrpos(nameFile, "."));
	var extFile = nameFile.substring(strrpos(nameFile, "."), stringFile.length);
	var fileDir = stringFile.substring(0, strrpos(stringFile, "/") + 1);
	
	if (typeof(restric) != "undefined")
	{
		if (restric == "dir")
		{
			return fileDir;
		}
		else if (restric == "name")
		{
			return nameFile;
		}
		else if (restric == "name_no_ext")
		{
			return nameFileNoExt;
		}
		else if (restric == "ext")
		{
			return extFile;
		}
		else
		{
			return stringFile;
		}
	}
	else
	{
		return stringFile;
	}
}

function in_array(needle, haystack, argStrict)
{
	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 detectIE(IEnum)
{
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
	
	return (strChMid.indexOf("MSIE "+IEnum) != -1);
}
