function FindSpace(objectname){
//busca el espacio en blanco y devuelve la posicion en que se encuentra				 		
	if (objectname.value.indexOf(" ") >= 0){
		alert('Este campo no permite espacios en blanco'); 
	        objectname.focus();
		//objectname.selected();
		return true;
	}
	else{return false;
	}
}

function checkExtension(value) 	{
	var AllowExtensions = new Array("jpg","jpeg","gif","png","bmp","swf","JPG","JPEG","GIF","PNG","BMP","SWF")
	var FileOK = false;
	//we assume that Extension is false;
	var ExtensionOK = false;

	// retreive the value of the file-box
	//var fieldVal = document.from[0].elements.insertImage.value;
	var fieldVal = value;
		   
	// loop through array of allowed extensions
	for(var i = 0; i < AllowExtensions.length; i++) {
		if(AllowExtensions[i] == fieldVal.substring(fieldVal.length - AllowExtensions[i].length, fieldVal.length)) {
			// The choosen extension matches one of the allowed ones
		        ExtensionOK = true;
		}
	}

	if(ExtensionOK == false) {
		// file extension didn't match any of the allowed ones, signal user with an alert
	        // unfortunately we're not able to reset the file-box
		         alert(fieldVal + " no es un tipo de archivo permitido.");
		}

		// update the valid marker for the current file
		FileOK = ExtensionOK;
		return (FileOK)
}	
function showImage(textEdit,value,image_height,image_width,root){
	var FileOK;
	var n;
	var ext;
	var sheight;
	var swidth;
	if (image_height>0) {sheight = "height='" + image_height+"'"} else {sheight = ""}
	if (image_width>0) {swidth = "width='" + image_width+"'"} else {swidth = ""}

	FileOK = checkExtension(value);
	if (FileOK == true){
		file = "<table width=100% cellpadding=0 cellspacing=0 border=0><tr><td valign=middle><img src='"+ value + "' " + swidth + sheight + "></td></tr></table>";
		n = value.length;
		ext = value.substring(n-3, n);
		if (ext == "swf"){
			file = "<div><object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" + " width=" + image_width + " height=" + image_height + ">"
			file = file + "<param name=movie value='" + value + "'>"
			file = file + "<param name=quality value=high><param name=SCALE value=exactfit>"
			file = file + "</object></div>"
		}
		initEditor(textEdit,'#ffffff', file, 'read');
	}

}

function rightclick() { 
	if (event.button==2) { 
		alert ('Este boton esta deshabilitado.') 
	} 
} 
		

function trim (value)
{
	while('' + value.charAt(value.length-1)==' ')
	{
		value=value.substring(0,value.length-1)
	}
	return value;
}

function SetChecked(theForm, chkPrincipal, chkArrayName)
{   	
	val=chkPrincipal.value;
	if (val==0)
	{
		chkPrincipal.value = 1;
		val = 1;
	}
	else
	{	
		chkPrincipal.value = 0;
		val = 0;
	}          
	dml=theForm;
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) 
	{
		if (dml.elements[i].name==chkArrayName)
		{
			dml.elements[i].checked=val;
		}
	}
}

function OpenWindow(href, name, width, height)
{
	//onClick="window.open('mos_motivos.asp?NoCache=9/7/20015:41:09 PM','Motivos','width=630,height=400')"
	window.open(href,name,'width=' + width + ',height=' + height + ',scrollbars=yes, left=0, top=0, resizable=yes');
}

// Mensaje de confirmación al eliminar un detalle

function confirmDeleteDetail()
{
	return confirm('Desea eliminar este detalle');
	 
}



// Mensaje de confirmación al eliminar un item

function confirmDeleteItem()
{
	return confirm('Desea eliminar este item');
	
}


// Mensaje de confirmación al eliminar una imagen

function confirmDeleteImage()
{
	return confirm('Desea eliminar esta imagen');
		
}

// Mensaje de confirmación al eliminar un Links

function confirmDeleteLink()
{
	return confirm('Desea eliminar este Link');
		
}


/*************************************************************
 Nombre Función : swap()
 Parametro		: l1,l2 (son objetos de tipo lista)
 Descripción	: Función para mover elementos entre dos campos 
				tipo select
**************************************************************/
function swap (l1, l2) {
	
	var texto,value, list1, list2, x, y;
	var optsnew1, txttmp, valtmp;
	
	list1 = l1;
	list2 = l2;
	
	if (list2.selectedIndex == -1) return;
	texto = list2.options[list2.selectedIndex].text;
	value = list2.options[list2.selectedIndex].value;

	y = 0;
	optsnew1 = new Array;
	for (x = 0; x < list2.length; x++) {
		if (list2.options[x].text != texto || list2.options[x].value != value) {
			txttmp = list2.options[x].text;
			valtmp = list2.options[x].value;
			list2.options[y].value = valtmp;
			list2.options[y].text = txttmp;
			y++;
		} 
	}
	list2.options[list2.options.length - 1] = null;

	y = list1.options.length;
	list1.options[y] = new Option;
	list1.options[y].text = texto;
	list1.options[y].value = value;	
}

/*************************************************************
 Nombre Función : swapall()
 Parametro		: l1,l2 (son objetos de tipo lista)
 Descripción	: Funcion encargada de pasar todos los elementos 
				entre listas
 **************************************************************/
function swapall (l1,l2) {
	
	var texto,value, list1, list2, x, y;
	var optsnew1, txttmp, valtmp, inicio;
	
	list1 = l1;
	list2 = l2;
	
	if (list2.length == 0) return;
	
	optsnew1 = new Array;
	
	if (list1.length!=0)
	 {
		inicio=list1.length;
		y = inicio;
		list1.length=list2.length + inicio;
	 }
	else
	 {
		y=0
		list1.length=list2.length
	 }
	
		
	for (x = 0; x < list2.length; x++) {
		if (list2.options[x].text != texto) {
			txttmp = list2.options[x].text;
			valtmp = list2.options[x].value;
			list1.options[y] = new Option
			list1.options[y].value = valtmp;
			list1.options[y].text = txttmp;
			y++;
		} 
	}
	
	list2.length=0;
}

/******************************************************************
Funciones de Validacion de Campos.
Autor: Jose Esteban Plaza
Nota:	Todas las funciones son genericas y pueden ser usadas
		por otras aplicaciones.
*******************************************************************/

/******************************************************************
Funcion: valNumber
Parametros:
- sInput: objeto completo del campo (i.e. document.theForm.theInput)
- sMsg:	  mensaje que se desea mostrar como el mensaje de error
Descripcion: Funcion que valida el campo introducido como un Numero
Retorna:
false en caso de encontrar el error. true en caso contrario
*******************************************************************/
function valNumber(sInput, sMsg)
{
	var nNumber;
	nNumber = sInput.value;
	if(isNaN(nNumber))
	{
		alert(sMsg);
		sInput.select();
		return false;
	}
	else
	{
		return true;
	}
}
/******************************************************************
Funcion: valNumber0
Parametros:
- sInput: objeto completo del campo (i.e. document.theForm.theInput)
- sMsg:	  mensaje que se desea mostrar como el mensaje de error
Descripcion: Funcion que valida el campo introducido como un Numero
mayor que cero (0)
Retorna:
false en caso de encontrar el error. true en caso contrario
*******************************************************************/
function valNumber0(sInput, sMsg)
{
	var nNumber;
	nNumber = sInput.value;
	if (nNumber!==''){
		if(isNaN(nNumber))
		{
			alert(sMsg);
			sInput.select();
			return false;
		}
		else
		{
			if(nNumber==0){
				alert(sMsg);
				sInput.select();
				return false;
			}
			else{
				return true;
			}
		}
	}
}
/******************************************************************
Funcion: valNull
Parametros:
- sInput: objeto completo del campo (i.e. document.theForm.theInput)
- sMsg:	  mensaje que se desea mostrar como el mensaje de error
Descripcion: Funcion que valida la nulidad de un campo
Retorna:
false en caso de encontrar el error. true en caso contrario
*******************************************************************/
function valNull(sInput, sMsg)
{
	var sVal;
	sVal = sInput.value;
	if(trim(sVal) == '')
	{
		alert(sMsg);
		sInput.value = "";
		sInput.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/******************************************************************
Funcion: valAllNull
Parametros:
- sForm: objeto completo del formulario (i.e. document.theForm)
- sMsg:	  mensaje generico a mostrar como el mensaje de error
Descripcion: Funcion que valida todos los campos de un Formulario
Retorna:
false en caso de encontrar el error. true en caso contrario
*******************************************************************/
function valAllNull(sForm, sMsg)
{
	var i, sVal;
	for (i = 0; i < sForm.length; i++)
	{
		sVal = sForm[i].value;
		if(trim(sVal) == '')
		{
			alert(sMsg);
			sVal.value = "";
			sForm[i].focus();
			return false;
		}
	}
	return true;
}

/******************************************************************
Funcion: valEmail
Parametros:
- sInput: objeto completo del campo (i.e. document.theForm.theInput)
- sMsg:	  mensaje que se desea mostrar como el mensaje de error
Descripcion:
Funcion que valida una direccion de correo electronico
Verifica que exista @ en alguna parte del string
que no sea el principio ni el final
Retorna:
false en caso de encontrar el error. true en caso contrario
*******************************************************************/
function valEmail(sInput, sMsg)
{
	var sEmail;
	sEmail = sInput.value;
	nPos = sEmail.search(new RegExp("@"));
	if (nPos == -1 || nPos == (sEmail.length - 1) || nPos == 0)
	{
		alert(sMsg);
		sInput.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/******************************************************************
Funcion: checkFileLength
Parametros:
- sInput: objeto completo del campo (i.e. document.theForm.theInput)
- sMsg:	  mensaje que se desea mostrar como el mensaje de error
- nMax:	  tope para el tamano del nombre del archivo
Descripcion:
Funcion que valida una el tamano del nombre de un archivo
Retorna:
false en caso de encontrar el error. true en caso contrario
*******************************************************************/
function checkFileLength(sInput,sMsg,nMax)
{
	var sValue, nLast, vValues, sName;
	vValues = new Array();
	sValue = sInput.value;
	vValues = sValue.split("\\");
	sName = vValues[vValues.length - 1];
	if (sName.length > nMax)
	{
		alert(sMsg);
		sInput.select();
		return false;
	}
	else
	{
		return true;
	}
}

/******************************************************************
Funcion: checkDate
Parametros:
- sD1: objeto que contiene el dia de inicio (i.e. document.theForm.sD1)
- sM1: objeto que contiene el mes de inicio (i.e. document.theForm.sM1)
- sY1: objeto que contiene el anio de inicio (i.e. document.theForm.sY1)
- sD2: objeto que contiene el dia de fin (i.e. document.theForm.sD2)
- sM2: objeto que contiene el mes de fin (i.e. document.theForm.sM2)
- sY2: objeto que contiene el anio de fin (i.e. document.theForm.sY2)
- sMsg:	  mensaje que se desea mostrar como el mensaje de error
Descripcion:
Funcion que valida las fechas de inicio y fin
Verifica que la de fin sea mayor a la de inicio al menos un dia
Retorna:
false en caso de encontrar el error. true en caso contrario
*******************************************************************/
function checkDate(sD1,sM1,sY1,sD2,sM2,sY2,sMsg)
{
	var dIni, dFin;
	dIni = new Date(sY1.value,sM1.value,sD1.value);
	dFin = new Date(sY2.value,sM2.value,sD2.value);
	
	if (dIni > dFin)
	{
		alert(sMsg);
		return false;
	}
	else
	{
		return true;
	}
}

/******************************************************************
Funcion: checkCmbBox
Parametros:
- sInput: objeto completo del campo (i.e. document.theForm.theInput)
- sMsg:	  mensaje que se desea mostrar como el mensaje de error
Descripcion:
Funcion que valida un ComboBox en un formulario
Valida que se halla seleccionado alguna de las opciones
SOLO debe usarse con ComboBox hechos con una opcion Nula de valor 0
Retorna:
false en caso de encontrar el error. true en caso contrario
*******************************************************************/
function checkCmbBox(sInput,sMsg)
{
	var sValue = sInput.value;
	if (sValue == '-1')
	{
		alert(sMsg);
		sInput.focus();
		return false;
	}
	else
	{
		return true;
	}
}
document.onkeydown = mykeyhandler;

function mykeyhandler() {

/*if(event.altLeft&&window.event.keyCode==37 || event.ctrlKey) alert("Función no permitida");

     if ((window.event && window.event.keyCode == 8) || (window.event && window.event.keyCode == 116) || (window.event && window.event.keyCode == 122)) {
         // try to cancel the backspace

         window.event.cancelBubble = true;
         window.event.keyCode = 8;
         window.event.returnValue = false;
         return false;
     }*/
}


function mouseDown(e) {
  var ctrlPressed=0;
  var altPressed=0;
  var shiftPressed=0;
  if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    var mString =(e.modifiers+32).toString(2).substring(3,6);
    shiftPressed=(mString.charAt(0)=="1");
    ctrlPressed =(mString.charAt(1)=="1");
    altPressed  =(mString.charAt(2)=="1");
    self.status="modifiers="+e.modifiers+" ("+mString+")"
   }
   else {
    shiftPressed=event.shiftKey;
    altPressed  =event.altKey;
    ctrlPressed =event.ctrlKey;
   }
   if (shiftPressed || altPressed || ctrlPressed)
    alert ("Función no permitida");

  }
  return true;
}
if (parseInt(navigator.appVersion)>3) {
  document.onmousedown = mouseDown;
  if (navigator.appName=="Netscape")
   document.captureEvents(Event.MOUSEDOWN);
}

function clickIE() {
	if (document.all) {(message);return false;}
	} 
function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) { 
		if (e.which==2||e.which==3) {(message);return false;}}} 
	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
	else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false");
