var uriBase = "http://www.nicoweb.fr/ajax/";
var urls = new Array();
urls['conn'] = "connexionSms.php";
urls['sends'] = "sendSms.php";
urls['inds'] = "listeInds.php";

/*
	* sends ( string ou DOM_object idElementToUpdate , string idElBut)
*/
function sends (idEl,idBut) {
	
	$(idBut).disabled = true;
	opt = {
	    method: 'post',
	    evalScripts : true,
	    postBody: "apikey=nicowebv3&"+Form.serialize('envoisms'),
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    onSuccess : function (t) { $(idBut).disabled = false; },
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	new Ajax.Updater(idEl,uriBase+urls['sends'], opt);
}

/*
	* ident ( string ou DOM_object idElementToUpdate )
*/
function ident (idEl) {
	

	opt = {
	    method: 'post',
	    evalScripts : true,
	    postBody: "apikey=nicowebv3&"+Form.serialize('connexion'),
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    onSuccess : function (t) { },
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	new Ajax.Updater(idEl,uriBase+urls['conn'], opt);
}


/*
	* inds ( string ou DOM_object idElementToUpdate )
*/
function inds (idEl) {
	
	opt = {
	    method: 'post',
	    evalScripts : true,
	    postBody: "apikey=nicowebv3",
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    onSuccess : function (t) {  } ,
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	new Ajax.Updater(idEl,uriBase+urls['inds'], opt);
}

function chargerFenetre () {
	
	inds('inds');
	Form.disable('envoisms');
	$('envoisms').style.opacity = '0.3';
}

/*
	*
*/
function verifNb(nb,str,el) {
	//alert(str.length);
	if (str.length+1 == 158) alert("attention !!! le caractère que vous allez taper après est le dernier autorisé pour l'envoi du texto.\nSi vous continuez de taper des caractères le champ sera réinitialisé ou remis à zéro ce qui provoquera l'effacement de votre message en cours de rédaction.");
	else if (str.length+1 >= nb) {
		$('nbc').innerHTML = str.length;
		el.value = "";
		return false;
	}
	else {
		var temp = Number($('nbc').innerHTML);
		gererNbChar(str.length+1);
		$('nbc').innerHTML = str.length;
		return true;
	}
}

/*
	* gererNbChar ( Number nbChar )
*/
function gererNbChar (nbc) {
	if (nbc < 53) {
		$('vertc').style.opacity = '1.0';
		$('orangec').style.opacity = '0.0';
		$('redc').style.opacity = '0.0';
	}
	else if (nbc < 106) {
		$('vertc').style.opacity = '1.0';
		$('orangec').style.opacity = '1.0';
		$('redc').style.opacity = '0.0';
	}
	else if (nbc < 160) {
		$('vertc').style.opacity = '1.0';
		$('orangec').style.opacity = '1.0';
		$('redc').style.opacity = '1.0';
	}
}

/*
	* function suiteConnexion ()
*/
function suiteConnexion () {
	
	$("ok_00").disabled = true; $("ok_0").disabled = false; 
	Form.enable('envoisms'); 
	$("log").value = $('login').value; $('pas').value = $('pass').value;
	$('login').disabled = true; $('pass').disabled = true; 
	$('envoisms').style.opacity = '1.0';
}

/*
	* changerIdent ()
*/
function changerIdent () {
	$('log').value = ""; $('pas').value = "";
	Form.reset('envoisms'); Form.disable('envoisms');
	Form.enable('connexion'); 
	$('rspServ').innerHTML = "";
	$('ok_0').disabled = true;
	$('login').value = ""; $('pass').value = "";
	alert ("vous avez été déconnecté de votre compte nicowebSms.");
	
}