///////////////////////////////////////////////
// POPUP   LIVE-SCORING (fake)
// Open a window of the desired size in the centre of the screen.
function openLSWindowTandR(year, wkno, lang, tabno, eventid, ref_file, width, height, hasScrollBars) {
/*
	// ADD NAME FIELD and make sure it get's focus!!!
	var theWidth = width;
	var theHeight = height;
	var scrollBars = "scrollbars";
	if (hasScrollBars == false) scrollBars = "scrollbars=0";
	if ((theWidth == "")||(theWidth == null)) theWidth =500;
	if ((theHeight == "")||(theHeight == null)) theHeight =668;
	var theLeft = (screen.availWidth - theWidth)/2;
	var theTop = (screen.availHeight - theHeight)/2;
	var strCheckRef = escape(ref_file);

	var lsURL = "http://www.protennislive.com/frameset.asp?year="+year+"&wkno="+wkno+"&lang="+lang+"&tabno="+tabno+"&eventid="+eventid+"&ref="+strCheckRef;
	var popupWin = window.open(lsURL, '_' + Math.round(Math.random() * 1000000),'top='+theTop+',left='+theLeft+',menubar=0,toolbar=0,location=0,directories=0,status=0,'+scrollBars+',width='+theWidth+', height='+theHeight);
*/
}



///////////////////////////////////////////////
// LA UNE ON
var initTweenJNews = function(){
 posXstart = 0;
 posXend = 0;
 timerNews = 0; 
 var timerInterval = 10000;
 
 var width = jQuery('#maskUne').css('width');
 max = width.length - 2;
 width = width.substring(0, max);
 
 //foreach #articleVignette a > mouseover
 var tab = document.getElementById('articleVignetteUne').getElementsByTagName('a');
 
for(var i = 0; i < tab.length; i++)
{
	tab[i].index = i;
	tab[i].onmouseover = function() {
		var index = this.index;
		posXend = (width*(index)*-1);
		//Animation + décélération
		jQuery('#articleUne').animate({left: posXend - 20}, {queue: false, duration: 150}).animate({left: posXend }, {queue: false, duration: 250});
		posXstart = posXend;
		//Réinitiasation de nextNews
		clearInterval(timerNews);
		timerNews = setInterval('nextNews()', timerInterval);
	}	
}

 timerNews = setInterval("nextNews()", timerInterval);

}; function nextNews(){
	 var size = jQuery('#articleUne').css('width');
	 var width = jQuery('#maskUne').css('width');
	 max = size.length - 2;
	 size = size.substring(0, max);
	 
	 max = width.length - 2;
	 width = width.substring(0, max);
	 
	 
	 posXend -= width;
	 if(posXend <= size*-1)
	 posXend = 0;
		 jQuery('#articleUne').animate({left: posXend -20}, {queue: false, duration: 150}).animate({left: posXend}, {queue: false, duration: 250});
	 posXstart = posXend;
 }; 
// LA UNE OFF
///////////////////////////////////////////////


// Open/Close id
function oc(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function verifmail(adrr){
  var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  if(reg.test(adrr)==true) return true;
  else return false;
}

function supp(typ,id) {
	// usr
	if(typ=="usr") {
		if (confirm ("Cet utilisateur va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=usr&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// galerie
	if(typ=="img") {
		if (confirm ("Cette image va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=img&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	if(typ=="vid") {
		if (confirm ("Cette vidéo va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=vid&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// article
	if(typ=="cat") {
		if (confirm ("Cette catégorie va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=cat&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	if(typ=="art") {
		if (confirm ("Cet article va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=art&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	if(typ=="cmt") {
		if (confirm ("Ce commentaire va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=cmt&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// navigation
	if(typ=="nav") {
		if (confirm ("Cette rubrique va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=nav&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// publictes
	if(typ=="pub") {
		if (confirm ("Cette publicté va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=pub&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// sondage
	if(typ=="sond") {
		if (confirm ("Ce sondage va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=sond&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// forum
	if(typ=="sujet") {
		if (confirm ("Ce Sujet de discussions va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=sujet&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// forum
	if(typ=="rep") {
		if (confirm ("Cette reponse va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=rep&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	
	// jeux
	if(typ=="jeu") {
		if (confirm ("Ce jeu va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=jeu&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// flux
	if(typ=="rss") {
		if (confirm ("Ce flux va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=rss&op=sup&id=";
			window.open(script+id, "_top");
		}
	}
	// partenaires
	if(typ=="part") {
		if (confirm ("Ce partenaire va être supprimer.\n\nSouhaitez-vous continuer ?")) {
			var script = "?sc=particip&op=sup&id=";
			window.open(script+id, "_top");
		}
	}

}

function img(id) { 
	var xhr_object = null; 
	if(window.XMLHttpRequest)
		xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) 
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else { 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		return; 
	} 
	var method = "GET";
	if(window.location.pathname=="/"){
		var filename = "./_ajax.img.php?img="+id;
	} else {
		var filename = "./_ajax.img.php?img="+id;
	}
	xhr_object.open(method, filename, true); 
	xhr_object.onreadystatechange = function() { 
		if(xhr_object.readyState == 1) { 
			var img = xhr_object.responseText; 
			document.getElementById('img_ajax').innerHTML = '<img src="./_themes/chargmnt.gif" style="border:none"/>';
		} 
		if(xhr_object.readyState == 4) { 
			var img = xhr_object.responseText; 
			document.getElementById('img_ajax').innerHTML = img;
		} 
		} 
	xhr_object.send(null);
}

function vid(id) { 
	var xhr_object = null; 
	if(window.XMLHttpRequest)
		xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) 
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else { 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		return; 
	} 
	var method = "GET";
	if(window.location.pathname=="/"){
		var filename = "./_ajax.vid.php?vid="+id;
	} else {
		var filename = "./_ajax.vid.php?vid="+id;
	}
	xhr_object.open(method, filename, true); 
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 1) { 
			var vid = xhr_object.responseText; 
			document.getElementById('vid_ajax').innerHTML = '<img src="./_themes/chargmnt.gif" style="border:none"/>';
		}
		if(xhr_object.readyState == 4) { 
			var vid = xhr_object.responseText; 
			document.getElementById('vid_ajax').innerHTML = vid;
		}
		}
	xhr_object.send(null);
}

////////////////////////////////////////////////
// Barre de raccourcis ON
// derive du:
// bbCode control by subBlue design : www.subBlue.com

// Startup variables
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);


//barre_raccourci("[",   "|http://toto.com]", champ);
function barre_raccourci(debut,fin,champ) {
	var txtarea = champ;

	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {

			while (theSelection.substring(theSelection.length-1, theSelection.length) == ' ')
			{
				theSelection = theSelection.substring(0, theSelection.length-1);
				fin = fin + " ";
			}
			if (theSelection.substring(0,1) == '{' && debut.substring(0,1) == '{')
			{
				debut = debut + " ";
			}
			if (theSelection.substring(theSelection.length-1, theSelection.length) == '}' && fin.substring(0,1) == '}')
			{
				fin = " " + fin;
			}

			// Add tags around selection
			document.selection.createRange().text = debut + theSelection + fin;
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, debut, fin);
		return;
	}
}
/*
[ | ] http://toto.com lien
barre_demande('[','|',']', 'Veuillez indiquer l\'adresse de votre lien', document.getElementById('formulaire_1'))
*/
function barre_demande(debut,milieu,fin,affich,champ) {
	var inserer = prompt(affich);
	var txtarea = champ;
	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (inserer != null) {

		if (debut == "[[") {
			if (inserer == "") {
				inserer = "wWw"; 
			} 
		
			if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
			{
				barre_raccourci(debut, milieu+inserer+fin,  champ);
				return;
			} else {
				barre_inserer(debut+inserer+fin, champ)
				return;	
			}
		}

		if (debut == "((") {
			if (inserer == "") {
				inserer = "image.png"; 
			} 		
			barre_inserer(debut+inserer+fin, champ)
			return;	
		}

		if (debut == "{{") {
			if (inserer == "") {
				inserer = "video.png"; 
			}	
			barre_inserer(debut+inserer+fin, champ)
			return;
		}		
		
	}


	

}

function barre_inserer(text,champ) {
	var txtarea = champ;

	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		//txtarea.value  += text;
		//txtarea.focus();
		mozWrap(txtarea, '', text);
		return;
	}
}


// D'apres Nicolas Hoizey
function barre_tableau(toolbarfield)
{
	var txtarea = toolbarfield;
	txtarea.focus();
	var cols = prompt("Nombre de colonnes du tableau :", "");
	var rows = prompt("Nombre de lignes du tableau :", "");
	if (cols != null && rows != null) {
		var tbl = '';
		var ligne = '|';
		var entete = '|';
		for(i = 0; i < cols; i++) {
			ligne = ligne + ' valeur |';
			entete = entete + ' {{entete}} |';
		}
		for (i = 0; i < rows; i++) {
			tbl = tbl + ligne + '\n';
		}
		if (confirm('Voulez vous ajouter une ligne d\'en-tï¿½e ?')) {
			tbl = entete + '\n' + tbl;
		}
		if ((clientVer >= 4) && is_ie && is_win) {
			var str = document.selection.createRange().text;
			var sel = document.selection.createRange();
			sel.text = str + '\n\n' + tbl + '\n\n';
		} else {
			mozWrap(txtarea, '', "\n\n" + tbl + "\n\n");
		}
	}
	return;
}



// Shows the help messages in the helpline window
function helpline(help, champ) {
	champ.value = help;
}


function setCaretToEnd (input) {
  setSelectionRange(input, input.value.length, input.value.length);
}


function setSelectionRange(input, selectionStart, selectionEnd) {
  if (input.setSelectionRange) {
    input.focus();
    input.setSelectionRange(selectionStart, selectionEnd);
  }
  else if (input.createTextRange) {
    var range = input.createTextRange();
    range.collapse(true);
    range.moveEnd('character', selectionEnd);
    range.moveStart('character', selectionStart);
    range.select();
  }
}

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;
	var selTop = txtarea.scrollTop;

	// Raccourcir la selection par double-clic si dernier caractere est espace
	if (selEnd - selStart > 0 && (txtarea.value).substring(selEnd-1,selEnd) == ' ') selEnd = selEnd-1;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);

	// Eviter melange bold-italic-intertitre
	if ((txtarea.value).substring(selEnd,selEnd+1) == '}' && close.substring(0,1) == "}") close = close + " ";
	if ((txtarea.value).substring(selEnd-1,selEnd) == '}' && close.substring(0,1) == "}") close = " " + close;
	if ((txtarea.value).substring(selStart-1,selStart) == '{' && open.substring(0,1) == "{") open = " " + open;
	if ((txtarea.value).substring(selStart,selStart+1) == '{' && open.substring(0,1) == "{") open = open + " ";

	txtarea.value = s1 + open + s2 + close + s3;
	selDeb = selStart + open.length;
	selFin = selEnd + close.length;
	window.setSelectionRange(txtarea, selDeb, selFin);
	txtarea.scrollTop = selTop;
	txtarea.focus();

	return;
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
     function storeCaret (textEl) {
       if (textEl.createTextRange)
         textEl.caretPos = document.selection.createRange().duplicate();
     }

// Barre de raccourcis OFF
///////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////
// JCAROOUSSEL FOOTER

$(function() {
		$('.mediastore_item').click(function(){
			window.location = $(this).find('a:first').attr('href');
		});
		
		$('.mediastore_item').hover(function(){
			$(this).animate({'opacity': 1}, {queue: false, speed: 200}).addClass('itemHover');
		},
		function(){
			$(this).animate({'opacity': 0.6}, {queue: false, speed: 200}).removeClass('itemHover');			
		});
  
});

// JCAROOUSSEL FOOTER
///////////////////////////////////////////////////////////

function resizePhoto(where, widthMax, heightMax)
{
	where.load(function(){
	$(this).width("");
	$(this).height("");

	var	width = $(this).width()
	var height = $(this).height()

	
	if(height > heightMax)
	{
		var ratio = width / widthMax;
		if(height * ratio > heightMax)
		{
				$(this).width("");
				$(this).height(heightMax)
		}
	}
});
}	





/********* LIEN PARTENAIRES FOOTER **********/
function partenaire(lien){
  window.open(lien,"Partenaire","");
}



/********* CAROUSELE JOUEUSE**********/
function FicheJoueuse(lien){
  window.open(lien,"Joueuse","");
}




/********* RSS **********/
function Voir_flux(lien){
//  alert(lien);
  window.open(lien,"Flux RSS","");
}
