

function displayAdvanced()
{ 
	document.getElementById('AdvancedOptions').style.display="block";
	document.getElementById('SearchButtons').style.display="none";
	document.forms[0].elements['AdvancedSearch'].value='true';
}
		
function markCheck(oObject)
{
	sControlName = oObject.name.substr(3);

	if (oObject.check!="yes" )
	{
	  	oObject.src="/img/check_ok.gif"
		oObject.check="yes" ;
		document.forms[0].elements[sControlName].value ="true";
	}else{
		oObject.src="/img/check.gif"
	  	oObject.check="no" ;
		document.forms[0].elements[sControlName].value ="false";
	}
}

function markCheck(oObject,sPath)
{
	sControlName = oObject.name.substr(3);
	if (oObject.check!="yes" )
	{
  		oObject.src= sPath + "/img/check_ok.gif";
		oObject.check="yes" ;
		document.forms[0].elements[sControlName].value ="Y";
	}else{
		oObject.src= sPath + "/img/check.gif";
	  	oObject.check="no" ;
		document.forms[0].elements[sControlName].value ="";
	}
}




function checkRow(oObject)
{	
	 iComparisonNum = 0;
	if (document.forms[0].elements["Comparison1"].value !="null")
	{
		 iComparisonNum = 1;
	}
	if (document.forms[0].elements["Comparison2"].value !="null")
	{	
		++ iComparisonNum;
	}
	if (document.forms[0].elements["Comparison3"].value !="null")
	{	
		 ++ iComparisonNum;
	}
	if (document.forms[0].elements["Comparison4"].value !="null") 
	{	
		++ iComparisonNum;
	}

	var sResidenceName = oObject.name.substr(3);
	
	if (oObject.check!="yes" )
	{
		if ( iComparisonNum < 4)
		{
	  	     oObject.src="/img/check_ok.gif"
		     oObject.check="yes" ;
		      oObject.comparison=iComparisonNum + 1 ;
		     document.forms[0].elements["Comparison" + (iComparisonNum+1)].value = sResidenceName ;		     
		}else{
                                alert("Ya se han seleccionado el m?ximo de 4 residencias permitidas en la comparativa. ");
		}
	}else{
		oObject.src="/img/check.gif";
	  	oObject.check="no" ;		 
		document.forms[0].elements["Comparison" + oObject.comparison ].value ="null";
		oObject.comparison = "";
	}
}




function checkMandatoryFields()
{   
	var oMandatories = document.forms[0].MandatoryFields;
	var bSubmit = true;

	for (i=0;i<oMandatories.length;i++ )
		{   
			if (oMandatories[i].tagName.toUpperCase()=="SELECT" && oMandatories[i].value=="NO_DATA")
			{
				alert("Por favor, seleccione la informacion obligatoria que falta.");
				oMandatories[i].focus();
				bSubmit = false;
				break;
			}else if (oMandatories[i].tagName.toUpperCase()=="INPUT" && oMandatories[i].value.length==0)
			{
			    alert("Por favor, escriba la informacion obligatoria que falta.");
				oMandatories[i].focus();
				bSubmit = false;
				break;
			}else if (oMandatories[i].tagName.toUpperCase()=="TEXTAREA" && oMandatories[i].value.length == 0)
			{
				alert("Es obligatorio introducir texto, por favor, escriba la informacion que falta.");
				oMandatories[i].focus();
				return false;
			}
		}		
		return bSubmit;
}




function checkNumeric(aFields)
{	
	var bResult = true;
	for (i=0;i<aFields.length;i++)
	{
		if (aFields[i]!="" && isNaN(document.forms[0].elements[aFields[i]].value))
		{
			alert("El valor del campo deber?a ser n?merico");
			document.forms[0].elements[aFields[i]].focus();
			bResult = false;
			break;
		}
	}
	return bResult;
}


function trim(sData)
{
	for (i=0; i<sData.length;i++)
	{
		if(sData.charAt(i) !=" ")
		{           
			sData = sData.substring(i,sData.length);
			break;			
		}else{
			sData = sData.substring(i,sData.length);
		}
	}

	for (i=sData.length-1;i>=0; i--)
	{
		if(sData.charAt(i) !=" ")
		{
			sData = sData.substring(0,i+1);
			break;			
		}
	}
	
	return sData;
}


function updateChecks()
{
	var oChecks = document.forms["frmSearch"].imgChecks;
	var sImgName = "";
	for( i=0; i < oChecks.length ; i++)
	{			
 		if (oChecks[i].value == "Y" )
		{    
			sImgName = "img" + oChecks[i].name;
			document.getElementById(sImgName).src="/img/check_ok.gif";
			document.getElementById(sImgName).check="yes" ;
		}	 
	}
}

function doSubmitLogin()
{     
	if ( document.getElementById("ClientID").value == "") {
		alert ("Por favor, introduzca su nombre de usuario");
		document.getElementById("ClientID").focus();
		return false;		
	} else if  (document.getElementById("Pwd").value== "") {
		alert ("Por favor, introduzca su contrase?a");
		document.getElementById("Pwd").focus();
		return false;	
	}
}

function doSubmitHome()
{    
	if (document.forms[0].Community.value == "NO_DATA") {
		alert ("El campo comunidad es obligatorio. Por favor, seleccione una comunidad aut?noma");					
		window.frames["GeographicSearch"].document.frmCombos.Community.focus();
	} else if  (document.forms[0].Province.value == "NO_DATA") {
		alert ("El campo provincia es obligatorio. Por favor, seleccione una provincia");
		window.frames["GeographicSearch"].document.frmCombos.Province.focus();
	}else {
		document.getElementById("frmSearch").submit();
	}
}


// Menu Lateral
function List_click(eSrc,ID)
{      
	var eChild = document.getElementById(ID);
	var bChildDisplayed = eChild.style.display;
	HideAll("table");
	if(bChildDisplayed == "none" )
	{    
		eSrc.style.color = "maroon";
		eChild.style.display ="block";
	}else{ 
		eSrc.style.color = "black";
		eChild.style.display ="none";
	}
}

// Menu Lateral
function ShowAll(sTagName)
{
	var cElems = document.getElementsByTagName(sTagName);
	var iNumElems = cElems.length;
	for (var i=1;i<iNumElems;i++) cElems[i].style.display = "block";
}

// Menu Lateral
function HideAll(sTagName)
{
	var cElems = document.getElementsByTagName(sTagName);
	var iNumElems = cElems.length;
	for (var i=1;i<iNumElems;i++) {
		if(cElems[i].className=="submenu")cElems[i].style.display = "none";
	}
	SetDefaultColor("td");
}

// Menu Lateral
function SetDefaultColor(sTagName)
{
	var cElems = document.getElementsByTagName(sTagName);
	var iNumElems = cElems.length;
	for (var i=0;i<iNumElems;i++) cElems[i].style.color = "";
}


function checkFieldsSuggestions(){	

	if (document.forms[0].elements["Text"].value !=null) {	
			if (document.forms[0].elements["Text"].value.length > 255) {
				alert("El texto introducido es demasiado largo. No puede sobrepasar los 255 caracteres.");
				document.forms[0].elements["Text"].focus();
				return false;
			}

			if (document.forms[0].elements["Text"].value.length == 0)
			{
				alert("Es obligatorio introducir texto, por favor, escriba la informaci?n que falta.");
				document.forms[0].elements["Text"].focus();
				return false;
			}
									
	} 
	return true;
}




function checkFieldsTellAFriend(){			
	if (document.getElementById("Comments").value!=null) {							
			if (document.getElementById("Comments").value.length > 255) {
				alert("El texto introducido en los comentarios es demasiado largo. No puede sobrepasar los 255 caracteres.");
				document.getElementById("Comments").focus();
				return false;
			}
	}
	
	if (!checkMandatoryFields()) return false;
	
	return true;
}


					
// Change of cursor if Firefox
	if(navigator.appName=="Netscape"){
		for(i = 0; document.styleSheets.length > i; i++) 
		{	
			var oCssRules = document.styleSheets[i].cssRules;
			for(j = 0; oCssRules.length > j; j++)
			{     
				if(oCssRules[j].selectorText.toUpperCase() == "INPUT.BUTTON")
				{
			     		oCssRules[j].style["cursor"] = "pointer";
			    }
			    if(oCssRules[j].selectorText.toLowerCase() == "td.clshaskids" || oCssRules[j].selectorText.toLowerCase() == "td.clsnokids")
				{
 					oCssRules[j].style["cursor"] = "pointer";
				}
			} 
		}
	}


					
