var _reg = new RegExp("[_]", "g");
var _accountType = null;

function refreshImgConfirm(e) {
  var random = Math.floor(Math.random()*1000);
  var src = $('imgConfirm').src;
  var file = src.substring(0, src.indexOf('?', 0));
  var args = src.toQueryParams();
  args['rnd'] = random;
  $('imgConfirm').src = file+'?'+$H(args).toQueryString();
}

function postDelete(e) {
	var id=Event.element(e).id;    
	var infos = id.split(_reg);
	
	
	if (confirm("Supprimer cet article?")) {
	
		var myAjax = new Ajax.Request(_rootPath+'arts.php', {
			postBody: $H({
			'mode'	: 'del_post',
			'id'      : infos[1]
		  }).toQueryString(),
			onComplete: function (xhr, json) {
			  if (json.error == 0) {
			  $('row_'+infos[1]).replace('');
			  messageGlobal('valid',xhr.responseText);
			  } else {
				messageGlobal('error',xhr.responseText);
			}
		  }
		});
	}
}  

function messageGlobal(style,msg,dest) {
  var id = dest || 'ajaxMessageGlobal';
  if (style!="") {
    $(id).className = 'message-'+style;
    new $(id).update(msg);
  } else {
    new $(id).update('');
    $(id).className = '';
  }
}


/* création d'un mot de passe (piqué à phpMyAdmin) */
function suggestPassword(e) {
  if (confirm("Êtes vous sûr de vouloir générer un mot de passe ? Ceci pourrait modifier le mot de passe courant")) {
    var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
    var passwordlength = 8;    // do we want that to be dynamic?  no, keep it simple :)
    var passwd = '';

    for ( i = 0; i < passwordlength; i++ ) {
        passwd += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) );
    }
    
    $('password').value = passwd;
    return ;
  }
}

