/*var prix = new Array();
prix[0]=0.29;
prix[1]=0.28;
prix[2]=0.27;
prix[3]=0.26;
prix[4]=0.25;

function change(nb,s,total)
{
	var price=0;
	s.value=nb;
	if (nb >= 5 && nb < 50) price=nb*prix[0];
	else if (nb >= 50 && nb < 100) price=nb*prix[1]; 
	else if (nb >= 100 && nb < 250) price=nb*prix[2];
	else if (nb >= 250 && nb < 500) price=nb*prix[3];
	else if (nb >= 500 && nb <= 1000) price=nb*prix[4];
	else { total.value=''; document.getElementById("amount").value=0 };
	if (price !=0)
	{
		price=Math.round(price*100)/100;
		total.value=price;
		document.getElementById("amount").value=price;
	}
}
*/
function purger()
{
	if(confirm("Etes-vous sur de vouloir supprimer l'historique de vos envois datant de plus de 2 mois ? "))
	{
		document.location = 'historique-sms.php?action=purger';
	}
	else return false;
}

function confirmDelete(form)
{
	if(confirm('Etes-vous sur de vouloir supprimer les messages selectionnés ?'))
	{
		form.submit();
	}
	return false;
}

function deleteContact(form)
{
	if(confirm('Etes-vous sur de vouloir supprimer ce contacts ?'))
	{
		/*elRow = 0;
		elRow = p_myDataTable.getTrEl(elRow);   
        
        if(elRow) {   
                     switch(task.index) {   
                         case 0:     // Delete row upon confirmation   
                             var oRecord = p_myDataTable.getRecord(elRow);   
                             if(confirm("Are you sure you want to delete SKU " +   
                                     oRecord.getData("name") + " (" +   
                                     oRecord.getData("Description") + ")?")) {   
                                 p_myDataTable.deleteRow(elRow);   
                             }   
                     }   
        }   */
		document.location = 'gerer-contact-sms.php';//form.submit();
	}
	return false;
}

function checkHistoBox(field, obj){
	var checked = (!obj.checked)? false : true;

	if(isNaN(field.length)) field.checked = checked;
	else{
		for(i=0;i<field.length;i++){
			field[i].checked = checked;
		}
	}
}

function setDiffere()
{
	var form = document.getElementById('envoyerMessage');
	form.differe[0].checked=false;
	form.differe[1].checked=true;
}

function check()
{
	var it =  document.getElementById("item_count"); 
	if (it.value <5 || it.value > 1000) return false;
	return true;
}

function checksms(s)
{
	var total = document.getElementById("tot_paypal");
	if(s.value=="") {total.value=''; return;}
	var nb=parseInt(s.value);
	if(isNaN(nb)) change(5,s,total);
	else
	{
		
		if (nb<=0) change(5,s,total);
		else if (nb > 1000) change(1000,s,total);
		else change(nb,s,total);
	}
} 

function ouvrir(page)
{
	var left,hauteur,largeur;
	largeur=750;
	hauteur=screen.height-120;
	left =	(screen.width - largeur) / 2;
	win  = window.open(page, "listeindicatif", "toolbar=0,scrollbars=1,location=0,status=0,menubar=0,directories=0,resizable=1,width="+largeur+",height="+hauteur+",left="+left+",top=40")
}

function mediapop(i)
{
	var page=window.open(i,"new","toolbar=no,left=200,top=100,width=550,height=425,directories=no,status=no,scrollbars=auto,resizable=no,menubar=no");
	page.focus();
}

function ouvre(id,numero){
	var left;
	var URL;
	URL="http://composants.rentabiliweb.com/Numeros.php?id="+id+"&idmp="+numero;
	left =	((screen.width - 320) / 2);
	win  = window.open(URL, "Micropaiement", "toolbar=0,scrollbars=0,location=0,status=0,menubar=0,directories=0,resizable=0,width=310,height=191,left="+left+",top=40")
}

function popup(url, titre, largeur, hauteur, scroll) 
{
  window.open(url, titre, 'width=' + largeur + ', height=' + hauteur + ', scrollbars=' + scroll);
} 

function addSmiley()
{
	var form = document.getElementById('envoyerMessage');
	form.message.value += form.smiley.options[form.smiley.selectedIndex].value;
	return; 
}

function compter_full(msg){
	var L = msg.value.length;
	if(L>160) m = 153;
	else m = 160;

	var n = Math.floor(L/m);
	var c = m-(L-(n*m));
	document.getElementById('compteur').innerHTML = c+' caract&egrave;re'+((c>1)? 's' : '' )+' restant'+((c>1)? 's' : '' )+' sur votre '+(n+1)+((n>=1)? '<sup>&egrave;me</sup>' : '<sup>er</sup>' )+' SMS.';
}

/*
var m_norm = 160;
var m_udh = 153;
var m = m_udh;

function Compter(msg){
	var L = msg.value.length;

	if(L > 160) m = m_udh;
	else m = m_norm;

	var n = Math.floor(L/m);
	var c = m-(L-(n*m));
	document.getElementById('compteur').innerHTML = c+' caract&egrave;re'+((c>1)? 's' : '' )+' restant'+((c>1)? 's' : '' )+' sur votre '+(n+1)+((n>=1)? '<sup>&egrave;me</sup>' : '<sup>er</sup>' )+' SMS.';
}
*/
function isInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
 } 


function Compter(message)
{
	var L = message.value.length;

	if(L>160) m = 153;
	else m = 160;

	var n = Math.floor(L/m);
	if( isInt(L/m) && n > 0) n = n-1;
	var c = m-(L-(n*m));
	
	document.getElementById('compteur').innerHTML = c+' caract&egrave;re'+((c>1)? 's' : '' )+' restant'+((c>1)? 's' : '' )+' sur votre '+(n+1)+((n>=1)? '<sup>&egrave;me</sup>' : '<sup>er</sup>' )+' SMS.';
		
	if (n==0) document.getElementById('envoyer').value="Envoyer le SMS";
	else document.getElementById('envoyer').value="Envoyer les SMS";

	var MaxLength = 817;
	if (L >= MaxLength )
	{
		message.value = message.value.substring(0,MaxLength);
	}

}

function addContactToList(contact, list){
	var contactlist = document.getElementById('contactlist');

	if(!isNaN(contact.value) && contact.value.length>=9 && contact.value.length<=20){
		if(!isContactInList(contact.value, list)) list.options.add(new Option(contact.value, contact.value));
		//else alert('Numéro déjà présent dans la liste !');

		contact.value = '06';
	}

	for(j=0;j<contactlist.length;j++){
		lcontact = contactlist.options[j].value;
		if(contactlist.options[j].selected){
			if(!isContactInList(lcontact, list)) list.options.add(new Option(lcontact, lcontact));
			contactlist.options[j].selected = false;
		}
	}
}

function delContactFromList(list){
	for(k=list.length-1;k>=0;k--){
		if(list.options[k].selected) list.removeChild(list.options[k]);
	}
}

function isContactInList(contact, list){
	for(i=0;i<list.length;i++){
		if(list.options[i].value==contact) return true;
	}

	return false;
}

function remplir(champs, list){
	var tab = new Array();

	for(i=0;i<list.length;i++){
		tab[i] = list.options[i].value;
	}
	champs.value = tab.join(';');
	return true;
}

function favoris() {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{ window.sidebar.addPanel("Envoyer des SMS","http://www.envoyersms.org",""); }
else { window.external.AddFavorite("http://www.envoyersms.org","Envoyer des SMS"); } }
