var new_fieldname = ""
var comboMunicipios = "";
var codigoVarRango = "";
var valorRango = -1;
var comboDepartamentos = "";
var comboCargue;
var inputHint;
var strMonthArray = new Array(12);

var req; // global request and XML document objects

function check(form,x)
{
	if( valFechaForma() == false ) return false;

	//If you would like to use this script please do not remove the next 4 lines
	script_name = "Form Validator ver 2.0"
	action =  "Checks Required, Integer and Date"
	copyright = "(c) 1998 - Art Lubin / Artswork"
	email = "perflunk@aol.com"
	var set_up_var = doall(script_name, copyright, email)
	var message = ""
	var more_message = ""
	var showmsg = "no"
	if (set_up_var == 5872)
	{
		x = x - 1
		for (var i = 0; i <= x; i++)
			{

	 			var messenger = form.elements[i].name
				messenger = messenger.substring(0, 2)
				var fieldname = form.elements[i].name
				fieldname = fieldname.substring(2)
					{
						if (messenger == "r_")
							{
								more_message = r_check(form,x,fieldname,i)
							}
						else if (messenger == "i_")
							{
								more_message = i_check(form,x,fieldname,i)
							}
						else if (messenger == "d_")
								{
									more_message = d_check(form,x,fieldname,i)
								}
						else if (messenger == "e_")
								{
									more_message = e_check(form,x,fieldname,i)
								}			
							 if (more_message != "")
	        {
									if (message == "")
										{
											message = more_message
											more_message=""
										}
									else
										{
			        message = message + "\n" + more_message
											more_message=""
										}
	        }
											
						if (message > "")
								{
										showmsg = "yes"
								}													
						}
				}
			
		
		//This code will prevent a submit if data is incoorect
		if (showmsg == "yes")
			{
				alert("La Forma esta incompleta o incorrecta:\n\n" + message + "\n\n Por favor complete la forma o corrijala.")
                                return false; 
			}
		else
			{
			 if (confirm("Confirma la transacción"))
                           {
                            // form.submit();
                            return true;
                           }
                         else
                           {
                            return false;
                           }
			}
		}
	else
		{
			alert ("The copyright information has been changed. \n In order to use this javascript please keep the copyright information intact. \n\n Script Name: Form Validator ver 2.0 \n Copyright: (c) 1998 - Art Lubin / Artswork \n Email: perflunk@aol.com")
		}
}	

function r_check(form,x,fieldname,i)
	{
		var msg_addition = ""
		new_fieldname = fieldname
		for (var y = 0; y <= x; y++)
			{

				if ((form.elements[y].type == "radio" || form.elements[y].type == "checkbox") && form.elements[y].name == new_fieldname && form.elements[y].checked == true)
					{
							msg_addition = ""
							break
					}
				else if ((form.elements[y].type == "radio" || form.elements[y].type == "checkbox") && form.elements[y].name == new_fieldname && form.elements[y].checked == false)
					{
						msg_addition = form.elements[i].value
					}

			else if (form.elements[y].type == "select-one")
							{
								var l = form.elements[y].selectedIndex
								if (form.elements[y].name == fieldname && form.elements[y].options[l].value != "")
									{
										msg_addition = ""
										break
									}
								else if (form.elements[y].name == fieldname && form.elements[y].options[l].value == "")
									{
										
										msg_addition = form.elements[i].value

									}
								}
		 else if (form.elements[y].name == fieldname && form.elements[y].value == "" && form.elements[y].type != "radio" && form.elements[y].type != "checkbox" && form.elements[y].type != "select-one")
							{
								
								msg_addition = form.elements[i].value
								break
							}
				else if (form.elements[y].name == fieldname && form.elements[y].value != "" && form.elements[y].type != "radio" && form.elements[y].type != "checkbox" && form.elements[y].type != "select-one")
							{
								msg_addition = ""

							}
				}
			return(msg_addition)
		}

			
function i_check(form,x,fieldname,i)
	{
		for (var y = 0; y <= x; y++)
			{
				if (form.elements[y].name == fieldname)
				break
			}				
	
	var msg_addition = ""
	var decimal = ""
	inputStr = form.elements[y].value.toString().replace(/\$|\,/g,'');
	
	if (inputStr == "")
		{
			//msg_addition = form.elements[i].value
		}
	else
		{
			for (var c = 0; c < inputStr.length; c++)
				{
					var oneChar = inputStr.charAt(c)
/*
					if (c == 0 && oneChar == "-" || oneChar == "."  && decimal == "")
							{
								if (oneChar == ".")
									{
										decimal = "yes"
									}
								continue
								
							}
*/
								if ( oneChar != '.' && (oneChar < "0" || oneChar > "9") )
									{
										msg_addition = form.elements[i].value
									}
				}
		}
    
		return(msg_addition)
	}	
	
	
	//Email validation added 6/20/98
	function e_check(form,x,fieldname,i)
	{
		for (var y = 0; y <= x; y++)
			{
				if (form.elements[y].name == fieldname)
				break
			}						
		
	var msg_addition = ""
	period = ".";

                
                if (form.elements[y].value == "" || form.elements[y].value.indexOf ('@', 0) < 3)
                        error = 1;
																						
																else
                  {
	                   test = form.elements[y].value.indexOf('.', form.elements[y].value.indexOf ('@', 0))
										 if (test != -1)
																					{
																						error = 0;
																					}
																				else
																				{
	                    	 error=1;
																				}
                  }
                if (error == 1)
																	{
               				msg_addition = form.elements[i].value
																	}
                else
                 {
								 		new_length = form.elements[y].value.length - test
             if (new_length == 4 || new_length == 3 || (new_length >= 5 && form.elements[y].value.indexOf ('.', (test+1)) != -1))
																						{
																							msg_addition = ""
																						}
																					else
																							msg_addition = form.elements[i].value;
																	}
	return(msg_addition)
	}

	function d_check(form,x,fieldname,i)
//date must be in MM/DD/YY format OR M/D/YY or a MIX of the two
 {
    alert( x );
		for (var y = 0; y <= x; y++)
			{
				if (form.elements[y].name == fieldname)
				break
			}		
			
		var msg_addition = ""	
		if( chkdate(form.elements[y]) == false )
    		msg_addition = form.elements[i].value;

		return(msg_addition)
			
		var sDate = form.elements[y].value
		var int_or_not = isInteger(form.elements[y].value)
		if (int_or_not == "true")
			{
				if ((!(form.elements[y].value.length >= 6)) || (!(form.elements[y].value.length <= 8)))
   		{
    		msg_addition = form.elements[i].value
   		}
  		else
   		{
					 var SlashlPos = form.elements[y].value.indexOf("/",0)
					 alert( 'slash en pos: ' + SlashlPos );
						if (SlashlPos != 4 )
								msg_addition = form.elements[i].value
						else if (SlashlPos > 0 && SlashlPos <= 2)
							{
								if (SlashlPos == 1)
									{
										if (form.elements[y].value.charAt(0) < 1 || form.elements[y].value.charAt(0) > 9)
											{
												msg_addition = form.elements[i].value
											}
										else
											{
												if ((form.elements[y].value.charAt(0) == 1 || form.elements[y].value.charAt(0) == 3 || form.elements[y].value.charAt(0) == 5 || form.elements[y].value.charAt(0) == 7 || form.elements[y].value.charAt(0) == 8) && ((form.elements[y].value.charAt(2) == 0 && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(3) == "/" && form.elements[y].value.length >= 7) || (form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(2) == "/")))
													{
														msg_addition = form.elements[i].value
													}
												else if ((form.elements[y].value.charAt(0) == 1 || form.elements[y].value.charAt(0) == 3 || form.elements[y].value.charAt(0) == 5 || form.elements[y].value.charAt(0) == 7 || form.elements[y].value.charAt(0) == 8) && ((form.elements[y].value.charAt(2) >= 3 && form.elements[y].value.charAt(3) > 1) || (form.elements[y].value.charAt(2) == 0 && form.elements[y].value.charAt(3) == 0) || (form.elements[y].value.charAt(1) == "/" && (form.elements[y].value.charAt(3) != "/" && form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/"))))
													{ 
														msg_addition = form.elements[i].value + "hi"
													}
												else if ((form.elements[y].value.charAt(0) == 1 || form.elements[y].value.charAt(0) == 3 || form.elements[y].value.charAt(0) == 5 || form.elements[y].value.charAt(0) == 7 || form.elements[y].value.charAt(0) == 8) && (((form.elements[y].value.charAt(2) > 3 && form.elements[y].value.charAt(3) != "/") || (((form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(4) == "/")) && ((form.elements[y].value.length == 6 || form.elements[y].value.length == 8)))) || form.elements[y].value.charAt(5) == "/"))
													{
														msg_addition = form.elements[i].value
													}
												else
													{
														if ((form.elements[y].value.charAt(0) == 2 && ((form.elements[y].value.charAt(2) == 0 && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(3) == "/" && form.elements[y].value.length >= 7) || (form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(2) == "/") || (form.elements[y].value.charAt(2) == 0 && form.elements[y].value.charAt(3) == 0) || (form.elements[y].value.charAt(1) == "/" && (form.elements[y].value.charAt(3) != "/" && form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/")))))
															{ 
																msg_addition = form.elements[i].value
															}
														else if (form.elements[y].value.charAt(0) == 2 && ((form.elements[y].value.charAt(2) > 2 && form.elements[y].value.charAt(3) != "/") || (((form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(4) == "/") && ((form.elements[y].value.length == 6 || form.elements[y].value.length == 8)))) || form.elements[y].value.charAt(5) == "/"))
															{ 
																msg_addition = form.elements[i].value
															}
														else
															{
																if ((form.elements[y].value.charAt(0) == 4 || form.elements[y].value.charAt(0) == 6 || form.elements[y].value.charAt(0) == 9) && ((form.elements[y].value.charAt(2) == 0 && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(3) == "/" && form.elements[y].value.length >= 7) || (form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(2) == "/")))
																	{ 
																		msg_addition = form.elements[i].value
																	}
																else if ((form.elements[y].value.charAt(0) == 4 || form.elements[y].value.charAt(0) == 6 || form.elements[y].value.charAt(0) == 9) && ((form.elements[y].value.charAt(2) >= 3 && form.elements[y].value.charAt(3) > 0) || (form.elements[y].value.charAt(2) == 0 && form.elements[y].value.charAt(3) == 0) || (form.elements[y].value.charAt(1) == "/" && (form.elements[y].value.charAt(3) != "/" && form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/"))))
																	{ 
																		msg_addition = form.elements[i].value
																	}
																else if ((form.elements[y].value.charAt(0) == 4 || form.elements[y].value.charAt(0) == 6 || form.elements[y].value.charAt(0) == 9) && (((form.elements[y].value.charAt(2) > 3 && form.elements[y].value.charAt(3) != "/") || ((form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(4) == "/") && ((form.elements[y].value.length == 6 || form.elements[y].value.length == 8)))) || form.elements[y].value.charAt(5) == "/"))
																	{
																		msg_addition = form.elements[i].value
																	}
															}
													}
											}
									}
								else
									{
										if (form.elements[y].value.charAt(0) > 1 || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) > 2) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 0))
											{
												msg_addition = form.elements[i].value
											}
										else
											{
												if (((form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 1) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 3) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 5) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 7) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 8) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 0) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 2)) && ((form.elements[y].value.charAt(3) == 0 && form.elements[y].value.charAt(4) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(2) == "/" && (form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/" && form.elements[y].value.charAt(7) != "/"))))
													{
														msg_addition = form.elements[i].value		
													}
												else if (((form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 1) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 3) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 5) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 7) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 8) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 0) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 2)) && ((form.elements[y].value.charAt(3) >= 3 && form.elements[y].value.charAt(4) > 1) || (form.elements[y].value.charAt(3) == 0 && form.elements[y].value.charAt(4) == 0) || form.elements[y].value.length < 7))
													{
														msg_addition = form.elements[i].value
													}
			else if (((form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 1) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 3) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 5) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 7) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 8) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 0) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 2)) && ((form.elements[y].value.charAt(3) > 3 && form.elements[y].value.charAt(4) != "/")	|| ((form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(5) == "/" && form.elements[y].value.length == 7 || form.elements[y].value.charAt(6) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(4) == "/" && (form.elements[y].value.length == 6 || form.elements[y].value.length == 8)))))
													{
														msg_addition = form.elements[i].value
													}
												else
													{
														if (((form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 2) && ((form.elements[y].value.charAt(3) == 0 && form.elements[y].value.charAt(4) == "/") || (form.elements[y].value.charAt(3) == 0 && form.elements[y].value.charAt(4) == 0)) || form.elements[y].value.length < 7) || (form.elements[y].value.charAt(2) == "/" && (form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/" && form.elements[y].value.charAt(7) != "/")))
															{
																msg_addition = form.elements[i].value
															}
														else if ((form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 2) && ((form.elements[y].value.charAt(3) > 2 && form.elements[y].value.charAt(4) != "/") || ((form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(5) == "/" && form.elements[y].value.length == 7 || form.elements[y].value.charAt(6) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(4) == "/" && (form.elements[y].value.length == 6 || form.elements[y].value.length == 8)))))
															{
																msg_addition = form.elements[i].value
															}
														else
															{			
																if (((form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 4) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 6) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 9) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 1)) && ((form.elements[y].value.charAt(3) == 0 && form.elements[y].value.charAt(4) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(2) == "/" && (form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/" && form.elements[y].value.charAt(7) != "/"))))
																	{
																		msg_addition = form.elements[i].value
																	}
																else if (((form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 4) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 6) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 9) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 1)) && ((form.elements[y].value.charAt(3) >= 3 && form.elements[y].value.charAt(4) > 0) || (form.elements[y].value.charAt(3) == 0 && form.elements[y].value.charAt(4) == 0) || form.elements[y].value.length < 7))
																	{
																		msg_addition = form.elements[i].value
																	}
																else if (((form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 4) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 6) || (form.elements[y].value.charAt(0) == 0 && form.elements[y].value.charAt(1) == 9) || (form.elements[y].value.charAt(0) == 1 && form.elements[y].value.charAt(1) == 1)) && ((form.elements[y].value.charAt(3) > 3 && form.elements[y].value.charAt(4) != "/") || ((form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(5) == "/" && form.elements[y].value.length == 7 || form.elements[y].value.charAt(6) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(4) == "/" && (form.elements[y].value.length == 6 || form.elements[y].value.length == 8)))))
																	{
																		msg_addition = form.elements[i].value
																	}
															}
													}
											}
									}
							}
		    else
							{
								msg_addition = form.elements[i].value
							}
					}
			}
		else
			{
				msg_addition = form.elements[i].value
			}
		return(msg_addition)
	}
	
	function isInteger(sDate)
	{
		var new_msg = "true"
		inputStr = sDate.toString()
		for (var i = 0; i < inputStr.length; i++)
			{
			var oneChar = inputStr.charAt(i)			
			if ((oneChar < "0" || oneChar > "9") && oneChar != "/")
					{
						new_msg = "false"
					}
			}
		return (new_msg)
	}
	
	function doall(script_name, copyright, email)
	{
	var code = 0
	var test = script_name + copyright + email
	for (var a = 0; a < test.length; a++)
		{
		var each_char = test.charAt(a)
		var x = asc(each_char)
		code += x
		}
	return (code)
	}
	
	function asc(each_char)
		{
		var n = 0
			var char_str = charSetStr()
			for (i = 0; i < char_str.length; i++)
				{
					if (each_char == char_str.substring(i, i+1))
						{
							break
						}
				}
			return i + 32
		}
		
		function charSetStr()
			{
				var str
 			str = ' !"#$%&' + "'" + '()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
				return str
			}



function checkrequired(which)
{
 var pass=true;
 if (document.images)
   {
    for (i=0;i<which.length;i++)
       {
        var tempobj=which.elements[i];
        if ((tempobj.name.substring(0,11)=="obligatorio"))
          {
           if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value==""))
             {
              pass=false;
              break;
             }
          }
       }
   }
 if (!pass)
  {
   shortFieldName=tempobj.name.toUpperCase();
   alert("Verifique que todos los campos con asterisco esten con datos");
   return false;
  }
 else
   return true;
}


function checkdate(objName, validacion)
{
 var datefield = objName;
 if (chkdate(objName,validacion) == false)
   {
    datefield.select();
    
    if (validacion)
      alert("La fecha es invalida o es mayor a la fecha actual");
    else 
      alert("La fecha es invalida")
      
    datefield.focus();
    return false;
   }
  
  if( validacion && document.captura.tipo_tercero.value != '1' && objName.nombre_variable == 'fecha_nacimiento' ) {
    var ano = objName.value.substr(0,4);
    var mes = objName.value.substr(5,2);
    var dia = objName.value.substr(8,2);
    var fechaHoy = new Date();
    var anoHoy = fechaHoy.getYear();
    var mesHoy = fechaHoy.getMonth()+1;
    var diaHoy = fechaHoy.getDate();
    var mensaje = "** Edad invalida para deudor solidario";
    
    if( (anoHoy - ano) > 60 ) {
      alert( mensaje );
      datefield.select();
      return false;
    } else if( (anoHoy - ano) == 60 && mesHoy > mes  ) {
      alert( mensaje );
      datefield.select();
      return false;
    } else if( (anoHoy - ano) == 60 && mesHoy == mes && diaHoy >= dia  ) {
      alert( mensaje );
      datefield.select();
      return false;
    }
  }
}



function chkdate(objName,validacion,validaPosterior)
{
 var strDatestyle ="US"; //United States date style
 if (objName.value.length < 1)
  return true;
 if (objName.value.length < 6)
  return false;
 var strDate;
 var strDateArray;
 var strDay;
 var strMonth;
 var strYear;
 var intday;
 var intMonth;
 var intYear;
 var booFound = false;
 var datefield = objName;
 var strSeparatorArray = new Array("-"," ","/",".");
 var intElementNr;
 var err = 0;

 strMonthArray[0] = "01";
 strMonthArray[1] = "02";
 strMonthArray[2] = "03";
 strMonthArray[3] = "04";
 strMonthArray[4] = "05";
 strMonthArray[5] = "06";
 strMonthArray[6] = "07";
 strMonthArray[7] = "08";
 strMonthArray[8] = "09";
 strMonthArray[9] = "10";
 strMonthArray[10] = "11";
 strMonthArray[11] = "12";
 strDate = datefield.value;
 if (strDate.length < 1)
   {
    return false;
   }
 for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++)
    {
     if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
       {
        strDateArray = strDate.split(strSeparatorArray[intElementNr]);
        if (strDateArray.length != 3)
          {
           err = 1;
           return false;
          }
        else
          {
           strDay = strDateArray[1];
           strMonth = strDateArray[2];
           strYear = strDateArray[0];
          }
        booFound = true;
       }
    }
 if (booFound == false)
   {
    if (strDate.length>5)
      {
       strDay = strDate.substr(6);
       strMonth = strDate.substr(4, 6);
       strYear = strDate.substr(0, 4);
      }
   }
 if (strYear.length == 2)
   {
    strYear = "20" + strYear;
   }
 if (strYear.length == 1)
   {
    return false
   }
 if (strYear.length == 3)
   {
    return false
   }
 if (strYear.length > 4)
   {
    return false
   }
// US style
 if (strDatestyle == "US")
   {
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
   }
 intday = parseInt(strDay, 10);
 if (isNaN(intday))
   {
    err = 2;
    return false;
   }
 intMonth = parseInt(strMonth, 10);
 if (isNaN(intMonth))
   {
    for (i = 0; i<12; i++)
       {
        if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase())
          {
           intMonth = i+1;
           strMonth = strMonthArray[i];
           i = 12;
          }
       }
    if (isNaN(intMonth))
      {
       err = 3;
       return false;
      }
   }

 intYear = parseInt(strYear, 10);
 if (isNaN(intYear))
   {
    err = 4;
    return false;
   }
 if (intMonth>12 || intMonth<1)
   {
    err = 5;
    return false;
   }
 if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
   {
    err = 6;
    return false;
   }
 if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
   {
    err = 7;
    return false;
   }
 if (intMonth == 2)
   {
    if (intday < 1)
      {
       err = 8;
       return false;
      }
    if (LeapYear(intYear) == true)
      {
       if (intday > 29)
         {
          err = 9;
          return false;
         }
      }
    else
      {
       if (intday > 28)
         {
          err = 10;
          return false;
         }
      }
   }
 if (strDatestyle == "US")
   {
    if (intday < 10)
      datefield.value = strYear + "/" + strMonthArray[intMonth-1] + "/0" + intday;
    else
      datefield.value = strYear + "/" + strMonthArray[intMonth-1] + "/" + intday;
   }
 else
   {
    datefield.value = intday + "-" + strMonthArray[intMonth-1] + "-" + strYear;
   }
   
   //if (validacion){
     if ( validacion && !validarFechaActual(datefield) ) {
        alert( "La fecha es mayor a la fecha actual." );
        datefield.focus();
     }
   // }
   
   return true;
}

function LeapYear(intYear)
{
 if (intYear % 100 == 0)
   {
    if (intYear % 400 == 0) { return true; }
   }
 else
   {
    if ((intYear % 4) == 0) { return true; }
   }
return false;
}



function llenarconceros1(valor, len)
{
 var srci;
 var tamsrci;
 var rci = valor;
 srci = rci.value;
 rci.value = "";
 tamsrci = len - srci.length;
 for (i = 0; i<tamsrci; i++)
    rci.value += "0"
 rci.value += srci
 return true
}

function llenarconceros(valor)
{
  return llenarconceros1(valor, 20);
}


function llenarconblancos1(valor, len)
{
 var srci;
 var tamsrci;
 var rci = valor;
 srci = rci.value;
 rci.value = "";
 tamsrci = len - srci.length;
 for (i = 0; i<tamsrci; i++)
    rci.value += " "
 rci.value += srci
 return true
}

function llenarconblancos(valor)
{
  return llenarconblancos1(valor, 20);
}



function ConfirmaEliminar(form)
{
if (confirm("Confirma la transacción"))
  {
   form.submit();
   return true;   
  }
else
  {
   return false;//history.go(-2);
  }
}


function esMayor(objeto)
{
 if (objeto.value<0 || objeto.value=='.')
   {
    alert("Valor invalido");
    objeto.focus();
    objeto.select();
    // objeto.value=0;
    return true;
   }
 else  
    return false;
}


	function cargaFormato() {
		cmbOpcion = document.frmEg.opcion;
		op = cmbOpcion.options[cmbOpcion.selectedIndex].value;
		cmbFormato = document.frmEg.formato;

          for( i = cmbFormato.options.length; i > 0; --i )
              cmbFormato.options[i] = null;  
          	//***END2002 REQ13 MAcosta *	
            if (( op == "inclusion" ) || ( op == "correccion" ) ||
                ( op == "eliminacion" ) || ( op == "actualizacion")
               )
            {
			var op1 = new Option( "273", "138" );
			var op2 = new Option( "277", "248" );
                  var op3 = new Option( "275", "275" );
                  var op4 = new Option( "279", "279" );
		}
            cmbFormato.options[1] = op1;
            cmbFormato.options[2] = op2;
            cmbFormato.options[3] = op3;
            cmbFormato.options[4] = op4;
            //***END2002 fin *
	}



	function valFechaForma() {
		forma = document.forms[0].forma_pago;
		fecha = document.forms[0].fecha_pago;

		if( forma == null || fecha == null ) return true;

		if( (forma.value != 0 && fecha.value == "" ) ) {
			alert( 'Debe digitar una fecha de pago' );
			return false;
		}

		if( forma.value == 0 && fecha.value != "" ) {
			alert( 'Debe seleccionar una forma de pago' );
			return false;
		}
	}


	function cambiaLista( caja ) {
		var combo1, combo2;
		chulo = caja.checked;
		lista = caja.value.substring(caja.value.indexOf('|')+1,999);
		lista = 'estado_registro|' + lista;

		if( chulo ) {
			combo1 = document.all( 'x_'+lista );
			combo1.name = 'r_' + lista;
		}
		else {
			combo2 = document.all( 'x_'+lista );
			combo2.name = 'x_' + lista;
		}
	}

function valPorcentaje(objName)
{
	var valor = objName;
	val = parseInt( valor.value );

	if ( val > 100 || val < 0 )
	{
		valor.select();
		alert("La probabilidad debe encontrarse entre 0 y 100");
		valor.focus();
		return false;
	}
}


function clickCheck( e ) {
	estado = e.checked;
	presentar = ( estado == true ) ? '' : 'none';
		
	d = document.all( "div_" + e.name + '_-1' );
	
	if( d ) {
		d.style.display = presentar;
		tabla = d.children[0].children[0].children[0];
		
		for( i=0; i < tabla.children.length; ++i ) {
			fila = tabla.children[i];
			campoH = fila.children[1].children[1];
			if( campoH != null ) {
				if( estado ) {
					campoH.name = "r_" + campoH.id;
				} else {
					campoH.name = "nr_" + campoH.id;
				}
			}
		}
	}
}

var div_activado;

function selectChange( e ) {
	valorActual = e.value;
	var activo = false;
	
	var arregloVar = e.vars.split( '|' );
	var arregloVal = e.vals.split( '|' );
	
	if( e.nombre_variable == 'fecha_nacimiento' && e.value == '61_99' ) {
    alert( 'Edad invalida para deudor solidario' );
    e.value = '';
    return false;
  }
  
	// Oculta los layers que esten visibles y que sean hijos de la variable actual
	// Tambien deja los campos contenidos en ese layer como no requeridos
	
	for( k=0; k < arregloVal.length-1; ++k ) {
		if( arregloVal[k] != valorActual ) {
			d = document.all( "div_" + e.name + '_' + arregloVal[k] );
		
			if( d && d.style.display == '' ) {
				d.style.display = 'none';
			}

			// Cambia los nombres de los campos 'hidden' de r_* a nr_* para que queden
			// como no requeridos.
		
				if( d ) {
					tabla = d.children[0].children[0].children[0];
		
					for( j=0; j < tabla.children.length; ++j ) {
            fila = tabla.children[j]; 
            for( m=0; m < fila.children.length; ++m ) {
              // alert( fila.children[m].name );
              if( fila.children[m].nodeName == 'INPUT' && fila.children[m].name.substring(0,2) == 'r_' ) {
                campoH = fila.children[m];
                if( campoH != null ) {
                  campoH.name = "nr_" + campoH.id;
                }
              }
            }
					}
				}
		}
	}

	// Recorre el arreglo de Valores para ver si coincide con el seleccionado,
	// si es asi lo presenta y ademas lo pone obligatorio.
	
	for( i=0; i < arregloVar.length-1; ++i ) {
		if( arregloVal[i] == valorActual ) {
			activo = true;
			d = document.all( "div_" + e.name + '_' + e.value );
			if( d ) {
				d.style.display = '';
				dir_activado = d;
				tabla = d.children[0].children[0].children[0];
		
				for( j=0; j < tabla.children.length; ++j ) {
					fila = tabla.children[j];
          for( k=0; k < fila.children.length; ++k ) {
            // alert( fila.children[k].name );
            if( fila.children[k].nodeName == 'INPUT' && fila.children[k].name.substring(0,3) == 'nr_' ) {
              campoH = fila.children[k];
              if( campoH != null ) {
                campoH.name = "r_" + campoH.id;
              }
            }
          }
				}
			}
		}
	}
}



function departamentoChange( object, combo ) {
  comboMunicipios = combo;  // Lo pone en variable global

	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
	if(req) {
		req.onreadystatechange = processReqChange;
		req.open("GET", "/cifin/icetexv2/registro?accion=consultarMunicipios&departamento=" + object.value, true);
		req.send("");
    // while( req.readyState != 4 );
    // alert(req.responseXml);
	}
}


function processReqChange( combo ) {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            limpiarListaMunicipios();
            generarListaMunicipios();
        } else {
            alert("No es posible obtener la lista de ciudades para este departamento:\n" +
                req.statusText);
        }
    }
}

function generarListaMunicipios() {
    // Ubica el elemento select que corresponde al combo en el que se van a
    // cargar los municipios
    var select = document.getElementById( comboMunicipios );

    // Obtiene la lista de tags municipios para recorrerla y llenar el
    // combo
    var items  = req.responseXML.getElementsByTagName("municipio");
    var oOpcion = document.createElement("OPTION");
    oOpcion.value = "";
    oOpcion.text  = "Seleccione una";
    select.add( oOpcion );

    for (var i = 0; i < items.length; i++) {
        var oOpcion = document.createElement("OPTION");
        var itemIndicativo = document.createAttribute( "indicativo" );
        oOpcion.value = items.item(i).childNodes.item(0).firstChild.nodeValue;
        oOpcion.text  = items.item(i).childNodes.item(1).firstChild.nodeValue;
        itemIndicativo.value = items.item(i).childNodes.item(2).firstChild.nodeValue;
        oOpcion.attributes.setNamedItem( itemIndicativo );
        select.add( oOpcion );
    }
}


function limpiarListaMunicipios() {
    var select = document.getElementById( comboMunicipios );
	  var arregloInd = select.varsIndicativo.split( '|' );
  
    for( k=0; k < arregloInd.length-1; ++k ) {
      oIndicativo = document.all( "ind_" + arregloInd[k] );
      if( oIndicativo != null ) {
        oIndicativo.value = '';
      }
    }

    while (select.length > 0) {
        select.remove(0);
    }
}


function asignarIndicativo( combo ) {
	var arregloInd = combo.varsIndicativo.split( '|' );
  
  for( k=0; k < arregloInd.length-1; ++k ) {
    oIndicativo = document.all( "ind_" + arregloInd[k] );
    oIndicativo.value = combo.options[combo.selectedIndex].indicativo;
  }
}



function mostrarAyuda( variable ) {
  window.showModalDialog( 'registro?accion=mostrarAyuda&variable='+variable, '', '' );
}


function calcularTotal( numero, total ) {
 inputTotal = document.getElementById( "" + total ) ;
  var a = inputTotal.getAttributeNode("vars");
 
  vars = a.value;

  var valorTotal = 0;
  var arregloVar =  vars.split( '|' );

	for( k=0; k < arregloVar.length-1; ++k ) { 
		 inputValor = document.getElementById( arregloVar[k] ); 
     
     if( inputValor.value.length == 0 )
       valorTotal += 0;
     else
       valorTotal += parseInt( inputValor.value.replace(/\$|\,/g,'') );
  }

  inputTotal.value = formatCurrency( String(valorTotal) );
  numero.value = formatCurrency( numero.value );
  vars = inputTotal.getAttributeNode("rango").value;

  if( vars != "" ) {
    codigoVarRango = inputTotal.getAttributeNode("name").value; 
    valorRango = valorTotal;
    rango = calcularRango( vars , valorTotal );
  }
}



function calcularRango( codigoRango, valor ) {
	req = false;
  bool = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
			  req = new XMLHttpRequest();
        bool = true;
      } catch(e) {
			  req = false;
      }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
	if(req) {
		req.onreadystatechange = processReqRango;
		req.open("GET", "/cifin/icetexv2/registro?accion=consultarRango&rango=" + codigoRango + "&valor=" + valor, true);
		req.send("");
	}
}


function processReqRango() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
          if (bool){
            llenarCampoRangoOtros();
          }
          else{
            llenarCampoRango();
          }
        } else {
            alert("No es posible obtener la descripción del rango:\n" +
                req.statusText);
        }
    }
}

function llenarCampoRangoOtros() {
    // Ubica el elemento span en el cual se va a poner la descripcion
    // del rango
 
    var spanRango = document.getElementById( "rango_" + codigoVarRango );
    // Obtiene la lista de tags rangos para recorrerla y llenar el
    // combo

    var items  = req.responseXML.getElementsByTagName("rangos")[0];

    for (var i = 0; i < items.childNodes.length; i++) {

        var nodo = items.childNodes[i];
       
        var inferior  = nodo.getElementsByTagName("valor_inferior")[0];
        var superior  = nodo.getElementsByTagName("valor_superior")[0];
        var valRango  = nodo.getElementsByTagName("descripcion")[0];
        
        if( valorRango >= inferior.childNodes[0].nodeValue && valorRango <= superior.childNodes[0].nodeValue ) {
           spanRango.textContent = valRango.childNodes[0].nodeValue;
        }
    }
}

function llenarCampoRango() {
    // Ubica el elemento span en el cual se va a poner la descripcion
    // del rango
    var spanRango = document.getElementById( codigoVarRango );

    // Obtiene la lista de tags rangos para recorrerla y llenar el
    // combo
    var items  = req.responseXML.getElementsByTagName("rango");

    for (var i = 0; i < items.length; i++) {
        
        var inferior  = parseInt( items.item(i).childNodes.item(1).firstChild.nodeValue );
        var superior  = parseInt( items.item(i).childNodes.item(2).firstChild.nodeValue );
      
        if( valorRango >= inferior && valorRango <= superior ) {
          spanRango.innerText = items.item(i).childNodes.item(3).firstChild.nodeValue;
        }
    }
}


function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + '$' + num + '.' + cents);
}


function formatCurrency2(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  // cents = num%100;
  num = Math.floor(num/100).toString();
  // if(cents<10)
  // cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + num);
}


function cargarDepartamentos( combo ) {
  comboDepartamentos = combo;  // Lo pone en variable global

	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
	if(req) {
		req.onreadystatechange = processReqDeptos;
		req.open("GET", "/cifin/icetexv2/registro?accion=consultarDepartamentos", true);
		req.send("");
    // while( req.readyState != 4 );
    // alert(req.responseXml);
	}
}


function processReqDeptos() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            limpiarListaDepartamentos();
            generarListaDepartamentos();
        } else {
            alert("No es posible obtener la lista de ciudades para este departamento:\n" +
                req.statusText);
        }
    }
}



function limpiarListaDepartamentos() {
    var select = document.getElementById( comboDepartamentos );
  
    while (select.length > 0) {
        select.remove(0);
    }
}

function generarListaDepartamentos() {
    // Ubica el elemento select que corresponde al combo en el que se van a
    // cargar los municipios
    var select = document.getElementById( comboDepartamentos );

    // Obtiene la lista de tags municipios para recorrerla y llenar el
    // combo
    var items  = req.responseXML.getElementsByTagName("departamento");
    var oOpcion = document.createElement("OPTION");
    oOpcion.value = "";
    oOpcion.text  = "Seleccione uno";
    select.add( oOpcion );

    for (var i = 0; i < items.length; i++) {
        var oOpcion = document.createElement("OPTION");
        oOpcion.value = items.item(i).childNodes.item(0).firstChild.nodeValue;
        oOpcion.text  = items.item(i).childNodes.item(1).firstChild.nodeValue;
        select.add( oOpcion );
    }
}



function departamentoPagoChange( object, combo ) {
  comboMunicipios = combo;  // Lo pone en variable global

	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
	if(req) {
		req.onreadystatechange = processReqMunicipiosPago;
		req.open("GET", "/cifin/icetexv2/registro?accion=consultarMunicipiosPago&departamento=" + object.value, true);
		req.send("");
    // while( req.readyState != 4 );
    // alert(req.responseXml);
	}
}


function processReqMunicipiosPago() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            limpiarListaMunicipiosPago();
            generarListaMunicipiosPago();
        } else {
            alert("No es posible obtener la lista de ciudades para este departamento:\n" +
                req.statusText);
        }
    }
}


function limpiarListaMunicipiosPago() {
    var select = document.getElementById( comboMunicipios );
  
    while (select.length > 0) {
        select.remove(0);
    }
}


function generarListaMunicipiosPago() {
    // Ubica el elemento select que corresponde al combo en el que se van a
    // cargar los municipios
    var select = document.getElementById( comboMunicipios );

    // Obtiene la lista de tags municipios para recorrerla y llenar el
    // combo
    var items  = req.responseXML.getElementsByTagName("municipio");
    var oOpcion = document.createElement("OPTION");
    oOpcion.value = "";
    oOpcion.text  = "Seleccione una";
    select.add( oOpcion );

    for (var i = 0; i < items.length; i++) {
        var oOpcion = document.createElement("OPTION");
        var tipoPago = obtenerTipoPago( items.item(i).childNodes.item(0).firstChild.nodeValue, items.item(i).childNodes.item(1).firstChild.nodeValue );
        oOpcion.value = tipoPago;
        oOpcion.text  = items.item(i).childNodes.item(3).firstChild.nodeValue;
        select.add( oOpcion );
    }
}


function obtenerTipoPago( tipo_entidad, codigo_entidad ) {
  if( tipo_entidad == '1' && codigo_entidad == '7' ) {  /* Bancolombia */
    return '0';
  }
  if( tipo_entidad == '1' && codigo_entidad == '47' ) {  /* Bancolombia - Conavi */
    return '0';
  }
  else if( tipo_entidad == '1' && codigo_entidad == '1' ) { /* Banco de Bogota */
    return '2';
  }
  else if( tipo_entidad == '1' && codigo_entidad == '30' ) { /* Caja Social */
    return '3';
  }
  else if( tipo_entidad == '1' && codigo_entidad == '46' ) { /* Colmena */
    return '4';
  }
}

/* 
 * Desde aqui funciones paa validación de los campos tipo diReccion
 */
function reemplazar(cadena,remplazar,por)
{
    while(cadena.indexOf(remplazar,0)!=-1)
    {
      cadena=cadena.replace(remplazar,por);
    }
  return cadena;
}


function fdireccion(entry)
{
    temp="" + entry.value;
		temp=temp.toUpperCase();
    temp=reemplazar(temp,"#"," ");
    temp=reemplazar(temp,"-"," ");
    temp=reemplazar(temp,"°"," ");
    temp=reemplazar(temp,"/"," ");
    temp=reemplazar(temp,"ñ"," ");
    temp=reemplazar(temp,"Ñ"," ");
    temp=reemplazar(temp,"."," ");
    temp=reemplazar(temp,"kilometro","**Km ");
    temp=reemplazar(temp,"CARRERA","KR ");
    temp=reemplazar(temp,"CRA","KR ");
    temp=reemplazar(temp,"CR","KR ");
    temp=reemplazar(temp,"CLE","CL ");
    temp=reemplazar(temp,"CLL","CL ");
    temp=reemplazar(temp,"ClL","CL ");
    temp=reemplazar(temp,"CLL","CL ");
		temp=reemplazar(temp,"CALLE ","CL ");
    temp=reemplazar(temp,"-"," ");
    temp=reemplazar(temp,"AVENIDA","AV ");
    temp=reemplazar(temp,"BARRIO","B ");
    temp=reemplazar(temp,"KRA","KR ");
    temp=reemplazar(temp,"TRV","TV ");
    temp=reemplazar(temp,"TRAN","TV ");
    temp=reemplazar(temp,"MANZ","MZ ");
    temp=reemplazar(temp,"MANZANA","MZ ");
    temp=reemplazar(temp,"MZA","MZ ");    
    temp=reemplazar(temp,"DIAGONAL","DG ");
    temp=reemplazar(temp,"TRANSVERSAL","TR ");
    temp=reemplazar(temp,"TRANSV","TR ");
    temp=reemplazar(temp,"TRANS","TR ");
    temp=reemplazar(temp,"DIAG","DG ");
    temp=reemplazar(temp,"calle","CL ");
    temp=reemplazar(temp,"KA","KR ");
    temp=reemplazar(temp,"°"," ");
    temp=reemplazar(temp,"á","a ");
    temp=reemplazar(temp,"é","e ");
    temp=reemplazar(temp,"í","i ");
    temp=reemplazar(temp,"ó","o ");
    temp=reemplazar(temp,"ú","u ");
    temp=reemplazar(temp,"ª"," ");
    entry.value=temp;
    temp=temp.toUpperCase();
    if(temp.substring(0,3)!="** " && temp.substring(0,3)!="AC " && temp.substring(0,3)!="AK " && temp.substring(0,3)!="AP "  && temp.substring(0,3)!="AU " && temp.substring(0,3)!="AV " && temp.substring(0,3)!="BL " && temp.substring(0,3)!="CL " && temp.substring(0,3)!="DG " && temp.substring(0,3)!="ET " && temp.substring(0,3)!="FI "
     && temp.substring(0,3)!="KR " && temp.substring(0,3)!="LC " && temp.substring(0,3)!="MZ "  && temp.substring(0,3)!="OF " && temp.substring(0,3)!="PA " && temp.substring(0,3)!="TR " && temp.substring(0,3)!="TV " && temp.substring(0,3)!="UN " && temp.substring(0,3)!="UR " && temp.substring(0,3)!="VE ")
      {
       return false;
      }
 }


 function ValidarDireccion( campo )
 {
    /*
    ** 2007/05/09
    ** Se pone en comentario para inhabilitar la validacion de direcciones
    ** si se desea volver a habilitar dejar nuevamente disponible el bloque if
    **
    if( campo.value != '' && fdireccion( campo ) == false )
		{
		   alert('dirección no valida');
       campo.focus();
		}
    **
    **/
    null;
 }
/*
 * Hasta aqui funciones para validacion de campos tipo diReccion
 */
 
 
 
 /*
  * Funciones para cargue de los combos de la pagina de Administracion de Ayudas
  */

function cargarDatosCombo( combo, tipo, key, key1, nombre ) {

 if ( document.getElementById("center") != null  )
    comboCargue =  document.getElementById("center");
 else
   comboCargue = combo;  // Lo pone en variable global
  
  valor = nombre;
  linea = key;
  tipoTercero = key1;
	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
  			req = new XMLHttpRequest();
      } catch(e) {
    		req = false;
      }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
	if(req) {
		req.onreadystatechange = processReqCombo;
    req.open("GET", "/cifin/icetexv2/registro?accion=datosAdminAyudas&tipo=" + tipo + "&key=" + key + "&key1=" + key1, true);
    req.send("");
 	}
}


function processReqCombo() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
  
           limpiarListaCombo();
           if ( ( valor == "valoresLista" ) || ( valor == "grupo") || ( valor == "variables" ) || ( valor == "variablesHijas" ) || (valor == "variablesSinPadre") ){
              llenarLista();
              if ( valor == "variablesHijas" ){
                consultarRangos1();
              }
           }else if ( valor != "Tabla" ){
              generarListaCombo();
           } else if ( valor != "" ) { 
              PlantillaLinea=comboCargue.rows.item(0);
              PlantillaLinea.parentNode.removeChild(PlantillaLinea);
              generarTabla();
            }
        } else {
            alert("No es posible obtener la lista solicitada:\n" +
                req.statusText);
        }
    }
}



function limpiarListaCombo() {
    // var select = document.getElementById( comboCargue );
  
    while (comboCargue.length > 0) {
        comboCargue.remove(0);
    }
}

function generarListaCombo() {
    // Ubica el elemento select que corresponde al combo en el que se van a
    // cargar los municipios
    var select = comboCargue;

    // Obtiene la lista de tags municipios para recorrerla y llenar el
    // combo
    var items  = req.responseXML.getElementsByTagName('row');
    var oOpcion = document.createElement("OPTION");
    oOpcion.value = "";
    //oOpcion.text  = "-- Seleccione una opcion --";
    select.add( oOpcion );
 
    for (var i = 0; i < items.length; i++) {
        var oOpcion = document.createElement("OPTION");
        oOpcion.value = items.item(i).childNodes.item(0).firstChild.nodeValue;
        oOpcion.text  = items.item(i).childNodes.item(1).firstChild.nodeValue;
        select.add( oOpcion );
    }
}


function cargarDatosAyuda( area, hint, codVar ) {
  comboCargue = area;  // Lo pone en variable global
  inputHint = hint;

	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
	if(req) {
		req.onreadystatechange = processReqAyuda;
		req.open("GET", "/cifin/icetexv2/registro?accion=datosAdminAyudas&tipo=ayuda&key=" + codVar, true);
		req.send("");
    // while( req.readyState != 4 );
 	}
}


function processReqAyuda() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            limpiarTextoAyuda();
            generarTextoAyuda();
        } else {
            alert("No es posible obtener la lista solicitada:\n" +
                req.statusText);
        }
    }
}



function limpiarTextoAyuda() {
    // var select = document.getElementById( comboCargue );
  
    comboCargue.value = '';
}

function generarTextoAyuda() {
    // Ubica el elemento select que corresponde al combo en el que se van a
    // cargar los municipios
    var area = comboCargue;

    // Obtiene la lista de tags municipios para recorrerla y llenar el
    // combo
    var items  = req.responseXML.getElementsByTagName('row');
    area.value = items.item(0).childNodes.item(1).firstChild.nodeValue;
    inputHint.value = items.item(0).childNodes.item(2).firstChild.nodeValue;
}

/*
 * Hasta aqui funciones para cargue de combos de Administracion de Ayudas
 */
 
 
 
 
 /*
  * Comienzo administracion de variables
  */
  
  function cargarLinea( combo, tipo, key, key1, nombre ) {
  
  comboCargue = combo;  // Lo pone en variable global
  valor = nombre;
  linea = key;
  tipoTercero = key1;
	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
  			req = new XMLHttpRequest();
      } catch(e) {
    		req = false;
      }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
	if(req) {
		req.onreadystatechange = processReqLinea;
    req.open("GET", "/cifin/icetexv2/registro?accion=datosAdminAyudas&tipo=" + tipo + "&key=" + key + "&key1=" + key1, true);
    req.send("");
 	}
}


function processReqLinea() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
           limpiarListaCombo();
           generarListaCombo();          
        } else {
            alert("No es posible obtener la lista solicitada:\n" + req.statusText);
        }
    }
}

function limpiarListaCombo() {

    if ( valor != "Tabla" ){  
      
      if (valor == "grupo"){
        var element = document.getElementById("center");
  
        while (element.firstChild) 
           element.removeChild(element.firstChild);
      }
    }
    
    if ( valor == "listaVariables" ){
      
      var i = comboCargue.length;

      while (comboCargue.length > 1){
        comboCargue.removeChild( comboCargue.item(i-1) );
        i--;  
      }
    }
    
    if ( valor == "listaGrupos" ){
      
      var i = comboCargue.length;

      while (comboCargue.length > 1){
        comboCargue.removeChild( comboCargue.item(i-1) );
        i--;  
      }
    }
}

function generarListaCombo() {
    // Ubica el elemento select que corresponde al combo en el que se van a
    // cargar los municipios
    var select = comboCargue;
    // Obtiene la lista de tags municipios para recorrerla y llenar el
    // combo
    
      var items  = req.responseXML.getElementsByTagName('row');
      if ( ( valor != "listaGrupos") && ( valor != "listaVariables" ) ){
        var inicio = document.createElement("OPTION");
      
        inicio.value = "";
        inicio.text  = "-- Seleccione una opcion --";
    
         select.add( inicio );
        }
     
        for (var i = 0; i < items.length; i++) {
          var oOpcion = document.createElement("OPTION");
          oOpcion.value = items.item(i).childNodes.item(0).firstChild.nodeValue;
          oOpcion.text  = items.item(i).childNodes.item(1).firstChild.nodeValue;
          select.add( oOpcion );
        }
      
}

function cargarDatosCombo( combo, tipo, key, key1, nombre ) {
 if ( document.getElementById("center") != null  )
    comboCargue =  document.getElementById("center");
 else {
   comboCargue = combo;  // Lo pone en variable global

  }
  valor = nombre;
  linea = key;
  tipoTercero = key1;
	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
  			req = new XMLHttpRequest();
      } catch(e) {
    		req = false;
      }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
	if(req) {
		req.onreadystatechange = processReqCombo;
    req.open("GET", "/cifin/icetexv2/registro?accion=datosAdminAyudas&tipo=" + tipo + "&key=" + key + "&key1=" + key1, true);
    req.send("");
 	}
}


function processReqCombo() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
  
           limpiarListaCombo();
           if ( ( valor == "valoresLista" ) || ( valor == "grupo") || ( valor == "variables" ) || ( valor == "variablesHijas" ) || (valor == "variablesSinPadre") ){
              llenarLista();
              if ( valor == "variablesHijas" ){
                consultarRangos1();
              }
           }else if ( valor != "Tabla" ){
              generarListaCombo();
           } else if ( valor != "" ) { 
              PlantillaLinea=comboCargue.rows.item(0);
              PlantillaLinea.parentNode.removeChild(PlantillaLinea);
              generarTabla();
            }
        } else {
            alert("No es posible obtener la lista solicitada:\n" +
                req.statusText);
        }
    }
}

function llenarLista() {

      var select = comboCargue;
      var items  = req.responseXML.getElementsByTagName('row');
      
      for (var i = 0; i < items.length; i++) {
   
        var oOpcion = document.createElement("li");
        id[i] = items.item(i).childNodes.item(0).firstChild.nodeValue;
        oOpcion.innerText = items.item(i).childNodes.item(1).firstChild.nodeValue;
        oOpcion.innerValue = items.item(i).childNodes.item(0).firstChild.nodeValue;
        oOpcion.setAttribute( "value", i );
        oOpcion.id = items.item(i).childNodes.item(0).firstChild.nodeValue;  

        if ( valor == "grupo" )
            oOpcion.ondblclick = function() { modificarGrupo( this ); };
            
        else if ( valor == "valoresLista" ) 
            oOpcion.ondblclick = function() { modificarValorLista( this ); };
          
        else
            oOpcion.ondblclick = function() { modificarVariable( this ); };
            
        comboCargue.insertBefore(oOpcion);  

      }

      if (valor != "grupo"){   
        DragDrop.makeListContainer( comboCargue, 'g1' );
        comboCargue.onDragOver = function() { this.style["background"] = "#EEF"; };
        comboCargue.onDragOut = function() {this.style["background"] = "none"; };
      }
}

function limpiarListaCombo() {

    if ( valor != "Tabla" ){  
      
      if (valor == "grupo"){
        var element = document.getElementById("center");
  
        while (element.firstChild) 
           element.removeChild(element.firstChild);
      }
    }
    
    if ( valor == "listaVariables" ){
      
      var i = comboCargue.length;

      while (comboCargue.length > 1){
        comboCargue.removeChild( comboCargue.item(i-1) );
        i--;  
      }
    }
    
    if ( valor == "listaGrupos" ){
      
      var i = comboCargue.length;

      while (comboCargue.length > 1){
        comboCargue.removeChild( comboCargue.item(i-1) );
        i--;  
      }
    }
}

function consultarRangos1( ) {
  
    var lista = document.getElementById( "secRango" );
    select1 = req.responseXML.getElementsByTagName("rango");
    var items  = req.responseXML.getElementsByTagName("rowset");
    
    var inicio = document.createElement("OPTION");
    inicio.value = "";
    inicio.text  = "-- Seleccione una opcion --";
    lista.add( inicio );
      for (var i = 0; i < select1.length; i++) {
        var oOpcion = document.createElement("OPTION");
        oOpcion.value = select1.item(i).childNodes.item(2).firstChild.nodeValue;
        oOpcion.text  = select1.item(i).childNodes.item(3).firstChild.nodeValue;
        lista.add( oOpcion );    
      }
    
      inicio = document.createElement("OPTION");
      inicio.value = "N";
      inicio.text  = " Ninguno ";
      lista.add( inicio );

}


function generarTabla(sucursalesResponse)
{
  var msg=null;
  var items  = req.responseXML.getElementsByTagName('row');
    var eGrupo,ns;
  
    for (eGrupo=items(0),ns=0; eGrupo; eGrupo=eGrupo.nextSibling,++ns)
    {
      if ( eGrupo.nodeName == "row"){
        var codigo=eGrupo.firstChild.firstChild.nodeValue; 
        var descripcion=eGrupo.lastChild.firstChild.nodeValue;
        muestraTabla(codigo,descripcion);
      }
    }
  
  return msg;
}

function clickCheck1( e ) {
	estado = e.checked;
	presentar = ( estado == true ) ? '' : 'none';
  d = document.all( "div_" + e.name + '_-1' );
	
	if( d ) {
		d.style.display = presentar;
  }
}

function obtenerRangos( r, rango ) {

  idRango = r ;
	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    	try {
			  req = new XMLHttpRequest();
      } catch(e) {
			  req = false;
      }
    // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	      }
  }
  
  if(req) {
		req.onreadystatechange = processConsultarRangos;
		req.open("GET", "/cifin/icetexv2/registro?accion=consultarRango&rango="+rango, true);
		req.send("");
	}
}

function processConsultarRangos() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
              consultarRangos();
        } else {
            alert("No es posible obtener los rangos:\n" +
                req.statusText);
        }
    }
}

function consultarRangos( ) {
  
    var lista = document.getElementById( idRango );
    select1 = req.responseXML.getElementsByTagName("rango");
    var items  = req.responseXML.getElementsByTagName("rangos");
    
    var inicio = document.createElement("OPTION");
    inicio.value = "";
    inicio.text  = "-- Seleccione una opcion --";
    lista.add( inicio );

      for (var i = 0; i < select1.length; i++) {
        var oOpcion = document.createElement("OPTION");
        oOpcion.value = select1.item(i).childNodes.item(0).firstChild.nodeValue;
        oOpcion.text  = select1.item(i).childNodes.item(3).firstChild.nodeValue;
        lista.add( oOpcion );
      }
    
      inicio = document.createElement("OPTION");
      inicio.value = "N";
      inicio.text  = " Ninguno ";
      lista.add( inicio );

}

function i_check1( inputStr )	
		{
			var msg_addition = "";
			var decimal = "";

			for (var c = 0; c < inputStr.length; c++)
			{
				var oneChar = inputStr.charAt(c);
	
				if (c == 0 && oneChar == "-" || oneChar == "."  && decimal == "")
				{
					if (oneChar == ".")
					{
						decimal = "yes";
					}
					continue;
				}
		
				if (oneChar < "0" || oneChar > "9")
				{
					msg_addition = "Mensaje";
				}
			}
	
			return(msg_addition);
		}
    
/* 
* Validar la fecha de entrada que sea menor que la fecha actual
*/
function validarFechaActual(e) {
    //SS 29220 Hermes Navarro
    fechaHoy = new Date();
    var anio = fechaHoy.getFullYear();
    var mes = fechaHoy.getMonth() + 1;
    var dia = fechaHoy.getDate();
    if( mes < 10 ){
        mes = "0" + mes;
    }
    if( dia < 10 ){
        dia = "0" + dia;
    }
    var strin = anio + "/" + mes + "/" + dia;
    if ( ! Comparar_Fecha( e.value , strin ) ) {
        return false
    } else {
        return true;
    }
    //FIN SS 29220 Hermes Navarro
    // strMonthArray lOS DIAS
    /*var today = new Date();
    var day   = today.getDate();
    var month = today.getMonth();
    //SS 29220 Hermes Navarro, se utiliza el metodo getFullYear porque el anterior tiene inconvenientes con los años postetiores al 2000
    //var year  = today.getYear();
    var year  = today.getFullYear();
    
    if ( month == "1" || month == "2" || month == "3" || month == "4" || month == "5" ||  
    month == "6" || month == "7" || month == "8" || month == "9" )
    month = strMonthArray[month];
    
    if ( day == "1" || day == "2" || day == "3" || day == "4" || day == "5" ||  
    day == "6" || day == "7" || day == "8" || day == "9" )
    day = strMonthArray[day-1];
    
    //SS 29220 Hermes Navarro, se deja el 01 cuando el mes es el 0 Enero para que quede en el mismo formato de la fecha del metodo Comparar_Fecha
    //var strin = year+"/"+(month+1)+"/"+day;
    var strin;
    if( month == "0" ){
    var strin = year+"/01/"+day;
    }else{
    var strin = year+"/"+(month+1)+"/"+day;
    }
    
    if (!Comparar_Fecha(e.value,strin)){
    return false
    }
    else {
    return true;
    }*/
}

/*
* Comparar dos fechas 
*/

function Comparar_Fecha(Obj1,Obj2) 
{
    String1 = Obj1;
    String2 = Obj2;
    
    var anyo1=String1.substring(0,4);
    var anyo2=String2.substring(0,4);
    var mes1=String1.substring(5,7);
    var mes2=String2.substring(5,7);  
    var dia1=String1.substring(8,11);
    var dia2=String2.substring(8,11);
    
    if (dia1 == "08") // parseInt("08") == 10 base octogonal
    dia1 = "8";
    if (dia1 == '09') // parseInt("09") == 11 base octogonal
    dia1 = "9";
    if (mes1 == "08") // parseInt("08") == 10 base octogonal
    mes1 = "8";
    if (mes1 == "09") // parseInt("09") == 11 base octogonal
    mes1 = "9";
    if (dia2 == "08") // parseInt("08") == 10 base octogonal
    dia2 = "8";
    if (dia2 == '09') // parseInt("09") == 11 base octogonal
    dia2 = "9";
    if (mes2 == "08") // parseInt("08") == 10 base octogonal
    mes2 = "8";
    if (mes2 == "09") // parseInt("09") == 11 base octogonal
    mes2 = "9";
    
    dia1=parseInt(dia1);
    dia2=parseInt(dia2);
    mes1=parseInt(mes1);
    mes2=parseInt(mes2);
    anyo1=parseInt(anyo1);
    anyo2=parseInt(anyo2);
    
    if ( anyo1 > anyo2 )
    {
      return false;
    }
    
    if ((anyo1==anyo2) && (mes1>mes2))
    {
      return false;
    }
    if ((anyo1==anyo2) && (mes1==mes2) && (dia1>dia2))
    {
      return false;
    } 
    
    return true;
}


function validarValor(e){
  
  var valor = parseInt(e.value);
  
  if ( valor <= 0 ){
    alert ("El numero ingresado debe ser mayor a cero (0)")
    return false;
  }
}


/*
* Validar q una entrada numerica solamente sea numerica
*/

function validarNumero(e) {

  var cadena = e.value.toString().replace(/\$|\,/g,'');
  
  for (var i = 0; i < cadena.length; i++ )
  {
    if ( ! esInteger(cadena.charAt(i)) ){
      alert("Debe ingresar un valor numerico")
      e.select();  
      e.focus(); 
      return false;
    }
    else {
      e.value = formatCurrency2( e.value );
    }
  }
  return true;
}

function esInteger(e) {
 
  var charCode = e.charCodeAt();
 
  if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;
    
  return true;
   
}


String.prototype.trim = function() {
  a = this.replace(/^\s+/, '');
  return a.replace(/\s+$/, '');
};