var bgEdo=new Hash();
var colEdo=new Hash();

bgEdo.set('AGUASCALIENTES','E17F4A');
bgEdo.set('BAJA CALIFORNIA','');
bgEdo.set('BAJA CALIFORNIA SUR','');
bgEdo.set('CAMPECHE','4E399F');
bgEdo.set('CHIAPAS','94A510');
bgEdo.set('CHIHUAHUA','A2D542');
bgEdo.set('COAHUILA','');
bgEdo.set('COLIMA','');
bgEdo.set('DISTRITO FEDERAL','F7432F');
bgEdo.set('DURANGO','');
bgEdo.set('ESTADO DE MÉXICO','134D1D');
bgEdo.set('GUANAGUATO','');
bgEdo.set('GUERRERO','CE1885');
bgEdo.set('HIDALGO','');
bgEdo.set('JALISCO','');
bgEdo.set('MICHOACAN','');
bgEdo.set('MORELOS','4EA791');
bgEdo.set('NAYARIT','');
bgEdo.set('NUEVO LEÓN','');
bgEdo.set('OAXACA','007654');
bgEdo.set('PUEBLA','7EC937');
bgEdo.set('QUERETARO','');
bgEdo.set('QUINTANA ROO','3DCCA2');
bgEdo.set('SAN LUIS POTOSí','BF804D');
bgEdo.set('SINALOA','021A7D');
bgEdo.set('SONORA','');
bgEdo.set('TABASCO','');
bgEdo.set('TAMAULIPAS','');
bgEdo.set('TLAXCALA','');
bgEdo.set('VERACRUZ','CA292D');
bgEdo.set('YUCATAN','6A1865');
bgEdo.set('ZACATECAS','');




function sendQuery(){
	$('_form').submit();
}

function buildQueryString(type){
	var items= new Array();
	var collection= new Array();
	
	switch(type){
		case 1:
			collection=$$('input[type=text].personal');
		break;
		case 2:
			var collection=$$('input[type=hidden].lengua');
		break;
		case 3:
			var collection=$$('input[type=hidden].ubicacion');
		break;
	}
	
	collection.each(function(el){
		if(el.value!=''){
			items.push(el.name+':'+el.value.toUpperCase());
		}
	});
	
	$('_form').query.value=items.length>0?items.join(';'):'*';
	$('_form').type.value=type;
	
	sendQuery();
}

function setInputValue(id,val){
	$(id).value=val;
}

function setMainContainerSize(){
	var ws=$(document.body).getCoordinates();
	var hcs=$('header-container').getCoordinates();
	var mcs=$('menu-container').getCoordinates();
	var fcs=$('footer-container').getCoordinates();
					
	$('main-container').setStyle('height',(ws.height-(hcs.height+mcs.height+fcs.height+16))+'px');
}

function setResultContainerSize(){
	var mcs=$('main-container').getCoordinates();
	//$('result-container').setStyle('height',((mcs.height-8)/2)+'px');
	$('result-container').setStyle('height',(mcs.height-5)+'px');
}

function setMapContainerSize(){
	var mcs=$('main-container').getCoordinates();
	var rcs=$('result-container').getCoordinates();
	
	$('map-container').setStyle('height',(mcs.height-2)+'px');
	$('map-container').setStyle('width',(mcs.width-rcs.width-3)+'px');
	$('map-container').setStyle('left',(rcs.left+rcs.width+1)+'px');
	$('map-container').setStyle('top',(rcs.top)+'px');
}

function initInfoUbicacion(){
		var m=$('map-container');
		var mcs=m.getCoordinates();
		
		$('info-ubicacion').setStyle('top',mcs.top+'px');
		$('info-ubicacion').setStyle('left',mcs.left+'px');
		//$('info-ubicacion').setStyle('z-index','99999');
		
}


function setInfoContainerSize(){
	var hcs=$('header-container').getCoordinates();
	var ics=$('info-container').getCoordinates();
	
	$('info-container').setStyle('left',((hcs.width-ics.width)+5)+'px');
}

function clearSelecBox(sb){
	var l=sb.length;
	
	for(var i=l;i>0;i--){
		sb.options[i]=null;
	}
}

function findRegistroByLoc(loc){	
	var i=0;
	$$('div.locs').each(function(item,index){
		if(item.get('text')!=loc){
			$(item.getParent().id).hide();
		}
		else{
			$(item.getParent().id).show();
			i++;
		}
	});
	
	zoomAddress(loc,12);
	$('counter-reg').set('text',i)
	
}

function zoomAddress(address,zoom){
	if(geocoder){
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				map.setCenter(results[0].geometry.location);
				map.setZoom(zoom);
			}
			else{
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}
}


function resetMap(){
	map.setCenter(myLatlng);
	map.setZoom(5);
}

function showAllData(){
	var i=0;
	$$('div.registro').each(function(item,index){
		item.show();
		i++;
	});
	
	$('counter-reg').set('text',i);
	
	resetMap();
}

function showInfo(t,pos){
	//infoWindow.close();
	var ls= new Array();
	var li=new Hash();
	
	infoWindow.setPosition(pos);
	ls.push('<span style="font-weight:bold">'+t.title+'</span>');
	
	$$('div.locs').each(function(item,index){
		if(item.get('text')==t.title){
			li.set(item.get('rel'),item.get('rel'));
		}
	});
	
	li.each(function(k,v){
			ls.push('&nbsp;&nbsp;&nbsp;'+k);
	});
	
	
	infoWindow.setContent(ls.join('<br>'));
	infoWindow.open(map);
	
	map.setCenter(pos);
	map.setZoom(14);
}

function sendLoginData(_url){
	var rq= new Request({
				url:_url,
				method:'POST',
				data:$('Login'),
				evalScripts:true
	});
		
	rq.send();
}

