String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

//this function includes all necessary js files for the application   
function include(file)   
{   
	var script  = document.createElement('script');   
	script.src  = file;   
	script.type = 'text/javascript';   
	script.defer = true;   
	
	document.getElementsByTagName('head').item(0).appendChild(script);   
}   
  
/* include any js files here */   
//include('js/myFile1.js');   
/***********************
	Class for JavaScript
************************/
function MyJS() {
	return true;
}
//MyJS.prototype.
MyJS.prototype.elt = function (id_elt) {
	return document.getElementById(id_elt);
}

MyJS.prototype.dispElt = function (object) {
	object.style.display = 'block';
}

MyJS.prototype.hideElt = function (object) {
	object.style.display = 'none';
}

MyJS.prototype.dispById = function (id_elt) {
	document.getElementById(id_elt).display = 'block';
}

MyJS.prototype.hideById = function (id_elt) {
	document.getElementById(id_elt).display = 'none';
}


var js = new MyJS();
/***********************
	Class for Website
************************/
function MyWeb() {
	this.winAdminPassword = null;
	this.winMp3 = null;
	this.isWinMp3InUse = false;
	this.isWinAdminPassword = false;
	this.error_msg = '';
	return true;
}

/* Onload */
MyWeb.prototype.onload = function(page) {
	switch(page) {
		case 'exhortation' : {
			this.viewBook('book9');
			break;
		}
		// home page as default
		default : {
			if( page == 'home' ) {
			}
			break;
		}
	}
}
MyWeb.prototype.setErrorOnFormElt = function(form_elt, error_msg) {
	this.error_msg = error_msg;
	form_elt.focus();
}

MyWeb.prototype.isNotSameText = function(input_text1, input_text2) {
	if( input_text1.value != input_text2.value ) {
		this.setErrorOnFormElt(input_text2, "Saisies differentes !");
		return true;
	}
	return false;
}

MyWeb.prototype.isEmptyText = function(input_text, condition ) {
	if( condition === undefined ) {
		condition = " <= 0";
	}
	condition = eval( input_text.value.trim().length + condition );
	if( condition ) {
		this.setErrorOnFormElt(input_text, "Saisie Incorrect !");
		return true;
	}
	return false;
}

MyWeb.prototype.isNotValidEmailText = function(input_text) {
	if( input_text.value ) {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if ( !filter.test(input_text.value) ) {
			this.setErrorOnFormElt(input_text, "Email invalide !");
			return true;
		}
		return false;
	}
}

MyWeb.prototype.verifForm = function(name_form) {
	this.error_msg = '';
	var verifOk = true;
	var frm = document.getElementsByName(name_form)[0];
	switch(name_form) {
		case 'frm_login' : {
			if( this.isEmptyText( frm.pseudo) || 
				this.isEmptyText( frm.crypt_password ) ) verifOk = false;
			break;
		}
		case 'frm_register' : {
			if( this.isEmptyText( frm.pseudo ) || 
				this.isEmptyText( frm.crypt_password ) || 
				this.isEmptyText( frm.crypt_password2 ) || 
				this.isNotSameText( frm.crypt_password, frm.crypt_password2 ) || 
				this.isEmptyText( frm.surname ) || 
				this.isEmptyText( frm.firstnames ) || 
				this.isEmptyText( frm.email ) || 
				this.isNotValidEmailText( frm.email ) ) verifOk = false;
			break;
		}
		case 'frm_convention' : {
			if( this.isEmptyText( frm.surname ) || 
				this.isEmptyText( frm.firstnames ) || 
				this.isEmptyText( frm.email ) || 
				this.isNotValidEmailText( frm.email ) ||
				this.isEmptyText( frm.mobilePhone ) ) verifOk = false;
			break;
		}
		case 'frm_email' : {
			if( this.isEmptyText( frm.from ) ||
				this.isNotValidEmailText( frm.from ) ||
				this.isEmptyText( frm.subject ) || 
				this.isEmptyText( frm.content ) ) verifOk = false;
			break;
		}
		case 'frm_book' : {
			if( this.isEmptyText( frm.label ) ||
				this.isEmptyText( frm.content ) ) verifOk = false;
			break;
		}
		case 'frm_newpass' : {
			if( this.isEmptyText( frm.pseudo ) ) verifOk = false;
			break;
		}
	}
	if( this.error_msg != '' ) {
		error = document.getElementById("msg_" + name_form);
		error.style.display = 'block';
		error.innerHTML = this.error_msg;
	}
	return verifOk;
}
/* me : 
represents the current Window with :
- a Minimize Button
- a Hide Button
*/
MyWeb.prototype.me = function() {
	return 	document.activeElement.parentNode.parentNode.parentNode;
}

MyWeb.prototype.meHide = function () {
	this.me().style.display = 'none';
}

MyWeb.prototype.meMin = function () {
	s =this.me().childNodes[1].nodeName;
	alert( s );
	this.me().childNodes[1].style.display = 'none';
}

MyWeb.prototype.meShow = function () {
	s =this.me().childNodes[1].nodeName;
	alert( s );
	this.me().childNodes[1].style.display = 'none';
}

MyWeb.prototype.viewBook = function (id_book) {
	var element = document.getElementById(id_book);
	document.getElementById("book").innerHTML = element.innerHTML;
	document.getElementById("book").style.display = 'block';
}

MyWeb.prototype.viewAllBooks = function (id_book) {
	document.getElementById("book").style.display = 'none';
	document.getElementById("allBooks").style.display = 'block';
}

MyWeb.prototype.openWinMp3 = function(filename) {
	var opt = 'menubar=0,status=0,scrollbars=0,resizable=0,toolbar=0,location=0,';
	var path_mp3 = 'http://www.fr.ofdfev.com/uploads/mp3/' + filename;
	var winMp3 = window.open("", "", opt + 'width=410, height=40');
	simple = '<EMBED SRC="' + path_mp3 + '" VOLUME="50" HEIGHT="40" WIDTH="400">';
	//yahoo = '<embed src="http://webjay.org/flash/dark_player" autostart="true" width="400" height="40" wmode="transparent" flashVars="playlist_url=' + path_mp3 + '&amp;skin_color_1=-145,-89,-4,5&skin_color_2=-141,20,0,0" type="application/x-shockwave-flash" /><br/>';
	//google = '<embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=' + path_mp3 + '" width="400" height="27" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" />';
	winMp3.document.write(simple);
	
	//document.getElementById('mp3player').innerHTML = simple;
	winMp3.focus();	
}

MyWeb.prototype.openWinAdminPass = function(link_file) {
	var opt = 'menubar=0,status=0,scrollbars=0,resizable=0,toolbar=0,location=0,';
	this.winAdminPassword = window.open(link_file, "f1", opt + 'width=300, height=200');
	this.winAdminPassword.focus();
}
var web = new MyWeb();
//document.getElementsByTagName("li")[i]
//document.getElementsByName("cible")[0]

//document.getElementById('id_element').value
//document.getElementById('id_element').innerHTML
//document.getElementById('id_element').style.display=none
//document.activeElement
//element.focus()
//window.location.href='../../../index.htm'; return false
//window.confirm(msg)

/*
var theNewParagraph = document.createElement('p');
var theTextOfTheParagraph = document.createTextNode('Some content.');
theNewParagraph.appendChild(theTextOfTheParagraph);
document.getElementById('someElementId').appendChild(theNewParagraph);
*/
/*
theParagraph.attributes[x].nodeName.toLowerCase()
theParagraph.getAttribute['name']
*/

/*
function countChars(elm) {
if (elm.nodeType == 3) { // TEXT_NODE
return elm.nodeValue.length;
}
var count = 0;
for (var i = 0, child; child = elm.childNodes[i]; i++) {
count += countChars(child);
}
return count;
}
*/

/***********************
	Class for Layout
************************/
/*
function MyLayout ( pageWidth, leftWidth, RightWidth ) {
	this.pW = pageWidth;
	this.lW = leftWidth;
	this.rW = RightWidth;
	this.tW = 0;
	this.idLayout = ["container", "col_left", "col_middle", "col_right" ];
}
MyLayout.prototype.applyModel = function (modelNum) {
	switch( modelNum ) {
		// 2 columns : Left + Page
		case 0 : {
			this.tW = this.pW - this.lW;
			document.getElementById(this.idLayout[0]).style.width = this.pW;
			document.getElementById(this.idLayout[1]).style.width = this.lW;
			document.getElementById(this.idLayout[2]).style.width = this.tW;
			document.getElementById(this.idLayout[3]).style.display = 'none';
			break;
		}
		// 2 columns : Page + Right
		case 1 : {
			this.tW = this.pW - this.rW;
			document.getElementById(this.idLayout[0]).style.width = this.pW;
			document.getElementById(this.idLayout[1]).style.display = 'none';
			document.getElementById(this.idLayout[2]).style.width = this.tW;
			document.getElementById(this.idLayout[3]).style.width = this.rW;
			break;
		}
		// 3 column : Left+ Page + Right
		case 2 : {
			this.tW = this.pW - this.lW - this.rW;
			document.getElementById(this.idLayout[0]).style.width = this.pW;
			document.getElementById(this.idLayout[1]).style.width = this.lW;
			document.getElementById(this.idLayout[2]).style.width = this.tW;
			document.getElementById(this.idLayout[3]).style.width = this.rW;
			break;	
		}
	}
}

var lay = new MyLayout(975,190,190);
*/