function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function actionForms() { 
	if (!document.getElementsByTagName) {
 		return false;
	} 
	var forms = document.getElementsByTagName("form")
	for (var i=0; i < forms.length; i++) { 
    	if (forms[i].getAttribute("class") == "cargarVenta") { 
			forms[i].setAttribute('action', '');
			forms[i].onsubmit = function() {   
          	agregarVenta();   
        	return false;    
         	}  
		}
    } 	  
}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;
}
   
function agregarVenta(){  
	tipo=document.formVender.tipo.value;
	precio=document.formVender.precio.value;
	descripcion=document.formVender.descripcion.value;
	foto1=document.formVender.foto1.value;
	foto2=document.formVender.foto2.value;
	foto3=document.formVender.foto3.value;
	foto4=document.formVender.foto4.value;
	fecha=document.formVender.fecha.value;
	idRegistrados=document.formVender.idRegistrados.value;
	estado=document.formVender.estado.value;

	if (IsNumeric(precio.replace('.',''))){
		if (descripcion.length > 100 ){
			if(tipo != 0){
				var url 	=	'../scriptVenta.php';
				var pars	= 'tipo='+tipo+'&precio='+precio+'&descripcion='+escape(descripcion)+'&foto1='+foto1+'&foto2='+foto2+'&foto3='+foto3+'&foto4='+foto4+'&fecha='+fecha+'&idRegistrados='+idRegistrados+'&estado='+estado;
				var myAjax = new Ajax.Request( url,
						{
							method: 'get',
							parameters: pars,		
							onComplete: cerrarCargar
						}
				);
			}else{
				alert('Seleccione una categoria para su articulo.');
			}
		}else{
			alert('Ingrese una descripcion para su articulo');		
		}
	}else{
		alert('El Precio ingresado es invalido.');	
	}
}

function eliminarArticulo(idPersonal){
	var url 	=	'scriptEliminarPersonal.php';
	var pars	= 'id='+escape(idPersonal);
	var myAjax = new Ajax.Request( url,
			{
				method: 'get',
				parameters: pars,		
				onComplete: cerrarCargar
			}
	);
}

function cerrarCargar(){
	alert('Termine');
}





function buscarListaPersonal() {
	var imgLink = document.getElementById('imgActualizarPersonal');
		imgLink.setAttribute('src', 'imagenes/icn_refreshAni.gif'); 
			
 	var objDDL = document.getElementById('divListaPersonal');
 	var img = document.createElement('img');
 		img.height = img.width = 30;
 		img.width = img.width = 220;
		img.src = 'imagenes/ajax-loader.gif';
		img.id ='imgAjaxLoading';
		objDDL.appendChild(img);
		

	var url 	=	'traerListaPersonal.php';
	var myAjax = new Ajax.Request( url,
			{
				method: 'get',
				parameters: '',		
				onComplete: cargarListaPersonal3
			}
	);
}

// Para una lista DL

function cargarListaPersonal2(originalRequest)	{
 	var objDDL = document.getElementById('divListaPersonal');
	eval("var personas=" + originalRequest.responseText);
 	var dl = document.createElement('dl');
		dl.id ='listaPersonal';

	var dt = dl.appendChild(document.createElement('dt'));
		dt.appendChild(document.createTextNode('Personal de Bluesoft'));
	objDDL.appendChild(dt)	
	
	for(i=0;i<personas.length;i++){
		var text	= unescape(personas[i]);
		var dd = document.createElement('dd');
		var a = document.createElement('a');
		
		var img = a.appendChild(document.createElement('img'));
 			img.height = img.width = 16;
			img.src = 'imagenes/icon_modificar.gif';
			a.setAttribute('href', 'formModPersona.php');
			a.appendChild(img);
			dd.appendChild(a);					

		var a2 = document.createElement('a');
		var img2 = a.appendChild(document.createElement('img'));
 			img2.height = img.width = 16;
			img2.src = 'imagenes/icon_borrar.gif';
			a2.setAttribute('href', 'scriptEliminarPersonal.php');
			a2.appendChild(img);
			dd.appendChild(a2);	
 
			dd.appendChild(document.createTextNode(text));
			dl.appendChild(dd);
	}
	objDDL.appendChild(dl)	
};	
// Para una lista UL

 
function cargarListaPersonal3(originalRequest)	{
eval("var personas=" + originalRequest.responseText);
  	var hijo  = document.getElementById('listaPersonalBS');
 	if (hijo != null){
		var padre = hijo.parentNode;
		padre.removeChild(hijo);
	}
	var objDDL = document.getElementById('divListaPersonal');
 	var ul = document.createElement('ul');
 		ul.setAttribute('id', 'listaPersonalBS');	
 
	for(i=0;i<personas.length;i++){
		var text	= unescape(personas[i]);
		var datoResultPersonal = text.split(";"); 
		
		var li = document.createElement('li');
		var a = document.createElement('a');
		
		var img = a.appendChild(document.createElement('img'));
 			img.height = img.width = 16;
			img.src = 'imagenes/icon_borrar.gif';
			a.setAttribute('name', 'EliPersona-' + datoResultPersonal[0]);
			a.setAttribute('class', 'onclick');						
			a.appendChild(img);
			li.appendChild(a);					

		var a2 = document.createElement('a');
		var img2 = a.appendChild(document.createElement('img'));
 			img2.height = img.width = 16;
			img2.src = 'imagenes/icon_modificar.gif';
			a2.setAttribute('name', 'ModPersona-' + datoResultPersonal[0]);
			a2.setAttribute('class', 'onclick');			
			a2.appendChild(img2);
			li.appendChild(a2);	
 
			li.appendChild(document.createTextNode(datoResultPersonal[1]));
			ul.appendChild(li);
	}
	objDDL.appendChild(ul);
	objDDL.removeChild(document.getElementById('imgAjaxLoading'));
	
	vinculosPersonal();
};

