// JavaScript Document

function checkSearchButtonIsActive( ){
	
	if( document.getElementById('phdd_search').className = 'property-home-search-button-disabled'){
		
		//Show an error message
		alert('Please select a country before neginning your property search');
		
	}
	
}

function closePopupSiteHelpMenu(){

	document.getElementById('site-help-popup-wrapper').style.display = 'none';
}

//This function creates and returns a marker with the specified colour
function createColouredIcon( strMarkerColour ){

	//Create the icon
	var googleMapsIcon = new GIcon();
	googleMapsIcon.image = "/images/icons/google-maps/" + strMarkerColour + ".png";
	googleMapsIcon.shadow = "/images/icons/google-maps/shadow50.png";
	googleMapsIcon.iconSize = new GSize(32, 32);
	googleMapsIcon.shadowSize = new GSize(37, 34);
	googleMapsIcon.iconAnchor = new GPoint(9, 34);
	googleMapsIcon.infoWindowAnchor = new GPoint(9, 2);
	googleMapsIcon.infoShadowAnchor = new GPoint(18, 25);
	googleMapsIcon.transparent = "/images/icons/google-maps/markerTransparent.png";

	//Return the marker
	return googleMapsIcon;
	
}

//This function creates and returns a marker for the google maps
function createUrlMarker( intLat, intLong, strUrl, featureCode ) {

	var mapIcon, infoMarker, mapPoint;
	
	//Create the icon
	mapIcon = createColouredIcon( featureCode );
	
	mapPoint = new GLatLng(intLat, intLong);
			
   	infoMarker = new GMarker(mapPoint, mapIcon);

   	GEvent.addListener(infoMarker, "click",

      function() {

         document.location.href = strUrl;

      }

   );

  return infoMarker;

}

//This function creates and returns a marker for the google maps
function createInfoMarker( intLat, intLong, popupText, featureCode ) {

	var mapIcon, mapPoint, infomarker;
	
	//Create the icon
	mapIcon = createColouredIcon( featureCode );
	
	mapPoint = new GLatLng( intLat, intLong );
			
   	infomarker = new GMarker(mapPoint, mapIcon);

   	GEvent.addListener(infomarker, "click",

      function() {

         infomarker.openInfoWindowHtml(popupText);
         //document.location.href = '/spain/';

      }

   );

  return infomarker;

}

//This function gets the value of a radio button
function get_radio_value( strRadioGroup ){
	
	//Get the radio button group
	var grpRadioButtons = MM_findObj( strRadioGroup );
	
	var rad_val = '';
	
	//Loop through and find the checked value
	for (var i=0; i < grpRadioButtons.length; i++)
	   {
	   if ( grpRadioButtons[i].checked )
		  {
		  rad_val = grpRadioButtons[i].value;
		  }
	   }
	   
	//Return the value
	return rad_val;
}


//This function creates an RSS url from the selected country and channels (if any)
function createRSSFeedUrl( strCountryName, strChannel ){
	
	//The variable to store the built url
	var strRSSFeedUrl = '';
	
	//Firstly check if a country name or channel was selected
	if( strCountryName != '' || strChannel != '' ){
		
		//Check if a country was selected
		if( strCountryName != '' ){
		
			//Check for a channel also
			if( strChannel != '' ){
				
				//Country and channel selected
				strRSSFeedUrl = '/' + strCountryName + '/property/news/channels/' + strChannel + '/rss/'
		
			}else{
				
				//Country but no channel
				strRSSFeedUrl = '/' + strCountryName + '/property/news/rss/'
				
			}
			
		}else{
		
			//Because a country or channel was selected and no country, then a channel must be selected
			strRSSFeedUrl = '/news/channels/' + strChannel + '/rss/'
			
		}
	}else{
		
		strRSSFeedUrl = '/rss/';
		
	}
	
	//Send the visitor to the RSS Feed
	return strRSSFeedUrl;
}


function SwitchItems(str)
	{
		document.getElementById('overview').className = '';
		document.getElementById('development').className = '';
		document.getElementById('location').className = '';
		document.getElementById('images').className = '';
		document.getElementById('finance').className = '';
		document.getElementById('additional').className = '';
		if( document.getElementById('financequalification') != null ){
			document.getElementById('financequalification').className = '';
		}
		<!--document.getElementById('inspection').className = '';	-->		
		document.getElementById('overview_panel').style.display = 'none';
		document.getElementById('development_panel').style.display = 'none';
		document.getElementById('location_panel').style.display = 'none';
		document.getElementById('images_panel').style.display = 'none';
		document.getElementById('finance_panel').style.display = 'none';
		document.getElementById('additional_panel').style.display = 'none';
		document.getElementById('financequalification_panel').style.display = 'none';
		if( document.getElementById('financequalification') != null ){
			if ( str == 'financequalification' ){ 
				document.getElementById('report-right-menu').style.display = 'none';
			}else{
				document.getElementById('report-right-menu').style.display = 'block';
			}
		}
		<!--document.getElementById('inspection_panel').style.display = 'none';-->
		document.getElementById(str).className = 'current';
		document.getElementById(str + '_panel').style.display = 'block';
			
		if (str=='location' || str== 'overview' )
		{
			load() ;
		}	
	}
	
function SwitchSecureExitItems(str)
	{
		document.getElementById('overview').className = '';
		document.getElementById('secure').className = '';
		document.getElementById('development').className = '';
		document.getElementById('location').className = '';
		
		<!--document.getElementById('inspection').className = '';	-->		
		document.getElementById('overview_panel').style.display = 'none';
		document.getElementById('secure_panel').style.display = 'none';
		document.getElementById('development_panel').style.display = 'none';
		document.getElementById('location_panel').style.display = 'none';
		
		
		<!--document.getElementById('inspection_panel').style.display = 'none';-->
		document.getElementById(str).className = 'current';
		document.getElementById(str + '_panel').style.display = 'block';
		
	}
	
function SwitchLosPandosItems(str)
	{
		document.getElementById('investmentoverview').className = '';
		document.getElementById('redevelopmentplan').className = '';
		document.getElementById('founderssyndicate').className = '';
		document.getElementById('financials').className = '';
		document.getElementById('investorbenefits').className = '';
		document.getElementById('risksecurity').className = '';
		
		document.getElementById('investmentoverview_panel').style.display = 'none';
		document.getElementById('redevelopmentplan_panel').style.display = 'none';
		document.getElementById('founderssyndicate_panel').style.display = 'none';
		document.getElementById('financials_panel').style.display = 'none';
		document.getElementById('investorbenefits_panel').style.display = 'none';
		document.getElementById('risksecurity_panel').style.display = 'none';
		
		<!--document.getElementById('inspection_panel').style.display = 'none';-->
		document.getElementById(str).className = 'current';
		document.getElementById(str + '_panel').style.display = 'block';
		
	}
	
function SwitchFractionalItems(str)
	{
		document.getElementById('investmentoverview').className = '';
		document.getElementById('redevelopmentplan').className = '';
		document.getElementById('imagegallery').className = '';
		document.getElementById('financials').className = '';
		document.getElementById('investorbenefits').className = '';
		document.getElementById('risksecurity').className = '';
		
		document.getElementById('investmentoverview_panel').style.display = 'none';
		document.getElementById('redevelopmentplan_panel').style.display = 'none';
		document.getElementById('imagegallery_panel').style.display = 'none';
		document.getElementById('financials_panel').style.display = 'none';
		document.getElementById('investorbenefits_panel').style.display = 'none';
		document.getElementById('risksecurity_panel').style.display = 'none';
		
		<!--document.getElementById('inspection_panel').style.display = 'none';-->
		document.getElementById(str).className = 'current';
		document.getElementById(str + '_panel').style.display = 'block';
		
	}
	
function SwitchDistressedPortfolioItems(str)
	{
		document.getElementById('investmentoverview').className = '';
		document.getElementById('redevelopmentplan').className = '';
		document.getElementById('imagegallery').className = '';


		
		document.getElementById('investmentoverview_panel').style.display = 'none';
		document.getElementById('redevelopmentplan_panel').style.display = 'none';
		document.getElementById('imagegallery_panel').style.display = 'none';


		
		<!--document.getElementById('inspection_panel').style.display = 'none';-->
		document.getElementById(str).className = 'current';
		document.getElementById(str + '_panel').style.display = 'block';
		
	}
	
function switchFundItems(str)
	{
		document.getElementById('overview').className = '';
		document.getElementById('development').className = '';
		document.getElementById('location').className = '';
		document.getElementById('images').className = '';
		document.getElementById('howtoinvest').className = '';
		document.getElementById('finance').className = '';
		document.getElementById('additional').className = '';
		document.getElementById('inspection').className = '';
		document.getElementById('overview_panel').style.display = 'none';
		document.getElementById('development_panel').style.display = 'none';
		document.getElementById('location_panel').style.display = 'none';
		document.getElementById('images_panel').style.display = 'none';
		document.getElementById('howtoinvest_panel').style.display = 'none';
		document.getElementById('finance_panel').style.display = 'none';
		document.getElementById('additional_panel').style.display = 'none';
		document.getElementById('inspection_panel').style.display = 'none';
		document.getElementById(str).className = 'current';
		document.getElementById(str + '_panel').style.display = 'block';

	}
	
function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
}

function showBrowserWindow( URLStr,w,h,sbars )  {

	var popUpWin = 0;
	
	stname = Math.floor(Math.random()*10000);
	
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	
	popUpWin = open( URLStr, stname, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + sbars + ',resizable=no,copyhistory=no,width='+w+',height='+h+',left='+LeftPosition+', top='+TopPosition+',screenX=220,screenY=180');
//	popUpWin.document.write('<html><head><title>Propertyshowrooms.com :: View Image </title></head>');

}

function showGraph( URLStr )  {
  var popUpWin = 0;
  popUpWin = open( URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width=520,height=520,left=180, top=180,screenX=180,screenY=180');
}





function convertCurrency( amount, from, to ){
 
  conPopUpWin = open( 'http://www.moneycorp.com/tools/currency_converter/autoConverterIndex.cfm?amount=' + amount  + '&fromCurrency='+ from +'&toCurrency='+ to + '&ReferringAgentID=10004788', 'conPopUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbar=yes,resizable=yes,copyhistory=yes,width=335,height=370,left=180, top=180,screenX=180,screenY=180');
	//enlargePhoto( 'http://www.xe.com/ucc/convert.cgi?From=' + from + '&To=' + to + '&Amount=' + amount + '&<%=server.HTMLEncode("Header=[html][head][title]Bar in the Sun Currency Conversion - by XE.com[/title][/head][body]")%>&Footer=<%=server.HTMLEncode("[/body][/html]")%>' );
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
  		test=args[i+2];
		//alert('Testing the ' + args[i]);
		val=MM_findObj(args[i]);
		//alert('found the obj ' + val.name );
    	if (val) { 
			nm=val.name; 
			if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@');
        			if (p<1 || p==(val.length-1)) errors+='- '+stripFormIdentifiers(nm)+' must contain an e-mail address.\n';
      			} 
				else if (test!='R') { 
					//num = parseFloat(val);
        			//if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('isDropDown') != -1) { 
						p=MM_findObj(args[i]);
						p = p.selectedIndex;
          				if (p==0) errors+='- Select a valid '+stripFormIdentifiers(nm)+'.\n';
    				}
					if (test.indexOf('isPrivacyBox') != -1) { 
						p=MM_findObj(args[i]);
          				if (p.checked == false) errors+='- You must read and understand our privacy statement.\n';
    				}
					if (test.indexOf('isCheckBox') != -1) { 
						p=MM_findObj(args[i]);
          				if (p.checked == false) errors+='- '+stripFormIdentifiers(nm)+' must be checked.\n';
    				}
					if (test.indexOf('isRadio') != -1) {
						p=get_radio_value( args[i] );
						if (p=='') errors+='- '+stripFormIdentifiers(args[i])+' must be checked.\n';
					}
				} 
			} 
			else if (test.charAt(0) == 'R') errors += '- '+stripFormIdentifiers(nm)+' is required.\n'; 
		}
		//alert(args[i] + ' was ok');
	} 
	if (errors) alert('Please correct the following before continuing:\n\n'+errors);
  	document.MM_returnValue = (errors == '');
}

function MM_validatePropertyDetailForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validatePropertyDetailForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
  		test=args[i+2];
		//alert('Testing the ' + args[i]);
		val=MM_findObj(args[i]);

		//alert('found the obj ' + val.name );
    	if (val) { 
			nm=val.name; 
			val=val.value;
			if (val!="" && val!="First Name" && val!="Surname" && val!="Email Address" && val!="Telephone Number") {
				if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@');
        			if (p<1 || p==(val.length-1)) errors+='- '+stripFormIdentifiers(nm)+' must contain an e-mail address.\n';
      			} 
			} 
			else if (test.charAt(0) == 'R') errors += '- '+stripFormIdentifiers(nm)+' is required.\n'; 
		}
		//alert(args[i] + ' was ok');
	} 
	if (errors) alert('Please correct the following before continuing:\n\n'+errors);
  	document.MM_returnValue = (errors == '');
}
	

function MM_validateExtendEnquiryForm() { //v4.0
	
	var errors = '';
	//Check if any check boxes were checked
	if( MM_findObj('ER_Property').checked == false && MM_findObj('ER_Mortgages').checked == false && MM_findObj('ER_Foreign_Exchange').checked == false && MM_findObj('ER_Insurance').checked == false && MM_findObj('ER_Furniture_Packs').checked == false && MM_findObj('ER_Fractional').checked == false ){
	
		errors = 'You must select at least one service before submitting.';
	}
	
	//If any errors were encountered then show them
	if (errors) alert('Please correct the following before continuing:\n\n'+errors);
  	document.MM_returnValue = (errors == '');
}

function MM_validatePropertySearchForm() { //v4.0
	
	var errors = '';
	//Check if any check boxes were checked
	if( MM_findObj('loc').value == ''){
	
		//errors = 'Please enter a location to continue';
	}
	else if( MM_findObj('loc').value.length < 3){
	
		//errors = 'Please enter at least 3 characters to continue';
	}
	
	//If any errors were encountered then show them
	if (errors) alert(errors);
  	document.MM_returnValue = (errors == '');
}

function MM_validateIpinSignupForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateIpinSignupForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
  		test=args[i+2];
		//alert('Testing the ' + args[i]);
		val=MM_findObj(args[i]);
		//alert('found the obj ' + val.name );
    	if (val) { 
			nm=val.name; 
			if ((val=val.value)!="") {
      			if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@');
        			if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      			} 
				else if (test!='R') { 
					//num = parseFloat(val);
        			//if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('isDropDown') != -1 && test.indexOf('isDropDown') != 0) { 
						p=MM_findObj(args[i]);
						p = p.selectedIndex;
          				if (p==0){
							if (nm == 'CountryOfResidence') nm = 'Country of residence';
							errors+='- '+nm+' is required.\n';
						}
    				}
					if (test.indexOf('isPrivacyBox') != -1) { 
						p=MM_findObj(args[i]);
          				if (p.checked == false) errors+='- You must read and understand our privacy statement.\n';
    				}
				} 
			} 
			else{ 
				if (test.charAt(0) == 'R'){
					if (nm == 'firstName') nm = 'First name';
					if (nm == 'surname') nm = 'Surname';
					if (nm == 'EmailAddress') nm = 'Email address';
					if (nm == 'ConfirmPassword') nm = 'Confirm Password';
					errors += '- '+nm+' is required.\n'; 
				}
			}
		}
		//alert(args[i] + ' was ok');
	} 
	//We need to check the password was confirmed correctly
	/*if( (MM_findObj('Password').value != MM_findObj('ConfirmPassword').value) && MM_findObj('ConfirmPassword').value != '' ){			
			errors += '- Your password was not confirmed properly.\n'; 
	}*/
	if (errors) alert('Please correct the following before continuing:\n\n'+errors);
  	document.MM_returnValue = (errors == '');
}

function MM_validateAlternateIpinSignupForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateAlternateIpinSignupForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
  		test=args[i+2];
		//alert('Testing the ' + args[i]);
		val=MM_findObj(args[i]);
		//alert('found the obj ' + val.name );
    	if (val) { 
			nm=val.name; 
			if ((val=val.value)!="") {
      			if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@');
        			if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      			} 
				else if (test!='R') { 
					//num = parseFloat(val);
        			//if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('isDropDown') != -1 && test.indexOf('isDropDown') != 0) { 
						p=MM_findObj(args[i]);
						p = p.selectedIndex;
          				if (p==0){
							if (nm == 'CountryOfResidence') nm = 'Country code';
							errors+='- '+nm+' is required.\n';
						}
    				}
					if (test.indexOf('isPrivacyBox') != -1) { 
						p=MM_findObj(args[i]);
          				if (p.checked == false) errors+='- You must read and understand our privacy statement.\n';
    				}
				} 
			} 
			else{ 
				if (test.charAt(0) == 'R'){
					if (nm == 'firstName') nm = 'First name';
					if (nm == 'surname') nm = 'Surname';
					if (nm == 'EmailAddress') nm = 'Email address';
					if (nm == 'ConfirmPassword') nm = 'Confirm Password';
					errors += '- '+nm+' is required.\n'; 
				}
			}
		}
		//alert(args[i] + ' was ok');
	} 
	//We need to check the password was confirmed correctly
	/*if( (MM_findObj('Password').value != MM_findObj('ConfirmPassword').value) && MM_findObj('ConfirmPassword').value != '' ){			
			errors += '- Your password was not confirmed properly.\n'; 
	}*/
	if (errors) alert('Please correct the following before continuing:\n\n'+errors);
  	document.MM_returnValue = (errors == '');
}

function stripFormIdentifiers( strElement ){

	//Remove the form identifiers e.g. EF_ or CF_
	strElement = strElement.substring( 3, strElement.length );
	//Loop through and replace all underscores with spaces
	i = strElement.indexOf('_');
	while (i > -1){
		strElement = strElement.replace( '_', " " );
		i = strElement.indexOf('_');
	}
	//Return the formatted element name
	return strElement;
}

var list; // global list variable cache
var tickerObj; // global tickerObj cache
var hex = 255;

function fadeText(divId) {
  if(tickerObj)
  {
    if(hex>0) {
      hex-=5; // increase color darkness
      tickerObj.style.color="rgb("+hex+","+hex+","+hex+")";
      setTimeout("fadeText('" + divId + "')", fadeSpeed); 
    } else
      hex=255; //reset hex value
  }
}

function initialiseList(divId) {
  tickerObj = document.getElementById(divId);
  if(!tickerObj)
    reportError("Could not find a div element with id \"" + divId + "\"");
  list = tickerObj.childNodes;
  if(list.length <= 0)
    reportError("The div element \"" + divId + "\" does not have any children");
  for (var i=0; i<list.length; i++) {
    var node = list[i];
    if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
              tickerObj.removeChild(node);
  }
  run(divId, 0);
}

function run(divId, count) {
  fadeText(divId);
  list[count].style.display = "block";
  if(count > 0)
    list[count-1].style.display = "none";
  else
    list[list.length-1].style.display = "none";
  count++;
  if(count == list.length)
    count = 0;
  window.setTimeout("run('" + divId + "', " + count+ ")", interval*1000);
}

function reportError(error) {
  alert("The script could not run because you have errors:\n\n" + error);
  return false;
}

function toggleLayer( whichLayer ){  
	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
		elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work      
		elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works    
	elem = document.layers[whichLayer];  vis = elem.style;  
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function switchOffLayer( whichLayer ){
	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
		elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work      
		elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works    
		elem = document.layers[whichLayer];  vis = elem.style;  
	vis.display = 'none';
}

//This function accepts a search tab, switches it on and switches the other 2 off, except for advanced which switches adv and basic on
function activateSearchTab( whichTab ){

	//First switch off all tabs
	switchOffLayer( 'section-search-basic-container' );
	//switchOffLayer( 'section-search-advanced-container' );
	switchOffLayer( 'section-search-ipin-container' );
	switchOffLayer( 'section-search-submit-container' );
	
	//which tab are we activating
	switch(whichTab){
		
	
		case 'section-search-basic-container':
	  		toggleLayer( 'section-search-basic-container' );
			toggleLayer( 'section-search-submit-container' );
	  		break;    
	
		case 'section-search-advanced-container':
	  		toggleLayer( 'section-search-basic-container' );
			//toggleLayer( 'section-search-advanced-container' );
			toggleLayer( 'section-search-submit-container' );
	  		break;
	
		case 'section-search-ipin-container':
	  		toggleLayer( 'section-search-ipin-container' );
	  		break;
	}
	
}

function checkCountry( intIndex, strSourceRef ){
	
	if( intIndex == 'Select a Country...' ){
		//Check if an entry was made in the property ref box, if not return false
		//if( strSourceRef == '' ){
			alert('To begin a search, please first select a country');
			return false;
		//}else{
			//setFormDestination(Left(document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value,1));
			//return true;
		//}
	}else{
		
		setFormDestination(Left(document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value,1));
		return true;
	}
}

// Sets the destination of the form depending on whether we are on a full or semi country
function setFormDestination( strCountryStatus ){

	//Check the status of the country
	if( strCountryStatus == '1'){
		
		// Strip the identifier off the beginning of the country name
		document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value = Right(document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value,(document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value.length-2))
		
		//Get the name of the country
		strCountry = document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value;
		
		//Check for the capeverde legacy name
		if( strCountry == 'Cape Verde'){ strCountry = 'CapeVerde'; }
		
		//Set the action of the form
		document.searchform.action = '/' + strCountry.toLowerCase() + '/property/search.asp';
	}
	else{
		
		// Strip the identifier off the beginning of the country name
		document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value = Right(document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value,(document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value.length-2))
		
		//Get the name of the country
		strCountry = document.searchform.fldCountry.options[document.searchform.fldCountry.selectedIndex].value;
		
		//Set the action of the form
		document.searchform.action = '/' + strCountry.toLowerCase() + '/default.asp';
	}
	
}

function toggleAdvancedInput(){
	if( document.searchform.fldShowAdvanced.value == '0' ){ document.searchform.fldShowAdvanced.value = '1'; }
	else{ document.searchform.fldShowAdvanced.value = '0'; }
	//alert(document.searchform.fldShowAdvanced.value);
}

// adapted from http://jibbering.com/2002/4/httprequest.html
function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function getUrl(url, cb) {
  var xmlhttp = getXmlHttp();
  xmlhttp.open("GET", url);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
      cb(xmlhttp.status, 
         xmlhttp.getAllResponseHeaders(), 
         xmlhttp.responseText);
      }
  }
  xmlhttp.send(null);
}

function hitUrl(url) {
  //alert('starting');
  var xmlhttp = getXmlHttp();
  xmlhttp.open("GET", url);
  xmlhttp.onreadystatechange = function() {
	  if (xmlhttp.readyState == 4) {
    	//alert('Ready state: ' + xmlhttp.readyState + '. Status: ' + xmlhttp.status);
	  }
  }
  xmlhttp.send(null);
}

function updateSaveDiv( status, headers, result ){
	//Convert the result into an int to check for a negative value
	//try { 
		var intPropertyId = parseInt(result);
		//If the return value is -1 then we must sign in
		if( intPropertyId < 0 ){
			intPropertyId = ( intPropertyId * -1 );
			document.getElementById('SaveProperty_' + intPropertyId.toString()).innerHTML = '<img src="/images/save-property-icon.gif" alt="Saved Properties" hspace="5" border="0" align="absmiddle" />You are not signed in. <a href="/member-sign-in.asp" title="Click here to sign in">Sign In</a>';
		}else{
			document.getElementById('SaveProperty_' + intPropertyId.toString()).innerHTML = '<img src="/images/save-property-icon.gif" alt="Saved Properties" hspace="5" border="0" align="absmiddle" />Saved to My Properties';
		}
	//} 
	//catch(NumberFormatException e) { return true; }	
}





function updateRefineSearchLocaleDropDown( status, headers, result ){

	//Empty and disable the second level drop down
	//document.getElementById('rssl').style.color = '#000000';
	//document.getElementById('rssl').options.length = 0;
	//document.getElementById('rssl').disabled = true;
	document.getElementById('phdd_loader_le').style.display='block';
	//Split the results by comma
	var regions = result.split("#");
	//Get the drop down element
	var ddRegions = document.getElementById('rsle');
	var ddPrimaryRegions = document.getElementById('rsfl');
	var ddSecondaryRegions = document.getElementById('rssl');

	//Check if a valid region/secondary region was chosen
	if( ddSecondaryRegions.value == -1 && ddSecondaryRegions.disabled == false ){
		
		ddRegions.options.length = 0;
		ddRegions.disabled = true;
		
	}else{
		
		//Clear the current options in the dropdown
		ddRegions.options.length = 0;
		//Add the first option
		ddRegions.options[ddRegions.options.length] = new Option('All Cities/Towns/Areas','-1');
		//Loop through the result set 2 at a time as every first element is a name and every second element is a value
		for (i=0; i<(regions.length-1); i+=2) {
			//Add a new option
			ddRegions.options[ddRegions.options.length] = new Option(regions[i],regions[i+1]);
		}
		
		//Add the more locations option
		//ddRegions.options[ddRegions.options.length] = new Option('More locations.......',-2);
		
		//Set the selected index to 0
		//alert('Value of region is ' + ddRegions.options[0].value);
		ddRegions.options[0].selected = true;
		ddRegions.disabled = false;
	}
	//ddRegions.style.color = '#0e5530';
	//ddRegions.style.border = '1px solid black;'
	//ddRegions.setFocus();
	document.getElementById('phdd_loader_sl').style.display='none';
	document.getElementById('phdd_loader_le').style.display='none';
}

function updateRefineSearchFirstLevelDropDown( status, headers, result ){

	//Empty and disable the second level drop down
	
	/*document.getElementById('rssl').options.length = 0;
	document.getElementById('rssl').options[document.getElementById('rssl').options.length] = new Option('Select Secondary Region','-1');
	document.getElementById('rssl').disabled = true;
	document.getElementById('rsle').options.length = 0;
	document.getElementById('rsle').disabled = true;
	document.getElementById('rsle').options[document.getElementById('rsle').options.length] = new Option('Select City/Town/Area','-1');*/
	resetRefineSearchDropDown('rsfl');
	resetRefineSearchDropDown('rssl');
	resetRefineSearchDropDown('rsle');
	
	//Split the results by comma
	var regions = result.split("#");

	//Check if any were returned
	if( regions.length == 1){

		document.getElementById('rsfl').disabled = true;
		document.getElementById('rsfl').options.length = 0;
		document.getElementById('rsfl').options[document.getElementById('rsfl').options.length] = new Option('All Regions','-1');
		if(document.getElementById('phdd_search') != null){
			document.getElementById('phdd_search').disabled = true;
			document.getElementById('phdd_search').className = 'property-home-search-button-disabled';
			}
		
		
	}else{
		
		document.getElementById('rsfl').disabled = false;
		if(document.getElementById('phdd_search') != null){
			document.getElementById('phdd_search').disabled = false;
			document.getElementById('phdd_search').className = 'property-home-search-button';
		}
		
		//Get the drop down element
		var ddRegions = document.getElementById('rsfl');
		//Clear the current options in the dropdown
		ddRegions.options.length = 0;
		//Add the first option
		ddRegions.options[ddRegions.options.length] = new Option('All Regions','-1');
		//Loop through the result set 2 at a time as every first element is a name and every second element is a value
		for (i=0; i<(regions.length-1); i+=2) {
			//Add a new option
			ddRegions.options[ddRegions.options.length] = new Option(regions[i],regions[i+1]);
		}
		
		//Set the selected index to 0
		//alert('Value of region is ' + ddRegions.options[0].value);
		ddRegions.options[0].selected = true;
		ddRegions.disabled = false;
		//ddRegions.style.color = '#0e5530';
		//ddRegions.style.border = '1px solid black;'
		//document.getElementById('rsfl').setFocus();
		
	}
	
	document.getElementById('phdd_loader_c').style.display='none';
}


function resetRefineSearchDropDown( strDropDown ){

	var strMessage = '';
	
	switch(strDropDown){
		case 'rsc':
			strMessage = 'Select Country';
			break;
		case 'rsfl':
			strMessage = 'Select Region';
			break;
		case 'rssl':
			strMessage = 'Select Secondary Region';
			break;
		case 'rsle':
			strMessage = 'Select City/Town/Area';
			break;
	}
			
	document.getElementById(strDropDown).options.length = 0;
	//alert('len is now: ' + document.getElementById(strDropDown).options.length);
	document.getElementById(strDropDown).options[document.getElementById(strDropDown).options.length] = new Option(strMessage,'-1');
	document.getElementById(strDropDown).disabled = true;
}

function updateRefineSearchSecondLevelDropDown( status, headers, result ){
	
	resetRefineSearchDropDown('rssl');
	resetRefineSearchDropDown('rsle');

	//Get a reference to the second level drop down
	var ddSecondaryRegions = document.getElementById('rssl');
	var ddLocales = document.getElementById('rsle');
	var ddRegions = document.getElementById('rsfl');
	
	//Check if a valid region has been selected
	if( ddRegions.value == -1 ){
		
		ddSecondaryRegions.options.length = 0;
		ddSecondaryRegions.disabled = true;
		ddLocales.options.length = 0;
		ddLocales.disabled = true;
		
	}else{
		
		//Split the results by comma
		var regions = result.split("#");
	
		//Check for any result
		if( regions.length == 1 ){
			
			//Clear the current options in the dropdown
			ddSecondaryRegions.options.length = 0;
			
			//Add an option indicating no second levels
			ddSecondaryRegions.options[ddSecondaryRegions.options.length] = new Option('No Secondary Regions','-1');
			ddSecondaryRegions.disabled = true;
	
			document.getElementById('phdd_loader_sl').style.display='none';
			document.getElementById('phdd_loader_le').style.display='block';
			getUrl('/xmlhttp/get-locales.asp?rsfl=' + document.getElementById('rsfl').value + '&rssl=', updateRefineSearchLocaleDropDown);
			
		}else{
			
			
			//Get the drop down element
			
			//Clear the current options in the dropdown
			ddSecondaryRegions.options.length = 0;
			//Add the first option
			ddSecondaryRegions.options[ddSecondaryRegions.options.length] = new Option('All Secondary Regions','-1');
			//Loop through the result set 2 at a time as every first element is a name and every second element is a value
			for (i=0; i<(regions.length-1); i+=2) {
				//Add a new option
				ddSecondaryRegions.options[ddSecondaryRegions.options.length] = new Option(regions[i],regions[i+1]);
			}
			//Set the selected index to 0
			//alert('Value of region is ' + ddRegions.options[0].value);
			ddSecondaryRegions.options[0].selected = true;
			ddSecondaryRegions.disabled = false;
			//ddRegions.style.color = '#0e5530';
			//ddRegions.selectedIndex = 0;
		}
	}
	
	document.getElementById('phdd_loader_fl').style.display='none';
	//document.getElementById('phdd_loader_le').style.display='none';
}


function selectLocationInDropDown( strDropDown, itemToSelect ){

	//Get a reference to the drop down
	var myDropdownList = document.getElementById(strDropDown);

	// Loop through all the items
    for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++)
    {    
      if (myDropdownList.options[iLoop].value == itemToSelect)
      {
        // Item is found. Set its selected property, and exit the loop
        myDropdownList.options[iLoop].selected = true;
        break;
      }
    }
	
}

function showPropertyHomeBasicTab(){
	
	document.getElementById('ph_basic_tab').style.display = 'block'; 
	document.getElementById('ph_advanced_tab').style.display = 'none'; 
	
}

function showPropertyHomeAdvancedTab(){
	
	document.getElementById('ph_basic_tab').style.display = 'none'; 
	document.getElementById('ph_advanced_tab').style.display = 'block'; 
	
}

function showPropertySearchBasicTab(){
	
	document.getElementById('ph_basic_tab_header').style.display = 'block'; 
	document.getElementById('ph_location_tab_header').style.display = 'none'; 
	document.getElementById('ph_advanced_tab_header').style.display = 'none'; 
	document.getElementById('ph_location_panel').style.display = 'none'; 
	document.getElementById('ph_easy_filter_options_panel').style.display = 'block'; 
	document.getElementById('ph_basic_options_panel').style.display = 'none'; 
	document.getElementById('ph_advanced_options_panel').style.display = 'none'; 
	document.getElementById('geo-search-button-panel').style.display = 'none'; 
}

function showPropertySearchLocationTab(){
	
	document.getElementById('ph_basic_tab_header').style.display = 'none'; 
	document.getElementById('ph_location_tab_header').style.display = 'block'; 
	document.getElementById('ph_advanced_tab_header').style.display = 'none'; 
	document.getElementById('ph_location_panel').style.display = 'block'; 
	document.getElementById('ph_easy_filter_options_panel').style.display = 'none'; 
	document.getElementById('ph_basic_options_panel').style.display = 'none'; 
	document.getElementById('ph_advanced_options_panel').style.display = 'none'; 
	document.getElementById('geo-search-button-panel').style.display = 'block'; 
	
}

function showPropertySearchAdvancedTab(){
	
	document.getElementById('ph_basic_tab_header').style.display = 'none'; 
	document.getElementById('ph_location_tab_header').style.display = 'none'; 
	document.getElementById('ph_advanced_tab_header').style.display = 'block'; 
	document.getElementById('ph_location_panel').style.display = 'none'; 
	document.getElementById('ph_easy_filter_options_panel').style.display = 'none'; 
	document.getElementById('ph_basic_options_panel').style.display = 'block'; 
	document.getElementById('ph_advanced_options_panel').style.display = 'block'; 
	document.getElementById('geo-search-button-panel').style.display = 'block'; 
	
}

function updateRegionDropDown( status, headers, result ){
	//Split the results by comma
	//alert(result);
	var regions = result.split("#");
	//Get the containing div
	var region_div = document.getElementById('region_div');
	region_div.style.display = 'block';
	//Get the drop down element
	var ddRegions = document.getElementById('fldRegionFilter');
	//Clear the current options in the dropdown
	ddRegions.options.length = 0;
	//Add the first option
	ddRegions.options[ddRegions.options.length] = new Option('All Regions','-1');
	//Loop through the result set 2 at a time as every first element is a name and every second element is a value
	for (i=0; i<(regions.length-1); i+=2) {
		//Add a new option
		ddRegions.options[ddRegions.options.length] = new Option(regions[i],regions[i+1]);
	}
	//Set the selected index to 0
	//alert('Value of region is ' + ddRegions.options[0].value);
	ddRegions.options[0].selected = true;
	//ddRegions.selectedIndex = 0;
}

function updateTownDropDown( status, headers, result ){
	//Split the results by comma
	var towns = result.split("#");
	//Get the containing div
	var town_div = document.getElementById('town_div');
	town_div.style.display = 'block';
	//Get the drop down element
	var ddTowns = document.getElementById('fldTownId');
	//Clear the current options in the dropdown
	ddTowns.options.length = 0;
	//Add the first option
	ddTowns.options[ddTowns.options.length] = new Option('All Towns','-1');
	//Loop through the result set 2 at a time as every first element is a name and every second element is a value
	for (i=0; i<(towns.length-1); i+=2) {
		//Add a new option
		ddTowns.options[ddTowns.options.length] = new Option(towns[i],towns[i+1]);
	}
}

function updateRegionOfPreferenceDropDown( status, headers, result ){
	//Split the results by comma
	//alert(result);
	var regions = result.split("#");
	//Get the containing div
	var region_div = document.getElementById('region_of_preference_div');
	region_div.style.display = 'block';
	//Get the drop down element
	var ddRegions = document.getElementById('PAF_Region_Of_Preference');
	//Clear the current options in the dropdown
	ddRegions.options.length = 0;
	//Add the first option
	ddRegions.options[ddRegions.options.length] = new Option('All Regions','-1');
	//Loop through the result set 2 at a time as every first element is a name and every second element is a value
	for (i=0; i<(regions.length-1); i+=2) {
		//Add a new option
		ddRegions.options[ddRegions.options.length] = new Option(regions[i],regions[i+1]);
	}
	//Set the selected index to 0
	//alert('Value of region is ' + ddRegions.options[0].value);
	ddRegions.options[0].selected = true;
	//ddRegions.selectedIndex = 0;
}

function updateTownOfPreferenceDropDown( status, headers, result ){
	//Split the results by comma
	var towns = result.split("#");
	//Get the containing div
	var town_div = document.getElementById('town_of_preference_div');
	town_div.style.display = 'block';
	//Get the drop down element
	var ddTowns = document.getElementById('PAF_Town_Of_Preference');
	//Clear the current options in the dropdown
	ddTowns.options.length = 0;
	//Add the first option
	ddTowns.options[ddTowns.options.length] = new Option('All Towns','-1');
	//Loop through the result set 2 at a time as every first element is a name and every second element is a value
	for (i=0; i<(towns.length-1); i+=2) {
		//Add a new option
		ddTowns.options[ddTowns.options.length] = new Option(towns[i],towns[i+1]);
	}
}

function updateSearchIndexRegionOfPreferenceDropDown( status, headers, result ){
	//Split the results by comma
	//alert(result);
	var regions = result.split("#");
	//Get the containing div
	var region_div = document.getElementById('region_of_preference_div');
	//region_div.style.display = 'block';
	//Get the drop down element
	var ddRegions = document.getElementById('PAF_Region_Of_Preference');
	//Clear the current options in the dropdown
	ddRegions.options.length = 0;
	//Add the first option
	ddRegions.options[ddRegions.options.length] = new Option('All Regions','-1');
	//Loop through the result set 2 at a time as every first element is a name and every second element is a value
	for (i=0; i<(regions.length-1); i+=2) {
		//Add a new option
		ddRegions.options[ddRegions.options.length] = new Option(regions[i],regions[i+1]);
	}
	//Set the selected index to 0
	//alert('Value of region is ' + ddRegions.options[0].value);
	ddRegions.options[0].selected = true;
	//ddRegions.selectedIndex = 0;
}

function updateSearchIndexTownOfPreferenceDropDown( status, headers, result ){
	//Split the results by comma
	var towns = result.split("#");
	//Get the containing div
	var town_div = document.getElementById('town_of_preference_div');
	//town_div.style.display = 'block';
	//Get the drop down element
	var ddTowns = document.getElementById('PAF_Town_Of_Preference');
	//Clear the current options in the dropdown
	ddTowns.options.length = 0;
	//Add the first option
	ddTowns.options[ddTowns.options.length] = new Option('All Towns','-1');
	//Loop through the result set 2 at a time as every first element is a name and every second element is a value
	for (i=0; i<(towns.length-1); i+=2) {
		//Add a new option
		ddTowns.options[ddTowns.options.length] = new Option(towns[i],towns[i+1]);
	}
}

function focusElement( element ){
	
	//Get a reference to the element and focus
	document.getElementById(element).focus();
}

function updateListingsFound( ){
	
}

function updateSearchButton( status, headers, result ){
	//Get the containing div
	document.getElementById('sbt_btn').value = 'View ' + result + ' Listings';
	//var sbt_btn = document.getElementById('sbt_btn');
	//sbt_btn.value = 'View ' + result + ' Listings';
}

function getSearchFieldValue( whichField, fieldType ){
	if( document.getElementById ) // this is the way the standards work    
		var elem = document.getElementById( whichField );  
	else if( document.all ) // this is the way old msie versions work      
		var elem = document.all[whichField];  
	else if( document.layers ) // this is the way nn4 works    
		var elem = document.layers[whichField];
	var elem = document.getElementById(whichField);
	//alert(fieldType);
	if( fieldType == 1 ){ //drop-down
		//alert(elem.name);
		if (elem.options.length > 0 ){
			return elem.options[elem.selectedIndex].value;
		}
		else{
			return -1;
		}
	}
	else if( fieldType == 2 ){ //text box
		return elem.value;
	}
}

function checkGraphDate(){
	
	var ddGraph = document.getElementById('dateselect');
	if( ddGraph.selectedIndex == '-1') {
		alert('Please select a date before procedding');
		return false;
	}
	else return true;
}

function emptyTownDropDown(){
	//Get a reference to the element
	var ddTowns = document.getElementById('fldTownId');
	//Clear the current options in the dropdown
	ddTowns.options.length = 0;
}

function emptyTownOfPreferenceDropDown(){
	//Get a reference to the element
	var ddTowns = document.getElementById('PAF_Town_Of_Preference');
	//Clear the current options in the dropdown
	ddTowns.options.length = 0;
}

function automateCountryDropDown(intIndex){
	var dd = document.getElementById('fldCountry');
	dd.selectedIndex = intIndex;
	dd.style.backgroundColor = '#99c0db';
	dd.fireEvent('onChange');
	//for( i = 0; i < 8; i++){
		intInterval = setInterval("flashCountryDropDown()", 100);
		setTimeout( 'clearInterval(intInterval)', 1000 );
	//}
}

function flashCountryDropDown(){ 
	if (!document.all) return;
	var objCountryDropDown = document.getElementById('fldCountry');
	if (objCountryDropDown.style.backgroundColor == "#99c0db")
		objCountryDropDown.style.backgroundColor = "#ffffff";
	else 
		objCountryDropDown.style.backgroundColor = "#99c0db";
}

function Left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }

function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }
		
function popupWindow( URLStr, intWidth, intHeight )  {
  var popUpWin = 0;
  popUpWin = open( URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=' + intWidth + ',height=' + intHeight + ',left=180, top=180,screenX=180,screenY=180');
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function popupMiniGoogleMap( strIdentifier, intLatitude, intLongitude ){

		// gets note1 element
		var note1=document.getElementById(strIdentifier);
		// assigns X,Y mouse coordinates to 'note1' element\
		note1.style.left=event.clientX;
		note1.style.top=event.clientY;
		alert(event.clientX + ', ' + event.clientY);
		// makes note1 element visible
		note1.style.visibility='visible';
		note1.style.display = 'block';
}