function trim(str) {
   if (typeof str == 'string')return str.replace(/^\s*|\s*$/gi,"");
   else return str;
}

function ltrim(str) {
	if (typeof str == 'string')return str.replace(/(^\s*)/g, "");
}

function rtrim(str) {
	if (typeof str == 'string')return str.replace(/(\s*$)/g, "");
}

//Verify is the passed string only contains numbers
function isDigit(fData)
{
	var reg = new RegExp("^[0-9]+$");
	return (reg.test(fData));
}

function isNumber(a) {
	return typeof a == 'number' && isFinite(a);
}

function isNumeric(a) {
	return !isNaN(a);
}

function isArray(a) {
    return ajaxIsObject(a) && a.constructor == Array;
}
function isString(a) {
    return typeof a == 'string';
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isFunction(a) {
    return typeof a == 'function';
}
function isObject(a) {
    return (a && typeof a == 'object') || ajaxIsFunction(a);
}
function isUndefined(a) {
    return typeof a == 'undefined';
}

function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isNull(a) {
    return a === null;
}

function podz_preview(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
	 for(var item in arr) {
	  var value = arr[item];
	 
	  if(typeof(value) == 'object') { //If it is an array,
	   dumped_text += level_padding + "'" + item + "' ...\n";
	   dumped_text += podz_preview(value,level+1);
	  } else {
	   dumped_text += level_padding + "'" + item.toString() + "' => \"" + value + "\"\n";
	  }
	 }
	} else { //Stings/Chars/Numbers etc.
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

//retourne le schema d'un objet ou tableau sans les fonctions 

function podz_preview2(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object')
	{ //Array/Hashes/Objects
	 if (typeof(arr) != 'function')	
	 {
		 for(var item in arr)
		 {
		  var value = arr[item];

			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += podz_preview2(value,level+1);
			} else {
				if (typeof(value) != 'function'){
					dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
				}
			}

		 }
	 }
	} else { //Stings/Chars/Numbers etc.
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

/*
--- fonction serialize et unserialize ---
auteur : XoraX
email : xxorax@gmail.com
info : http://www.xorax.info/blog/programmation/40-javascript-serialize-php.html
version : 1.2 - 2007/04/23

ChangeLog:
----------
1.2 : ajout du support pour la srialization d'Object php (case "O") + maj de la page de test
1.1 : fix bug dans unserialize sur boolean 

Description:
------------
permet de dcoder la chaine revoy par la fonction serialize php.
ne prend pas (encore?) en compte les objects.
*/

function serialize (txt) {
	switch(typeof(txt)){
	case 'string':
		return 's:'+txt.length+':"'+txt+'";';
	case 'number':
		if(txt>=0 && String(txt).indexOf('.') == -1 && txt < 65536) return 'i:'+txt+';';
		return 'd:'+txt+';';
	case 'boolean':
		return 'b:'+( (txt)?'1':'0' )+';';
	case 'object':
		var i=0,k,ret='';
		for(k in txt){
			//alert(isNaN(k));
			if(!isNaN(k)) k = Number(k);
			ret += serialize(k)+serialize(txt[k]);
			i++;
		}
		return 'a:'+i+':{'+ret+'}';
	default:
		return 'N;';
		alert('var undefined: '+typeof(txt));return undefined;
	}
}

function unserialize(txt){
	var level=0,arrlen=new Array(),del=0,final=new Array(),key=new Array(),save=txt;
	while(1){
		switch(txt.substr(0,1)){
		case 'N':
			del = 2;
			ret = null;
		break;
		case 'b':
			del = txt.indexOf(';')+1;
			ret = (txt.substring(2,del-1) == '1')?true:false;
		break;
		case 'i':
			del = txt.indexOf(';')+1;
			ret = Number(txt.substring(2,del-1));
		break;
		case 'd':
			del = txt.indexOf(';')+1;
			ret = Number(txt.substring(2,del-1));
		break;
		case 's':
			del = txt.substr(2,txt.substr(2).indexOf(':'));
			ret = txt.substr( 1+txt.indexOf('"'),del);
			del = txt.indexOf('"')+ 1 + ret.length + 2;
		break;
		case 'a':
			del = txt.indexOf(':{')+2;
			ret = new Array();
			arrlen[level+1] = Number(txt.substring(txt.indexOf(':')+1, del-2))*2;
		break;
		case 'O':
			txt = txt.substr(2);
			var tmp = txt.indexOf(':"')+2;
			var nlen = Number(txt.substring(0, txt.indexOf(':')));
			name = txt.substring(tmp, tmp+nlen );
			//alert(name);
			txt = txt.substring(tmp+nlen+2);
			del = txt.indexOf(':{')+2;
			ret = new Object();
			arrlen[level+1] = Number(txt.substring(0, del-2))*2;
		break;
		case '}':
			txt = txt.substr(1);
			if(arrlen[level] != 0){alert('var missed : '+save); return undefined;};
			//alert(arrlen[level]);
			level--;
		continue;
		default:
			if(level==0) return final;
			alert('syntax invalid(1) : '+save+"\nat\n"+txt+"level is at "+level);
			return undefined;
		}
		if(arrlen[level]%2 == 0){
			if(typeof(ret) == 'object'){alert('array index object no accepted : '+save);return undefined;}
			if(ret == undefined){alert('syntax invalid(2) : '+save);return undefined;}
			key[level] = ret;
		} else {
			var ev = '';
			for(var i=1;i<=level;i++){
				if(typeof(key[i]) == 'number'){
					ev += '['+key[i]+']';
				}else{
					ev += '["'+key[i]+'"]';
				}
			}
			eval('final'+ev+'= ret;');
		}
		arrlen[level]--;//alert(arrlen[level]-1);
		if(typeof(ret) == 'object') level++;
		txt = txt.substr(del);
		continue;
	}
}

function podz_hash(sFile)
{
	if (!sFile || sFile=="") return 1;
	var h=0,g=0;
	for (var i=sFile.length-1;i>=0;i--)
	{
 		var c=parseInt(sFile.charCodeAt(i));
		h=((h << 6) & 0xfffffff) + c + (c << 14);
		if ((g=h & 0xfe00000)!=0) h=(h ^ (g >> 21));
	}
	return h.toString();
}








if (Ext != null)
{

	/**
	 * Returns a string of Json that represents the tree
	 * @param {Function} (optional) A function, which when passed the node, returns true or false to include
	 * or exclude the node.
	 * @param {Function} (optional) A function, which when passed an attribute name, and an attribute value,
	 * returns true or false to include or exclude the attribute.
	 * @return {String}
	 */
	Ext.data.Tree.prototype.toJsonString = function(nodeFilter, attributeFilter){
	      return this.getRootNode().toJsonString(nodeFilter, attributeFilter);
	};
	/**
	 * Returns a string of Json that represents the node
	 * @param {Function} (optional) A function, which when passed the node, returns true or false to include
	 * or exclude the node.
	 * @param {Function} (optional) A function, which when passed an attribute name, and an attribute value,
	 * returns true or false to include or exclude the attribute.
	 * @return {String}
	 */
	Ext.data.Node.prototype.toJsonString = function(nodeFilter, attributeFilter){
	// Exclude nodes based on caller-supplied filtering function
	    if (nodeFilter && (nodeFilter(this) == false)) {
	        return '';
	    }
	    var c = false, result = "{";
	// Add the id attribute unless the attribute filter rejects it.
	    if (!attributeFilter || attributeFilter("id", this.id)) {
	        result += '"id":"' + this.id + '"';
	        c = true;
	    }
	// Add all user-added attributes unless rejected by the attributeFilter.
	    for(var key in this.attributes) {
	        if ((key != 'id') && (!attributeFilter || attributeFilter(key, this.attributes[key]))) {
	         if (c) result += ',';
	         result += '"' + key + '":"' + this.attributes[key] + '"';
	         c = true;
	     }
	    }
	// Add child nodes if any
	    var children = this.childNodes;
	    var clen = children.length;
	    if(clen != 0){
	        if (c) result += ',';
	        result += '"children":['
	        for(var i = 0; i < clen; i++){
	            if (i > 0) result += ',';
	            result += children[i].toJsonString(nodeFilter, attributeFilter);
	        }
	        result += ']';
	    }
	    return result + "}";
	};
	/**
	 * Returns a string of XML that represents the tree
	 * @param {Function} (optional) A function, which when passed the node, returns true or false to include
	 * or exclude the node.
	 * @param {Function} (optional) A function, which when passed an attribute name, and an attribute value,
	 * returns true or false to include or exclude the attribute.
	 * @return {String}
	 */
	Ext.data.Tree.prototype.toXmlString = function(nodeFilter, attributeFilter){
	 return '\u003C?xml version="1.0"?>\u003Ctree>' +
	  this.getRootNode().toXmlString(nodeFilter, attributeFilter) +
	  '\u003C/tree>';
	};
	/**
	 * Returns a string of XML that represents the node
	 * @param {Function} (optional) A function, which when passed the node, returns true or false to include
	 * or exclude the node.
	 * @param {Function} (optional) A function, which when passed an attribute name, and an attribute value,
	 * returns true or false to include or exclude the attribute.
	 * @return {String}
	 */
	Ext.data.Node.prototype.toXmlString = function(nodeFilter, attributeFilter){
	// Exclude nodes based on caller-supplied filtering function
	    if (nodeFilter && (nodeFilter(this) == false)) {
	        return '';
	    }
	    var result = '\u003Cnode';
	// Add the id attribute unless the attribute filter rejects it.
	    if (!attributeFilter || attributeFilter("id", this.id)) {
	        result += ' id="' + this.id + '"';
	    }
	// Add all user-added attributes unless rejected by the attributeFilter.
	    for(var key in this.attributes) {
	        if ((key != 'id') && (!attributeFilter || attributeFilter(key, this.attributes[key]))) {
	         result += ' ' + key + '="' + this.attributes[key] + '"';
	     }
	    }
	// Add child nodes if any
	    var children = this.childNodes;
	    var clen = children.length;
	    if(clen == 0){
	        result += '/>';
	    }else{
	        result += '>';
	        for(var i = 0; i < clen; i++){
	            result += children[i].toXmlString(nodeFilter, attributeFilter);
	        }
	        result += '\u003C/node>';
	    }
	    return result;
	};

}


function htmlentities( s ){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: htmlentities('Kevin & van Zonneveld');
    // *     returns 1: 'Kevin &amp; van Zonneveld'
 
    var div = document.createElement('div');
    var text = document.createTextNode(s);
    div.appendChild(text);
    return div.innerHTML;
}

function HTMLentities(texte) {

//texte = texte.replace(/&/g,'&amp;'); // 38 26
texte = texte.replace(/"/g,'&quot;'); // 34 22
texte = texte.replace(/\'/g,'&#39;'); // 39 27
//texte = texte.replace(/</g,'&lt;'); // 60 3C
//texte = texte.replace(/>/g,'&gt;'); // 62 3E
texte = texte.replace(/\^/g,'&circ;'); // 94 5E
texte = texte.replace(//g,'&lsquo;'); // 145 91
texte = texte.replace(//g,'&rsquo;'); // 146 92
texte = texte.replace(//g,'&ldquo;'); // 147 93
texte = texte.replace(//g,'&rdquo;'); // 148 94
texte = texte.replace(//g,'&bull;'); // 149 95
texte = texte.replace(//g,'&ndash;'); // 150 96
texte = texte.replace(//g,'&mdash;'); // 151 97
texte = texte.replace(//g,'&tilde;'); // 152 98
texte = texte.replace(//g,'&trade;'); // 153 99
texte = texte.replace(//g,'&scaron;'); // 154 9A
texte = texte.replace(//g,'&rsaquo;'); // 155 9B
texte = texte.replace(//g,'&oelig;'); // 156 9C
texte = texte.replace(//g,'&#357;'); // 157 9D
texte = texte.replace(//g,'&#382;'); // 158 9E
texte = texte.replace(//g,'&Yuml;'); // 159 9F
// texte = texte.replace(/ /g,'&nbsp;'); // 160 A0
texte = texte.replace(//g,'&iexcl;'); // 161 A1
texte = texte.replace(//g,'&cent;'); // 162 A2
texte = texte.replace(//g,'&pound;'); // 163 A3
//texte = texte.replace(/ /g,'&curren;'); // 164 A4
texte = texte.replace(//g,'&yen;'); // 165 A5
texte = texte.replace(//g,'&brvbar;'); // 166 A6
texte = texte.replace(//g,'&sect;'); // 167 A7
texte = texte.replace(//g,'&uml;'); // 168 A8
texte = texte.replace(//g,'&copy;'); // 169 A9
texte = texte.replace(//g,'&ordf;'); // 170 AA
texte = texte.replace(//g,'&laquo;'); // 171 AB
texte = texte.replace(//g,'&not;'); // 172 AC
texte = texte.replace(//g,'&shy;'); // 173 AD
texte = texte.replace(//g,'&reg;'); // 174 AE
texte = texte.replace(//g,'&macr;'); // 175 AF
texte = texte.replace(//g,'&deg;'); // 176 B0
texte = texte.replace(//g,'&plusmn;'); // 177 B1
texte = texte.replace(//g,'&sup2;'); // 178 B2
texte = texte.replace(//g,'&sup3;'); // 179 B3
texte = texte.replace(//g,'&acute;'); // 180 B4
texte = texte.replace(//g,'&micro;'); // 181 B5
texte = texte.replace(//g,'&para'); // 182 B6
texte = texte.replace(//g,'&middot;'); // 183 B7
texte = texte.replace(//g,'&cedil;'); // 184 B8
texte = texte.replace(//g,'&sup1;'); // 185 B9
texte = texte.replace(//g,'&ordm;'); // 186 BA
texte = texte.replace(//g,'&raquo;'); // 187 BB
texte = texte.replace(//g,'&frac14;'); // 188 BC
texte = texte.replace(//g,'&frac12;'); // 189 BD
texte = texte.replace(//g,'&frac34;'); // 190 BE
texte = texte.replace(//g,'&iquest;'); // 191 BF
texte = texte.replace(//g,'&Agrave;'); // 192 C0
texte = texte.replace(//g,'&Aacute;'); // 193 C1
texte = texte.replace(//g,'&Acirc;'); // 194 C2
texte = texte.replace(//g,'&Atilde;'); // 195 C3
texte = texte.replace(//g,'&Auml;'); // 196 C4
texte = texte.replace(//g,'&Aring;'); // 197 C5
texte = texte.replace(//g,'&AElig;'); // 198 C6
texte = texte.replace(//g,'&Ccedil;'); // 199 C7
texte = texte.replace(//g,'&Egrave;'); // 200 C8
texte = texte.replace(//g,'&Eacute;'); // 201 C9
texte = texte.replace(//g,'&Ecirc;'); // 202 CA
texte = texte.replace(//g,'&Euml;'); // 203 CB
texte = texte.replace(//g,'&Igrave;'); // 204 CC
texte = texte.replace(//g,'&Iacute;'); // 205 CD
texte = texte.replace(//g,'&Icirc;'); // 206 CE
texte = texte.replace(//g,'&Iuml;'); // 207 CF
texte = texte.replace(//g,'&ETH;'); // 208 D0
texte = texte.replace(//g,'&Ntilde;'); // 209 D1
texte = texte.replace(//g,'&Ograve;'); // 210 D2
texte = texte.replace(//g,'&Oacute;'); // 211 D3
texte = texte.replace(//g,'&Ocirc;'); // 212 D4
texte = texte.replace(//g,'&Otilde;'); // 213 D5
texte = texte.replace(//g,'&Ouml;'); // 214 D6
texte = texte.replace(//g,'&times;'); // 215 D7
texte = texte.replace(//g,'&Oslash;'); // 216 D8
texte = texte.replace(//g,'&Ugrave;'); // 217 D9
texte = texte.replace(//g,'&Uacute;'); // 218 DA
texte = texte.replace(//g,'&Ucirc;'); // 219 DB
texte = texte.replace(//g,'&Uuml;'); // 220 DC
texte = texte.replace(//g,'&Yacute;'); // 221 DD
texte = texte.replace(//g,'&THORN;'); // 222 DE
texte = texte.replace(//g,'&szlig;'); // 223 DF
texte = texte.replace(//g,'&aacute;'); // 224 E0
texte = texte.replace(//g,'&aacute;'); // 225 E1
texte = texte.replace(//g,'&acirc;'); // 226 E2
texte = texte.replace(//g,'&atilde;'); // 227 E3
texte = texte.replace(//g,'&auml;'); // 228 E4
texte = texte.replace(//g,'&aring;'); // 229 E5
texte = texte.replace(//g,'&aelig;'); // 230 E6
texte = texte.replace(//g,'&ccedil;'); // 231 E7
texte = texte.replace(//g,'&egrave;'); // 232 E8
texte = texte.replace(//g,'&eacute;'); // 233 E9
texte = texte.replace(//g,'&ecirc;'); // 234 EA
texte = texte.replace(//g,'&euml;'); // 235 EB
texte = texte.replace(//g,'&igrave;'); // 236 EC
texte = texte.replace(//g,'&iacute;'); // 237 ED
texte = texte.replace(//g,'&icirc;'); // 238 EE
texte = texte.replace(//g,'&iuml;'); // 239 EF
texte = texte.replace(//g,'&eth;'); // 240 F0
texte = texte.replace(//g,'&ntilde;'); // 241 F1
texte = texte.replace(//g,'&ograve;'); // 242 F2
texte = texte.replace(//g,'&oacute;'); // 243 F3
texte = texte.replace(//g,'&ocirc;'); // 244 F4
texte = texte.replace(//g,'&otilde;'); // 245 F5
texte = texte.replace(//g,'&ouml;'); // 246 F6
texte = texte.replace(//g,'&divide;'); // 247 F7
texte = texte.replace(//g,'&oslash;'); // 248 F8
texte = texte.replace(//g,'&ugrave;'); // 249 F9
texte = texte.replace(//g,'&uacute;'); // 250 FA
texte = texte.replace(//g,'&ucirc;'); // 251 FB
texte = texte.replace(//g,'&uuml;'); // 252 FC
texte = texte.replace(//g,'&yacute;'); // 253 FD
texte = texte.replace(//g,'&thorn;'); // 254 FE
texte = texte.replace(//g,'&yuml;'); // 255 FF
return texte;
}

function html_entity_decode( string ) {
    // http://kevin.vanzonneveld.net
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'
 
    var ret, tarea = document.createElement('textarea');
    tarea.innerHTML = string;
    ret = tarea.value;
    return ret;
}

function htmlspecialchars(string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Nathan
    // +   bugfixed by: Arno
    // *     example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
    // *     returns 1: '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;'
    
    string = string.toString();
    
    // Always encode
    string = string.replace(/&/g, '&amp;');
    string = string.replace(/</g, '&lt;');
    string = string.replace(/>/g, '&gt;');
    
    // Encode depending on quote_style
    if (quote_style == 'ENT_QUOTES') {
        string = string.replace(/"/g, '&quot;');
        string = string.replace(/'/g, '&#039;');
    } else if (quote_style != 'ENT_NOQUOTES') {
        // All other cases (ENT_COMPAT, default, but not ENT_NOQUOTES)
        string = string.replace(/"/g, '&quot;');
    }
    
    return string;
}

function basename (path, suffix) {
    // Returns the filename component of the path  
    // 
    // version: 910.820
    // discuss at: http://phpjs.org/functions/basename    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');    // *     returns 1: 'home'
    // *     example 2: basename('ecra.php?p=1');
    // *     returns 2: 'ecra.php?p=1'
	var b=null;
	if (path != undefined)
	{
	    b = path.replace(/^.*[\/\\]/g, '');
	        if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
	        b = b.substr(0, b.length-suffix.length);
	    }
	}
    return b;
}

function isEmailValid(email)
{
	if(email == null){ //if no email entered ->
		return false; //exit with FALSE
	}
	var atPos = email.indexOf("@"); //get position of AT char
	if( atPos < 1 || email.indexOf(".", atPos) == -1 ){ //if "@" is first, or "." is before "@"
		return false //exit with FALSE
	}
	var login = email.substring(0, atPos); //get lagin name
	var domain = email.substring(atPos + 1, email.length); //get domain
	var atom = "\[^\\s\\(\\)<>@,;:\\\\\\\"\\.\\[\\]\]+"; //login pattern
	var word = "(" + atom + '(|-("[^\"]*")))'; //finish pattern
	var loginRE = new RegExp('^' + word + '(\\.' + word + ')*$'); //create regexp object
	for (var i = 0; i < login.length; i++){ //for all characters ->
		if (login.charCodeAt(i) > 127){ //if not latin ->
			return false; //exit with FALSE
		}
	}
	if (!login.match(loginRE)){ //if login not valid ->
		return false; //exit with FALSE
	}
	return isDomainValid(domain); //check domain and return result
}

function emailCheck (emailStr) {

	var myEMailIsValid = true;
	var myAtSymbolAt = emailStr.indexOf('@');
	var myLastDotAt = emailStr.lastIndexOf('.');
	var mySpaceAt = emailStr.indexOf(' ');
	var myLength = emailStr.length;
	
	// at least one @ must be present and not before position 2
	// @yellow.com : NOT valid
	// x@yellow.com : VALID
	
	if (myAtSymbolAt < 1 ) {
		myEMailIsValid = false;
	}
	
	
	// at least one . (dot) afer the @ is required
	// x@yellow : NOT valid
	// x.y@yellow : NOT valid
	// x@yellow.org : VALID
	
	if (myLastDotAt < myAtSymbolAt) {
		myEMailIsValid = false;
	}
	
	// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
	// x.y@yellow. : NOT valid
	// x.y@yellow.a : NOT valid
	// x.y@yellow.ca : VALID
	 
	if (myLength - myLastDotAt <= 2) {
		myEMailIsValid = false;
	}
	
	// no empty space " " is permitted (one may trim the email)
	// x.y@yell ow.com : NOT valid
	
	if (mySpaceAt != -1) {
		myEMailIsValid = false
	}
		
	if (myEMailIsValid == true) {
		return true;
	}
	else {
		return false;
	}

}
