function valida_entrada()// VALIDAMOS ENTRADA
{
	if(document.forma_entrada.titulo.value=="")//titulo
	{
		alert("Ingresa un titulo.");
		document.forma_entrada.titulo.focus();
		return false;
	}
	if(forma_entrada.id_seccion.value=="0")//seccion
	{
		alert("Selecciona una seccion.");
		forma_entrada.id_seccion.focus();
		return false;
	}
	else
	{
		loading('boton_div','espere_div');
		// when all input are correct 
		// return true so the form will submit
		return document.forma_entrada.submit();
	}
}
function valida_acceso()// VALIDAMOS ACCESO
{
	if(document.forma_acceso.usuario.value=="")
	{
		alert("Ingresa un nombre de usuario.");
		document.forma_acceso.usuario.focus();
		return false;
	}
	else
	{
		loading('boton_div','espere_div');
		// when all input are correct 
		// return true so the form will submit
		return document.forma_acceso.submit();
	}
}
function valida_usuario()// VALIDAMOS USUARIO
{
	if(document.forma_usuario.usuario.value=="")
	{
		alert("Ingresa un nombre de usuario.");
		document.forma_usuario.usuario.focus();
		return false;
	}
	if(document.forma_usuario.clave.value=="")
	{
		alert("Ingresa una clave.");
		document.forma_usuario.clave.focus();
		return false;
	}
	if(document.forma_usuario.email.value=="")
	{
		alert("Ingresa un email.");
		document.forma_usuario.email.focus();
		return false;
	}
	if(document.forma_usuario.estado.value=="0")
	{
		alert("Selecciona un Estado.");
		document.forma_usuario.estado.focus();
		return false;
	}
	if(document.forma_usuario.ci.value=="0")
	{
		alert("Selecciona una Ciudad.");
		document.forma_usuario.ci.focus();
		return false;
	}
	else
	{
		loading('boton_div','espere_div');
		// when all input are correct 
		// return true so the form will submit
		return document.forma_usuario.submit();
	}
}
function valida_seccion()// VALIDAMOS SECCION
{
	if(document.forma_seccion.nombre.value=="")
	{
		alert("Ingrese un titulo.");
		document.forma_seccion.nombre.focus();
		return false;
	}
	else
	{
		loading('boton_div','espere_div');
		// when all input are correct 
		// return true so the form will submit
		return document.forma_seccion.submit();
	}
}
function valida_loading()// VALIDAMOS ORDEN SECCION
{
		loading('boton_div','espere_div');
		// when all input are correct 
		// return true so the form will submit
		//return document.forma_OrdenSeccion.submit();
}


//--codigo para quitar boton y poner mensaje de procesando...
function loading(id,idload)
{
	document.getElementById(id).style.display="none";
	document.getElementById(idload).style.display="block";
}

//--limitar textarea
function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

//-- bbcode
function bbcode_ins(fieldId, tag)
{
	field=document.getElementById(fieldId);
	if(tag=='b' || tag=='quote' || tag=='i' || tag=='u' || tag =='code' || tag=='list')
	{
		if (document.selection) 
		{
		field.focus();
		var selected = document.selection.createRange().text;
		sel = document.selection.createRange();
		sel.text = '[' + tag + ']' + selected + '[/' + tag+']';
		}
 
		//MOZILLA/NETSCAPE/SAFARI support
 
		else if (field.selectionStart || field.selectionStart == 0) 
		{
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;
		var selected = field.value.substring(startPos, endPos);
		field.focus();
		field.value = field.value.substring(0, startPos) + '[' + tag + ']' + selected + '[/' + tag +']' + field.value.substring(endPos, field.value.length);
		}
	}
	if(tag=='*')
	{
		if (document.selection) 
		{
		field.focus();
		var selected = document.selection.createRange().text;
		sel = document.selection.createRange();
		sel.text = '[' + tag + ']' + selected;
		}
 
		//MOZILLA/NETSCAPE/SAFARI support
 
		else if (field.selectionStart || field.selectionStart == 0) 
		{
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;
		var selected = field.value.substring(startPos, endPos);
		field.focus();
		field.value = field.value.substring(0, startPos) + '[' + tag + ']' + selected + field.value.substring(endPos, field.value.length);
		}
	}
	else if(tag == 'img')
	{
		var path = prompt('Enter image path', 'http://');
		if(!path)
		{
			return;
		}
		if (document.selection) 
		{
			field.focus();
			sel = document.selection.createRange();
			sel.text = '[' + tag + ']' + path + '[/' + tag+']';
		}
		//MOZILLA/NETSCAPE/SAFARI support
		else if (field.selectionStart || field.selectionStart == 0) 
		{
			var startPos = field.selectionStart;
			var endPos = field.selectionEnd;
			field.focus();
			field.value = field.value.substring(0, startPos)
			+ '[' + tag + ']' + path + '[/' + tag+']'
			+ field.value.substring(endPos, field.value.length);
		} 
	}
	else if(tag == 'url')
	{
		var url = prompt('Enter link URL', 'http://');
		var linkText = prompt('Enter link text', '');
		if(!url || !linkText)
		{
			return;
		}
		if (document.selection) 
		{
			field.focus();
			sel = document.selection.createRange();
			sel.text = '[' + tag + '='+url+']' + linkText + '[/' + tag+']';
		}
		//MOZILLA/NETSCAPE/SAFARI support
		else if (field.selectionStart || field.selectionStart == 0) 
		{
			var startPos = field.selectionStart;
			var endPos = field.selectionEnd;
			field.focus();
			field.value = field.value.substring(0, startPos)
			+ '[' + tag + '='+url+']' + linkText + '[/' + tag+']'
			+ field.value.substring(endPos, field.value.length);
		} 
	}
	else if(tag == 'size')
	{
		if (document.selection) 
		{
		field.focus();
		var selected = document.selection.createRange().text;
		sel = document.selection.createRange();
		sel.text = '[' + tag + '=' + document.getElementById("size").value + ']' + selected + '[/' + tag+']';
		}
 
		//MOZILLA/NETSCAPE/SAFARI support
 
		else if (field.selectionStart || field.selectionStart == 0) 
		{
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;
		var selected = field.value.substring(startPos, endPos);
		field.focus();
		field.value = field.value.substring(0, startPos) + '[' + tag + '=' + document.getElementById("size").value + '] ' + selected + '[/' + tag +']' + field.value.substring(endPos, field.value.length);
		}
	}
	else if(tag == 'color')
	{
		if (document.selection) 
		{
		field.focus();
		var selected = document.selection.createRange().text;
		sel = document.selection.createRange();
		sel.text = '[' + tag + '=' + document.getElementById("color").value + ']' + selected + '[/' + tag+']';
		}
 
		//MOZILLA/NETSCAPE/SAFARI support
 
		else if (field.selectionStart || field.selectionStart == 0) 
		{
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;
		var selected = field.value.substring(startPos, endPos);
		field.focus();
		field.value = field.value.substring(0, startPos) + '[' + tag + '=' + document.getElementById("color").value + '] ' + selected + '[/' + tag +']' + field.value.substring(endPos, field.value.length);
		}
	}
	else if(tag == 'youtube')
	{
		var path = prompt('Enter video code', '');
		if(!path)
		{
			return;
		}
		if (document.selection) 
		{
			field.focus();
			sel = document.selection.createRange();
			sel.text = '[' + tag + ']' + path + '[/' + tag+']';
		}
		//MOZILLA/NETSCAPE/SAFARI support
		else if (field.selectionStart || field.selectionStart == 0) 
		{
			var startPos = field.selectionStart;
			var endPos = field.selectionEnd;
			field.focus();
			field.value = field.value.substring(0, startPos)
			+ '[' + tag + ']' + path + '[/' + tag+']'
			+ field.value.substring(endPos, field.value.length);
		} 
	}
}
