////////////////////////////////////////////////////////////////////////////////////////////////////
//                                      JavaScript Document                                       //
//                                       © Lost-France.com                                        //
//                                               v4                                               //
////////////////////////////////////////////////////////////////////////////////////////////////////

//
/// COOKIES
//
function SetCookie(name, value)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "": ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : (";path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

//
/// AJAX
//
function changeEtatCom(id,etat)
{
	jsphp_shtml('com-'+id,'../../../php/scripts/manageCommentaires.php','action='+etat+'&com_id='+id)
}

function editCom(id, action)
{
	if(action=="edit") {
	tag = "editcom-"+id
	text = document.getElementById(tag).value
	jsphp_shtml('com-'+id,'../../../php/scripts/manageCommentaires.php','action='+action+'&com_id='+id+'&text='+text)
	}
	else jsphp_shtml('com-'+id,'../../../php/scripts/manageCommentaires.php','action='+action+'&com_id='+id)
}

//
/// STYLE
//
function changeCouleur(ligne)
{
  ligne.bgColor = '#C2D2E9';
}

function remetCouleur(ligne)
{
  ligne.bgColor = '#F0F0F0';
}

function changeBorder(element)
{
  element.style.border = '2px solid #D49F5A';
}

function remetBorder(element)
{
  element.style.border = '2px solid #93BA3D';
}

//
/// COMPTEUR PAGE ACCUEIL
//
function start_countdown()
{
	if (document.layers) document.countdownnsmain.visibility="show"
	else if (document.all||document.getElementById)
	crosscount=document.getElementById&&!document.all?document.getElementById("compteur_lost") : compteur_lost
	countdown()
}

function setcountdown(theyear,themonth,theday,thehour,themin,thesec)
{
	yr=theyear;mo=themonth;da=theday;hr=thehour;min=themin;sec=thesec
}

function countdown()
{
	var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
	var today=new Date()
	var todayy=today.getYear()
	if (todayy < 1000)
	todayy+=1900
	var todaym=today.getMonth()
	var todayd=today.getDate()
	var todayh=today.getHours()
	var todaymin=today.getMinutes()
	var todaysec=today.getSeconds()
	var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
	futurestring=montharray[mo-1]+" "+da+", "+yr+" "+hr+":"+min+":"+sec
	dd=Date.parse(futurestring)-Date.parse(todaystring)
	dday=Math.floor(dd/(60*60*1000*24)*1)
	dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
	dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
	dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
	dhour=(dhour>9)?dhour:('0'+dhour);
	dmin=(dmin>9)?dmin:('0'+dmin);
	dsec=(dsec>9)?dsec:('0'+dsec);
	//if passed day of occasion
	if (dday<=-1)
	{
		if (document.layers)
		{
			document.countdownnsmain.document.countdownnssub.document.write("L'évènement est déjà arrivé ! ")
			document.countdownnsmain.document.countdownnssub.document.close()
		}
		else if (document.all||document.getElementById)
		crosscount.innerHTML="L'évènement est déjà arrivé ! "
		return
	}
	//else, if not yet
	else
	{
	  var texte
    if(dday>0) texte = dday+ " Jours "
    else texte = ""
    texte = texte+dhour+"h"+dmin+"m"+dsec
		if (document.layers)
		{
			//var texte = convertToImg(dday+ "J"+dhour+"H"+dmin+"M"+dsec)		
			document.countdownnsmain.document.countdownnssub.document.write(texte)
			document.countdownnsmain.document.countdownnssub.document.close()
		}
		else if (document.all||document.getElementById)
		//crosscount.innerHTML=convertToImg(dday+ "J"+dhour+"H"+dmin+"M"+dsec)
		//crosscount.innerHTML=dday+ " Jour(s) "+dhour+"h"+dmin+"m"+dsec;
		crosscount.innerHTML=texte
	}
	setTimeout("countdown()",1000)
}

function convertToImg(texte)
{
	var output = ''
	for (var i=0; i<texte.length; i++)
	{
		if(texte[i]=='J') output = output + ' jour(s) ';
		else if(texte[i]=='M' || texte[i]=='H' || texte[i]=='S')  output = output + '<img src="appli/images/compteur_separator.gif" style="vertical-align:bottom" />';
		else output = output + '<img src="appli/images/compteur_'+texte[i]+'.gif" style="vertical-align:bottom"/>';
	}
	return output;
}

