var advanced = false;

function calcHeight() {
	var h = $('viewmylist').contentWindow.document.body.scrollHeight;
	$('viewmylist').height = h;
	RenderRoundCorner('membersarea');
}

function ajaxPost(f) 
{
	e = f.email.value;
	n = f.name.value;
	if (e != 'Email address' && n != 'Contact name') {
		setTimeout("getResponse('"+e+"', '"+n+"')", 500);
	} 
	return false;
} 

function getResponse(email, name)
{
	var url = '/'+dirOnly+'/php/newsletter.php';
	var params = 'email='+email+'&name='+name;
	var ajax = new Ajax.Request(url, {method:'get', parameters:params, onComplete: showResponse});
}

function getResponseBack()
{
	var url = '/'+dirOnly+'/php/ajax_form_subscribe_enewsletter.php';
	var ajax = new Ajax.Request(url, {method:'get', onComplete: showResponse});
}

function getResponseBackSTOP()
{
	var url = '/'+dirOnly+'/php/ajax_form_subscribe_enewsletter.php';
	var ajax = new Ajax.Request(url, {
	method:'get', 
	onComplete: function(transport){
	
		var data = transport.responseText;
		$('NewsLetterDiv').innerHTML = data;
	
	}
	});
}

function showResponse(req) 
{
	$('NewsLetterDiv').innerHTML = req.responseText;
	window.setTimeout(getResponseBackSTOP, 2000);
} 

function addtolist(method, id, purchase_type, name, show_message, image, thankyou, framename, divID) {
        id = id.replace (",b",'');
        id = id.replace (",r",'');

	name = name.split (",");
        var newlocation = '/'+dirOnly+'/panes/list.php?method=' + method + '&property=' + id + ',' + purchase_type +  "&image=" + escape(image) + "&name=" + escape(name[0]) + "&sort=" + purchase_type + "&type=" + purchase_type;
	
	//window.open(newlocation);
	parent.frames[framename].location=newlocation;
	$(divID).innerHTML="<span class='map_links1'>" + thankyou + "</span>";
}

function addtosearchlist(method, searchstr, search_type, thankyou, framename, divID) {

        var newlocation = '/'+dirOnly+'/panes/list.php?display=sprops&method=' + method + '&searchstr=' + searchstr + '&type=' + search_type;
	parent.frames[framename].location=newlocation;
	$(divID).innerHTML=thankyou;
}


function fixMoreBlock() {
	fixer();
  //a little bit of vertical alignment magic for stock man image
  fc = $('FeatureContainer');
  lc = $('LeftCell');

  more = $('More');

  if (more) {
    more.style.top = (fc.offsetHeight - lc.offsetHeight - 5)+'px';
  } //if
  
} //fixMoreBlock

function goToUrl(url) {
	document.location=url;
}

function fixer() {
//alert('fixer');
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		for(var i=0; i<document.images.length; i++)
	    {
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
			
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML;
			   	i = i-1;
			 }
		}	
	}
}

function sleepBeforePreload() {
  fixMoreBlock();
  window.setTimeout('waitPreloadPage()', 1000); // delays the preloader to display
} //sleepBeforePreload

function waitPreloadPage() { //DOM
	if (document.getElementById){
    $('RotateBox').style.visibility='hidden';
    $('RotateIframe').style.visibility='hidden';
	} else {
    if (document.layers) { //NS4
      document.RotateBox.visibility = 'hidden';
      document.RotateIframe.visibility = 'hidden';
    }	else { //IE4
      document.all.RotateBox.style.visibility = 'hidden';
      document.all.RotateIframe.style.visibility = 'hidden';
    } //else
	} //else
} //waitPreloadPage

function changeSearchVersion(obj) {
  f = $('frmQuickSearch');

  if (obj.checked) {
    f.searchversion.value = 1;
  } else {
    f.searchversion.value = 0;
  } //else
} //changeSearchVersion

function getGreet() {
  var currentTime = new Date();
  var hours = currentTime.getHours();
  var text = "Morning";

  if (hours>11) text = "Afternoon";
  if (hours>17) text = "Evening";

  return text;
} //writeGreet

function id$(name) {
    if (document.getElementById) {
        return $(name);
    } else if (document.all) {
        return document.all[name];
    } else if (document.layers) {
        return document.layers[name];
    }
}

var newsFade;
var newsDiv;
var newsSummary = false;
var newsLoadedID;

function initNews(div, summary) {
  newsDiv = div;
 // newsFade = new fx.Opacity(div, {duration: 400});
  newsSummary = summary;
} //initNews

function fetchNews(id, type, summary) {
        newsSummary = summary;
  if (id != newsLoadedID) {
    if (document.getElementById ('news_' + newsLoadedID)) {
        document.getElementById ('news_' + newsLoadedID).className = "none";
    }
    newsLoadedID = id;
   // newsFade.custom(1, 0);
   $('NewsArticle').innerHTML = '<div style="text-align: center;"><br/><br/><br/><br/><img border="0" title="" alt="" src="http://www.rawson.co.za/site/images/load.gif"/><br />Loading ...<span style="font-size: 12px;">please wait</span><br/><br/><br/><br/><br/><br/></div>';
    setTimeout("fetchSnippet("+id+", '"+type+"')", 500);
    if (document.getElementById ('news_' + newsLoadedID)) {
        document.getElementById ('news_' + newsLoadedID).className = "news_Selected";
        }
  } //if
  return false;
} //fetchNews

function fetchSnippet(id, type) {
  if (type == 'adv') {
    var url = '/'+dirOnly+'/php/fetchadvice.php';
  } else {
    var url = '/'+dirOnly+'/php/fetchnews.php';
  } //else

  var params = 'id='+id+'&ajax=1&summary='+newsSummary;
  var ajaxNews = new Ajax.Request(url, {method:'get', parameters:params, onComplete: showNews});
} //fetchSnippet

function showNews(req) {
  if (newsSummary != true) {
    regex = /setCookie\(.+?\);.+?\);/
    match = regex.exec(req.responseText);
    //eval(match.toString());
  } //if
  
	//alert ($(newsDiv) + " -> " + newsDiv); 
	if (!newsDiv) {
		newsDiv = 'NewsArticle';
	}
  $(newsDiv).innerHTML = req.responseText;
  fixMoreBlock();
//  newsFade.custom(0, 1);
} //showNews

var pollFade;

function pollVote(id, vote) {
  if (vote) {
    var check = false;
    var val;
    f = $('frmPoll');

    for (i = 0; i < f.pollAnswer.length; i++) {
      if (f.pollAnswer[i].checked == true) {
        val = f.pollAnswer[i].value;
        check = true;
        break;
      } //if
    } //for

    if (check) {
      setCookie('POLLVOTE', 'true', 1);
     // pollFade.custom(1, 0);
      setTimeout("pollVoteRequest("+id+", "+val+")", 500);
    } else {
      return;
    } //else
  } else {
 //   pollFade.custom(1, 0);
    setTimeout("pollResultRequest("+id+")", 500);
  } //else
} //pollVote

function pollVoteRequest(id, answer) {
  if (document.getElementById ('weeklypoll')) {
        document.getElementById ('weeklypoll').style.height = document.getElementById ('weeklypoll').scrollHeight + "px";
  }
  var url = '/'+dirOnly+'/php/vote.php';
  var params = 'id='+id+'&ans='+answer;
  var ajaxNews = new Ajax.Request(url, {method:'get', parameters:params, onComplete: showPollResult});
} //pollVoteRequest

function pollResultRequest(id) {
  var url = '/'+dirOnly+'/php/fetchpollresults.php';
  var params = 'id='+id;
  var ajaxNews = new Ajax.Request(url, {method:'get', parameters:params, onComplete: showPollResult});
} //pollResultRequest

function showPollResult(req) {
  $('pollResultBlock').innerHTML = req.responseText;
  pollFade.custom(0, 1);
} //pollResults

function setCookie(cookieName, cookieValue, nDays) {
   var today = new Date();
   var expire = new Date();
   if (nDays==null || nDays==0) nDays=1;
   expire.setTime(today.getTime() + 3600000*24*nDays);

   document.cookie = cookieName+"="+escape(cookieValue)
                   + ";expires="+expire.toGMTString()
                   + ";path=/";
} //setCookie


/*
 *
 *  Javascript for homepage search box
 *
 */

function clearBox(obj){
   if(obj.value == _placetext){
       obj.value = '';
   }
}

function frmPlaces() {
	AREAS ['placeName'] = new Array ();
	AREAS ['placeNames'] = new Array ();
    sendPlace();
    return false;
}

function sendPlace() {
    
    //WORK AROUND FOR IE 7
  if(document.getElementById('placeNames'))
  {
  pn = document.getElementById('placeNames').value;
  }
  else
  {
    pn = document.getElementById('placeName').value;
  }
  
    //END
    if(pn == "" || pn == _placetext || pn.length <= 2) {
        // $('indicator1').style.display = 'none';
        if ($('placeName')) {
            //$('placeName').style.display='none'
        }
        return false;
    } else {
         // $('indicator1').style.display = 'block';
    }
    xhr = createXHR();
    xhr.onreadystatechange=getPlaceResults;
    xhr.open("GET", _ajaxurl+"?type="+ntype+"&placeName="+escape(pn));
    xhr.send(null);
}

function getPlaceResults() {
  if(xhr.readyState == 4) {    // check responseText
    if(xhr.status == 200){
      var data = xhr.responseText;      
      if (data!='') {
	      $('autocomplete_choices').style.display = 'block'; 
	      $('autocomplete_choices').innerHTML = data;
	    //  $('indicator1').style.display = "none";
	}      else {
		$('autocomplete_choices').style.display = 'none'; 
	      $('autocomplete_choices').innerHTML = data;
	}
    } else {
      $('autocomplete_choices').style.display = 'block'; 
      $('autocomplete_choices').innerHTML = "<p>Ajax Error</p>";
     // $('indicator1').style.display = 'none';
    }
  }
}

function frmPlaces2(formid) {
	var formid2 = 'placeName' + formid;
AREAS [formid2] = new Array ();
    sendPlace2(formid);
    return false;
}

function sendPlace2(formid) {
  var pn = $('placeName' + formid).value;
  
  if(pn == "" || pn == _placetext || pn.length <= 2) {
   // $('indicator1').style.display = 'none';
   formid = 'autocomplete_choices_' + formid;
    $(formid).style.display='none';
    return false;
  } else {
   // $('indicator1').style.display = 'block';  
  }
    if (formid == 'Buy') {
        var ntype = 'b';
        xhr = createXHR();
        xhr.onreadystatechange=getPlaceResultsBuy;
        xhr.open("GET", _ajaxurl+"?type="+ntype+"&placeName="+escape(pn) + "&formID=" + formid);
        xhr.send(null);
    } else {
        var ntype = 'r';
        xhr = createXHR();
        xhr.onreadystatechange=getPlaceResultsRent;
        xhr.open("GET", _ajaxurl+"?type="+ntype+"&placeName="+escape(pn) + "&formID=" + formid);
        xhr.send(null);
    }
}

var areaSearchCounter = new Array ();
var totalCounter = 0;
var formIDCounter = '';
var searchTimmer;
var searchTimmerCounter;

function frmPlaces4(formid) {
		$('autocomplete_choices' + formid).style.display = 'none';
		advanced = false;
		if (searchTimmer) {
                if (searchTimmerCounter) {
                        clearTimeout(searchTimmerCounter);
                }
                searchTimmerCounter = setTimeout ("frmPlaces4('"+formid+"');searchTimmer = false;", 400);
        } else {
                var formid3 = 'placeName' + formid;
                AREAS [formid3] = new Array ();
                areaSearchCounter = new Array ();
                totalCounter = 0;
                sendPlace3(formid);
                return false;
        }
}

var myTimer;

function frmPlaces3_timer (formid) {
	//alert (document.getElementById('placeName'+formid));
	if (document.getElementById('placeName'+formid).value.length >= 3) {
		if (myTimer) {
			clearTimeout(myTimer);
		}
		myTimer = setTimeout('frmPlaces3(\''+formid+'\');', 1500)
	}
}

function frmPlaces3(formid) {
	$('autocomplete_choices' + formid).style.display = 'none';
	advanced = true;
	/*if (searchTimmer) {
		if (searchTimmerCounter) {
        	clearTimeout(searchTimmerCounter);
		}
		searchTimmerCounter = setTimeout ("frmPlaces3('"+formid+"');searchTimmer = false;", 400);
	} else {*/
		var formid3 = 'placeName' + formid;
	    AREAS [formid3] = new Array ();
	    areaSearchCounter = new Array ();
	    totalCounter = 0;
	    sendPlace3(formid);
	    return false;
	//}
}

function sendPlace3(formid) {
  var pn = $('placeName'+formid).value;
  formIDCounter = formid;
  if((pn == "" || pn == _placetext || pn.length <= 2) && (!$('showday').checked)) {
  //if((pn == "" || pn == _placetext || pn.length <= 2) && ($('searchExtras').value != "showday") && ($('searchExtras').value != "privateTender")) {
        formid = 'autocomplete_choices' +formid;
        $(formid).style.display='none';
        if ($('property_count' +formid)) {
                $('property_count' +formid).innerHTML = "";
        }
        return false;
  } else {
                $('autocomplete_choices' + formIDCounter).innerHTML = "";
                searchTimmer = true;
                xhr = createXHR();
                xhr.onreadystatechange=getPlaceResults3;
                xhr.open("GET", _ajaxurl+"?" + $(formid).serialize ());
                xhr.send(null);
    }
}

function getPlaceResults3() {
  if(xhr.readyState == 4) {    // check responseText
    if(xhr.status == 200){
      var data = xhr.responseText;
       displayAreaSearchData (data);
    } else {
      //$('autocomplete_choices' + formIDCounter).style.display = 'block'; 
      //$('autocomplete_choices' + formIDCounter).innerHTML = "<p>Ajax Error</p>";
    }
  }
}

function UpperCaseWords(str) {
	return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase ( ); } );
}

function displayAreaSearchData (data) {
		var content = "\n<div id='jump_results_holder2' >";
        if (data!='0' || data=='') {
				eval ("data = " + data);
                content = content + "\n<div id=\"smartsearchheadermain2\" style='height:22px;'><div id=\"smartsearchheader\">&nbsp;&nbsp;<strong>Select the areas to add to your search:</strong></div> <div id=\"smartsearchheaderright\"><a href=\"javascript:void(0);\" onclick=\"document.getElementById('autocomplete_choices"+formIDCounter+"').style.display='none'\"><img alt='' border='0' src='http://www.rawson.co.za/site/images/autocomplete_close.gif' /></a></div><br style=\"clear:both\" /></div><div id=\"smartsearchpadding\">";
                var sRow = 1;
                for (xyz in data [1]) {
                        var datapart = data [1] [xyz];
                        if (datapart.length == 4) {
                                if (sRow) {
                                        sRow = 0;
                                        bgCol = "#F5F5F5;";	
                                } else {
                                        sRow = 1;
                                        bgCol = "#fef3a3;";	
                                }
                                
                                var data0='';
                                var data1='';
                                var data2='';
                                var data3='';
                               
                                data0=datapart[0].replace("'", "\\'");
                                data1=datapart[1].replace("'", "\\'");
                                data2=datapart[2].replace("'", "\\'");
                                data3=datapart[3].replace("'", "\\'");
                                
                                content = content + "<div style='background-color: " + bgCol + "' id='resultrow'>&nbsp;<input onclick=\"addCitySuburb3('"+data0+"', '"+data1+"', '"+data2+"', '"+formIDCounter+"', this);\" type=\"checkbox\" id=\"Areas[]\" name=\"Areas[]\" value=\""+data2+"|"+data1+"|"+data0+"\" />"+UpperCaseWords(datapart[2].toLowerCase()) + " [" + UpperCaseWords(datapart[1].toLowerCase()) + "] (<b><font color='#525252'>"+data3+"</font></b>)</div>\n";
                                
                                areaSearchCounter.push (datapart);
                                
                        }
                }
                content += "\n</div></div>";
		//totalCounter = data [0];
                //$('property_count' + formIDCounter).innerHTML = data [0] + " Found";
                totalCounter = 0;
                $('property_count' + formIDCounter).innerHTML = 0 + " Found";
				if ((data [0] > 0)) {
					if (advanced) {
						$('autocomplete_choices' + formIDCounter).style.display = 'block';
					} else {
						$('autocomplete_choices' + formIDCounter).style.display = 'none';
					}
				}
				$('autocomplete_choices' + formIDCounter).innerHTML = content;
                //totalCounter = data [0];
        } else {
                //content = content + "<div id=\"smartsearchpadding2\"><div id='jump_no_results' ><span class='jump_no_results' >No Property found!</span></div><div id=\"smartsearchheaderright\"><a href=\"javascript:void(0);\" onclick=\"document.getElementById('autocomplete_choices"+formIDCounter+"').style.display='none'\"><img alt='' border='0' src='../images/autocomplete_close.gif' /></a></div><br style=\"clear:both\" /></div></div>";
                $('autocomplete_choices' + formIDCounter).style.display = 'none';
				content = content + "\n<div id=\"smartsearchheadermain2\" style='height:22px;'><div id=\"smartsearchheader\">&nbsp;&nbsp;<strong>No Property found!</strong></div> <div id=\"smartsearchheaderright\"><a href=\"javascript:void(0);\" onclick=\"document.getElementById('autocomplete_choices"+formIDCounter+"').style.display='none'\"><img alt='' border='0' src='../images/autocomplete_close.gif' /></a></div><br style=\"clear:both\" /></div><div id=\"smartsearchpadding\">";
                content += "\n</div>";
                $('autocomplete_choices' + formIDCounter).innerHTML = content;
                $('property_count' + formIDCounter).innerHTML = "0 Found";
                totalCounter = 0;
        }
}

function isdefined( variable) {
    return (typeof(window[variable]) == "undefined")?  false: true;
}


function getPlaceResultsBuy() {
  if(xhr.readyState == 4) {    // check responseText
    if(xhr.status == 200){
      var data = xhr.responseText;
        if (data!='') {
            $('autocomplete_choices_Buy').style.display = 'block'; 
            $('autocomplete_choices_Buy').innerHTML = data;
		    //  $('indicator1').style.display = "none";
		} else {
            $('autocomplete_choices_Buy').style.display = 'none'; 
            $('autocomplete_choices_Buy').innerHTML = data;
		}
      
    } else {
      $('autocomplete_choices_Buy').style.display = 'block'; 
      $('autocomplete_choices_Buy').innerHTML = "<p>Ajax Error</p>";
     // $('indicator1').style.display = 'none';
    }
  }
}

function getPlaceResultsRent() {
  if(xhr.readyState == 4) {    // check responseText
    if(xhr.status == 200){
      var data = xhr.responseText;
		if (data!='') {
		$('autocomplete_choices_Rent').style.display = 'block'; 
		$('autocomplete_choices_Rent').innerHTML = data;
		//  $('indicator1').style.display = "none";
		} else {
		$('autocomplete_choices_Rent').style.display = 'none'; 
		$('autocomplete_choices_Rent').innerHTML = data;
		}
      
    } else {
      $('autocomplete_choices_Rent').style.display = 'block'; 
      $('autocomplete_choices_Rent').innerHTML = "<p>Ajax Error</p>";
     // $('indicator1').style.display = 'none';
    }
  }
}

function createXHR() {
  var xhr;
  try {
    xhr = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xhr = false;
    }
  }
  if (!xhr && typeof XMLHttpRequest != ' undefined' ) {
    xhr = new XMLHttpRequest();
  }
  return xhr;
}

function changeLink(type) {
  ntype = type;
  $('typepassed3').value = type ;
  $('typepassed1').value = type ;
  frmPlaces();
} //changeLink

var node;
var nodes;
function navToggleFixerIE ()
{
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if ((version >= 5.5) && (document.body.filters)) 
	{
                  var navigation = $('TopNavigation');
                  
                  nodes = navigation.childNodes;
                  for ( var i = 0;i < nodes.length; i++ )
                  {
                        //if (node = nodes[i].childNodes[0]) {
                                     node = nodes[i].childNodes[0].childNodes; 
                                    // IF NAV HAS A DROP DOWN
                                    //alert ( node [0].title + " " + node.length)
                                    if (node && node.length == 4)
                                    {
                                          //REPLICATE CSS
                                          /* node[3].onmouseover = function (){
                                            this.style.display = "block";
                                          };
                                          node[3].onmouseout = function (){
                                            this.style.display = "none";
                                          };*/
                                          
                                          nodes[i].onmouseover = function (){
                                            if(this.childNodes[0].childNodes[3]) this.childNodes[0].childNodes[3].style.display = "block";
                                          };
                                          nodes[i].onmouseout = function (){
                                            this.childNodes[0].childNodes[3].style.display = "none";
                                          };
                                          
                                    }
                        //}
                  }
	}
}

/*******************************
@ TOGLE TAB APPLET LAYERS
@ PRAMS
	int 		activeindex		[index of tab to be activated]
	string 	tabprefix			[prefix for tab header]
	string 	paneprefix		[prefix for tab  pane divs]
	string 	activeurl			[ajaxcall for tab to be activated]
	string 	actiview			[value for active view]
	string 	searchform		[id for search again for]
	function 	java				[additional script to be executed on activated tab]
*******************************/
function tabCleanOut (activeobject,activeindex,tabprefix,paneprefix,activeurl,activeview,searchform,java,jdata,serialdata, inactivecss, activecss,useajax, chimg, firstload) {
	var cnt = 1;
	var TTAB;
	var TPANE;
	var ATAB = $(tabprefix + activeindex);
	var APANE = $(paneprefix + activeindex);
	var FORM = $(searchform);
	//alert (activecss + "1 => " + ATAB.className)
	if (ATAB.className == activecss && firstload != "1") {
		return;
	}
	//alert (ATAB)
	while ($(tabprefix + cnt) && $(paneprefix + cnt) && cnt < 100) {
		TTAB = $(tabprefix + cnt);
		var ccnt = 0;

		if (TTAB.childNodes && chimg) {
			while (TTAB.childNodes [ccnt] ) {
				if (TTAB.childNodes [ccnt].tagName ) {
					if ( TTAB.childNodes [ccnt].tagName.toLowerCase() == "img") {
						if (TTAB.id == ATAB.id) {
							TTAB.childNodes [ccnt].className = "tabActive";
						} else {
							TTAB.childNodes [ccnt].className = "tabInactive";
						}
						
					} else if (TTAB.childNodes [ccnt].tagName.toLowerCase() == "span") {
                                                var filterText = TTAB.childNodes [ccnt].style.filter;
                                                if (TTAB.id == ATAB.id) {
                                                        TTAB.childNodes [ccnt].ClassName = "tabActive";
						} else {
                                                        //if (!filterText.match ('_off.png')) {
							        TTAB.childNodes [ccnt].className = "tabInactive";
                                                        //}
						}
                                        }
				}
				ccnt ++;
			}
		}
		TPANE = $(paneprefix + cnt);
		if (TTAB.className != inactivecss) {
			TTAB.className = inactivecss;
			TPANE.style.display = "none";
		}
		cnt ++;
	}
	
	ATAB.className = activecss;
	APANE.style.display = 'block';
	var ccnt = 0;
	
	/*
	if (APANE.childNodes && chimg) {
		while (APANE.childNodes [ccnt] ) {
			// bottom was APANE
			try{
				if (ATAB.childNodes [ccnt].tagName ) {
					if ( ATAB.childNodes [ccnt].tagName.toLowerCase () == "img") {
						if (ATAB.className == activecss) {
							ATAB.childNodes [ccnt].src = "../images/tab_" +activeview+ ".png";
						} else {
							ATAB.childNodes [ccnt].src = "../images/tab_" +activeview+ "_off.png";
						}
						
					}
				}
			}
			catch(e){ }
			ccnt ++;
		}
	}
	*/
	if (FORM ) {
		//FORM.view.value = activeview;
		//alert(activeview);
	}
	
	if (activeurl != '' && activeurl != null) {
		var url =activeurl; 
		if (serialdata) serialdata['view'] = activeview;
		var ajx = new Ajax.Request(url, {
			 method: 'POST', 
			 parameters : serialdata,
			onSuccess: function(transport) {  	
				var data = transport.responseText; 
				APANE.innerHTML = data;
                                if ($('loader_div')) {
				        			document.getElementById('loader_div').style.display = 'none'; 
                                }
                                if ($('ccontainer')) {
				        $('ccontainer').style.height = "auto";
                                }
			},
			onFailure: function(transport) {
				//alert ("SCRIPT NOT FOUND");
			}
		});
	}
	
	if (java) {
		java(jdata);
	}
		
	activeobject.onclick = function () {
		if (!useajax) {
			activeurl = null;
			java = null;
			jdata = null;
			serialdata = null;
		}
		tabCleanOut (activeobject,activeindex,tabprefix,paneprefix,activeurl,activeview,searchform,java,jdata,serialdata, inactivecss, activecss,useajax,chimg);
		java = null; 
	};
	
	setTimeout('fixer();', 500);	
}

function showMore() {
	if (document.getElementById('MoreCriteria').style.display=='none') {
        document.getElementById('MoreCriteria').style.display='block';
        document.getElementById('MoreCriteriaLink').innerHTML='- Show Me More Criteria';
    } else {
        document.getElementById('MoreCriteria').style.display='none';
        document.getElementById('MoreCriteriaLink').innerHTML='+ Show Me More Criteria';
    }
}

var AREAS = {};
function addCitySuburb2(prov,city,town,formid) {
	
	var formid2 = 'placeName' + formid;
	AREAS[formid2] = new Array ();    	
	$(formid2).value= town + ' [' + city + ' - ' + prov + ']';
    var countyID = 'County' + formid;
    var cityID = 'City' + formid;
    var townID = 'Town' + formid;
	$(countyID).value=prov;
	$(cityID).value=city;
	$(townID).value=town;
	$('jump_results_holder').style.display="none";
}
function addCitySuburb3(prov,city,town,formid,obj) {
	var formid2 = 'placeName' + formid;
	
	if (!AREAS[formid2]) {
		AREAS[formid2] = new Array ();
	}
	
	if (obj.checked == true) {
		AREAS[formid2].push (town); 
		totalCounter +=  getAreaAmount (prov,city,town);
		if (AREAS[formid2].length == 1) {
        		//totalCounter = getAreaAmount (prov,city,town);
		} else {
			//totalCounter = totalCounter + getAreaAmount (prov,city,town);
		}
		
		
	} else {
		for (var i in AREAS[formid2]) {
			if (AREAS[formid2] [i] == (town)) {
				AREAS[formid2].splice (i,1);	
			}
		}
		totalCounter -= getAreaAmount (prov,city,town);
	}
	
	$(formid2).value = AREAS[formid2].join (",");
	$('property_count' + formid).innerHTML = totalCounter + " Found";
}

function getAreaAmount (prov,city,town) {
	for (var i in areaSearchCounter) {
		if (areaSearchCounter [i] [0] == prov && areaSearchCounter [i] [1] == city && areaSearchCounter [i] [2] == town) {
                        return (parseInt (areaSearchCounter [i] [3]));
                }
        }
}

function switchtype(type, part) {
        ctype = type;
        var ptype = (type=='b') ? 'Buy' : 'Rent' ;
        var mini = $('minprice' + part);
        var maxi = $('maxprice' + part);


        var minlen = mini.childNodes.length;
        var maxlen = maxi.childNodes.length;

        if(minlen > 1) {
                for(var g=0;g<minlen;g++) {
                        mini.removeChild(mini.firstChild);
                }
                for(var j in mins[type]) {
                        var oOption2 = document.createElement("option");
                        if(j != 'toJSONString') {
                                oOption2.value = j;
                                oOption2.innerHTML = mins[type][j];
                                mini.appendChild(oOption2);
                        }
                }
        }

        if(maxlen > 1) {
                for(var g=0;g<maxlen;g++) {
                        maxi.removeChild(maxi.firstChild);
                }
                for(var j in maxs[type]) {
                        var oOption3 = document.createElement("option");
                        if(j != 'toJSONString') {
                                oOption3.value = j;
                                oOption3.innerHTML = maxs[type][j];
                                maxi.appendChild(oOption3);
                        }
                }
        }
}

function addCitySuburb(prov,city,town)
{
	$('placeNames').value= town + ' [' + city + ' - ' + prov + ']';
	$('County').value=prov;
	$('City').value=city;
	$('Town').value=town;
	$('jump_results_holder').style.display='none';
}

function cform() {
	var list = '';
	if (id$('type').options[id$('type').selectedIndex].value == '') {
		list += ' Property Type \\n ';
	}
	if (list!='') {
		alert ('The following field(s) are required:\\n\\n' + list);
		return false;
	}

	document.frmqs.submit();
	return true;
}

function changeLink(type) {
	$('advsearchlink').href = '/'+dirOnly+'/search/full.php?type='+type;
} 

function toggleSearchAgain() 
{
	var s = $('SearchAgainTr').style;
	if (s.display == 'none' || s.display == '') {
		$('SearchAgain').innerHTML = "[-] Search Again";

		if (window.attachEvent) {
			s.display = 'block';
		} else {
			s.display = 'table-row';
		}
	} 
	else {
		$('SearchAgain').innerHTML = "[+] Search Again";
		s.display = 'none';
	} 
	fixMoreBlock();
}

var dropTimer;
var place_name;
var place_dropdown;

function showPropertyTypes (obj) {
        place_name = obj;
        place_dropdown = $(obj.id.replace ('_Names','_Dropdown'));
        if (place_dropdown) {
                place_dropdown.style.display='block';
                dropTimer = setTimeout ("place_dropdown.style.display='none'", 5000);
        }
}

function selectPlace (obj) {
        clearTimeout(dropTimer);
        dropTimer = setTimeout ("place_dropdown.style.display='none'", 5000);
        if (obj.checked) {
			if (place_name.value.length > 1) {
				place_name.value = place_name.value + ", " + obj.value;
			} else {
				place_name.value = place_name.value + obj.value;
			}
        } else {
                place_name.value = place_name.value.replace (obj.value + ", ","");
				place_name.value = place_name.value.replace (obj.value,"");
        }
}

function UpdateMap (frame, source) { 
	document.getElementById(frame).src = source;
}

function loadContent () {
        if ($('SEARCH_TAB_1')) {
                tabCleanOut ($('SEARCH_TAB_1'),1,'SEARCH_TAB_','SEARCH_PANE_','/' +dirOnly+ '/ajax/ajax_search_tabs.php?view=property_search&source=search','property_search','null',null,null,null, 'inactive_tab', 'active_tab',null,1,'1');
        }
}

function fnb_popup (form, type) {
        var url = '/'+dirOnly+'/ajax/ajax_fnb_sales.php?type='+type+'&form='+form;
	
        var ajx = new Ajax.Request(url, {
			 method: 'POST', 
			 parameters : '',
			onSuccess: function(transport) {  	
				var data = transport.responseText; 
				$(form+"_popup").style.display = 'block';
				$(form+"_popup").innerHTML = data;
			},
			onFailure: function(transport) {
				//alert ("SCRIPT NOT FOUND");
			}
        });
}

//This array is used to store all the id's needed for the quick search
FNBAREAIDS = new Array ();
function fnbQuickSelection (ids, checkbox) {
        
        /* if the checkbox is NOT seleced */
        if (document.getElementById(checkbox).checked) {
                
                // Add the ids to the javascript array
                FNBAREAIDS.push(ids);
        
        /* if the checkbox IS seleced */
        } else {
                
                // Loop threw the array
                for (var i in FNBAREAIDS) {
			//If the id already xsists in the array
                        if (FNBAREAIDS [i] == (ids)) {
                                // remove the ids from the javascript array
				FNBAREAIDS.splice (i,1);	
			}
		}
        }
        
        // Make the value of the hidden input equal to the array
        document.getElementById('ids2').value = FNBAREAIDS.join (",");
        
}