function validahttp(objeto) 
{
 var valor = objeto.value;
 if (valor.length<7)
 { 
 objeto.value="http://";
 }
}

function solo_numeros(objeto) 
{
 var valor = objeto.value;
 if (isNaN(valor))
 { 
 alert('Este campo solo apecta numeros');
 valor=valor.substring(0,valor.length-1);
 objeto.value=valor;
 }
}



function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- El campo '+nm+' solo acepta direcciones email.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- El campo '+nm+' solo acepta números.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- El campo '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- El campo '+nm+' es requerido.\n'; }
  } if (errors) alert('Ha ocurrido el siguiente error:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function cambiarEstado(obj){
	var estado, tabla, mensaje;
	door=['images/folder.gif','images/folderopen.gif'];
	estado=(obj.src.search("open")<0)?1:0;
	tabla = document.getElementById('t' + obj.id)
	tabla.style.display = (obj.src.search("open")<0)?"block":"none";
	obj.alt=(obj.src.search("open")<0)?"Ocultar Eventos":"Mostrar Eventos";
	obj.src=door[estado];
return
}

function changeCombo(id, combo, matriz) {
	var i;
	var cmb = document.getElementById(combo);
	cmb.options.length=0;
	if (id == ""){
		var opcion = new Option("Ninguno","",false,false);
		cmb.options[cmb.options.length] = opcion;
	}else {
		for (i=1; i <= window[matriz][id].length; i++) {
			if (window[matriz][id][i] != null) {
				var opcion= new Option(window[matriz][id][i],i,false,false);
				cmb.options[cmb.options.length]=opcion;
			};
		};
	};
}

/** EXPERIMENTAL - carga de Valores en Combo Dependiente**/
function ajaxChangeCombo(id) {
	showStatus("Cargando Datos...", document.getElementById('cmbServicio'), 1);
	var url = 'getValues.asp?comboId=' + id;
	if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.onreadystatechange = processRequest;
	req.open("GET", url, true);
	req.send(null);
}

function processRequest() {
    if (req.readyState == 4) {
        if (req.status == 200) {
          parseMessages();
        } else {
          alert ( "La Información solicitada actualmente no está disponible" );
				}
    }
}

function showStatus(message, obj, type){
	switch (type){
		case (1): //mostrar mensaje en un combo
			obj.options.length=0;
			var opcion = new Option(message,"",false,false);
			obj.options[obj.options.length] = opcion;
			break;
		case (2): //mostrar mensaje en un textbox
			obj.value = message;
			break;			
	}
}

function parseMessages() {
	var response  = req.responseXML.documentElement;
	var cmb = document.getElementById('cmbServicio');
	cmb.options.length=0;
	var opcion = new Option("Ninguno","",false,false);
	cmb.options[cmb.options.length] = opcion;
	var nodeServicio = response.getElementsByTagName('servicio');
	for (var i=0; i <= nodeServicio.length - 1; i++) {
		itemServicio = nodeServicio[i];
		opcion= new Option(itemServicio.firstChild.data, itemServicio.getAttribute('id'), false, false);
		cmb.options[cmb.options.length]=opcion;
	};
}

/** ---- FIN CARGA DE DATOS USANDIO AJAX EN COMBOS DEPENDIENTES ---- **/

/** FUNCIONES COMUNES PARA LAS PAGINAS DE SUSCRIPCION DE PROVEEDORES */
/** ---------------------------------------------------------------- */
/** ---------------------------------------------------------------- */

function agregarServicio(){
	if(document.getElementById('serv01').style.display == 'none'){
		document.getElementById('serv01').style.display = 'block';
	}	
	var servicioSeleccionado = document.getElementById('cmbServicio');
	var servicios = document.getElementById('servicios');
	for(i = servicios.length-1; i >= 0; i--)
	{
		if(servicios.options[i].value == servicioSeleccionado.value) return false;
	}
	servicios.options[servicios.length] = new Option(servicioSeleccionado.item(servicioSeleccionado.selectedIndex).text, servicioSeleccionado.value);
	return true
}

function eliminarServicio(){
	var servicios = document.getElementById('servicios');
	var selIndex = servicios.selectedIndex;
  if (selIndex != -1) {
    for(i = servicios.length-1; i >= 0; i--)
    {
      if(servicios.options[i].selected)
      {
        servicios.options[i] = null;
      }
    }
    if (servicios.length > 0) {
      servicios.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
    }
  }
	if (servicios.length == 0){
		document.getElementById('serv01').style.display = 'none';
		document.getElementById('serv02').style.display = 'none';
	}	
	return true	
}

function selAll() {
	var servicios = document.getElementById('servicios');
	 for(i = servicios.length-1; i >= 0; i--)
		servicios[i].selected = true;
	return true
}

/**
* Style Functions
*/
function swapClass(obj, curClass, newClass) {
	if (obj.className.toLowerCase() == curClass.toLowerCase() || obj.className == '') {
		obj.className = newClass;
	} else {
		if (obj.className.toLowerCase() == newClass.toLowerCase() || obj.className == '') {
			obj.className = curClass;
		}
	}
}
