/*  Piccolo
/* -------------------------------------------------------------------------- */
function lettersonly(myfield, e, dec)
{
   var key;
   var keychar;

   if (window.event)
   key = window.event.keyCode;
   else if (e)
   key = e.which;
   else
   return true;
   keychar = String.fromCharCode(key);

   // control keys
   if ((key == null) || (key == 0) || (key == 8) ||
   (key == 9) || (key == 13) || (key == 27) )
   return true;

   // numbers
   else if (((" abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZáéíóúÁÉÍÓÚ'´").indexOf(keychar) > - 1))
   return true;

   // decimal point jump
   else if (dec && (keychar == "."))
   {
      myfield.form.elements[dec].focus();
      return false;
   }
   else
   return false;
}

function numbersonly(myfield, e, dec)
{
   var key;
   var keychar;

   if (window.event)
   key = window.event.keyCode;
   else if (e)
   key = e.which;
   else
   return true;
   keychar = String.fromCharCode(key);

   // control keys
   if ((key == null) || (key == 0) || (key == 8) ||
   (key == 9) || (key == 13) || (key == 27) )
   return true;

   // numbers
   else if ((("0123456789").indexOf(keychar) > - 1))
   return true;

   // decimal point jump
   else if (dec && (keychar == "."))
   {
      myfield.form.elements[dec].focus();
      return false;
   }
   else
   return false;
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function getSelectedRadioValue(buttonGroup)
{

   var radio_opciones = document.getElementById(buttonGroup);
   var valCheck = 0;
   for (var i = 0; i < radio_opciones.length;
   i ++ )
   {
      if (radio_opciones[i].checked)
      {
         valCheck = 1;
         break
      }
   }
   return radio_opciones[i].value;
}
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function SeleccionDepartamento(val)
{
	fromList = document.getElementById('departamento');
	
	for (i=0;i<fromList.options.length;i++){
		
		valAct = fromList.options[i].value;
	
		valSel = valAct.toString();
		valDep = val.toString();
		
   		if(valSel.trim() == valDep.trim()){
			fromList.options[i].selected = true;
		}else{
			fromList.options[i].selected = false;
		}
		
	}
}

// Ajax Piccolo
function handleHttpCiudades()
{
   if (http.readyState == 4)
   {
      if (http.status == 200)
      {
            results = http.responseText.split("###");
            if(results[0].length > 1)
            {
               document.getElementById("s_ciudad").innerHTML = results[0];
            }

            enProceso = false;
      }
   }
}
function traerCiu(val)
{
   
   if(val != '')
   {
      if(val == "CUND" || val == "DC"){
		   document.getElementById("valciudad").value = "1067";
		 }else{
	  		document.getElementById("valciudad").value = "";
	}
	  document.getElementById("s_ciudad").innerHTML = "<img src='../lib/28-0.gif' width='16' height='16' />";
      if ( ! enProceso && http)
      {
         var x_ID = val;
         var url = "../lib/ciudades.php?x_ID=" + x_ID;
         var parameters = "";
         http.open("GET", url, true);
         http.onreadystatechange = handleHttpCiudades;
         http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
         enProceso = true;
         http.send(parameters);
      }
   }
}
function handleHttpCiudadesID()
{
   if (http.readyState == 4)
   {
      if (http.status == 200)
      {
            results = http.responseText.split("###");
            if(results[0].length > 1)
            {
               document.getElementById("s_ciudad").innerHTML = results[0];
			   SeleccionDepartamento(results[1]);
            }

            enProceso = false;
      }
   }
}
function traerCiuID(val)
{
   
   if(val != '')
   {
	  document.getElementById("s_ciudad").innerHTML = "<img src='../lib/28-0.gif' width='16' height='16' />";
      if ( ! enProceso && http)
      {
         var x_ID = val;
         var url = "../lib/ciudades.php?x_ID_c=" + x_ID;
         var parameters = "";
         http.open("GET", url, true);
         http.onreadystatechange = handleHttpCiudadesID;
         http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
         enProceso = true;
         http.send(parameters);
      }
   }
}


function getHTTPObject() {
       var xmlHttp=null;
   try{  // Firefox, Opera 8.0+, Safari, IE 6 and up 
     xmlHttp=new XMLHttpRequest(); 
   }catch (e){  // Internet Explorer  5 and before
      try{   
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");   
      }catch (e){   
         try{     
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");     
         }catch (e){     
            alert("Tu navegador no soporta AJAX!!!\nPor favor comentalo con Sistemas");     
            return false;     
         }   
      } 
   }
   return xmlHttp;
   
}
//function getHTTPObject()
//{
//   var xmlhttp;
//   /* @cc_on
//   @if (@_jscript_version >= 5)
//   try {
//   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
//   } catch (e) {
//   try {
//   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//   } catch (E) { xmlhttp = false; }
//   }
//   @else
//   xmlhttp = false;
//   @end @ */
//   if ( ! xmlhttp && typeof XMLHttpRequest != 'undefined')
//   {
//      try
//      {
//         xmlhttp = new XMLHttpRequest();
//      }
//      catch (e)
//      {
//         xmlhttp = false;
//
//      }
//   }
//   return xmlhttp;
//}
var enProceso = false;
var enProceso1 = false;
var enProceso2 = false;
var enProceso3 = false;
// lo usamos para ver si hay un proceso activo
var http = getHTTPObject();
// Creamos el objeto XMLHttpRequest
