var showedOverlay = 0;
function changeProvincia(id,pob)
{
	//alert(pob);
	var pars = 'id=' + id + '&divdestino=' + pob;
	new Ajax.Request( 'changeprov.php' , {
		method: 'get',
		parameters: pars,
		onSuccess: function(transport) {
			$resp = transport.responseText;
			$(pob).innerHTML = $resp;
		}
}); 
}


function preloadImages() 
{ 
	var d=document; if(d.images)
	{ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length;
		var a= new Array('img/poon_es.png',
		'img/coon_es.png',
		'img/bton_es.png',
		'img/poon_ca.png',
		'img/coon_ca.png',
		'img/bton_ca.png',
		'img/cat_on.png',
		'img/cast_on.png');
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0)
			{ 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
	}
}

function browserMesures()
{
	/*if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
		
  	}*/
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	var D = document.body;
	var DHeight = D.clientHeight;
	var DWidth = D.clientWidth;
	var browMesures = new Array (pageHeight, pageWidth, DHeight, DWidth);
	return browMesures;
}
function showForm(form)
{	
	var browMesures = browserMesures();
	var formID = $(form);
	/*var formHeight = formID.style.height;
	var formWidth = formID.style.width;*/
	/*var formMidHeight = Math.round(800/2);
	var formMidWidth = Math.round(500/2);
	var formLeft = Math.round((browMesures[3]/2)-formMidWidth);
	var formTop = Math.round((browMesures[2]/2)-formMidHeight);
	if (formTop < 0)
		formID.style.top = '10px';
	else
		formID.style.top = formTop + 'px';
	if (formLeft < 0)
		formID.style.left = '0px';
	else
		formID.style.left = formLeft + 'px';*/
	showOverlay('');
	Effect.toggle(form,'appear');
	positionsRecalc();
}

function showOverlay(action)
{
	if (action != 'donothing')
	{
		if ($('overlay').style.display == 'block')
			$('overlay').style.display = 'none';
		else
		{
			var browMesures = browserMesures();
			$('overlay').style.width = browMesures[1] + 'px';
			$('overlay').style.height = (browMesures[0] + 'px');
			$('overlay').style.display = 'block';
		}
	}
}

function positionsRecalc()
{
	if ($('overlay').style.display == 'block')
	{
		/*Recalculamos posición div flotante*/
		var browMesures = browserMesures();
		var formID = $('formDIV');
		/*var formMidHeight = Math.round(800/2);
		var formMidWidth = Math.round(900/2);
		var formLeft = Math.round((browMesures[3]/2)-formMidWidth);
		var formTop = Math.round((browMesures[2]/2)-formMidHeight);
		if (formTop < 0)
			formID.style.top = '10px';
		else
			formID.style.top = formTop + 'px';
		if (formLeft < 0)
			formID.style.left = '0px';
		else
			formID.style.left = formLeft + 'px';
		/* recalculamos posición overlay */
		var browMesures = browserMesures();
		$('overlay').style.width = browMesures[1] + 'px';
		$('overlay').style.height = (browMesures[0] + 'px');
	}
}

function valoraCheckbox()
{
	alert (document.poform.mismadireccion.checked);
	if ( (document.poform.mismadireccion.checked) == 'true')
	{
		alert('si');
		$('tipovia2').selectedIndex = $('tipovia').selectedIndex;
	}
}