function SendSMS(GadgetId, SMSParentDiv, WebDir2Add, MsgDiv)
{
	Movil = document.forms['FormSendSMS'+GadgetId]['SendSMSMovil'+GadgetId].value;
	Message = document.forms['FormSendSMS'+GadgetId]['SendSMSText'+GadgetId].value;
	if (Message == 'Ingresá aquí tu mensaje')
	    Message = "";

	Message = Message.replace(/\n/ig,'[E]');
	TypeDateSend = document.getElementById('TypeDateSend'+GadgetId).value;
	DateParams = '';
	if (TypeDateSend != 'Now')
	{
		if ( TypeDateSend != 'Today' && TypeDateSend != 'Tomorrow')
		{
			Day = document.forms['FormSendSMS'+GadgetId]['SendMessageDateDay'].value;
			Month = document.forms['FormSendSMS'+GadgetId]['SendMessageDateMonth'].value;
			Year = document.forms['FormSendSMS'+GadgetId]['SendMessageDateYear'].value;
			DateParams = Day+"/"+Month+"/"+Year;
		}
		else
		    DateParams = TypeDateSend;
		Hour = document.forms['FormSendSMS'+GadgetId]['SendMessageDateHour'].value;
		Minute = document.forms['FormSendSMS'+GadgetId]['SendMessageDateMinute'].value;
		DateParams = DateParams + " "+Hour+":"+Minute;
	}
	document.forms['FormSendSMS'+GadgetId]['SendSMSMovil'+GadgetId].readOnly="readonly";
	document.forms['FormSendSMS'+GadgetId]['SendSMSText'+GadgetId].readOnly="readonly";
        $('#'+MsgDiv).removeClass('SMSError');
	$('#'+MsgDiv).addClass("MsgSMS");
	$('#'+MsgDiv).html("Enviando...");
	$.ajax({
		type: "GET",
		url: WebDir2Add+"/ajax/process.php?Gadget="+GadgetId+"&Message="+escape(Movil+" "+DateParams+" "+Message)+"&Method=process",
		success: function(msg){
                        var Error;
                        var Message;
                        eval(msg);
                        if (!Error)
                        {
                            $('#'+MsgDiv).removeClass('SMSError');
                            setTimeout(function() {
                                    $('#'+MsgDiv).fadeOut();
                                    $('#'+MsgDiv).html(" ");
                                    $('#'+MsgDiv).fadeIn();
                            }, 10000);
                            document.forms['FormSendSMS'+GadgetId]['SendSMSText'+GadgetId].value="";
                        }
                        else
                        {
                            $('#'+MsgDiv).addClass('SMSError');
                        }
                        $('#'+MsgDiv).html(Message);
                        document.forms['FormSendSMS'+GadgetId]['SendSMSMovil'+GadgetId].readOnly="";
                        document.forms['FormSendSMS'+GadgetId]['SendSMSText'+GadgetId].readOnly="";
                        document.forms['FormSendSMS'+GadgetId]['SendSMSMovil'+GadgetId].value=Movil;
                        document.forms['FormSendSMS'+GadgetId]['SendSMSText'+GadgetId].focus();
                    }
		});
}


function InsertEmoticon(Emoticon, GadgetId)
{
	val = Emoticon.replace(/\[E\]/ig,"\n");
	if (insertAtCaret(val, 'SendSMSText'+GadgetId))	
		$(".word_count").counter();		
}

function insertAtCaret(text, areaId) 
{ 
	var txtarea = document.getElementById(areaId); 
	var scrollPos = txtarea.scrollTop; 
	var strPos = 0; 
	var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) );

	var val = $('#'+areaId).attr('value').toString();

	//Como estamos limitando a un mensaje, no permito que se inserte si supero un mensaje
	var Signature = $('#'+areaId).attr('Signature');
	var SignatureLarge = 0;

		if (Signature)
		   SignatureLarge = Signature.length+1;
		if (val.match("á|é|í|ó|ú|Á|É|Í|Ó|Ú|ñ|Ñ"))
			max = $('#'+areaId).attr('altmaxlength');
		else
			max =  $('#'+areaId).attr('maxlength');
		maxLength = val.length + SignatureLarge + text.length;

		if (maxLength  > max * 4 )
		{
			$('#'+areaId).focus();
			return false;
		}
	//FIN
	if (val == 'Ingresá aquí tu mensaje')
	{
		$('#'+areaId).attr('value', "");
		$('#'+areaId).removeClass('SmsFormDisable');
	}
	if (br == "ie") 
	{ 
		txtarea.focus(); 
		// The current selection
		var range = document.selection.createRange();
		var stored_range = range.duplicate();
		selLength = range.text.length;
		stored_range.moveToElementText(txtarea);
		textSize = stored_range.text.length;
		stored_range.setEndPoint( 'EndToEnd', range );
		if (selLength > 0)
		{
			strPos = stored_range.text.length - selLength;
			endStrPos = stored_range.text.length;
		}
		else
		{
			strPos = stored_range.text.length;
			endStrPos = strPos;
		}
		
	}	
	else if (br == "ff")
	{
		strPos = txtarea.selectionStart;
		endStrPos = txtarea.selectionEnd;
	}
	var front = (txtarea.value).substring(0,strPos);
	var back = (txtarea.value).substring(endStrPos,txtarea.value.length);
	txtarea.value=front+text+back; 
	if (br == "ie") 
	{ 
		txtarea.focus(); 
		var range = document.selection.createRange();
        range.moveToElementText(txtarea);
        if (selLength > 0)
        {
		    range.moveStart ('character', strPos + text.length); 
		    range.moveEnd ('character', - endStrPos + text.length); 
        }
        else
        {
		    range.moveStart ('character', strPos + text.length); 
		    range.moveEnd ('character', - endStrPos + text.length);        
        }
	    range.select(); 
		txtarea.focus(); 
	} 
	else if (br == "ff") 
	{ 
		txtarea.selectionStart = strPos + text.length; 
		txtarea.selectionEnd = strPos + text.length; 
		txtarea.focus();
	} 
	txtarea.scrollTop = scrollPos;
	return true;
}

function GetDateCombo(TypeCombo, GadgetId, DivName, WebDir2Add)
{
	$.ajax({
	type: "GET",
	url: WebDir2Add+"/ajax/process.php?Gadget="+GadgetId+"&Method=getdatecombo&TypeDate="+TypeCombo,
	before: function(){
		$('#'+DivName).fadeOut();			
	},
	success: function(msg){
				$('#'+DivName).html(msg);
				$('#'+DivName).fadeIn();
				document.getElementById('TypeDateSend'+GadgetId).value = TypeCombo;
				if (TypeCombo == 'Cancel')
					document.getElementById('TypeDateSend'+GadgetId).value = 'Now';
		}
	});
}

function EmptyFormField(FieldObj, Class2Remove)
{
    if (FieldObj.value == FieldObj.alt)
    {
        FieldObj.value = '';
        $('#'+FieldObj.id).removeClass(Class2Remove);
    }
}

