  $(document).ready(function(){
    $("#tabs").tabs();    
  });
  
var TEMPLATE = TEMPLATE || false;
var Fn = function () {};
var webRoot = '/';
var buildURL = function(controller, action) {
	if ( TEMPLATE ) return controller;
	var url = webRoot + '/' + controller;
	if ( !action && !controller )
		throw "No URL Specified";
	if ( action )
		url += '/' + action;
	url += '/';
	return url.replace(/[\/]{2,}/, '/');
};

var validateForm = function (form, url)
{
	jQuery(form).submit(function(){
		$('.submit_button').hide();
		$('.sending').html('Идет формирование рассылки...');
		
		var $t = jQuery(this);
		var result = true;
		jQuery.ajaxSetup({async: false});
		jQuery.post(url, $t.serialize(), function(data) {
			if (data.length) {
				result = false;
				$('#info_popup').html(data);

		$("#info_popup").dialog({
			bgiframe: true,
			draggable: true,
			resizable: false,
			modal: true,
			title: 'Информация',
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		}).dialog('open');
				//$.fn.nyroModalManual({content: data});
			}			
		});
		jQuery.ajaxSetup({async: true});

		$('.submit_button').show();
		$('.sending').html('');

		if ( result )
			return true;
		return false;
	})
};
  
function translit(el)
{
$.post("/page/translit/", { text: $('#'+el).val() },
  function(data){
    $('#'+el).val(data);
    $.post("/account/countSMS/", { sms: $('#'+el).val(), wap:$('#wap_'+el).val()  },
					function(data1){$('.sms_cnt').html(data1);});
  });
}
  
function insertAtCursor(myField, myValue) {
    //IE support
    if (document.selection) {
        myField.focus();

        //in effect we are creating a text range with zero
        //length at the cursor location and replacing it
        //with myValue
        sel = document.selection.createRange();
        sel.text = myValue;

    //Mozilla/Firefox/Netscape 7+ support
    } else if (myField.selectionStart || myField.selectionStart == '0') {

        myField.focus();
        //Here we get the start and end points of the
        //selection. Then we create substrings up to the
        //start of the selection and from the end point
        //of the selection to the end of the field value.
        //Then we concatenate the first substring, myValue,
        //and the second substring to get the new value.
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
        myField.setSelectionRange(endPos+myValue.length, endPos+myValue.length);
    } else {
        myField.value += myValue;
    }
}