$(function(){
	$('#telefono').keypress(function(e){
		if(/^\d$/.test(String.fromCharCode(e.which)) || e.which==8 || e.which == 0){
			return true;
		}else{
			return false;
		}
	});
});
function selectTabByDefault(tabId){
	$('#'+tabId)[0].className='blueTabOn active';
	return false;
}



/**
 * El player
 */
soundManager.url = context+'/linked/swf/'; // directory where SM2 .SWFs live
soundManager.defaultOptions.whileplaying = whilePlaying;
soundManager.debugMode = false;

function reloadTonos(){
	soundManager.onload();
}

soundManager.onload = function() {
	if (!soundManager.supported()){
	}else {
		soundManager.allowPolling = true;  
	  	if(initPlayList){
	  		createPlayerList(initPlayList)
	  	}
  	}
}

function createPlayerList(songs){
	$.each(songs,function(i){
		soundManager.createSound('sound'+i,this.toString());
	});
}

function removePlayerList(size){
	for(i=0;i<size;i++){
		soundManager.destroySound('sound'+i);
	}
}

var progressBarId = "divProgress";
var timer;

function whilePlaying(){		
	var width = Math.round(this.position  * 328 / this.durationEstimate);
	soundManager._writeDebug('sound '+this.sID+' playing, '+this.position+' of '+this.duration);
	var prgObj = document.getElementById(progressBarId);
	prgObj.style.display = "block";
	prgObj.style.width = width + "px";
	if(width>300&&timer==null){
		timer=setTimeout(function(){
			document.getElementById("divMainProgress").style.display="none";
			clearTimeout(timer);
			timer=null;
			currentIndex=null;
		},2000);
	}
}

var currentIndex;
function playRingtone(index){
	if(timer!=null){
		clearTimeout(timer);
		timer=null;
	}
	if(index==-1||index==currentIndex){
		var div = document.getElementById("divMainProgress");
		timer=setTimeout(function(){
			document.getElementById("divMainProgress").style.display="none";
			clearTimeout(timer);
			timer=null;
		},1000);
	}else{
		document.getElementById('divMainProgress').style.display='block';
	}

	soundManager.stop("sound"+index);
	if (currentIndex != null){
		soundManager.stop("sound"+currentIndex);
		var prgObj = document.getElementById(progressBarId);
		prgObj.style.display = "none";
		var imgToOff = document.getElementById("imgPlay");
		imgToOff.src = imgToOff.src.replace('on','off');	
	}
	
	if (currentIndex != index){
		currentIndex = index;
		var imgPlayId = "imgPlay";
		var imgPlay = document.getElementById(imgPlayId);
		imgPlay.src = imgPlay.src.replace('off','on');	
	
		soundManager.play("sound"+index);
	} else {
		currentIndex = null;
	}
}

