/**
* Vérifie l'état d'un groupe de cases à cocher
*
* Les CaC doivent avoir un id de la forme cb0, cb1...
* @param Le nombre de CaC à 'checker'
* @param Une alternative au nom du champ
*/
function checkAll( n, fldName ) {
  if (!fldName) {
     fldName = 'cb';
  }
	var f = document.adminForm;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	if (c) {
		document.adminForm.boxchecked.value = n2;
	} else {
		document.adminForm.boxchecked.value = 0;
	}
}
function isChecked(isitchecked){
	if (isitchecked == true){
		document.adminForm.boxchecked.value++;
	}
	else {
		document.adminForm.boxchecked.value--;
	}
}
function listItemTask( id, task ) {
    var f = document.adminForm;
    cb = eval( 'f.' + id );
    if (cb) {
        for (i = 0; true; i++) {
            cbx = eval('f.cb'+i);
            if (!cbx) break;
            cbx.checked = false;
        } // for
        cb.checked = true;
        f.boxchecked.value = 1;
        submitbutton(task);
    }
    return false;
}

/**
* Fonction pour poster
*/
function submitbutton(pressbutton) {
	submitform(pressbutton);
}

/**
* Poste le formulaire adminForm
*/
function submitform(pressbutton){
	document.adminForm.task.value=pressbutton;
	try {
		document.adminForm.onsubmit();
		}
	catch(e){}
	document.adminForm.submit();
}
/**
* Remplace une chaîne par une autre
*/
function Remplacer(texte, n) {
	var res = '';
	var l = texte.length;
  for (i=0; i<l; i++) {
    //strToFind = texte[i];
    //strReplacement = String.fromCharCode(String.charCodeAt(texte[i]) + n);
    //texte = texte.replace(strToFind, strReplacement);
    res = res + String.fromCharCode(String.charCodeAt(texte[i]) + n);
	}
	return res;
}
//MyFile :	  nom du fichier contenant le code HTML du pop-up
//MyWindow :	  nom de la fenêtre (ne pas mettre d'espace)
//MyWidth :	  entier indiquant la largeur de la fenêtre en pixels
//MyHeight :	  entier indiquant la hauteur de la fenêtre en pixels
function Infos(MyWidth, MyHeight, Param, Opt, MyToolBar) {
	var ns4 = (document.layers)? true:false; 	  //NS 4
	var ie4 = (document.all)? true:false;	  //IE 4
	var dom = (document.getElementById)? true:false;	  //DOM
	var xMax, yMax, xOffset, yOffset;
	var dest = '';

	if (ie4 || dom) {
		xMax = screen.width;
		yMax = screen.height;
	} else if (ns4) {
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	} else {
		xMax = 800;
		yMax = 600;
	}
	xOffset = (xMax - MyWidth)/2;
	yOffset = (yMax - MyHeight)/2;

	switch (Opt) {
		case 1 :
		  MyFile = 'preview.php?cpyId='+Param;
			break;

		case 2 :
		  MyFile = 'infos.transactions.php?trId='+Param;
		  break;

		case 21 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=images/societes/_images/';
		  break;

		case 22 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=images/contenus/';
		  break;

		case 23 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=images/evenements/';
		  break;

		case 31 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=audio/societes/';
		  break;

		case 32 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=audio/contenus/';
		  break;

		case 33 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=audio/evenements/';
		  break;

		case 41 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=videos/societes/';
		  break;

		case 42 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=videos/contenus/';
		  break;

		case 43 :
		  MyFile = 'includes/upload.php?id='+Param+'&directory=videos/evenements/';
		  break;

		case 50 :
		  MyFile = 'includes/addtype.php?famille='+Param;
		  break;

		default :
			MyFile = '';
		  break;
	}

	w = window.open(MyFile,'','width='+MyWidth+',height='+MyHeight+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=0, location=0, directories=0, status=0, scrollbars=1, resizable=0, copyhistory=0, menuBar='+MyToolBar);
	return w;
}
// Affichage aléatoire de caractères

function goTo(n,ch) {
	var nd=document.createElement('span');
	nd.appendChild(document.createTextNode(ch));
	cadre.appendChild(nd);
	this.t=tt();

	function tt() {
		if(String.fromCharCode(n)!=ch){
			if(n<256){n++}else{n=0};
			nd.firstChild.data=String.fromCharCode(n);
		}
	setTimeout(tt,50)
	}
}

var cadre;
function init(ch){
	cadre=document.getElementById('cadre');
	if(/.{1,50}/.test(ch)) {
		while(cadre.firstChild) {
			cadre.removeChild(cadre.firstChild)
		};

		for(i=0;i<ch.length;i++) {
			new goTo(Math.floor(Math.random()*255),ch.charAt(i))
		}
	}
}
// retourne un objet xmlHttpRequest.
// méthode compatible entre tous les navigateurs (IE/Firefox/Opera)
function getXMLHTTP(){
  var xhr_object = null;

  if(window.XMLHttpRequest) // Firefox, IE7 et autres
  	xhr_object = new XMLHttpRequest();
  else if(window.ActiveXObject) { // IE 5.x et 6.x
    try {
      xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e1) {
        xhr_object = null;
      }
    }
  }
  else { // XMLHttpRequest non supporté par le navigateur
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  }
  return xhr_object;
}

// Fonction qui se connecte à la page passée en paramètre
// Retour le contenu de la page
function file(fichier) {
	xhr_object = getXMLHTTP();
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);

	if(xhr_object.readyState == 4)
		return(xhr_object.responseText);
	else
		return(false);
}

function sendData(filename, method, data) {
	var xhr_object = getXMLHTTP();

  if ( method == "GET" ) {
		xhr_object.open("GET", filename, false);
		xhr_object.send(null);
  } else if ( method == "POST" ) {
    xhr_object.open("POST", filename, false);
    xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    data = 'filename=' + filename + '&' + data;
    xhr_object.send(data);
  }

	if ( xhr_object.readyState == 4 )
		return(xhr_object.responseText);
	else
		return(false);
}

function showCart(arg) {
	xhr_object = getXMLHTTP();
	if (texte = file(arg)) {
		return texte;
	}
}

/*
* Fonction utilisée pour créer des zones de liste dépendantes
*
*/
// Mise à jour des listes via XMLHttpRequest
function liste(frm,q,t,dest) {

	var l1    = frm.elements["list"+(q-1)];
  var l2    = frm.elements["list"+q];
  var index = l1.selectedIndex;

  for(i=q; i<=t; i++) {
		frm.elements["list"+i].options.length = 0;
	}

  if(index > 0) {
  	xhr_object = getXMLHTTP();

  	xhr_object.open("POST", dest+"?q="+q, true);
    xhr_object.onreadystatechange = function() {
    	if(xhr_object.readyState == 4)
      	eval(xhr_object.responseText);
    }

    xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    var data = "champ="+escape(l1.options[index].value)+"&form="+frm.name+"&select=list"+q;

    xhr_object.send(data);
  }
}
/**
* Crée une liste générée dynamiquement
* @param string Les paramètres à insérer dans la balise <select>
* @param array Un tableau javascript de la liste des options, style [key,value,text]
* @param string Valeur sélectionnée par défaut
* @param string La clé originale sélectionnée
* @param string Le texte originale sélectionnée
*/
function writeDynaList( selectParams, source, key, orig_key, orig_val ) {
	var html = '\n	<select ' + selectParams + '>';
	var i = 0;
	for (x in source) {
		if (source[x][0] == key) {
			var selected = '';
			if ((orig_key == key && orig_val == source[x][1]) || (i == 0 && orig_key != key)) {
				selected = 'selected="selected"';
			}
			html += '\n		<option value="'+source[x][1]+'" '+selected+'>'+source[x][2]+'</option>';
		}
		i++;
	}
	html += '\n	</select>';

	document.writeln( html );
}

/**
* Change une liste générée dynamiquement
* @param string Les paramètres à insérer dans la balise <select>
* @param array Un tableau javascript de la liste des options, style [key,value,text]
* @param string Valeur sélectionnée par défaut
* @param string La clé originale sélectionnée
* @param string Le texte originale sélectionnée
*/
function changeDynaList( listname, source, key, orig_key, orig_val ) {
	var list = eval( 'document.adminForm.' + listname );

	// On vide la liste
	for (i in list.options.length) {
		list.options[i] = null;
	}
	i = 0;
	for (x in source) {
		if (source[x][0] == key) {
			opt = new Option();
			opt.value = source[x][1];
			opt.text = source[x][2];

			if ((orig_key == key && orig_val == opt.value) || i == 0) {
				opt.selected = true;
			}
			list.options[i++] = opt;
		}
	}
	list.length = i;
}

/**
* Rajoute une item sélectionnée d'une liste à une autre
*/
function addSelectedToList( frmName, srcListName, tgtListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var tgtList = eval( 'form.' + tgtListName );

	var srcLen = srcList.length;
	var tgtLen = tgtList.length;
	var tgt = "x";

	//Génère un tableau pour la liste cîble
	for (var i=tgtLen-1; i > -1; i--) {
		tgt += "," + tgtList.options[i].value + ","
	}

	//Effectuer un 'pull' puis rajouter à la liste
	//for (var i=srcLen-1; i > -1; i--) {
	for (var i=0; i < srcLen; i++) {
		if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
			opt = new Option( srcList.options[i].text, srcList.options[i].value );
			tgtList.options[tgtList.length] = opt;
		}
	}
}

function delSelectedFromList( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected) {
			srcList.options[i] = null;
		}
	}
}

function moveInList( frmName, srcListName, index, to) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var total = srcList.options.length-1;

	if (index == -1) {
		return false;
	}
	if (to == +1 && index == total) {
		return false;
	}
	if (to == -1 && index == 0) {
		return false;
	}

	var items = new Array;
	var values = new Array;

	for (i=total; i >= 0; i--) {
		items[i] = srcList.options[i].text;
		values[i] = srcList.options[i].value;
	}
	for (i = total; i >= 0; i--) {
		if (index == i) {
			srcList.options[i + to] = new Option(items[i],values[i], 0, 1);
			srcList.options[i] = new Option(items[i+to], values[i+to]);
			i--;
		} else {
			srcList.options[i] = new Option(items[i], values[i]);
	   }
	}
	srcList.focus();
}

function getSelectedOption( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i];
	} else {
		return null;
	}
}

function setSelectedValue( frmName, srcListName, value ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=0; i < srcLen; i++) {
		srcList.options[i].selected = false;
		if (srcList.options[i].value == value) {
			srcList.options[i].selected = true;
		}
	}
}

function getSelectedRadio( frmName, srcGroupName ) {
	var form = eval( 'document.' + frmName );
	var srcGroup = eval( 'form.' + srcGroupName );

	if (srcGroup[0]) {
		for (var i=0, n=srcGroup.length; i < n; i++) {
			if (srcGroup[i].checked) {
				return srcGroup[i].value;
			}
		}
	} else {
		if (srcGroup.checked) {
			return srcGroup.value;
		} // si le bouton est sélectionné, renvoyer 0
	}
   // aucu bouton radio n'a été sélectionné
   return null;
}

function getSelectedValue( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i].value;
	} else {
		return null;
	}
}

function getSelectedText( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i].text;
	} else {
		return null;
	}
}

function chgSelectedValue( frmName, srcListName, value ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		srcList.options[i].value = value;
		return true;
	} else {
		return false;
	}
}

function showImageProps(base_path) {
	form = document.adminForm;
	value = getSelectedValue( 'adminForm', 'imagelist' );
	parts = value.split( '|' );
	form._source.value = parts[0];
	setSelectedValue( 'adminForm', '_align', parts[1] || '' );
	form._alt.value = parts[2] || '';
	form._border.value = parts[3] || '0';
	form._caption.value = parts[4] || '';
	setSelectedValue( 'adminForm', '_caption_position', parts[5] || '' );
	setSelectedValue( 'adminForm', '_caption_align', parts[6] || '' );
	form._width.value = parts[7] || '';

	//previewImage( 'imagelist', 'view_imagelist', base_path );
	srcImage = eval( "document." + 'view_imagelist' );
	srcImage.src = base_path + parts[0];
}

function applyImageProps() {
	form = document.adminForm;
	if (!getSelectedValue( 'adminForm', 'imagelist' )) {
		alert( "Select and image from the list" );
		return;
	}
	value = form._source.value + '|'
	+ getSelectedValue( 'adminForm', '_align' ) + '|'
	+ form._alt.value + '|'
	+ parseInt( form._border.value ) + '|'
	+ form._caption.value + '|'
	+ getSelectedValue( 'adminForm', '_caption_position' ) + '|'
	+ getSelectedValue( 'adminForm', '_caption_align' ) + '|'
	+ form._width.value;
	chgSelectedValue( 'adminForm', 'imagelist', value );
}

function previewImage( list, image, base_path ) {
	form = document.adminForm;
	srcList = eval( "form." + list );
	srcImage = eval( "document." + image );
	var fileName = srcList.options[srcList.selectedIndex].text;
	var fileName2 = srcList.options[srcList.selectedIndex].value;
	if (fileName.length == 0 || fileName2.length == 0) {
		srcImage.src = 'images/blank.gif';
	} else {
		srcImage.src = base_path + fileName2;
	}
}

function hideMainMenu()
{
	document.adminForm.hidemainmenu.value=1;
}
// LTrim(string) : Enlève l'espace au début d'une chaîne.
function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTrim(string) : Enlève l'espace à la fin d'une chaîne.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Enlève l'espace au début et à la fin d'une chaîne
function trim(str) {
   return rtrim(ltrim(str));
}

// Envoi formulaire par mail
function sendByMail(_err_no_mail, _err_invalid_mail, cpyId, where) {
	w = Infos(300, 55, '','');
	w.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	w.document.write('<head><title>DASOpharma</title></head>');
	w.document.write('<html>');
	w.document.write('<body leftmargin="10" topmargin="10" marginwidth="10" marginheight="10" bgcolor="#DEDEDE" background="images/deco/fond.gif">');
	w.document.write('<script language="javascript" type="text\/javascript">');
	w.document.write('function close() {');
	w.document.write('window.close;');
	w.document.write('}');
	w.document.write('function envoyer() {');
	w.document.write('var form = document.frm;');
	w.document.write('var place = form.to.value.indexOf("@",1);');
	w.document.write('var dot = form.to.value.indexOf(".",place+1);');
	w.document.write('if (form.to.value == "") {');
	w.document.write('alert("'+_err_no_mail+'");');
	w.document.write('} else if (!((place > -1) && (form.to.value.length >2) && (dot > 1))) {');
	w.document.write('alert("'+_err_invalid_mail+'");');
	w.document.write('} else {');
	w.document.write('form.action = "mail.php?action=sendbymail";');
	w.document.write('form.id.value = '+cpyId+';');
	w.document.write('form.where.value = '+where+';');
	w.document.write('form.submit();');
	w.document.write('}}');
	w.document.write('<\/script>');
	w.document.write('<form name="frm" method="post">');
	w.document.write("<tr>");
	w.document.write('<td>');
	w.document.write('<font color="#000000" size="2">Adresse</font>');
	w.document.write('<br><input type="text" name="to" height="5" maxlength="50" size="35" />');
	w.document.write('<\/td>');
	w.document.write('<\/tr>');
	w.document.write('<tr>');
	w.document.write('<input type="hidden" name="id" value="">');
	w.document.write('<input type="hidden" name="where" value="">');
	w.document.write('<td align="center">&nbsp;&nbsp;&nbsp;');
	w.document.write('<a href="javascript:envoyer();"><font color="#000000" size="2">Envoyer</font></a>');
	w.document.write('<\/td>');
	w.document.write('<\/tr>');
	w.document.write('<\/form>');
	w.document.write('<\/body>');
	w.document.write('<\/html>');
	//document.forms.frm.cpyId.value = cpyId;
}

// Fermer une fenêtre
function fermer() {
	window.close();
}

// Imprimer une fenêtre
function imprimer() {
	print();
}

// Permet de vérifier la validité d'une date au format jj/mm/aa ou jj/mm/aaaa
function isDate(d) {

	if (d == "") // si la variable est vide on retourne faux
		return false;

	e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
	// On teste l'expression régulière pour valider la forme de la date
	// Si pas bon, retourne faux
	if (!e.test(d))
		return false;

	// On sépare la date en 3 variables pour vérification, parseInt() converti du texte en entier
	var j = (d.split("/")[0]); // jour
	var m = (d.split("/")[1]); // mois
	var a = (d.split("/")[2]); // année

	// Si l'année n'est composée que de 2 chiffres on complète automatiquement
	if (a < 1000) {
		// Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
		if (a < 89) a+=2000;
			else a+=1900;
	}

	// Définition du dernier jour de février
	// Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
	if (a%4 == 0 && a%100 !=0 || a%400 == 0)
		fev = 29;
	else
		fev = 28;

	// Nombre de jours pour chaque mois
	nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
	// Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
	return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
}

// JS Calendar
var calendar = null; // Pour éviter de recréer un nouvel objet calendar

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		calendar.create();		// create a popup calendar
		calendar.parseDate(el.value); // set it to a new date
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}

function addMonth(d, m) {
	var time = d.split("-");
	var year = Math.round(time[0]);
	var month = Math.round(time[1]);
	var day = Math.round(time[2]);

	month = month + parseInt(m);

	if ( month > 12 ) {
		year = year + 1;
		month = month - 12;
	}

	day = day.toString();
	month = month.toString();

	if ( month.length < 2 ) {
		month = '0' + month;
	}

	if ( day.length < 2 ) {
		day = '0' + day;
	}

	return (year + '-' + month + '-' + day);
}

function isLeapYear(y) {
	if ( eval(y%4) == 0 ) {
	  if ( eval(y%100) == 0 ) {
			if( eval( y%400 ) == 0 ) {
	    	return true;
	    } else {
	    	return false;
	    }
	  } else {
		  return true;
	  }
	} else {
		return false;
	}
}

Array.prototype.in_array = function(search_term) {
  var i = this.length;
  if (i > 0) {
	 do {
		if (this[i] === search_term) {
		   return true;
		}
	 } while (i--);
  }
  return false;
}

function addDay(d, dy) {
	var time = d.split("-");
	var year = Math.round(time[0]);
	var month = Math.round(time[1]);
	var day = Math.round(time[2]);
	var mArray = new Array(1,3,5,7,8,10,12);

	day = day + parseInt(dy);

	if ( month == 2 ) {
		if ( isLeapYear(year) ) {
			dMax = 29;
		} else {
			dMax = 28;
		}
	} else if ( (mArray.in_array(month)) ) {
		dMax = 31;
	} else {
		dMax = 30;
	}

	if ( day > dMax ) {
		month = month + Math.floor(day / dMax);
		day = (day % dMax);
		if ( month > 12 ) {
			year = year + 1;
			month = month - 12;
		}
	}

	day = day.toString();
	month = month.toString();

	if ( month.length < 2 ) {
		month = '0' + month;
	}

	if ( day.length < 2 ) {
		day = '0' + day;
	}

	return (year + '-' + month + '-' + day);
}

