var bolMark = true;

function getXhr() {
	var xhr = null; 
	
	if(window.XMLHttpRequest) {
		xhr = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		xhr = false; 
	} 
	
	return xhr
}

function markall() {
	if (bolMark) {
		for (var i = 0; i < document.messform.length; i++) {
			if (document.messform.elements[i].type == 'checkbox') {
				document.messform.elements[i].checked = true;
			}
		}
	}
	else {
		for (var i = 0; i < document.messform.length; i++) {
			if (document.messform.elements[i].type == 'checkbox') {
				document.messform.elements[i].checked = false;
			}
		}
	}
	bolMark = !bolMark;
}

function MM_jumpMenu(targ,selObj,restore) {
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) {
		selObj.selectedIndex=0;
	}
}

function startFade(idDiv) {
	Effect.Fade(idDiv);return true;
}

function stopFade(idDiv) {
	Effect.Appear(idDiv);return true;
}

function infoBulle(action,divID) {
	if(action == 'hide') {
		document.getElementById(divID).style.display = 'none';
	}
	else {
		document.getElementById(divID).style.display = 'block';
	}
}

function insertTag(startTag, endTag, textareaId, tagType) {
	var field = document.getElementById(textareaId); 
	field.focus();

	if (window.ActiveXObject) {
		var textRange = document.selection.createRange();            
		var currentSelection = textRange.text;
	}
	else {
		var startSelection   = field.value.substring(0, field.selectionStart);
		var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
		var endSelection     = field.value.substring(field.selectionEnd);               
	}

	if (tagType) {
		switch (tagType) {
			case "lien":
			endTag = "[/url]";
				if (currentSelection) {
					if (currentSelection.indexOf("http://") == 0 || currentSelection.indexOf("https://") == 0 || currentSelection.indexOf("ftp://") == 0 || currentSelection.indexOf("www.") == 0) {
						var label = prompt("Quel est le libellé du lien ?") || "";
						startTag = "[url=" + currentSelection + "]";
						currentSelection = label;
					}
					else {
						var URL = prompt("Quelle est l'url ?");
						startTag = "[url=" + URL + "]";
					}
				}
				else {
					var URL = prompt("Quelle est l'url ?") || "";
					var label = prompt("Quel est le libellé du lien ?") || "";
					startTag = "[url=" + URL + "]";
					currentSelection = label;
				}
			break;
			
			case "citation":
				endTag = "[/quote]";
				if (currentSelection) {
					if (currentSelection.length > 30) {
						var auteur = prompt("Quel est l'auteur de la citation ?") || "";
						startTag = "[quote=" + auteur + "]";
					}
					else {
						var citation = prompt("Quelle est la citation ?") || "";
						startTag = "[quote=" + currentSelection + "]";
						currentSelection = citation;
					}
				}
				else {
					var auteur = prompt("Quel est l'auteur de la citation ?") || "";
					var citation = prompt("Quelle est la citation ?") || "";
					startTag = "[quote=" + auteur + "]";
					currentSelection = citation;
				}
			break;
		}
	}

	if (window.ActiveXObject) {
		textRange.text = startTag + currentSelection + endTag;
		textRange.moveStart("character", -endTag.length - currentSelection.length);
		textRange.moveEnd("character", -endTag.length);
		textRange.select();     
	}
	else {
		field.value = startSelection + startTag + currentSelection + endTag + endSelection;
		field.focus();
		field.setSelectionRange(startSelection.length + startTag.length, startSelection.length + startTag.length + currentSelection.length);
	}       
}

function inputLoginIn(divID, value, defaut) {
	if(value == defaut) {
		document.getElementById(divID).value = '';
	}
}

function changeSizeSponsor(type) {
	if(type == 1) {
		document.getElementById('hauteurSponsor').innerHTML = 'Block logo :';
	}
	else if(type == 2) {
		document.getElementById('hauteurSponsor').innerHTML = 'Block logo (??x66px) :';
	}
	else if(type == 3) {
		document.getElementById('hauteurSponsor').innerHTML = 'Block logo (121x105px) :';
	}
	else if(type == 4) {
		document.getElementById('hauteurSponsor').innerHTML = 'Block logo (728x90px) :';
	}
}

function createLinkNews(idnews) {
	if(idnews != "") {
		document.getElementById('urlFromNews').value = '?p=news&op=more&id='+idnews+'#lire';
	}
	else {
		document.getElementById('urlFromNews').value = '';
	}
}