var curTool;

var oldLay = null;

var overviewMap = null;

var searchStreet = null;

var baseWeb= '/sniiv/';

var ventana1 = null;

var oldSlider = null;

var wcount = 0;

function arrayContains( value , myArray ) {
	var k;
	for ( k=0; k < myArray.length; k++ ) {
		
		if( value == myArray[k] ) {
			return k;
			break;
		}
	}
	return -1;
}


function extra(  ) {

	var mySelect;


	if( oldSlider != null ) {
		if( document.getElementById( 'zs' + oldSlider ) ) {
			document.getElementById( 'zs' + oldSlider ).style.backgroundColor = '#ffffff';
//			document.getElementById( 'zs' + oldSlider ).className = 'nslider';
		}
	}
	

	
	if( document.forms.zoomsteper != null ) {
		if (  ( mySelect = arrayContains( crossGetFrame('map').status.z.value , zoomValues  ) ) > -1 ) {
			if( mySelect > 9 )
				mySelect++;
			document.forms.zoomsteper.zoomselect.value = mySelect;
		}
		else {
			var myOpt = new Option( parseFloat( parseInt( crossGetFrame('map').status.z.value * 1000 ) / 1000  )  + ' Km' , document.forms.zoomsteper.zoomselect.length , false, false );
			document.forms.zoomsteper.zoomselect.options[ document.forms.zoomsteper.zoomselect.length ] = myOpt;
			document.forms.zoomsteper.zoomselect.selectedIndex = document.forms.zoomsteper.zoomselect.length - 1;
			zoomValues[ zoomValues.length ] = parseFloat( crossGetFrame('map').status.z.value );
		}
	}
	else {

		document.getElementById('zs' + currentZV ).style.backgroundColor= "#ffffff";
		currentZV = crossGetFrame("map").forms['status'].zstep.value;		
		document.forms['czoom'].custzoom.value = crossGetFrame("map").forms['status'].z.value;
	       	document.getElementById('zs' + currentZV ).style.backgroundColor= "#efefef";         

	}

	currentZV = crossGetFrame("map").forms['status'].zstep.value;		

	if ( document.getElementById( 'sl' + ( currentZV  ) ) ) {

		document.getElementById( 'sl' + ( currentZV  ) ).className = 'nslideron';

	}


	oldSlider =   ( currentZV  ) ;

	var myOp = crossGetFrame('map').status.op.value;	

	if( myOp == 15 || myOp == 17 || myOp == 16 ||  myOp == 18 || myOp == 14 ) {
		showThematicLegend( );
	}
	
}

function localChangeZoom( s ) {

	document.getElementById('zs' + currentZV ).style.backgroundColor= "#ffffff";
	changeZoom(s);
}

function localZoomIn() {
	zoomIn();
}

function localZoomOut() {
	zoomOut();
}

function ekZoom( step ){


	if( step >= 0 &&  step < 10 ) {
		if( mapOn )
			changeZoom( step );
	}
	else if( step == 10 ) {
		if( mapOn )
			zoomTo( parseFloat( prompt('PROPORCIONE EL VALOR DE ZOOM DESEADO (KM):', zoomValues[currentZV] ) ) );
	}

}

function zoomByStep( step ) {

	if( step >= 0 &&  step < 10 ) {
		if( mapOn )
			changeZoom( step );
	}
}

function selTool( t , toolLink  ) {

	if( document.getElementById( t ) != null ) {
		if ( curTool != null )
			document.getElementById( curTool ).className = "tool";

		document.getElementById( t ).className = "toolon";


		if ( browser == 'moz'  ) {
			//window.frames['map'].hideSelect();
			hideSelect();
		}
		else if( browser == 'ie' ) {
			//window.document.frames['map'].hideSelect();
			hideSelect();
		}
		else {
			hideSelect();
		}



		curTool = t;

		setDefaultClickAction( toolLink);

	}
}


function printMap() {

	var x = crossGetFrame('map').status.x.value;
	var sx = crossGetFrame('map').status.sx.value;
	var y = crossGetFrame('map').status.y.value;
	var sy = crossGetFrame('map').status.sy.value;
	var z = crossGetFrame('map').status.z.value;

//	page =  'printmap.asp?x=' + x + '&y=' + y + '&z=' +  z  + '&sx=' + sx +  '&sy=' + sy + '&' + document.forms.localstatus.alterq.value;

	page =  'printmap.asp?x=' + x + '&y=' + y + '&z=' +  z  + '&sx=' + sx +  '&sy=' + sy ; //+ '&' + document.forms.localstatus.alterq.value;



//	 openPopUp( page, 700, 600 )
	alterOpenPopUp( page, 700, 600 , 'printwindow' );

}


function alterOpenPopUp( page, width, height , name ){
    ventana1 = window.open( page , name,'resizable=yes,scrollbars=yes,toolbars=no,statusbar=yes,status=yes,height=' + height + ',width=' + width);
    ventana1.focus();
}



function printMap3() {

	var x = crossGetFrame('map').status.x.value;
	var sx = crossGetFrame('map').status.sx.value;
	var y = crossGetFrame('map').status.y.value;
	var sy = crossGetFrame('map').status.sy.value;
	var z = crossGetFrame('map').status.z.value;
	var xs = crossGetFrame('map').status.xs.value;
	var ys = crossGetFrame('map').status.ys.value;
	var ids = crossGetFrame('map').status.ids.value;
	var sp = crossGetFrame('map').status.sp.value;
	var poi = crossGetFrame('map').status.poi.value;

	page =  'printmap3.asp?x=' + x + '&y=' + y + '&z=' +  z  + '&xs=' + xs +  '&ys=' + ys + '&ids=' + ids   + '&sx=' + sx +  '&sy=' + sy + '&sp=' + sp + '&poi=' + poi +'&' + document.forms.localstatus.alterq.value;


	alterOpenPopUp( page, 700, 600 , 'printwindow' );

//	 openPopUp( page, 700, 600 )
	
}



function showLayerControl() {

	var x = crossGetFrame('map').status.x.value;
	var sx = crossGetFrame('map').status.sx.value;
	var y = crossGetFrame('map').status.y.value;
	var sy = crossGetFrame('map').status.sy.value;
	var z = crossGetFrame('map').status.z.value;

	page =  'layers.asp?x=' + x + '&y=' + y + '&z=' +  z  + '&sx=' + sx +  '&sy=' + sy ; //+ '&' + document.forms.localstatus.alterq.value;

	alterOpenPopUp( page, 550, 250 , 'layercontrol' );	

}



function sendMap() {

	var x = crossGetFrame('map').status.x.value;
	var sx = crossGetFrame('map').status.sx.value;
	var y = crossGetFrame('map').status.y.value;
	var sy = crossGetFrame('map').status.sy.value;
	var z = crossGetFrame('map').status.z.value;



//	page =  'sendmap3.asp?x=' + x + '&y=' + y + '&z=' +  z  + '&sx=' + sx +  '&sy=' + sy + '&' + document.forms.localstatus.alterq.value;

	page =  'sendmap.asp?x=' + x + '&y=' + y + '&z=' +  z  + '&sx=' + sx +  '&sy=' + sy ; //+ '&' + document.forms.localstatus.alterq.value;


//	 openPopUp( page, 450, 350 )

	alterOpenPopUp( page, 450, 480 , 'mailwindow' );	

}

function sendMap3() {

	var x = crossGetFrame('map').status.x.value;
	var sx = crossGetFrame('map').status.sx.value;
	var y = crossGetFrame('map').status.y.value;
	var sy = crossGetFrame('map').status.sy.value;
	var z = crossGetFrame('map').status.z.value;
	var xs = crossGetFrame('map').status.xs.value;
	var ys = crossGetFrame('map').status.ys.value;
	var ids = crossGetFrame('map').status.ids.value;
	var sp = crossGetFrame('map').status.sp.value;
	var poi = crossGetFrame('map').status.poi.value;



	page =  'sendmap3.asp?x=' + x + '&y=' + y + '&z=' +  z  + '&xs=' + xs +  '&ys=' + ys + '&ids=' + ids  + '&sx=' + sx +  '&sy=' + sy + '&sp=' + sp + '&poi=' + poi + '&' + document.forms.localstatus.alterq.value;




//	 openPopUp( page, 450, 350 )
	
	alterOpenPopUp( page, 450, 480 , 'mailwindow' );

}





function centerMap( q) {


	q  += crossGetFrame('map').status.z.value;

	if ( browser == 'moz'  )
	       	document.getElementById("map").src = q ;
	else if( browser == 'ie' )
		window.document.frames['map'].location = q ;	
	else
		window.document.frames['map'].location = q ;	

	
}


function ekChangeSize( w, h ) {
	
	if( mapOn ) {

		document.getElementById("map").style.width = w;
		document.getElementById("map").style.height= h + 25;

	        crossGetFrame('map').forms['status'].mw.value= w;
	        crossGetFrame('map').forms['status'].mh.value= h;

		selectOpAndSubmit( 7 );
	}
		
}

function showOverview( ) {



	var x = crossGetFrame('map').status.x.value;
	var y = crossGetFrame('map').status.y.value;
  	var z = crossGetFrame('map').status.z.value;
	var mw = crossGetFrame('map').status.mw.value;
	var mh = crossGetFrame('map').status.mh.value;

	
	var page = 'overview.asp?x=' + x  + '&y=' + y + '&rz=' + z + '&rmw=150&rmh=140';

	var height=140;
	var width=150;

	overviewMap = window.open( page ,'overviewwindow','resizable=no,scrollbars=no,toolbars=no,status=no,height=' + height + ',width=' + width);

	overviewMap.focus();
}

function prepareSearch ( ) {
	searchStreet = window.open( 'buscadorcalle.asp' ,'buscador','resizable=yes,scrollbars=yes,toolbars=no,status=yes,height=235,width=520,closed=yes');

//	searchStreet.focus();


}



function updateOverViewMapL( x, y, mw, mh, wz ) {

	if(  overviewMap != null ) {

		if( overviewMap.closed != true ) {
			overviewMap.location.replace( 'overview.asp?x=' + x + '&y=' + y + '&rz=' + wz + '&rmw=' + mw + '&rmh=' + mh  );	
			overviewMap.focus();
		}
	}


	currentZV = crossGetFrame("map").forms['status'].zstep.value;		

}








/** Funciones para presentar extra layer  **/



function crossGetLayer( l ) {

 	if( browser == 'ie' ) {
		return document.all[ l ];
	}
	else {
		return document.getElementById( l );
	}

}

function showLayer( l ) {
	var lay=null;


	if ( oldLay != null ) {
		crossGetLayer( oldLay ).style.visibility = 'hidden';

	}


	lay = crossGetLayer( l );

	if ( lay != null ) {
		lay.style.visibility = 'visible';
	}


	oldLay = l;	
}


function showPOISDialog( ) {
	var pois = crossGetFrame('map').status.poi.value;

	openPopUp( 'pois_selector.asp?p=' + pois, 650, 120 );
}


function selCorner( f ) {
	var url;
	var newX,newY;
	var coords= new Array();

	coords = f.mapselector.value.split(',');

	newX = coords[0];
	newY = coords[1];

	if (mapOn ) {

		crossGetFrame('map').status.x.value = newX;
		crossGetFrame('map').status.y.value = newY;

		crossGetFrame('map').status.sx.value = newX;
		crossGetFrame('map').status.sy.value = newY;

		crossGetFrame('map').status.z.value = 0.5;
		crossGetFrame('map').status.sa.value = 1;

		showStatus();

		crossGetFrame('map').status.op.value = 777;
		crossGetFrame('map').status.submit();
	}

	
}



/** fin de las funciones extra **/

function hideLegendFrame( ) {

	
	document.getElementById( 'thematiclegend' ).style.width = 0;
	document.getElementById( 'thematiclegend' ).style.height = 0;


	if ( document.all ) {
		document.all[ 'legendbutton' ].style.display = 'block';
		document.all[ 'legendbutton' ].style.visibility = 'visible';
	}
	else {
		document.getElementById( 'legendbutton' ).style.display = 'block';
	}



}


function showLegendAsLayer( ) {
	var legend = crossGetFrame( 'map' ).status.tlegend.value;


//	var height = parseInt( crossGetFrame( 'map' ).status.tlh.value );

//	var width =  parseInt( crossGetFrame( 'map' ).status.tlw.value );

	var width = 720;

	var height= 180;


	if( ! isNaN( height ) && ! isNaN( width ) ) {
		height +=60;
		width += 30;
	}


	if (  legend != '' ) {
	
		document.getElementById( 'thematiclegend' ).style.width= width;
		document.getElementById( 'thematiclegend' ).style.height= height;

		if ( browser == 'moz'  )
		       	document.getElementById("thematiclegend").src = baseWeb + 'dialogs/legendframe.asp' ;
		else if( browser == 'ie' )
			window.document.frames['thematiclegend'].location.replace( baseWeb + 'dialogs/legendframe.asp' );
		else 
			window.document.frames['thematiclegend'].location.replace( baseWeb + 'dialogs/legendframe.asp' );
	}

}

function showThematicLegend( ) {

	var al = arguments.length;
	
	


	var legend = crossGetFrame( 'map' ).status.tlegend.value;
//	var height = parseInt( crossGetFrame( 'map' ).status.tlh.value ) + 120;
//	var width =  parseInt( crossGetFrame( 'map' ).status.tlw.value );

	var width=720;

	var height = 400;


	

	if( legend != '' ) {

		if( document.all ) 
			document.all['customizeTheme'].style.display = 'inline';
		else
			document.getElementById( 'customizeTheme' ).style.display= 'inline';
	
	

		if( browser == 'ie' && ( navigator.userAgent.indexOf('Opera') == -1 &&  navigator.userAgent.indexOf('Konqueror') == -1 &&  navigator.userAgent.indexOf('Safari') == -1  ) ) {

			//window.showModelessDialog(sURL [, vArguments] [, sFeatures])
			if( ventana1 != null ) {
				//ventana1.document.write( 'Cargando Leyenda...' ); 
				ventana1.close();
			}


			ventana1 = window.showModelessDialog( 'dialogs/legendcont.asp' ,  window ,'help:no;resizable:yes;scroll:yes;status:no;dialogHeight:' + height + 'px;dialogWidth:' + width + 'px;dialogTop:0px;');
		}
		else {

			if( al == 1 ) {

				ventana1 = window.open( '../dialogs/legendcont.asp' , 'legendtheme','top=0,resizable=yes,scrollbars=yes,toolbars=no,status=no,dependent=yes,height=' + height + ',width=' + width);

			}
			else {

				ventana1 = window.open( 'dialogs/legendcont.asp' , 'legendtheme','top=0,resizable=yes,scrollbars=yes,toolbars=no,status=no,dependent=yes,height=' + height + ',width=' + width);
			}
		}

		hideLegendFrame( );


		if( ventana1 == null ) {
			alert( 'Su navegador no permite ventanas emergentes (popups),\n por favor cambie sus preferencias para permitir que este sitio\n pueda abrir ventanas emergentes  ' );

			 showLegendAsLayer( );

		}


	}

}


function valThemeData( forma ) {
	
	var retorno = true;
	var mySel=0;
	

	if( forma.mv ) {

		if( forma.variable.value  == 0 && forma.variable2.value == 0 && !forma.mv.checked  ) {
			retorno = false;
		}
		else if ( forma.variable.value == 0  && forma.mv.checked  ) {
			retorno = false;
		}


		if( forma.variable2.value != 0  && !forma.mv.checked  ) {
			forma.op.value = 15;	
			forma.m.value = 10;	
		}
		else if ( forma.variable.value != 0  && !forma.mv.checked  ) {
			forma.op.value = 16;
			forma.m.value = 0;	
		}

	}
	else {

		if( forma.variable.value  == 0 ) {
			retorno = false;
		}
	}



	if( ! retorno )
		alert( 'Falta seleccionar la variable para generar el tema' );

	
	for( i=0 ; i < forma.variable.options.length; i++ ) {
		if( forma.variable.options[i].selected == true ) {
			mySel++;
		}
	}

	if( mySel > 6 )
		retorno = confirm('El número máximo de variables a tematizar es 6 \n ¿Desea continuar?');


	if( retorno ) {
		selTool('t1',1);
		document.themebuilder.mw.value = crossGetFrame('map').status.mw.value;
		document.themebuilder.mh.value = crossGetFrame('map').status.mh.value;
		document.themebuilder.daction.value = crossGetFrame('map').status.daction.value;

		showStatus();
	}

	
	return retorno;
}


function localShowInfo( page, width, height  ){
    var name =  'info';

    ventana1 = window.open( 'nada.html' , name,'resizable=yes,scrollbars=yes,toolbars=no,status=yes,height=' + height + ',width=' + width);


    if( browser == 'ie' && navigator.userAgent.indexOf( 'MSIE 5.0' ) == -1 )
	    ventana1.document.write('<html><head><title> - </title></head><body><div style="font-size:11px; font-family:Arial;">Cargando información...</div></body></html>');
    else if( browser == 'moz' ) {
	    ventana1.document.write('<html><head><title> - </title></head><body><div style="font-size:11px; font-family:Arial;">Cargando información...</div></body></html>');
    }
    else {
	    ventana1.location = 'nada.html';
    }

    ventana1.location = page;

    ventana1.focus();
}


/** Funciones para los wizards **/

function openWizard( page, width, height , name ){

    page += '?mw=' + crossGetFrame('map').status.mw.value;
    page += '&mh=' + crossGetFrame('map').status.mh.value;


    if( document.themebuilder.mv ) {

	if( document.themebuilder.mv.checked == true ) {
		
		page += '&mv=1';
		
	}
    }

    if( document.themebuilder.mvtipo ) {

	for( i=0; i < document.themebuilder.mvtipo.length; i++ ) {	

		if( document.themebuilder.mvtipo[i].checked == true )
			page += '&mvt=' + ( i + 1 );

	}

    }



    wizard1 = window.open( page , name,'resizable=no,scrollbars=yes,scroll=yes,toolbars=no,status=yes,height=' + height + ',width=' + width);

    wizard1.focus();
}

function clearMun( ) {



	document.themebuilder.municipio.value = 0;
	document.themebuilder.mun_name.value = ' -- Seleccione -- ';


	hideExtraVars();


}

function openMunSelector( ) {


	var height = 400;
	var width = 350;

	if ( document.themebuilder.entidad.value == 0  ) {

		alert(  'Debe seleccionar un estado ' );
	} 
	else {

		var page = 'dialogs/mun_selector.asp?e=' + document.themebuilder.entidad.value;
		var msel = window.open( page  , name,'resizable=yes,scrollbars=yes,toolbars=no,status=yes,height=' + height + ',width=' + width);

	}
}




function toggleButton( t , func ) {

	if( document.getElementById( t ) != null ) {
		if ( document.getElementById( t ).className == 'tool' ) {
			document.getElementById( t ).className = "toolon";
			
			func( true );
		}
		else {
			document.getElementById( t ).className = "tool";
			
			func( false );
		}
	}


}



function showSearchTools( v ) {

	if( v ) {
		if ( document.all ) {
			document.all['searchtools'].style.display='block';
			document.all['searchtools'].style.visibility='visible';
		}
		else {
			document.getElementById( 'searchtools' ).style.display = 'block';
			document.getElementById( 'searchtools' ).style.visibility = 'visible';
		}
	}
	else {

		if ( document.all ) {
			document.all['searchtools'].style.display='none';
			document.all['searchtools'].style.visibility='hidden';
		}
		else {
			document.getElementById( 'searchtools' ).style.display = 'none';
			document.getElementById( 'searchtools' ).style.visibility = 'hidden';
		}
	}


}


/** para el buscador de calles **/

function getWithCol( forma ) {
	
	if( forma.coloniaslist.value != 0 ) {

		colonia = new String( forma.coloniaslist.value );

		var parts = colonia.split( /\|/ );


		document.searchstreet.f.value = forma.f.value;

		document.searchstreet.colonia.value = parts[0];
		document.searchstreet.ic.value = parts[1];

				

		document.searchstreet.submit();

	}

}

function findLocalidad( l, m , e ) {
	crossGetFrame('map').status.l.value = l;
	crossGetFrame('map').status.e.value = e;
	crossGetFrame('map').status.m.value = m;

	showStatus();

	crossGetFrame('map').status.op.value = 23;
	crossGetFrame('map').status.submit();

}

function findMunicipio( m , e ) {

	crossGetFrame('map').status.e.value = e;
	crossGetFrame('map').status.m.value = m;

	showStatus();
	
	crossGetFrame('map').status.op.value = 22;
	crossGetFrame('map').status.submit();

}
function findState( estado ) {

	crossGetFrame('map').status.e.value = estado;

	showStatus();

	crossGetFrame('map').status.op.value = 21;
	crossGetFrame('map').status.submit();

}

/** fin de extra busqueda calles **/


function changeCard( val  ) {
	window.location = 'regiondatacard.asp?' + val;
}


function hideThrobber() {

	if( document.all ) {
		document.all['pmstatus'].style.visibility = 'hidden';
		document.all['pmstatus'].style.display = 'none';
	}
	else {

		document.getElementById('pmstatus').style.visibility = 'hidden';
		document.getElementById('pmstatus').style.display = 'none';

	}

}



/*** Cosas para seleccion multiple ***/

function enableMultiVar( forma ) {

	
	if( forma.mv.checked == true ) {


//		alert('The shadows');

		forma.variable.size=6;
		forma.variable.multiple = true;
		forma.m.value = 9;
		
		forma.op.value = 18;

		if( document.all ) {
			document.all['multivaroptions'].style.display = 'block';
			document.all['multivaroptions'].style.visibility = 'visible';
		}
		else {
			document.getElementById('multivaroptions').style.display = 'block';
			document.getElementById('multivaroptions').style.visibility = 'visible';
		}

		hideExtraVars();
	}
	else {
		forma.variable.size=1;
		forma.variable.multiple = false;
		forma.m.value = 0;

		forma.op.value = 16;



		if( document.all ) {
			document.all['multivaroptions'].style.display = 'none';
			document.all['multivaroptions'].style.visibility = 'hidden';

			

		}
		else {
			document.getElementById('multivaroptions').style.display = 'none';
			document.getElementById('multivaroptions').style.visibility = 'hidden';
		}



		if( forma.municipio.value != 0 ) {

			showExtraVars();			


		}


	}



}


function showExtraVars( ) {


	if( document.themebuilder.municipio.value != 0 && !document.themebuilder.mv.checked ) {

		document.all['imunicipio'].style.display = 'block';
		document.all['imunicipio'].style.visibility = 'visible';
	
	}
}

function hideExtraVars( ) {



		document.all['imunicipio'].style.display = 'none';
		document.all['imunicipio'].style.visibility = 'hidden';
	
}





function viewEntireLayer( l ) {

	if ( l != '' ) {
		crossGetFrame('map').status.extra.value = l;
		//crossGetFrame('map').status.op.value = 12;
		//crossGetFrame('map').status.submit();
		selectOpAndSubmit( 12 );

	}



}



/*** Fin seleccion multiple **/


function printCurrentMap( calle ) {
	var urlmap;

	var x, y, sx, sy, z, op, sa;

	x = crossGetFrame('map').status.x.value;
	y = crossGetFrame('map').status.y.value;
	sx = crossGetFrame('map').status.sx.value;
	sy = crossGetFrame('map').status.sy.value;
	z = crossGetFrame('map').status.z.value;
	sp = crossGetFrame('map').status.sp.value;
	poi = crossGetFrame('map').status.poi.value;
	op = parseInt( crossGetFrame('map').status.op.value );	

	sa = parseInt( crossGetFrame('map').status.sa.value );	

	urlmap = 'printmap.asp?x=' + x + '&y=' + y + '&sx=' + sx + '&sy=' + sy + '&z=' + z; 

	urlmap += '&sp=' + sp + '&poi=' + poi + '&sa=' + sa;
	urlmap += '&calle=' + calle ;

	if ( document.extra1 ) {
		urlmap += '&esquina='+ document.extra1.mapselector.options[ document.extra1.mapselector.selectedIndex ].text;
	}
	else if ( crossGetFrame('map').status && op == 42 ) {
		urlmap += '&colonia=' + crossGetFrame('map').status.extra.value;
	}
	else if ( crossGetFrame('map').status && op == 43 ) {
		urlmap += '&cp=' + crossGetFrame('map').status.extra.value;
	}


	openPopUp( urlmap, 700,650);

}


function sendCurrentMap( calle ) {
	var urlmap;

	var x, y, sx, sy, z , op , sa ;

	x = crossGetFrame('map').status.x.value;
	y = crossGetFrame('map').status.y.value;
	sx = crossGetFrame('map').status.sx.value;
	sy = crossGetFrame('map').status.sy.value;
	z = crossGetFrame('map').status.z.value;
	sp = crossGetFrame('map').status.sp.value;
	poi = crossGetFrame('map').status.poi.value;
	op = parseInt( crossGetFrame('map').status.op.value );
	sa = parseInt( crossGetFrame('map').status.sa.value );	


	urlmap = 'sendmap.asp?x=' + x + '&y=' + y + '&sx=' + sx + '&sy=' + sy + '&z=' + z; 

	urlmap += '&sp=' + sp + '&poi=' + poi + '&sa=' + sa;

	urlmap += '&calle=' + calle 

	if ( document.extra1 ) {
		urlmap += '&esquina='+ document.extra1.mapselector.options[ document.extra1.mapselector.selectedIndex ].text;
	}
	else if ( crossGetFrame('map').status && op == 42 ) {
		urlmap += '&colonia=' + crossGetFrame('map').status.extra.value;
	}
	else if ( crossGetFrame('map').status && op == 43 ) {
		urlmap += '&cp=' + crossGetFrame('map').status.extra.value;
	}

	openPopUp( urlmap, 440,380);

}

function loadMap( idPoi ) {
	var k = 0;
	var xtsuc  = '';

	if ( document.bypob ) {
		
		for( k = 0 ; k < 3 ; k++ ) {
			if ( document.bypob.suc[ k ].checked == true ) {
				break;
			}
		}
		
		xtsuc = '&suc=' + ( k + 1 );
	
	}
	else if ( document.suc ) {
		
		for( k = 0 ; k < 3 ; k++ ) {
			if ( document.suc.suc[ k ].checked == true ) {
				break;
			}
		}
		
		xtsuc = '&suc=' + ( k + 1 );
	
	}



		if ( document.bygeo  ) { 
			window.location = 'map_selector.asp?id=' + idPoi + xtsuc + '&bla=' +  document.bygeo.bla.value;

		}
		else if ( document.bypob ) {
			window.location = 'pob_search.asp?ee=1&pob=' + idPoi + '&e=' + document.bypob.e.value + xtsuc + '&bla=' + crossGetFrame('map').status.xtp.value


		}
		else {
			window.location = 'map_selector.asp?id=' + idPoi + xtsuc + '&bla=' +  document.geoform.bla.value;
		}
	

}

function searchByState( forma ) {

	if( parseInt( forma.e.value ) != 0 ) {
		// window.location = 'state_search.asp?e=' + state ;

		forma.submit();
	}

}


function searchByPob( ) {


}



function updateMaps( mapitas ) {


	if ( mapitas != null ) {
	
		if( mapitas.length > 0 ) {

			for( k=0; k < mapitas.length; k++ ) {

				eval( 'document.images.mapita' + k +'.src = "/mapimage/' + mapitas[k] + '" ' );

			}

		}
	}

}




function showPopUp( page, width, height , name ){

    ventana1 = window.open( page , name ,'resizable=yes,scrollbars=yes,toolbars=no,statusbar=no,height=' + height + ',width=' + width);
    ventana1.focus();
}



function valGF( forma ) {
	valid = true;

	var tu = 0;  
	var mensaje = '';

	for( k = 0; k <  forma.tu.length ; k++ ) {		
		if ( forma.tu[k].checked == true ) {
			tu = parseInt( forma.tu[k].value );
		}
	}


	switch ( tu ) {

		case 4:

			if( forma.icl.value == 0 ) {
				mensaje += '\n Debe seleccionar una colonia ';
				valid = false;	
			}

			if( forma.id1.value != 0 && forma.id2.value == 0 ) {
				mensaje += '\n Debe seleccionar una esquina ';
				valid = false;
			}



		/*
			if( forma.id1.value == '' ) {
				mensaje += '\n Debe indicar una calle ';
				valid = false;
			}
			if( forma.id2.value == 0 ) {
				mensaje += '\n Debe seleccionar una esquina ';
				valid = false;
			}	

		*/

		break;	

		case 5:
			if ( forma.poi.value == 0 ) {
				mensaje += 'Debe seleccionar un punto  de interés';
				valid = false;
			}
		break;

		case 6:
			if ( forma.metro.value == 0 ) {
				mensaje += 'Debe seleccionar una estación del metro';
				valid = false;
			}
		break;

	}
	
	if ( !valid )
		alert( mensaje );


	return valid;
}



function setSucType( t ) {

	document.bycp.suc.value = t;
	document.bypob.suc.value = t;
	document.bystate.suc.value = t;
}

function setSucType2(  t ) {

	if ( document.readyState == 'complete' ) {


		if ( document.geoform ) {
			document.geoform.suc.value = t;

			document.geoform.submit();

		}

	}
}


function setSucType3( forma ) {

	forma.action = 'state_search.asp';
	forma.submit();

}

function getStreets( forma  ) {
	
	var oldAction = forma.action;
	var oldTarget = forma.target;

	if ( forma.icl.value != 0 ) {

		forma.id1.options[0].text = 'Espere';
		forma.id1.disabled = true;
			
		forma.action = 'street_finder.asp';
		forma.target = 'streets';
		forma.submit();

		forma.action = oldAction;
		forma.target = oldTarget;	
		
	}

//	alert( 'AAA' );
}


function getCornersCol( forma  ) {

	var oldAction = forma.action;
	var oldTarget = forma.target;

	if ( forma.id1.value != 0 ) {

		forma.id2.options[0].text = 'Espere';
		forma.id2.disabled = true;
			
		forma.action = 'corner_selector2.asp';
		forma.target = 'corners';
		forma.submit();

		forma.action = oldAction;
		forma.target = oldTarget;	
		
	}


}



function mapByState( e ) {

	document.bystate.e.value = e;

	document.bystate.submit();

}



function enableByFocus( control, disablelist ) {
	var i = 0;

	control.disabled = false;

	for ( i = 0 ; i < disablelist.length; i++ ) {
		
		
		disablelist[i].disabled = true;
		
	}


}

function georeferencia( forma ){

var suc;

forma.id2.value = forma.mapselector.value;
forma.icl.value = forma.c.value;

//alert('Antes del for' +  window.opener.document.bypob.suc.length);

for(k=0 ; k< window.opener.document.bypob.suc.length; k++){
	if(window.opener.document.bypob.suc[k].checked == true){
		
		suc = window.opener.document.bypob.suc[k].value;
	}
//	alert('Suc valor ' + window.opener.document.bypob.suc[k].value);
}
window.opener.document.geosearch.cd.value = forma.cd.value;
window.opener.document.geosearch.pob.value = forma.pob.value;
//alert('suc= ' + suc);
window.opener.document.geosearch.suc.value = suc;
window.opener.document.geosearch.c.value = forma.c.value;
window.opener.document.geosearch.m.value = forma.m.value;
window.opener.document.geosearch.e.value = forma.e.value;
//window.opener.document.geosearch.tu.value = forma.tu.value;
window.opener.document.geosearch.d.value = forma.d.value;
window.opener.document.geosearch.icl.value = forma.icl.value;
window.opener.document.geosearch.id1.value = forma.id1.value;
window.opener.document.geosearch.id2.value = forma.id2.value;

window.opener.document.geosearch.submit();
window.close();
}
