// menus dinamicos...
/******************************************************************************************************************/
/*     Estados y Ciudades         */
/******************************************************************************************************************/
function init_states_list( obj_id ) {

   var obj = findObj ( obj_id );

   if (obj && obj.options) {

     reset_list ( obj ); // eliminando todos los elementos...

     var items = estados['states'];

	 insert_into_list (obj, '', 'Seleccionar una Opción');

     for(var n=0; n < items.length; n++)

	   insert_into_list (obj, items[n].s, items[n].s);

	 return true;

   } 

   else

     return false;   

}

function init_cities_list( obj_id, state_id ) {

   var obj = findObj ( obj_id );

   var sta = findObj ( state_id );

   var indx = prepare_indx ( sta.value );

   if (sta && sta.options && sta.value && obj && obj.options && (ciudades[indx])) {

     reset_list ( obj ); // eliminando todos los elementos...

     var items = ciudades[indx];

	 insert_into_list (obj, '', '');

     for(var n=0; n < items.length; n++)

	   insert_into_list (obj, items[n].c, items[n].c);

	 return true;

   } 

   else

     return false;   

}
/*
function prepare_indx ( i ) {

   var indx = new String ( i );

   while (indx.indexOf ( '/' ) > -1)

     indx = indx.replace ( '/', ' ' );

   while (indx.indexOf ( ' ' ) > -1)

     indx = indx.replace ( ' ', '_' );

   return indx;

}
*/
/*********************************************************************************************/
function prepare_indx ( i ) {
     var indx = new String ( i );

     while (indx.indexOf ( '/' ) > -1)
          indx = indx.replace ( '/', ' ' );

     while (indx.indexOf ( ' ' ) > -1)
          indx = indx.replace ( ' ', '_' );
					
		 while (indx.indexOf ( '-' ) > -1)
          indx = indx.replace ( '-', '_' );
					
		 while (indx.indexOf ( '(' ) > -1)
          indx = indx.replace ( '(', '_' );
					
		 while (indx.indexOf ( ')' ) > -1)
          indx = indx.replace ( ')', '_' );
		
		 while (indx.indexOf ( 'ñ' ) > -1)
          indx = indx.replace ( 'ñ', 'n' );
		
		 while (indx.indexOf ( 'Ñ' ) > -1)
          indx = indx.replace ( 'Ñ', 'N' );
		
		 while (indx.indexOf ( 'á' ) > -1)
          indx = indx.replace ( 'á', 'a' );
					
		 while (indx.indexOf ( 'é' ) > -1)
          indx = indx.replace ( 'é', 'e' );
					
		 while (indx.indexOf ( 'í' ) > -1)
          indx = indx.replace ( 'í', 'i' );
					
		 while (indx.indexOf ( 'ó' ) > -1)
          indx = indx.replace ( 'ó', 'o' );
					
		 while (indx.indexOf ( 'ú' ) > -1)
          indx = indx.replace ( 'ú', 'u' );
					
		 while (indx.indexOf ( 'Á' ) > -1)
          indx = indx.replace ( 'Á', 'A' );
					
		 while (indx.indexOf ( 'É' ) > -1)
          indx = indx.replace ( 'É', 'E' );
					
		 while (indx.indexOf ( 'Í' ) > -1)
          indx = indx.replace ( 'Í', 'I' );
					
		 while (indx.indexOf ( 'Ó' ) > -1)
          indx = indx.replace ( 'Ó', 'O' );
					
		 while (indx.indexOf ( 'Ú' ) > -1)
          indx = indx.replace ( 'Ú', 'U' );

     return indx;
}
/*********************************************************************************************/

function findObj(theObj, theDoc)
{
  var p, i, foundObj;

  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  return foundObj;
}

