var commentsopen=false;

function hideButton(){
document.getElementById('commentformbutton').style.display='none';
}

document.onclick = function (e) { 
  e = e || window.event; 
  var element = e.target || e.srcElement; 

  if (element.tagName != "TEXTAREA" && element.tagName != "INPUT" && element.type != "submit" && document.getElementById('commentformbutton') != null) { 
    hideButton()
  } 
};

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 comments_open() {
			commentsopen=true;
			$("#contenu").animate({"height": $("div.photo-img").height()+$("div.stuff").height()+$("#comments").height()}, 750, 
			function (){
			$("#comments").fadeIn(750);
			});
			document.getElementById('comments_toggler').innerHTML = '<a href="#" onclick="window.scroll(0,0); comments_close(); return false;" title="Fermer">Poster un commentaire</a>';
	
		}

function comments_close() {
	commentsopen=false;
	$("#comments").fadeOut(750,function(){
			$("#contenu").animate({"height": $("div.photo-img").height()+$("div.stuff").height()+13});
			document.getElementById('comments_toggler').innerHTML = '<a href="#" onclick="window.scroll(0,0); comments_open(); return false;" title="Dérouler">Poster un commentaire</a>';
		});
}

function incriz(id,e,mid,phid,aip) {
	var OAjax;
	if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
	else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
	OAjax.open('POST',"includes/incriz.php",true);
    OAjax.onreadystatechange = function()
    {
		if (OAjax.readyState == 4 && OAjax.status==200)
        {
			if (document.getElementById)
            {
				if(OAjax.responseText=='Success')
				{
					$("#"+id).fadeOut(300, function(){
					var i=e+1;
					document.getElementById(id).innerHTML = i;
					});
					$("#"+id).fadeIn(300);
				}
				else if(OAjax.responseText=='D&eacute;j&agrave; vot&eacute;')
				{
					var ez=document.getElementById(id).innerHTML;
					$('#'+id).fadeOut(300, function(){
					document.getElementById(id).style.color = '#FF3000';
					document.getElementById(id).innerHTML = 'déjà voté';
					});
					$('#'+id).fadeIn(300);
					$('#'+id).animate({opacity: 1.0},600);
					$('#'+id).fadeOut(300, function(){
					document.getElementById(id).style.color = '';
					document.getElementById(id).innerHTML = ez;
					});
					$('#'+id).fadeIn(300);
				}
				else if(OAjax.responseText=='Fail')
				{
					var ez=document.getElementById(id).innerHTML;
					$('#'+id).fadeOut(300, function(){
					document.getElementById(id).style.color = '#FF3000';
					document.getElementById(id).innerHTML = 'erreur';
					});
					$('#'+id).fadeIn(300);
					$('#'+id).animate({opacity: 1.0},600);
					$('#'+id).fadeOut(300, function(){
					document.getElementById(id).style.color = '';
					document.getElementById(id).innerHTML = ez;
					});
					$('#'+id).fadeIn(300);
				}
			}
		}
	
	}
    OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    OAjax.send('Id='+escape(id)+'&Phid='+escape(phid)+'&Mid='+escape(mid)+'&Aip='+escape(aip));                 
}

function sendForm(Pseudo, Nom, Email, Pass, Sexe, Day, Month, Year, Pays, Site){
      var OAjax;
      if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
      else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
      OAjax.open('POST',"includes/inscription-ajax.php",true);
      OAjax.onreadystatechange = function()
      {
          if (OAjax.readyState == 4 && OAjax.status==200)
          {
              if (document.getElementById)
              {   
					$("div#msgform").css({visibility: 'hidden'});
					document.getElementById('msgform').innerHTML=''+OAjax.responseText+'';
					var newheight=$("#msgform").height()+32;
					var newtop=newheight/2;
					$("div.inscription2").animate({height: ''+newheight+'px','margin-top': '-'+newtop+'px'}, 400, function(){
						$("div#msgform").css({visibility: 'visible'});
						var ctime;
						ctime = 2;
						document.getElementById('counterb').innerHTML = '2';
						$("div#counterb").css({display: "block"});
						setInterval(
							function(){
								if (ctime > 0)
								{
									document.getElementById('counterb').innerHTML = --ctime;
								}
							}, 1000
						);
						setTimeout(function(){
								$("div.inscription2").stop().animate({opacity: 0}, 300, function(){
									$("div.inscription2").css({display: "none"});
									$("div.blackbg").stop().animate({opacity: 0}, 300, function(){
									$("div.blackbg").css({display: "none"});
									window.location.replace("./");
								});
								});
						},2000);
					});
              }     
          }
      }
      OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
      OAjax.send('Pseudo='+escape(Pseudo)+'&Nom='+escape(Nom)+'&Email='+escape(Email)+'&Pass='+escape(Pass)+'&Sexe='+escape(Sexe)+'&Day='+escape(Day)+'&Month='+escape(Month)+'&Year='+escape(Year)+'&Pays='+escape(Pays)+'&Site='+escape(Site));                 
}

function editForm(Pseudo, Nom, Email, Pass, Sexe, Day, Month, Year, Pays, Site, Mid){
      var OAjax;
      if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
      else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
      OAjax.open('POST',"includes/edition-ajax.php",true);
      OAjax.onreadystatechange = function()
      {
          if (OAjax.readyState == 4 && OAjax.status==200)
          {
              if (document.getElementById)
              {   
					$("div#editform").css({visibility: 'hidden'});
					document.getElementById('editform').innerHTML=''+OAjax.responseText+'';
					var newheight=$("#editform").height()+32;
					var newtop=newheight/2;
					$("div.edit2").animate({height: ''+newheight+'px','margin-top': '-'+newtop+'px'}, 400, function(){
						$("div#editform").css({visibility: 'visible'});
						var ctimee;
						ctimee = 2;
						document.getElementById('countere').innerHTML = '2';
						$("div#countere").css({display: "block"});
						setInterval(
							function(){
								if (ctimee > 0)
								{
									document.getElementById('countere').innerHTML = --ctimee;
								}
							}, 1000
						);
						setTimeout(function(){
							$("div.edit2").stop().animate({opacity: 0}, 300, function(){
									$("div.edit2").css({display: "none"});
									$("div.blackbg").stop().animate({opacity: 0}, 300, function(){
									$("div.blackbg").css({display: "none"});
									window.location.replace("./");
								});
								});
						},2000);
					});
              }     
          }
      }
      OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
      OAjax.send('Pseudo='+escape(Pseudo)+'&Nom='+escape(Nom)+'&Email='+escape(Email)+'&Pass='+escape(Pass)+'&Sexe='+escape(Sexe)+'&Day='+escape(Day)+'&Month='+escape(Month)+'&Year='+escape(Year)+'&Pays='+escape(Pays)+'&Site='+escape(Site)+'&Mid='+escape(Mid));                 
}

function commentForm(Commentaire,Mid,Phid,Psd){
      var OAjax;
      if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
      else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
      OAjax.open('POST',"includes/comments-ajax.php",true);
      OAjax.onreadystatechange = function()
      {
          if (OAjax.readyState == 4 && OAjax.status==200)
          {
              if (document.getElementById)
              {   
					$("div.blackbg").css({display: "block"});
					$("div.blackbg").stop().animate({opacity: 0.60}, 300, function(){
						$("div.commentconfirm").css({display: "block"});
						$("div.commentconfirm").stop().animate({opacity: 1}, 300);
						document.getElementById('commentmsg').innerHTML=''+OAjax.responseText+'';
					});
					setTimeout(function(){
						$("div.commentconfirm").stop().animate({opacity: 0}, 300, function(){
							$("div.commentconfirm").css({display: "none"});
							$("div.blackbg").stop().animate({opacity: 0}, 300, function(){
								$("div.blackbg").css({display: "none"});
								window.location.replace("./");
							});
						});
					},2000);
              }     
          }
      }
      OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
      OAjax.send('Com='+escape(Commentaire)+'&Mid='+escape(Mid)+'&Phid='+escape(Phid)+'&Psd='+escape(Psd));                 
}

function connectForm(Email, Pass){
      var OAjax;
      if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
      else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
      OAjax.open('POST',"includes/connect-ajax.php",true);
      OAjax.onreadystatechange = function()
      {
          if (OAjax.readyState == 4 && OAjax.status==200)
          {
              if (document.getElementById)
              {   
							$("div#connectform").css({visibility: 'hidden'});
							document.getElementById('connectform').innerHTML=''+OAjax.responseText+'';
							var newheight=$("#connectform").height()+32;
							var newtop=newheight/2;
							$("div.connexion2").animate({height: ''+newheight+'px','margin-top': '-'+newtop+'px'}, 400, function(){
								$("div#connectform").css({visibility: 'visible'});
								var ctimer;
								ctimer = 2;
								document.getElementById('counter').innerHTML = '2';
								$("div#counter").css({display: "block"});
								setInterval(
									function(){
										if (ctimer > 0)
										{
											document.getElementById('counter').innerHTML = --ctimer;
										}
									}, 1000
								);
								setTimeout(function(){
									$("div.connexion2").stop().animate({opacity: 0}, 300, function(){
											$("div.connexion2").css({display: "none"});
											$("div.blackbg").stop().animate({opacity: 0}, 300, function(){
											$("div.blackbg").css({display: "none"});
											window.location.replace("./");
										});
										});
								},2000);
							});
              }     
          }
      }
      OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
      OAjax.send('Email='+escape(Email)+'&Pass='+escape(Pass));                 
}
