function traitement_en_cours(id) {	
	
	//id.style.display = "none";
	
	id.style.opacity = 0.01;
	id.style.filter = 'alpha(opacity=' + 1 + ')';
	

	x = parseInt(document.body.clientWidth)/2 ;
	y = parseInt(document.body.clientHeight)/2 - 50;
	
	var newdiv=document.createElement("div");
	newdiv.id = 'wait_pannel';
	newdiv.style.textAlign = "center";

	newdiv.style.position = "absolute";
	newdiv.style.height = "50px";
	newdiv.style.width = "175px";
	newdiv.style.top = y+"px";
	newdiv.style.left = x+"px";
	newdiv.style.display = "block";
	
	newdiv.innerHTML = "<img src=\"../../image_intra/wait_blue.gif\"  /><br />Traitement en cours ...";
	
	document.body.appendChild(newdiv);
	
	
}
function fill_date(textbox)
{
	if(textbox.value.length ==4 || textbox.value.length ==7)
	{
		textbox.value = textbox.value + "-";
	}
}
function isEmpty(str) {
  if (str==null || str=="")
    return true;
  return false;
}

var xmlHttp;
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
 		// Firefox, Opera 8.0+, Safari
		 xmlHttp=new XMLHttpRequest();
	 }
	 catch (e)
	 {
 //Internet Explorer
		 try
		  {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		 catch (e)
		  {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
 	 }
	 return xmlHttp;
}
function remplir_ordre()
{
	var input = arguments[0];
	var table = arguments[1];
	var champ_ordre = arguments[2];
	var champ_isactif = arguments[3];
	var selected = (arguments[4] ? arguments[4] : 0 );
  
  
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
	//C'est dans la focntion  ajax qui est la traitement des modification
	xmlHttp.onreadystatechange=function()
      {
        if(xmlHttp.readyState==4)
        {
			//alert(xmlHttp.responseText);
			var max_ordre = eval(xmlHttp.responseText);
			if(selected != 0)
			{
				//alert(-1);
				max_ordre = max_ordre-1;
			}
			
			document.getElementById(input).length=0;
			for (i=0;i<max_ordre;i++)
			{
				document.getElementById(input).options[i] = new Option(i+1);
				if(selected == 0)
				{
					if (i==0)
						{document.getElementById(input).selectedIndex = i;}
				}
				else
				{
					if (i==selected-1)
							{document.getElementById(input).selectedIndex = i;}
				}
			}
        } // if ready state 
      }// 
    xmlHttp.open("POST",'general_ajax.php',true);
    //Pour envoyer les parametre au serveur 
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	//Recuperation des variable pour l'envoi pour enregistrement 
 	var param = "get_ordre=1&table="+table+"&champ_ordre="+champ_ordre+"&champ_isactif="+champ_isactif;
	//alert(param);
	xmlHttp.send(param);


}
function remplir_ordre_cat()
{
	alert("test");
	
	var input = arguments[0];
	var table = arguments[1];
	var champ_cat = arguments[2];
	var cat = arguments[3];
	var champ_ordre = arguments[4];
	var champ_isactif = arguments[5];
	var selected = (arguments[6] ? arguments[6] : 0 );
  
  
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
	//C'est dans la focntion  ajax qui est la traitement des modification
	xmlHttp.onreadystatechange=function()
      {
        if(xmlHttp.readyState==4)
        {
			//alert(xmlHttp.responseText);
			var max_ordre = eval(xmlHttp.responseText);
			if(selected != 0)
				max_ordre = max_ordre-1;
			document.getElementById(input).length=0;
			for (i=0;i<max_ordre;i++)
			{
				document.getElementById(input).options[i] = new Option(i+1);
				if(selected == 0)
				{
					if (i==0)
						{document.getElementById(input).selectedIndex = i;}
				}
				else
				{
					if (i==selected-1)
							{document.getElementById(input).selectedIndex = i;}
				}
			}
        } // if ready state 
      }// 
    xmlHttp.open("POST",'general_ajax.php',true);
    //Pour envoyer les parametre au serveur 
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	//Recuperation des variable pour l'envoi pour enregistrement 
 	var param = "get_ordre_cat=1&table="+table+"&champ_cat="+champ_cat+"&cat="+cat+"&champ_ordre="+champ_ordre+"&champ_isactif="+champ_isactif;
	//alert(param);
	xmlHttp.send(param);


}
function isUSDate(str) {
 
  if (str.length!=10 || str.charAt(4)!="-" || str.charAt(7)!="-" || (str.substring(0,4) + str.substring(5,7) + str.substring(8,10)) < 0)
    return false;
  
  // a modifier 
  var y = str.substring(0,4) - 0;
  var m = str.substring(5,7) - 0;
  var d = str.substring(8,10) - 0;  
   //alert(y + "-" + m + "-" + d);	
   
  if (d==0 || m==0 || y==0)
    return false;

  if (m>12) return false;
  
  if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) 
  {
    var dmax = 31;
  }
  else
  {
    if (m==4 || m==6 || m==9 || m==11) 
		dmax = 30;
	else 
    {
	  if ((y%400==0) || (y%4==0 && y%100!=0)) 
	  	dmax = 29;
      else 
	  	dmax = 28;
	}
  }
  if (d>dmax) return false;
  
  return true;
   
}
function popupcentree(page,largeur,hauteur,options, nom)
{
	var top= 40 ///(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2; 	
	window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options).focus();

}
// Liste des pays et provinces
var tb_ListePays = new Array("Canada", "EtatsUnis", "Afghanistan", "Afrique du Sud", "Albanie", "Algerie", "Allemagne", "Andorre", "Angola", "Anguilla", "Antarctique", "Antigua et Barbuda", "Antilles neerlandaises", "Arabie saoudite", "Argentine", "Armenie", "Aruba", "Australie", "Autriche", "Azerbaidjan", "Bahamas", "Bahrein", "Barbade", "Belgique", "Belize", "Benin", "Bangladesh", "Bermudes", "Bhoutan", "Bolivie", "Bosnie-Herzegovine", "Botswana", "Bresil", "Brunei Darussalam", "Bulgarie", "Burkina Faso", "Burundi", "Cambodge", "Cameroun", "Canada", "Cap-Vert", "Chili", "Chine", "Chypre", "Comores", "Congo", "Costa Rica", "Cote d'Ivoire", "Croatie (Hrvatska)", "Cuba", "Danemark", "Ethiopie", "Dominique", "El Salvador", "Emirats arabes unis", "Equateur", "Erythree", "Espagne", "Estonie", "EtatsUnis", "Ethiopie", "Fidji", "Finlande", "France", "East Timor", "France metropolitaine", "Guinee-Bissau", "Gambie", "Georgie", "Georgie du Sud et iles Hawaii", "Ghana", "Gibraltar", "Grece", "Faroe Islands", "Grenade", "Groenland", "France", "Guam", "Guatemala", "Guinee", "Guinee equatorienne", "Guinee francaise", "Guinee-Bissau", "Guyane", "Haiti", "Honduras", "Hong Kong", "Hongrie", "Ile Bouvet", "Ile Christmas", "Ile Norfolk", "Iles Caiman", "Iles Cocos (Keeling)", "Iles Cook", "Iles Feroe", "Iles Heard et Mc Donald", "Iles Malouines", "Iles Mariannes du Nord", "Iles Marshall", "Iles mineures voisines des Etats-Unis", "Iles Salomon", "Iles Turks et Caicos", "Iles Vierges americaines", "Iles Vierges britanniques", "Iles Wallis et Futuna", "Inde", "Iran ", "Iraq", "Irlande", "Islande", "Israel", "Italie", "Jamaique", "Japon", "Jordanie", "Kazakhstan", "Kenya", "Kirghizistan", "Kiribati", "Koweit", "Liban", "Liberia", "Libye", "Liechtenstein", "Luxembourg", "Macao", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malte", "Maroc", "Martinique", "Mauritania", "Maurice", "Mayotte", "Mexique", "Micronesie", "Moldavie", "Monaco", "Mongolie", "Montserrat", "Mozambique", "Myanmar", "Namibie", "Nauru", "Nepal", "Nicaragua", "Niger", "Norvege", "Nicaragua", "Niger", "Niue", "Nouvelle-Caledonie", "Nouvelle-Zelande", "Oman", "Ouganda", "Ouzbekistan", "Palaos", "Panama", "Papouasie-Nouvelle-Guinee", "Paraguay", "Pays-Bas", "Philippines", "Pitcairn", "Pologne", "Portugal", "Puerto Rico", "Qatar", "Republique arabe syrienne", "Republique centrafricaine", "Republique de Coree", "Republique de Lettonie", "Republique democratique populaire lao", "Republique dominicaine", "Republique populaire democratique de Coree", "Republique tcheque", "Republique-Unie de Tanzanie", "Reunion", "Royaume-Uni", "Rwanda", "Sahara occidental", "Sainte-Helene", "Sainte-Lucie", "Saint-Kitts-et-Nevis", "Saint-Marin", "Saint-Pierre et Miquelon", "Saint-Siege (Cite du Vatican)", "Saint-Vincent et les Grenadines", "Samoa", "Samoa americaines", "Sao Tome-et-Principe", "Senegal", "Seychelles", "Sierra Leone", "Singapour", "Slovaquie", "Slovenie", "Somalie", "Soudan", "Sri Lanka", "Suede", "Suisse", "Suriname", "Svalbard et Jan Meyen", "Swaziland ", "Tadjikistan ", "Taiwan", "Tchad", "Terres australes francaises", "Territoire britannique de l'ocean Indien", "Thailande", "Timor-Oriental", "Togo", "Tokelau", "Tonga", "Trinite-et-Tobago", "Tunisie", "Turkmenistan", "Turquie", "Tuvalu", "Ukraine", "Uruguay", "Vanuatu", "Vietnam", "Yemen", "Yougaslavie", "Zaire", "Zambie", "Zimbabwe");

var tb_EtatsUnis = new Array("Alaska","Alabama","Arkansas","American Samoa","Arizona","California","Colorado","Connecticut","District of Columbia","Delaware","Florida","Federated States of Micronesia","Georgia","Guam","Hawaii","Iowa","Idaho ","Illinois","Indiana","Kansas","Kentucky","Louisiana ","Massachusetts","Maryland","Maine","Marshall Islands","Michigan","Minnesota","Missouri","Northern Mariana Islands","Mississippi","Montana","North Carolina","North Dakota","Nebraska","New Hampshire","New Jersey","New Mexico","Nevada","New York","Ohio","Oklahoma","Oregon","Pennsylvania","Puerto Rico","Palau","Rhode Island","South Carolina","South Dakota","Tennessee","Trust Territories","Texas","Utah","Virginia","Virgin Islands","Vermont","Washington","Wisconsin","West Virginia","Wyoming");
var tb_Canada = new Array("Québec","Alberta","Colombie-Britannique","Manitoba","Nouveau-Brunswick","Nouvelle-Ecosse","Nunavut","Territoires du Nord-Ouest","Terre-Neuve","Ontario","Ile-du-Prince Edouard","Saskatchewan","Yukon");
var tb_Autre = new Array("---- Autre----");

/*********************************************************************************************
Remplit le combo passé en paramètre avec le tableau passé en paramètre et sélectionne 
l'élément "id_to_select".
*/
function load_combo(LeCombo, Tableau_Valeurs, id_to_select){
	LeCombo.options.length = 0;
	for (i=0;i<Tableau_Valeurs.length;i++){
		LeCombo.options[i] = new Option(Tableau_Valeurs[i]);
		if (i==id_to_select){LeCombo.selectedIndex = i;}
	}
}

/*********************************************************************************************
Remplit le combo passé en paramètre avec le tableau passé en paramètre et sélectionne 
l'élément "id_to_select".
*/
function load_combo3d(LeCombo, Tableau_Valeurs, id_to_select){
	LeCombo.options.length = 0;
	for (i=0;i<Tableau_Valeurs.length;i++){
		LeCombo.options[i] = new Option(Tableau_Valeurs[i][1],Tableau_Valeurs[i][0]);
		if (i==id_to_select){LeCombo.selectedIndex = i;}
	}
}

/*********************************************************************************************
Remplit le combo passé en paramètre avec le tableau des pays
*/
function load_pays(LeCombo, id_to_select){
	load_combo(LeCombo, tb_ListePays, id_to_select);
}

/*********************************************************************************************
Remplit le combo "LeComboProvince" avec le tableau des provinces selon le pays 
sélectionné dans le combo "LeComboPays" et sélectionne la province "id_to_select"
*/
function load_province(LeComboPays, LeComboProvince, id_to_select){
	var id_Canada = 0;
	var id_EtatUnis = 1;
	
	switch(LeComboPays.selectedIndex){
	case id_Canada: 
		load_combo(LeComboProvince, tb_Canada, id_to_select);
		break;
	case id_EtatUnis : 
		load_combo(LeComboProvince, tb_EtatsUnis, id_to_select);
		break;
	default : 
		load_combo(LeComboProvince, tb_Autre, id_to_select);
		break;
	}
}



/*********************************************************************************************
Retourne l'indice du pays recherché (nom_pays_rech) dans le tableau "tb_ListePays"
*/
function get_pays_id(nom_pays_rech){
	return get_indice(tb_ListePays, nom_pays_rech);
}

/*********************************************************************************************
Retourne l'indice de la province recherchée (nom_province_rech) dans le tableau des provinces correspondant au pays
*/
function get_province_id(indice_pays, nom_province_rech){
	var id_Canada = 0;
	var id_EtatUnis = 1;

	switch(indice_pays){
	case id_Canada : 
		return get_indice(tb_Canada, nom_province_rech);
		break;
	case id_EtatUnis : 
		return get_indice(tb_EtatsUnis, nom_province_rech);
		break;
	default : 
		return get_indice(tb_Autre, nom_province_rech);
		break;
	}
}

/*********************************************************************************************
Retourne l'indice d'un élément dans un tableau
*/
function get_indice(le_tableau, chaine_rech){
	for(i=0;i<le_tableau.length;i++){
		if (le_tableau[i]==chaine_rech){
			return i;
		}
	}
	return -1;
}

// Fonction Valid Date 
function inValidCharSet(str,charset)
{
	var result = true;
	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}


function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}


function validDate(formField)
{
	var result = true;
 	if (result)
 	{
 		var elems = formField.value.split("-");
 		
 		result = (elems.length == 3); // should be three components
 		
 		if (result)
 		{
 			var month = parseInt(elems[1],10);
  			var day = parseInt(elems[2],10);
 			var year = parseInt(elems[0],10);
			result = allDigits(elems[1]) && (month > 0) && (month < 13) &&
					 allDigits(elems[2]) && (day > 0) && (day < 32) &&
					 allDigits(elems[0]) && ((elems[2].length == 2) || (elems[2].length == 4));
 		}
	} 
	
	return result;
}

var n;
var p;
var p1;
function ValidatePhone(){
	p=p1.value
	if(p.length==3){
		//d10=p.indexOf('(')
		pp=p;
		d4=p.indexOf('(')
		d5=p.indexOf(')')
		if(d4==-1){
			pp="("+pp;
		}
		if(d5==-1){
			pp=pp+")";
		}
		//pp="("+pp+")";
		p1.value="";
		p1.value=pp;
	}
	if(p.length>3){
		d1=p.indexOf('(')
		d2=p.indexOf(')')
		if (d2==-1){
			l30=p.length;
			p30=p.substring(0,4);
			//alert(p30);
			p30=p30+")"
			p31=p.substring(4,l30);
			pp=p30+p31;
			//alert(p31);
			p1.value="";
			p1.value=pp;
		}
		}
	if(p.length>5){
		p11=p.substring(d1+1,d2);
		if(p11.length>3){
		p12=p11;
		l12=p12.length;
		l15=p.length
		//l12=l12-3
		p13=p11.substring(0,3);
		p14=p11.substring(3,l12);
		p15=p.substring(d2+1,l15);
		p1.value="";
		pp="("+p13+")"+p14+p15;
		p1.value=pp;
		//obj1.value="";
		//obj1.value=pp;
		}
		l16=p.length;
		p16=p.substring(d2+1,l16);
		l17=p16.length;
		if(l17>3&&p16.indexOf('-')==-1){
			p17=p.substring(d2+1,d2+4);
			p18=p.substring(d2+4,l16);
			p19=p.substring(0,d2+1);
			//alert(p19);
		pp=p19+p17+"-"+p18;
		p1.value="";
		p1.value=pp;
		//obj1.value="";
		//obj1.value=pp;
		}
}
//}
	setTimeout(ValidatePhone,100)
}
function getIt(m){
	n=m.name;
	//p1=document.forms[0].elements[n]
	p1=m;
	ValidatePhone();
}
function isValidePhone(p){
	//alert(p)
	p=p.replace("(","");
	p=p.replace(")","");
	p=p.replace("-","");
	p=p.replace("-","");
	//alert(p.length)
	return (!isNaN(p) && p.length == 10);
}


//	####################################	MASQUE DE SAISIE POUR TELEPHONE, FAX ET CODE POSTAL [DEBUT]
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
//	alert('Follow that path !');
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].select();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)
				index = i;
			else 
				i++;
		return index;
	}
	return true;
}
//	####################################	MASQUE DE SAISIE POUR TELEPHONE, FAX ET CODE POSTAL [FIN]
function isPostCode(entry){ // CANADIAN CODES ONLY
	strlen=entry.length; if (strlen!=6) {return false}
	entry=entry.toUpperCase();    // in case of lowercase characters
	// Check for legal characters in string - note index starts at zero
	if ('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0) {return false}
	if ('0123456789'.indexOf(entry.charAt(1))<0) {return false}
	if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0) {return false}
	if ('0123456789'.indexOf(entry.charAt(3))<0) {return false}
	if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4))<0) {return false}
	if ('0123456789'.indexOf(entry.charAt(5))<0) {return false}
	return true; 
}

function confirmDelete()
{
	var rep=confirm("Voulez-vous vraiment effacer cet élément?");
	if (rep)
		return true ;
	else
		return false ;
}
function isValidExtention(filename, validExtentions)
{
	var valid = false;
	var parts = filename.split(".");
	
	for(i = 0;i < validExtentions.length;i++)
	{
		if(parts[parts.length-1].toUpperCase() == validExtentions[i].toUpperCase())
			valid = true;
	}
	
	if(valid == true)
		return valid;
	else
	{
		var message = "-> fichier *."+parts[parts.length-1].toUpperCase()+" invalides : Les type de fichier suivants sont acceptés: "; 
		for(i = 0;i < validExtentions.length;i++)
		{
			message += validExtentions[i] + " ";
		}
	}
	return message;

}
function copyToClipboard(s)
{
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", s);
	}
	else
	{
		// You have to sign the code to enable this or allow the action in about:config by changing
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);	   
	}
}

function remplir_ordre_section()
{
	var input = arguments[0];
	var table = arguments[1];
	var cat = arguments[2];
	var selected = (arguments[3] ? arguments[3] : 0 );
  
  
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
	//C'est dans la focntion  ajax qui est la traitement des modification
	xmlHttp.onreadystatechange=function()
      {
        if(xmlHttp.readyState==4)
        {
			//alert(xmlHttp.responseText);
			var max_ordre = eval(xmlHttp.responseText);
			if(selected != 0)
				max_ordre = max_ordre-1;
			document.getElementById(input).length=0;
			for (i=0;i<max_ordre;i++)
			{
				document.getElementById(input).options[i] = new Option(i+1);
				if(selected == 0)
				{
					if (i==0)
						{document.getElementById(input).selectedIndex = i;}
				}
				else
				{
					if (i==selected-1)
							{document.getElementById(input).selectedIndex = i;}
				}
			}
        } // if ready state 
      }// 
    xmlHttp.open("POST",'general_ajax.php',true);
    //Pour envoyer les parametre au serveur 
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	//Recuperation des variable pour l'envoi pour enregistrement 
 	var param = "get_ordre_cat=1&table="+table+"&cat="+cat;
	//alert(param);
	xmlHttp.send(param);


}

function strip_tags(str, allowed_tags) {
    // Strips HTML and PHP tags from a string 
    //
    // version: 903.3016
    // discuss at: http://phpjs.org/functions/strip_tags
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Eric Nagel
    // +      input by: Bobby Drake
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    // *     example 4: strip_tags('1 < 5 5 > 1');
    // *     returns 4: '1 < 5 5 > 1'
    var key = '', allowed = false;
    var matches = [];
    var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = '';
 
    var replacer = function(search, replace, str) {
        return str.split(search).join(replace);
    };
 
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
    }
   
    str += '';
 
    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);
 
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
 
        // Save HTML tag
        html = matches[key].toString();
 
        // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
 
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
 
    return str;
}

