var aux = "";
var miss = "";
var aux2 = "";
var domini = "dreamstorespain.com";


window.onresize = function()
	{
	resizeContenidor();
	}
function resizeContenidor()
	{
	var wW = document.documentElement.clientWidth;
	var hW = document.documentElement.clientHeight;
	var wC = document.getElementById("contenidor").offsetWidth;
	var hC = document.getElementById("contenidor").offsetHeight;
	
	if(wW < wC)
		{
		document.getElementById("contenidor").style.left = "0px";
		document.getElementById("contenidor").style.marginLeft = "0px";
		document.getElementById("contenidor").style.top = "0px";
		document.getElementById("contenidor").style.marginTop = "0px";
		}
	else
		{
		document.getElementById("contenidor").style.left = "50%";
		document.getElementById("contenidor").style.marginLeft = "-492.5px";
		document.getElementById("contenidor").style.top = "50%";
		document.getElementById("contenidor").style.marginTop = "-295px";
		}
	}


function show(id1)
	{
	document.getElementById(id1).style.display = "block";
	}
function hide(id1)
	{
	document.getElementById(id1).style.display = "none";
	}
function show_hide(id1)
	{
	if(document.getElementById(id1))
		{
		if(document.getElementById(id1).style.display == "none" || document.getElementById(id1).style.display == "")
			{
			document.getElementById(id1).style.display = "block";
			whoisBlock = id1;
			}
		else 
			{
			document.getElementById(id1).style.display = "none";
 			whoisBlock = "";
			}
		}
	}
	



function textLegal()
	{ 
	window.open("textlegal.htm","column","toolbar=no,directories=no,menubar=no,location=no,scrollbars=no,resizable=no,width=640,height=290");
	}
	
function mostrarcapa(idcapa,altura) 
	{
	if (document.getElementById) 
		{
		// Tipus Standar
		var mstyle = document.getElementById(idcapa).style;
		mstyle.display = "block";
		mstyle.height = altura;
		}
	else if (document.all) 
			{
		// Versions antigues de Internet Explorer
		var mstyle = document.all[idcapa].style;
		mstyle.display = "block";
		mstyle.height = altura;
		}
	else if (document.layers)
		{
		// Versio per a Navigator
		var mstyle = document.layers[idcapa].style;
		mstyle.display = "block";
		mstyle.height = altura;
		}
	}
function ocultarcapa(idcapa) 
	{
	if (document.getElementById) 
		{
		// Tipus Standar
		var mstyle = document.getElementById(idcapa).style;
		mstyle.display = "none";
		}
	else if (document.all) 
		{
		// Versions antigues de Internet Explorer
		var mstyle = document.all[idcapa].style;
		mstyle.display = "none";
		}
	else if (document.layers)
		{
		// Versio per a Navigator
		var mstyle = document.layers[idcapa].style;
		mstyle.display = "none";
		}
	}

function showMissatge(idu)
	{
	show("missatge");
	show(idu);
	}


function enquesta()
	{
	var tmp = "";
	if(document.getElementById('rad1').checked == true) tmp = document.getElementById('rad1').value;
	else if(document.getElementById('rad2').checked == true) tmp = document.getElementById('rad2').value;
	else if(document.getElementById('rad3').checked == true) tmp = document.getElementById('rad3').value;
	else 
		{
		showMissatge("miss_1");
		return;
		}
	
	//[ Deletes user from the database ]//
	if (window.XMLHttpRequest) 
		xmlhttprequest = new XMLHttpRequest();
	else if (window.ActiveXObject) 
		xmlhttprequest = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttprequest.onreadystatechange = function() { p_enquesta(xmlhttprequest); };
	xmlhttprequest.open('POST', 'ajax/enquesta.php', true);
	xmlhttprequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttprequest.send("res="+tmp);
	}
function p_enquesta(xhr) 
	{
	if (xhr.readyState == 4)
		if (xhr.status == 200)
			{
			var wazzup = xhr.responseText;
			showMissatge("miss_0");
			}
	}


function destacados(id)
	{
	show("destaca2_"+id);
	}

function showUrb(capa)
	{
	hideUrb();
	show(capa);
	}
function hideUrb()
	{
	for(var i=1;i<11;i++)
		{
		hide("layer_"+i);
		}
	}
function fadeBack(id, web)
	{
	fade(id);
	setTimeout("window.location='"+web+"'",1000);
	}

function urbDetails(id)
	{
	for(var i=1; i<=10; i++)
		{
		if(id>0)hide('oculta_'+i);
		$('parcela'+i).className = 'parcelaUnselected';
		$('td'+i).className = 'parcela';
		$('a'+i).className = 'grey';
		}
	if(id>0)
		{
		$('oculta_'+id).className = 'oculta';
		show('oculta_'+id);
		$('parcela'+id).className = 'parcelaSelected';
		$('td'+id).className = 'parcelaSelectedTD';
		$('a'+id).className = 'greySelected';
		}
	}

function finestra (url,nomfinestra,parametres) {
	w=window.open(url,nomfinestra,parametres);
}

function finestra_div(url,capamostrar,nomfoto) {
	var el = document.getElementById(nomfoto);
	el.src = url;
	mostrarcapaSinAltura(capamostrar);
}

function mostrarcapaSinAltura(idcapa)
	{
	if (document.getElementById) 
		{
		// Tipus Standar
		var mstyle = document.getElementById(idcapa).style;
		mstyle.display = "block";
		}
	else if (document.all) 
		{
		// Versions antigues de Internet Explorer
		var mstyle = document.all[idcapa].style;
		mstyle.display = "block";
		}
	else if (document.layers)
		{
		// Versio per a Navigator
		var mstyle = document.layers[idcapa].style;
		mstyle.display = "block";
		}
	}

/***** ARRASTRE FINESTRA *****/
function iniarrastre(capa,event) {
	if (document.all)
	{
		var strposx = capa.currentStyle.left;
		var strposy = capa.currentStyle.top;
	}
	else
	{
		var strposx = window.getComputedStyle(capa, "").left;
		var strposy = window.getComputedStyle(capa, "").top;
	}


	capa.posini_x = parseInt(strposx.substr(0, strposx.length-2));
	capa.posini_y = parseInt(strposy.substr(0, strposy.length-2));
	capa.mouseini_x = event.clientX;
	capa.mouseini_y = event.clientY;
	capa.moure = true;
}
function fiarrastre(capa) {
	capa.moure = false;
}
function arrastrar(capa,event) {
	if (capa.moure)
	{
		if (document.all)
		{
			strposx = capa.currentStyle.left;
			strposy = capa.currentStyle.top;
		}
		else
		{
			strposx = window.getComputedStyle(capa, "").left;
			strposy = window.getComputedStyle(capa, "").top;
		}

		var pos_actx = parseInt(strposx.substr(0, strposx.length-2));
		var pos_acty = parseInt(strposy.substr(0, strposy.length-2));

		var ds_x = event.clientX - capa.mouseini_x;
		var ds_y = event.clientY - capa.mouseini_y;

		pos_actx = pos_actx + ds_x;
		pos_acty = pos_acty + ds_y;

		capa.style.left = pos_actx+"px";
		capa.posini_x= pos_actx;
		capa.style.top = pos_acty+"px";
		capa.posini_y= pos_acty;

		capa.mouseini_x = event.clientX;
		capa.mouseini_y = event.clientY;
	}
}


function handle_roda(delta) 
	{
	if (delta < 0)
		{
		/* something. */;
		mou("content", "text", 1, 20);
		}
	else
		{
		/* something. */;
		mou("content", "text", -1, 20);
		}
	}

function roda(event)
	{
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) 
		{
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
		} 
	else if (event.detail) 
		{
		delta = -event.detail/3;
		}
	if (delta)
		handle_roda(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
	}

function mou(contingut, continent, spin, velocitat)
	{
	var tmpTOP = 0;
	if($(contingut).style.top=='')
		{
		tmpTOP = 0;
		}
	else
		{
		tmpTOP = parseInt($(contingut).style.top);
		}

	if(spin>0)
		{
		if($(continent).clientHeight < (($(contingut).clientHeight + tmpTOP + velocitat)))
			{
			if(((tmpTOP - velocitat)+$(continent).clientHeight)>$(contingut).clientHeight)
				{
				tmpTOP = $(continent).clientHeight;
				}
			else
				{
				tmpTOP = tmpTOP - velocitat;
				}
			}
		}
	else
		{
		if(tmpTOP<0)
			{
			if((tmpTOP + velocitat)>0)
				{
				tmpTOP = 0;
				}
			else
				{
				tmpTOP = tmpTOP + velocitat;
				}
			}
		else
			{
			tmpTOP = 0;
			}
			
		}
	$(contingut).style.top = tmpTOP+"px";
	}