// JavaScript Document

/*
  * http://phpjs.org/functions/var_dump:604
  */
function var_dump () {
    var output = "", pad_char = " ", pad_val = 4, lgth = 0, i = 0, d = this.window.document;
    var getFuncName = function (fn) {
        var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
        if (!name) {
            return '(Anonymous)';
        }
        return name[1];
    };
    var repeat_char = function (len, pad_char) {
        var str = "";
        for (var i=0; i < len; i++) {
            str += pad_char;
        }
        return str;
    };
    var getScalarVal = function (val) {
        var ret = '';
        if (val === null) {
            ret = 'NULL';
        }
        else if (typeof val === 'boolean') {
            ret = 'bool('+val+')';
        }
        else if (typeof val === 'string') {
            ret = 'string('+val.length+') "'+val+'"';
        }
        else if (typeof val === 'number') {
            if (parseFloat(val) == parseInt(val, 10)) {
                ret = 'int('+val+')';
            }
            else {
                ret = 'float('+val+')';
            }
        }
        else if (val === undefined) {
            ret = 'UNDEFINED'; // Not PHP behavior, but neither is undefined as value
        }
        else if (typeof val === 'function') {
            ret = 'FUNCTION'; // Not PHP behavior, but neither is function as value
			ret = val.toString().split("\n");
			txt = "";
			for(var j in ret) {
				txt+= (j !=0 ? thick_pad : '')+ret[j]+"\n";
			}
			ret = txt;
        }
		else if(val instanceof Date) {
			val = val.toString();
			ret = 'string('+val.length+') "'+val+'"'
		}
		else if(val.nodeName) {
			ret = 'HTMLElement("'+val.nodeName.toLowerCase()+'")';
		}
        return ret;
    };
    var formatArray = function (obj, cur_depth, pad_val, pad_char) {
        var someProp = '';
        if (cur_depth > 0) {
            cur_depth++;
        }
        base_pad = repeat_char(pad_val*(cur_depth-1), pad_char);
        thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
        var str = "";
        var val='';
        if (typeof obj === 'object' && obj !== null) {
            if (obj.constructor && getFuncName(obj.constructor) === 'PHPJS_Resource') {
                return obj.var_dump();
            }
            lgth = 0;
            for (someProp in obj) {
                lgth++;
            }
            str += "array("+lgth+") {\n";
            for (var key in obj) {
                if (typeof obj[key] === 'object' && obj[key] !== null && !(obj[key] instanceof Date) && !obj[key].nodeName) {
                    str += thick_pad + "["+key+"] =>\n"+thick_pad+formatArray(obj[key], cur_depth+1, pad_val, pad_char);
                } else {
                    val = getScalarVal(obj[key]);
                    str += thick_pad + "["+key+"] =>\n"+  thick_pad +val + "\n";
                }
            }
            str += base_pad + "}\n";
        } else {
            str = getScalarVal(obj);
        }
        return str;
    };
    output = formatArray(arguments[0], 0, pad_val, pad_char);
    for (i=1; i < arguments.length; i++) {
        output += '\n'+formatArray(arguments[i], 0, pad_val, pad_char);
    }
	return output;
}

/*
  * bug dans Mootools 1.2.* : le Fx.Scroll(...).toElement() ne marche pas.
  * workaround trouvé là : http://www.mooforum.net/solutions12/scroll-toelement-problem-with-mootools-t2051.html#p7766
  */
var Position = function(elementid) {
	var iReturnValue = 0;
	while( elementid != $('content') )
	{
		iReturnValue += elementid.offsetTop;
		elementid = elementid.offsetParent;
	}
	return iReturnValue;
};

/*
  * trouvée là : http://www.webdeveloper.com/forum/archive/index.php/t-98502.html
  */
function getImgSize(imgSrc) {
	var newImg = new Image();
	newImg.src = imgSrc;
	//var height = newImg.height;
	//var width = newImg.width;
	//alert ('The image size is '+width+'*'+height);
	return newImg;
}

//
// console log
// http://stackoverflow.com/questions/217957/how-to-print-debug-messages-in-the-google-chrome-javascript-console
if (!window.console) console = {};
console.log = console.log || function(){};
console.warn = console.warn || function(){};
console.error = console.error || function(){};
console.info = console.info || function(){};

/*
  * extension de l'objet string pour avoir les 2 fonctions PHP
  * addslashes()
  * stripslashes()
  * trouvé sur http://www.developpez.net/forums/d108937/webmasters-developpement-web/javascript/addslashes-stripslashes-javascript/
  */
String.prototype.addSlashes = function() {return this.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');};
String.prototype.stripSlashes = function() {return this.replace(/\\(.?)/g, function (s, n1){switch (n1){case '\\':return '\\';case '0':return '\u0000';case '':return '';default:return n1;}});};

/*
  * La même chose que ce dessus mais autonome
  * trouvé sur http://phpjs.org/functions/addslashes:303
  */
function addslashes (str) {
    // Escapes single quote, double quotes and backslash characters in a string with backslashes  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/addslashes
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +   improved by: marrtins
    // +   improved by: Nate
    // +   improved by: Onno Marsman
    // +   input by: Denny Wardhana
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Oskar Larsson Högfeldt (http://oskar-lh.name/)
    // *     example 1: addslashes("kevin's birthday");
    // *     returns 1: 'kevin\'s birthday'
    return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}
function stripslashes (str) {
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +      fixed by: Mick@el
    // +   improved by: marrtins
    // +   bugfixed by: Onno Marsman
    // +   improved by: rezna
    // +   input by: Rick Waldron
    // +   reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   input by: Brant Messenger (http://www.brantmessenger.com/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: stripslashes('Kevin\'s code');
    // *     returns 1: "Kevin's code"
    // *     example 2: stripslashes('Kevin\\\'s code');
    // *     returns 2: "Kevin\'s code"
    return (str + '').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
        case '\\':
            return '\\';
        case '0':
            return '\u0000';
        case '':
            return '';
        default:
            return n1;
        }
    });
}

// www.sean.co.uk
// fonction pour faire une pause
function pause(millis) {
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); } 
	while(curDate-date < millis);
} 

//
// Fonction de conversion de charactères spéciaux dans un text en leur équivalent octal
// nécéssaire pour les appels "alert" et globalement, tout ce qui est text affiché par du javascript.
//
function htmlspecialchars2octal(wText) {
	if(typeof(wText)!="string") { wText = wText.toString(); }

	wText = wText.replace(/&deg;/g, "\260") ;

	wText = wText.replace(/&Ecirc;/g, "\312") ;

	wText = wText.replace(/&eacute;/g, "\351") ;
	wText = wText.replace(/&ecirc;/g, "\352") ;
	wText = wText.replace(/&ucirc;/g, "\373") ;
	
	return wText;
}

function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end == -1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(arr,level,maxlevel) {
	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 + "' ...<br />\n";
				if (level < maxlevel ) dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"<br />\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function objectsAreSame(x, y) {
   var objectsAreSame = true;
   for(var propertyName in x) {
	   if (debug_on) { debug.innerHTML += "check si x[" + propertyName + "] == y[" + propertyName + "]<br />"; }
      if(x[propertyName] !== y[propertyName]) {
         objectsAreSame = false;
         break;
      }
   }
   return objectsAreSame;
}

