function SubmitForm (form) {
	//Hack added by Shaheed. This removes Staging or Site from the path that the form posts to..
    document.forms[form].action = document.forms[form].action.replace(DIRONLY + "/", "");
    setTimeout ("document.forms['" + form + "'].submit();", 500);
}

var arrowR;
var arrowD;
function Toggle_Div_Content( div2expand, arrowRight, arrowDown) {
	arrowR = arrowRight;
	arrowD = arrowDown;
	if( document.getElementById( div2expand ).style.display == 'block') { 
		DropUp_Effect( div2expand);
	} else {
		document.getElementById( div2expand + "_Content").style.display = 'block';
		document.getElementById( div2expand ).style.display = 'block';
		// Arrow down.
        document.getElementById( 'TabArrow_'+div2expand ).src = arrowD;
		DropDown_Effect( div2expand);
	}
}

function Toggle_Div_Edit(div2expand) {
	if( document.getElementById(div2expand).style.display == 'block') { 
		// Do Effect
                if (isNaN(parseInt (document.getElementById( div2expand).style.height))) {
                        document.getElementById( div2expand).style.height = parseInt (document.getElementById( div2expand).scrollHeight) + "px";
                }
		DropUp_Effect(div2expand);
		//document.getElementById( div2expand ).style.borderTop = '1px solid #B7B7B7';
	} else {
                if (document.getElementById( div2expand ).innerHTML == "") {
                        getObjectEdit (div2expand);
                } else {
                        // Do Effect
                        document.getElementById( div2expand ).style.display = 'block';
                        document.getElementById( div2expand.replace ("_Edit","") ).style.display = 'block';
                        //document.getElementById( 'RC_'+div2expand.replace ("_Edit","") ).style.display = 'block';
                        document.getElementById( div2expand ).style.height = '0px';
                        
                        document.getElementById( div2expand ).style.display = 'block';
                        document.getElementById( div2expand.replace ("_Edit","") ).style.display = 'block';
                        document.getElementById( div2expand.replace ("_Edit","_Content") ).style.display = 'block';
                        //document.getElementById( 'RC_'+div2expand.replace ("_Edit","") ).style.display = 'block';
                        if (isNaN(parseInt (document.getElementById( div2expand.replace ("_Edit","") ).style.height)) || parseInt (document.getElementById( div2expand.replace ("_Edit","") ).style.height) < 10) {
                                document.getElementById( div2expand ).style.height = "auto";
                                //document.getElementById( div2expand ).style.height = document.getElementById( div2expand ).scrollHeight;
		                DropDown_Effect(div2expand.replace ("_Edit",""));
                        } else {
                                DropDown_Effect(div2expand);
                        }
                        //document.getElementById( div2expand.replace ("_Edit","") ).style.height = 'auto';
                }
		//document.getElementById( div2expand ).style.borderTop = 'none';
	}
}

var Height = 0;
var scrollInterval = "";

function DropDown_Effect( div ) {
	clearInterval( scrollInterval );
	setTimeout("BeginScrollDown('" +div+ "');", 40);
}

function DropUp_Effect( div ) {
	clearInterval(scrollInterval);
	scrollInterval = setInterval("DropUp('" +div+ "');", 10);
}

function DropUp( div ) {
	if( parseInt(document.getElementById( div ).style.height) > 0 ) {
                if (div.match ("_Edit")) {
                        if (document.getElementById( div.replace ("_Edit","") )) {
                                //if (parseInt(document.getElementById( div.replace ("_Edit","") ).style.height) > 0) {
                                        //document.getElementById( div.replace ("_Edit","") ).style.height = (parseInt(document.getElementById( div.replace ("_Edit","") ).style.height) - 8) + "px";
                                        //document.getElementById( div ).style.height = parseInt(document.getElementById( div ).style.height) - 8 + "px";
                                //} else {
                                        document.getElementById( div ).style.height = parseInt(document.getElementById( div ).style.height) - 8 + "px";
                                //}
                                
                                if (parseInt(document.getElementById( div ).style.height) < 10) {
                                        document.getElementById( div ).style.height = 0;
                                }
                        }
                } else {
                        document.getElementById( div ).style.height = parseInt(document.getElementById( div ).style.height) - 8 + "px";
                }
	} else {
		Height = 0;
		clearInterval(scrollInterval);
                if (document.getElementById( 'TabArrow_'+div )) {
                        //document.getElementById( 'TabArrow_'+div ).src = 'images/tab_arrow_right.gif';
						// Arrow right
						document.getElementById( 'TabArrow_'+div ).src = arrowR;
                }
                if (document.getElementById( 'RC_'+div )) {
                        document.getElementById( 'RC_'+div ).style.display = 'none';
                }
                if (document.getElementById( div )) {
                        document.getElementById( div ).style.display = 'none';
                }
                if (document.getElementById( div + "_Edit" )) {
                        document.getElementById( div + "_Edit" ).style.display = 'none';
                }
	}
}	

function BeginScrollDown( div ) {
	var ScrollHeight = document.getElementById( div ).scrollHeight;
	scrollInterval = setInterval("DropDown('" +ScrollHeight+ "', '" +div+ "');", 10);
}

function DropDown( ScrollHeight, div ) {
	if( Height < ScrollHeight ) {
		Height = Height + 8;
                if (div.match ("_Edit")) {
                        if (document.getElementById( div.replace ("_Edit","") )) {
                                //if (parseInt(document.getElementById( div.replace ("_Edit","") ).style.height) > 0) {
                                        //document.getElementById( div.replace ("_Edit","") ).style.height = (parseInt(document.getElementById( div.replace ("_Edit","") ).style.height) + 8) + "px";
                                        //document.getElementById( div ).style.height = Height + "px";
                                //} else {
                                        document.getElementById( div ).style.height = Height + "px";
                                //}
                        }
                } else {
                        document.getElementById( div ).style.height = Height + "px";
                }
	} else {
		Height = 0;
		clearInterval(scrollInterval);
	}
}

function Toggle_Subnav(navobj) {
	document.getElementById( navobj ).style.display = 'block';
}

function Hide_Subnav() {
	document.getElementById( 'SN_ContactUs' ).style.display = 'none';
}

function Greeting_Message() {
	var dN = new Date();
	var Message = "<h7>Good ";
	if( dN.getHours() < 12 ) {
		/* Twelve in the Morning */
		Message = Message + "Morning, ";
	} else if( dN.getHours() < 17 ) {
		/* Nine in the Morning */
		Message = Message + "Afternoon, ";
	} else {
		Message = Message + "Evening, ";
	}
	
	Message = Message + "find your ideal home in and around the Western Cape</h7>";
	document.getElementById('Greeting_Message').innerHTML = Message;
}

function C_Tab( div ) {
	/* var HTML_FORM = <?= json_encode ($FORM_TABS) ?>; */
	var jtpane = new JTabbedPane ({relitive : div,
		navcss : "tab_div",
    	panelcss : "tabed_content_div",
	    	jtsets : [
	        	new JTabSet (null,new JTab ({
	        		name : "residential",
					active : "active_tab",
					inactive : "inactive_tab",
					CPane : new JContentPane ({
						HTML : HTML_FORMS ['residential_search'],
						css : "panel"
					})
				})),
                        new JTabSet (null,new JTab ({
	        		name : "developments",
					active : "active_tab",
					inactive : "inactive_tab",
					CPane : new JContentPane ({
						HTML : HTML_FORMS ['development_search'],
						css : "panel"
					})
				})),
                                new JTabSet (null,new JTab ({
	        		name : "sell",
					active : "active_tab_sell",
					inactive : "inactive_tab_sell",
					CPane : new JContentPane ({
						HTML : HTML_FORMS ['sell_search'],
						css : "panel"
					})
				}))
			]
		});
			
	jtpane.create();
}

function C_Tab_Ajaxed( div ) {
	/* var LINK = <?= json_encode ($FORM_TABS) ?>; */
	var tab_array = [];
	for( key in LINK ) {
		tab_array.push(
			new JTabSet (null,new JTab ({
		    	// name : "Residential",
				name : key,
				active : "active_tab_residential",
				inactive : "inactive_tab_residential",
				javadata : LINK  [key],
				onjavacode : function (data) {
					$(data ['searchagain']).view.value = data ['listview']; 
				},
				CPane : new JContentPane ({
					url : LINK[key]['ajax'],
					HTML : LINK[key]['html'],
					css : "panel_residential"
				})
			}))
		)
	}

	var jtpane = new JTabbedPane ({relitive : div,
		activeindex: ACTIVE_INDEX,
		navcss : "tab_div",
    	panelcss : "tabed_content_div_residential",
	    	jtsets : tab_array
		});
			
		jtpane.create();
}

function Toggle_Div_Visibility( div, image ) {
	if( document.getElementById(div).style.visibility == 'visible' ) {
		document.getElementById(div).style.visibility = 'hidden';
		document.getElementById(div).style.display = 'none';
		if(image.length > 0) {
                        var theImage = document.getElementById(image);
			if (theImage) {
			        theImage.src = search_arrow_right;
                        }
		}
	} else {
		document.getElementById(div).style.visibility = 'visible';
		document.getElementById(div).style.display = 'block';
		if(image.length > 0) {
                        var theImage = document.getElementById(image);
			if (theImage) {
                                theImage.src = search_arrow_down;
                        }
		}
	}
}
height = 0
function toggle_hide_show_div ( div ) {
    if( document.getElementById( div ).style.display == 'block') { 
		document.getElementById( div ).style.display = 'none';
	} else {
                document.getElementById( div ).style.display = 'block';
    }
}

function Toggle_Contact( div, image ) {
	if( document.getElementById( div ).style.visibility == 'hidden' ) {
		document.getElementById( div ).style.visibility = 'visible';
		if( image.length > 0 ) {
			document.getElementById(image).src = search_arrow_down;
		}
	} else {
		document.getElementById( div ).style.visibility = 'hidden';
		if( image.length > 0 ) {
			document.getElementById(image).src = search_arrow_right;
		}
	}
}

function Toggle_Contact2( div, image ) {
	if( document.getElementById( div ).style.display == 'none' ) {
		document.getElementById( div ).style.display = 'block';
		if( image.length > 0 ) {
			document.getElementById(image).src = search_arrow_down;
		}
	} else {
		document.getElementById( div ).style.display = 'none';
		if( image.length > 0 ) {
			document.getElementById(image).src = search_arrow_right;
		}
	}
}

function Toggle_arrow( div, image, right, down) {
	if (document.getElementById( div )) {
                if( document.getElementById( div ).style.display == 'none' ) {
                        document.getElementById( div ).style.display = 'block';
                        if( image.length > 0 ) {
                                document.getElementById(image).src = down;
                        }
                } else {
                        document.getElementById( div ).style.display = 'none';
                        if( image.length > 0 ) {
                                document.getElementById(image).src = right;
                        }
                }
        }
}

function close_control(obj,t) {
	destroyMapBackSession(t);
	if( obj.style.display == 'block' ) {
		obj.style.display = 'none';
	} else {
		obj.style.visibility = 'hidden';
	}
}

function navHover (obj) {
        if (obj.className.match ("_on")) {
                obj.className = obj.className.replace ("_on", "");
        } else {
                obj.className = obj.className + "_on";
        }
}

/*******************************
@ 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, extra) {
        
        // The tabOpen variable tells us which tab we are on.. used to refresh the saved list; file: search/index.php
        tabOpen = activeindex;
        
        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 && extra != 'load') 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") {
						TTAB.childNodes [ccnt].src = "images/tab_" +TTAB.childNodes [ccnt].name + "_off.png";
					}
				}
				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") {
						ATAB.childNodes [ccnt].src = "images/tab_" +activeview+ ".png";
					}
				}
			}
			catch(e){ }
			ccnt ++;
		}
	}
	if (FORM ) {
		//FORM.view.value = activeview;
		//alert(activeview);
	}
	
	if (activeurl != '' && activeurl != 'null' && 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;
                                
                                var newData = data.split("###--!--This will be intercepted by the tabcleanout function--!--###");
                                
                                APANE.innerHTML = newData[0];
                                if (newData[1]!=undefined) {
                                        eval(newData[1]);
                                } else {
                                        // Do nothing
                                }
                                
				if ((typeof campaign_wait !== "undefined") && campaign_wait) {
					campaign_wait=false;
					runCampaigns(campaign_remembered_num, campaign_remembered_affects, campaign_remembered_time);
				}
				if (document.getElementById('loader_div')) {
					document.getElementById('loader_div').style.display = 'none'; 
					$('ccontainer').style.height = "auto";
                                } else {
                                        //alert('problem with loader');
                                }
			},
			onFailure: function(transport) {
				//alert ("SCRIPT NOT FOUND: " + activeurl);
			}
		});
	}
	
	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,extra);
		java = null; 
	};
	
	setTimeout('fixer();', 500);
	setTimeout('initLytebox();', 2000);
}

function toggleSelect (BASE_ID,ACTION) {
	var cnt = 1;
//	alert ($(BASE_ID + cnt));
	while ($(BASE_ID + cnt) && cnt < 50) {
		if (ACTION == "select") {
			$(BASE_ID + cnt).checked = "checked";
		} else {
			$(BASE_ID + cnt).removeAttribute ("checked");
			$(BASE_ID + cnt).checked = false;
		}
		cnt ++;
	}
}

function Refine_Search_Text( ) {
	document.getElementById('refine_container').style.width = "150px";
	document.getElementById('refine_search_link').innerHTML = "<b>REFINE YOUR SEARCH</b>";
	document.getElementById('pagination_orderby_div10').style.display = "block";
	document.getElementById('paginationdiv10').style.display = 'block';
}

function updateMapSearch (obj,formID) {
	
	var values=obj.value.split("|");
	
	//alert (formID + "COUNT");
	
	var totals=parseInt($(formID + "COUNT").value);
	var map_totals=parseInt($(formID + "propertieswithxys").value);

        if ($(formID + "suburb_ids").value.match (values[0])) {
               $(formID + "suburb_ids").value = $(formID + "suburb_ids").value.replace (values[0],"");
	       totals-=parseInt(values[2]);
	       map_totals-=parseInt(values[3]);
        } else {
		if ($(formID + "suburb_ids").value=="") {
			$(formID + "suburb_ids").value = values[0];
		} else {
		$(formID + "suburb_ids").value = $(formID + "suburb_ids").value + "|" + values[0];
	       }
	       totals+=parseInt(values[2]);
	       map_totals+=parseInt(values[3]);
        }
        $(formID + "suburb_ids").value = $(formID + "suburb_ids").value.replace ("||","|");


        var temp = $(formID + "suburb_ids").value.split("|");
        var temp2 = new Array ();
        for (var i = 0; i < temp.length; i++) {
                if (temp [i]) {
                        temp2 [i] = temp [i];
                }
        }
        $(formID + "suburb_ids").value = temp2.join ("|");
	
        if (totals==0 || totals > 150) {
                $(formID + "total_prop_colour").style.color="#" + NONE_FOUND_NUMBERS_COLOUR;
        } else {
		$(formID + "total_prop_colour").style.color="#" + FOUND_NUMBERS_COLOUR;
	}
	
	$(formID + "total_prop_count").innerHTML=totals;
	
	$(formID + "COUNT").value=totals;
	$(formID + "propertieswithxys").value=map_totals;
	
}

/*
function updateMapSearch (obj,formID) { 
	var ajx = new Ajax.Request("ajax/ajax_join_area_names.php", {
	method: 'POST',
	parameters : $( formID + "areas_form").serialize(),
	onSuccess: function(transport) {
		data = transport.responseText;
			$(formID).location.value = data;
			$(formID).minprice.onchange();
		},
		onFailure: function(transport) {
			alert ("SCRIPT NOT FOUND");
		}
	});
}
*/

function fireEvent(element, eventName) {
	evt = element[eventName];
	alert (element.onclick);;
	alert (element.click);
	if (typeof(evt) == "function") {
		document.getElementById(element)[eventName]();
	} else {}
}


function selectAll(id, formID) {
        areas = document.forms["areas_form"][id];
        if (areas.length) {
                for (i = 0; i < areas.length; i++) {
                        areas[i].checked = true;
                        updateMapSearch (areas[i]);
                }
        } else {
                areas.checked = true;
                updateMapSearch (areas);
        }
        refineMapSearch (formID);
}

function clearAll(id, formID) {
        areas = document.forms["areas_form"][id];
        if (areas.length) {
                for (i = 0; i < areas.length; i++) {
                        areas[i].checked = false;
                        updateMapSearch (areas[i]);
                }
        } else {
                areas.checked = false;
                updateMapSearch (areas);
        }
        refineMapSearch (formID);
}

function getMapSearchLoader(p) {
	if (!p) p="";
	document.getElementById('map_search_ajax' + p).style.display = 'block'; 
	document.getElementById('map_search_ajax'+ p).innerHTML = "<center><div id=\"loader_div\" style=\"height: 297px; background-color: #FFF; margin-top: 156px; width: 414px; z-index: 120; font-size: 18px;\"><img src=\"" + loading_image + "\" border=\"0\" alt=\"\" title=\"\" /><br/><span style=\"font-size: 12px;\">Loading ...</span></div></center>";
}

function Change_ddlView(value) {
	switch(value) {
		case "in a list":
		case "saved":
			// setcookie: in list
			$('view').value = 'list';
			break;
			
		case "gallery":
			// setcookie: gallery
			$('view').value = 'gallery';
			break;
			
		case "on a map":
			// setcookie: map
			$('view').value = 'onmap';
			break;
			
		case "table":
			// setcookie: table
			$('view').value = 'intable';
			break;
	}
	
	alert( $('view').value );
	
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function displayAsMainImage (obj, flag, src, displayPassedSource) {

        if (flag == 1) {
                selected = 'dev_thumbnail_pics_selected';
                norm = 'dev_thumbnail_pics';
        } else if (flag == 2) {
                selected = 'image_small_selected';
                norm = 'image_small';
        }
        
        var topImage = document.getElementById ('Top_Image');
        var bottomImage = document.getElementById ('Bottom_Image');
        if (topImage.src != obj.src) {
                if (indexSmallPhoto) {
                        //set the default border of the thumbnail.
                        indexSmallPhoto.className = norm;
                } else {
                        document.getElementById ('Small_Photo_0_0').className = norm;
                }
                indexSmallPhoto = obj;
                indexSmallPhoto.className = selected;
                //setting the bottom image to the top.. used as a placeholder.
                bottomImage.src = topImage.src;
                //fade in the new image.
                changeOpac (1,'Top_Image');
                //display the new image.
                bottomImage.style.display = "block";
                if (displayPassedSource=="yes") {
                        topImage.src = src;
                } else {                        // I don't know who or why used the bottom method. I added the if statement and "displayPassedSource" not to break whatever there madness has intented # Shaheed 04 June 2010
                        topImage.src = obj.src;
                }
                
                if (!changeInProgress) {
                        opacity ('Top_Image',1,100, 1000);
                }
                if ($("image_info") && $(indexSmallPhoto.id + "_info")) {
                        $("image_info").innerHTML = $(indexSmallPhoto.id + "_info").innerHTML;
                }
                
                if ($('Top_Image_Link')) {
                        if (!src)  {
                                src = topImage.src;
                        }
                        $('Top_Image_Link').href = src;
                        $('Top_Image_Link').rel = "lightbox[" +src+"]";
                        $('Top_Image_Link').title = indexSmallPhoto.title;
                }
        }
}

function DevelopmentShowMore(container, height, image) {
	
        if( parseInt($(container).style.height) == height ) {
		$(container).style.height = $(container).scrollHeight + "px";
		$(image).src = showMeMore;
	} else {
		$(container).style.height =	height + "px";
		$(image).src = showMeLess;
	}
}

function Complete_LS(value, checkbox, form) {
	form = $(form);
	if(checkbox.checked) {
		if($('txtLS').value.length==0) {
			form.txtLS.value=value;
			form.lifestyleids.value=value;
		} else {
			form.txtLS.value=form.txtLS.value + ", " + value;
			form.lifestyleids.value=form.lifestyleids.value + "|" + value;
		}
	} else {
		form.txtLS.value=form.txtLS.value.replace(', '+value, '');
		form.txtLS.value=form.txtLS.value.replace(value, '');
		
		form.lifestyleids.value=form.lifestyleids.value.replace('|'+value, '');
		form.lifestyleids.value=form.lifestyleids.value.replace(value, '');
	}
}

function completePTypes(value, checkbox,form) {
	form = $(form);
	if(checkbox.checked) {
		if(form.textptypes.value.length==0) {
			form.textptypes.value=value;
			form.property_type.value=checkbox.value;
		} else {
			form.textptypes.value=form.textptypes.value + ", " + value;
			form.property_type.value=form.property_type.value+ "|" + checkbox.value;
		}
	} else {
		form.textptypes.value=form.textptypes.value.replace(', '+value, '');
		form.textptypes.value=form.textptypes.value.replace(value, '');
		
		form.property_type.value=form.property_type.value.replace('|'+checkbox.value, '');
		if (form.property_type.value.match ("|")) form.property_type.value=form.property_type.value.replace(checkbox.value, '');
	}
}

function openContactDiv (div) {
        if ($(div).style.display == 'none') {
             $(div).style.display = 'block';
        }
}

function toggle_divs (div1, div2) {
        var div1st = $(div1);
        var div2nd = $(div2);
        if (div1st.style.display == 'block') {
                div1st.style.display = 'none';
                div2nd.style.display = 'block';
        } else if (div1st.style.display == 'none') {
                div2nd.style.display = 'none';
                div1st.style.display = 'block';
        }
}

function Verify_Dev_List() {
	if( $('id').value.length < 1){
		$('valid_development_div').style.visibility = 'visible';
		setTimeout( "Show_Valid_Dev_Div();", 5000 );
		return false;
	} else {
		return true;
	}
}

function Show_Valid_Dev_Div() {
	$('valid_development_div').style.visibility = 'hidden';
}

/*function checkFullDetailsHeight () {
        if ($('full_details_information')) {
                if ($('full_details_information').scrollHeight - 20 > parseInt ($("full_details_information").style.height)) {
                        if ($('full_details_information_more')) {
                                $('full_details_information_more').style.display = "block";
                        }
                } else {
                        $("full_details_information").style.height = "auto";
                }
        }
}*/

function show_more_full_details () {
        if ($('full_details_information_summary')) {
                if ($('full_details_information_summary').style.display == "block") {
                        $('full_details_information_summary').style.display = "none";
                        $('full_details_information_full').style.display = "block";
                        $('full_details_information_more').innerHTML = $('Show_More_On').innerHTML;
                } else {
                        $('full_details_information_summary').style.display = "block";
                        $('full_details_information_full').style.display = "none";
                        $('full_details_information_more').innerHTML = $('Show_More').innerHTML;
                } 
        }
}

function show_more_Generic (summeryDiv, fullDiv, buttonDiv, hiddenButtonDiv) {
        if ($(summeryDiv)) {
                if ($(summeryDiv).style.display == "block") {
                        $(summeryDiv).style.display = "none";
                        $(fullDiv).style.display = "block";
                        $(buttonDiv).innerHTML = $(hiddenButtonDiv+'_On').innerHTML;
                } else {
                        $(summeryDiv).style.display = "block";
                        $(fullDiv).style.display = "none";
                        $(buttonDiv).innerHTML = $(hiddenButtonDiv).innerHTML;
                }
        }
}

function Move_Controls(browser) {
	return;
	if(browser == "firefox") {
		if( $('advanced_search_res_div').style.display == 'block' ) {
			$('search_property_numbers').style.marginTop = 310 + "px";
			$('search_property_numbers').style.marginLeft = -30 + "px";
			//$('res_search_button_div').style.marginTop = 305 + "px";
			//$('res_search_button_div').style.marginLeft = -74 + "px";
			//$('view_drop').style.marginTop = 306 + "px";
			//$('view_drop').style.marginLeft = -28 + "px";
			$('view_results_header').style.marginTop = 302 + "px";
			$('view_results_header').style.marginLeft = -30 + "px";
		} else {
			$('search_property_numbers').style.marginTop = -8 + "px";
			$('search_property_numbers').style.marginLeft = -30 + "px";
			//$('res_search_button_div').style.marginTop = -12 + "px";
			//$('res_search_button_div').style.marginLeft = -74 + "px";
			//$('view_drop').style.marginTop = -10 + "px";
			//$('view_drop').style.marginLeft = -28 + "px";
			$('view_results_header').style.marginTop = -12 + "px";
			$('view_results_header').style.marginLeft = -30 + "px";
		}
	}
	
	if(browser == "ie6" || browser == "ie7") {
		if( $('advanced_search_res_div').style.display == 'block' ) {
			$('search_property_numbers').style.marginTop = 332 + "px";
			$('search_property_numbers').style.marginLeft = -100 + "px";
			//$('res_search_button_div').style.marginTop = 338 + "px";
			//$('res_search_button_div').style.marginLeft = -100 + "px";
			//$('view_drop').style.marginTop = 330 + "px";
			//$('view_drop').style.marginLeft = -28 + "px";
			$('view_results_header').style.marginTop = 340 + "px";
			$('view_results_header').style.marginLeft = -30 + "px";
		} else {
			$('search_property_numbers').style.marginTop = -8 + "px";
			$('search_property_numbers').style.marginLeft = -100 + "px";
			//$('res_search_button_div').style.marginTop = -2 + "px";
			//$('res_search_button_div').style.marginLeft = -100 + "px";
			//$('view_drop').style.marginTop = -10 + "px";
			//$('view_drop').style.marginLeft = -28 + "px";
			$('view_results_header').style.marginTop = 0 + "px";
			$('view_results_header').style.marginLeft = -30 + "px";
		}
	}
}

function printContent (id) {
        var a = window.open('','','scrollbars=yes,width=300,height=300');
        a.document.open("text/html");
        a.document.write('<html><head><link rel="stylesheet" href="lycee-professionnel-nimes.css" /><style type="text/css">#frame{background-image:none;background-color:#FFFFFF;}</style></head><body style="padding-left:20px;background-image:none;background-color:#FFFFFF;">');
        a.document.write($(id).innerHTML);
        a.document.write('</body></html>');
        a.document.close();
        a.print();
        a.close ();
}

function Open_Location_Map(href) {
	window.open(href,'','scrollbars=no,toolbars=no,width=478px,height=430px,top=200px,left=200px');
}

function loadSearch () {
        var obj = null;
        var num = '';
        var home_obj = $('rental_search_form_holder');
        if (ACTIVE_VIEW && home_obj) {
                
                for (i=0; i<TABSARRAY.length; i++) {
                        
                        if (ACTIVE_VIEW == TABSARRAY[i]) {
                                
                                obj = $('SEARCH_TAB_'+(i+1));
                                num = (i+1);
                        }
                }
                
                if (obj) {
                        tabCleanOut (obj,num,'SEARCH_TAB_','SEARCH_PANE_','ajax/ajax_search_tabs.php?view=' + ACTIVE_VIEW,ACTIVE_VIEW,'null',null,null,null, 'inactive_tab', 'active_tab',null,null, 'load');
                }
        }
}

function clearInput (input) {
        input.value = "";
        input.focus();
}

// This funcion comma seperates a value. 
// It is used instead when the value or object holding the value is returned throught ajax so this function is used instead of the mask library because javascript cannot be run inside of ajaxed content..
// decimalPlaces when can be left blank and i would default to seperate after every 3rd character/number, Or you can specify one passing a number threw.
// Also sereraor can be left blank and it will default to a comma
function commaSeperateValueInAjaxedContent (obj, decimalPlaces,seperator) {

        if (obj.value) {
                
                obj.value=obj.value.replace(/[^0-9|^,]/, '');
                
        }
   
        if (decimalPlaces == "" || decimalPlaces == undefined) {
                
                // If a value is not specified, then default it to 3
                decimalPlaces = 3;
        }
        
        if (seperator == "" || seperator == undefined) {
                
                // If a value is not specified, then default it to 3
                seperator = ",";
        }
        
        
        
        var newValue = "";
        
        // remove all coma's from the string
        var stringLeft = obj.value.split(seperator).join("");
        
        var lengthOfStringToLoopThrough = stringLeft.length;
        
        // Loop through each letter
        for (var i=0; i < lengthOfStringToLoopThrough; i++) {
                
                // If we divide the current letter by three and a remainder there is a remainder we will not add a comma
                if (stringLeft.length%decimalPlaces) {
                        
                        newValue = newValue + stringLeft.substring(0,1);
                        
                } else { // If no remainder, add a comma
                        
                        if (newValue=="") {
                                newValue = stringLeft.substring(0,1);
                        } else {
                                newValue = newValue + seperator + stringLeft.substring(0,1);
                        }
                        
                }
                
                stringLeft = stringLeft.substring(1);
                
        }
        
        obj.value = newValue;
        
}

function get_rental_extras (formID, searchType) {
        
        if (searchType=="r") {
                
                if ($(formID+"_pix")) {
                        $(formID+"_pix").style.display = "block";
                        $(formID+"_pix_label").style.display = "block";
                }
                if ($(formID+"_furnished_holder")) {
                        $(formID+"_furnished_holder").style.display = "block";
                }
                if ($(formID+"_rent_sale_subtype")) {
                     $(formID+"_rent_sale_subtype").style.display = "block";
                }
                if ($(formID+"_buy_sale_subtype")) {
                     $(formID+"_buy_sale_subtype").style.display = "none";
                }
                
        } else {
                
                if ($(formID+"_pix")) {
                        $(formID+"_pix").style.display = "none";
                        $(formID+"_pix_label").style.display = "none";
                }
                if ($(formID+"_furnished_holder")) {
                        $(formID+"_furnished_holder").style.display = "none";
                }
                if ($(formID+"_rent_sale_subtype")) {
                     $(formID+"_rent_sale_subtype").style.display = "none";
                }
                if ($(formID+"_buy_sale_subtype")) {
                     $(formID+"_buy_sale_subtype").style.display = "block";
                }
                
        }
        
}


function selectSuburb(obj, id, form_id){

	var SelecInd = obj.selectedIndex;
	var SubSelectedValue = obj.options[SelecInd].value;
	var SubSelectedName = obj.options[SelecInd].text;
	var SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
	
	var looping_counter=true;
	
	var multi_flag=false;
	
	while (looping_counter) {
	
		looping_counter=false;
	
		if ((SubSelectedValue != null) && (SubSelectedValue != "undefined") && (SubSelectedValue != "")) {
			var already_added=false;
		} else {
			var already_added=false;
		}
		
		if (!already_added) {
		
			var elSel = $(id);
			
			if (elSel.length > 0) {
				for (var i=0; i < elSel.length; i++) {
					if (
						elSel.options[i].value==SubSelectedValue && (
							elSel.options[i].value!='' || (
								elSel.options[i].text==SubSelectedName
							)
						)
					) {
						
						if (multi_flag && (SubSelectedValue != null) && (SubSelectedValue != "undefined") && (SubSelectedValue != "")) {
			
							deSelectSuburbBasic(elSel, i, form_id);
							
						} else {
						
							already_added=true;
						
						}
						
						break;
					}
				}
			}
			
			if (!already_added) {
			
				if (SubSelectedValue) {
			
					var elOptNew = document.createElement('option');
					elOptNew.text = SubSelectedName;
					elOptNew.value = SubSelectedValue;
                                        elOptNew.style.backgroundColor=SubSelectedColor;
					
					var ids = SubSelectedValue.split('|');
					
					var suburb_ids_field=$(form_id + "suburb_ids_field");
					
					var propertieswithxys=$(form_id).propertieswithxys;
					
					if ((suburb_ids_field.value != null) && (suburb_ids_field.value != "undefined") && (suburb_ids_field.value != "")) {
						suburb_ids_field.value=suburb_ids_field.value+"|"+ids[0];
					} else {
						
						suburb_ids_field.value=ids[0];
						
					}
					
					propertieswithxys.value=parseInt(propertieswithxys.value)+parseInt(ids[2]);
					
					TOTAL_PROPERTIES+=parseInt(ids[1]);
					
					if (TOTAL_PROPERTIES == 0 || TOTAL_PROPERTIES > 150) {
						$(form_id + 'total_prop_display').style.color="#" + NONE_FOUND_NUMBERS_COLOUR;
					} else {
						$(form_id + 'total_prop_display').style.color="#" + FOUND_NUMBERS_COLOUR;
					}
					$(form_id + 'total_prop_display_numbers').innerHTML=TOTAL_PROPERTIES;
					$(form_id + 'COUNT').value=TOTAL_PROPERTIES;

					try {
						elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
					}
					catch(ex) {
						elSel.add(elOptNew); // IE only
					}
					
					if (multi_flag) {
						
						SelecInd++;
						
						SubSelectedValue = obj.options[SelecInd].value;
						SubSelectedName = obj.options[SelecInd].text;
						SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
						
						looping_counter=true;
						
					}
				
				} else {
				
					if (!multi_flag) {
					
						var elOptNew = document.createElement('option');
						elOptNew.text = SubSelectedName;
						elOptNew.value = SubSelectedValue;
                                                elOptNew.style.backgroundColor=SubSelectedColor;
						
						try {
							elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
						}
						catch(ex) {
							elSel.add(elOptNew); // IE only
						}
				
						SelecInd++;
					
						SubSelectedValue = obj.options[SelecInd].value;
						SubSelectedName = obj.options[SelecInd].text;
						SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
						
						multi_flag=true;
						
						if ((SubSelectedValue != null) && (SubSelectedValue != "undefined") && (SubSelectedValue != "")) {
							
							looping_counter=true;
							
						} else {
							
							looping_counter=false;
							multi_flag=false;
							
						}
					
					}
					
				}
				
			}
		
		}
	
	}

}

function deSelectSuburbBasic (obj, SelecInd, form_id) {
	
	var SubSelectedValue = obj.options[SelecInd].value;
	var SubSelectedName = obj.options[SelecInd].text;
	var SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
	
	var looping_counter=true;
	
	var multi_loop=false;
	
	while(looping_counter) {
	
		looping_counter=false;
	
		if (SubSelectedValue=='') {
			
			looping_counter=true;
			
		} else {
		
			var suburb_ids_field=$(form_id + "suburb_ids_field");
			
			var propertieswithxys=$(form_id).propertieswithxys;
			
			var suburb_ids_list = suburb_ids_field.value.split('|');
			
			var ids = SubSelectedValue.split('|');
			
			var first=true;
			
			TOTAL_PROPERTIES-=parseInt(ids[1]);
			
			propertieswithxys.value=parseInt(propertieswithxys.value)-parseInt(ids[2]);
			
			if (TOTAL_PROPERTIES == 0 || TOTAL_PROPERTIES > 150) {
				$(form_id + 'total_prop_display').style.color="#" + NONE_FOUND_NUMBERS_COLOUR;
			} else {
				$(form_id + 'total_prop_display').style.color="#" + FOUND_NUMBERS_COLOUR;
			}
			$(form_id + 'total_prop_display_numbers').innerHTML=TOTAL_PROPERTIES;
			$(form_id + 'COUNT').value=TOTAL_PROPERTIES;
			
			for (var i=0;i<suburb_ids_list.length; i++) {
				if (suburb_ids_list[i] != ids[0]) {
					if (first) {
						suburb_ids_field.value=suburb_ids_list[i];
						first=false;
					} else {
						suburb_ids_field.value=suburb_ids_field.value + "|" + suburb_ids_list[i];
					}
				}
			}
		
		}

		if (obj.length > 0) {
			obj.remove(SelecInd);
		}
		
		if (SubSelectedValue=='') {
			
			if (multi_loop) {
				
				multi_loop=false;
				looping_counter=false;
				
			} else {
				
				multi_loop=true;
				looping_counter=true;
				
			}
			
			if (multi_loop) {
			
				SelecInd++;
				
				SubSelectedValue = obj.options[SelecInd].value;
				SubSelectedName = obj.options[SelecInd].text;
				SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
			
			}
			
		} else if (multi_loop) {
				
			SelecInd++;
			
			SubSelectedValue = obj.options[SelecInd].value;
			SubSelectedName = obj.options[SelecInd].text;
			SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
			
			if ((SubSelectedValue != null) && (SubSelectedValue != "undefined") && (SubSelectedValue != "")) {
				
				looping_counter=true;
				
			}
			
		}
	
	}
	
}

function deSelectSuburbBasic (obj, SelecInd, form_id) {
	
	var SubSelectedValue = obj.options[SelecInd].value;
	var SubSelectedName = obj.options[SelecInd].text;
	var SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
	
	var looping_counter=true;
	var multi_loop=false;
	
	while (looping_counter) {
	
		looping_counter=false;
	
		if (SubSelectedValue!='' && SubSelectedValue!=null) {
	
			var suburb_ids_field=$(form_id + "suburb_ids_field");
			
			var propertieswithxys=$(form_id).propertieswithxys;
			
			var suburb_ids_list = suburb_ids_field.value.split('|');
			
			var ids = SubSelectedValue.split('|');
			
			var first=true;
			
			TOTAL_PROPERTIES-=parseInt(ids[1]);
			
			propertieswithxys.value=parseInt(propertieswithxys.value)-parseInt(ids[2]);
			
			if (TOTAL_PROPERTIES == 0 || TOTAL_PROPERTIES > 150) {
				$(form_id + 'total_prop_display').style.color="#" + NONE_FOUND_NUMBERS_COLOUR;
			} else {
				$(form_id + 'total_prop_display').style.color="#" + FOUND_NUMBERS_COLOUR;
			}
			$(form_id + 'total_prop_display_numbers').innerHTML=TOTAL_PROPERTIES;
			$(form_id + 'COUNT').value=TOTAL_PROPERTIES;
			
			for (var i=0;i<suburb_ids_list.length; i++) {
				if (suburb_ids_list[i] != ids[0]) {
					if (first) {
						suburb_ids_field.value=suburb_ids_list[i];
						first=false;
					} else {
						suburb_ids_field.value=suburb_ids_field.value + "|" + suburb_ids_list[i];
					}
				}
			}
			
			if (obj.length > 0) {
				obj.remove(SelecInd);
			}
			
			if (multi_loop) {
				
				looping_counter=true;
			
				if (obj.options[SelecInd]) {
			
					SubSelectedValue = obj.options[SelecInd].value;
					SubSelectedName = obj.options[SelecInd].text;
					SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
				
				} else {
					
					SubSelectedValue=null;
					SubSelectedName=null;
					SubSelectedColor=null;
					
				}
				
			}
		
		} else if (SubSelectedValue!=null){
			
			if (!multi_loop) {
				
				multi_loop=true;
				looping_counter=true;
				
				if (obj.length > 0) {
					obj.remove(SelecInd);
				}
				
				if (obj.options[SelecInd]) {
			
					SubSelectedValue = obj.options[SelecInd].value;
					SubSelectedName = obj.options[SelecInd].text;
					SubSelectedColor = obj.options[SelecInd].style.backgroundColor;
				
				} else {
					
					SubSelectedValue=null;
					SubSelectedName=null;
					SubSelectedColor=null;
					
				}
				
			} else {
				
				multi_loop=false;
				looping_counter=false;
				
			}
			
		}
	
	}
	
}


function deselectSuburb (obj, form_id) {

	var SelecInd = obj.selectedIndex;
	
	deSelectSuburbBasic(obj, SelecInd, form_id);
	

}

function compareSuburbSelections (id1, id2, form_id) {

	var yourlist=$(id2).options;
	var suburblist=$(id1).options;
	
	TOTAL_PROPERTIES=0;
	
	var suburb_ids_field=$(form_id + "suburb_ids_field");
	
	var propertieswithxys=$(form_id).propertieswithxys;
	
	var first=true;
	
	var found = false;
	
	if (yourlist.length>0) {
	
		suburb_ids_field.value="";
		propertieswithxys.value="0";
	
		for(var i=0;i<yourlist.length;i++) {
		
			var ids = yourlist[i].value.split('|');
			
			found = false;
		
			for(var y=0;y<suburblist.length;y++) {
			
				var ids2 = suburblist[y].value.split('|');
				
				if (ids[0]==ids2[0]) {
					TOTAL_PROPERTIES+=parseInt(ids2[1]);
					yourlist[i].value=suburblist[y].value;
					yourlist[i].text=suburblist[y].text;
					found=true;
					
					if (first) {
						suburb_ids_field.value=ids2[0];
						yourlist[i].style.color="";
						first=false;
					} else {
						suburb_ids_field.value=suburb_ids_field.value + "|" + ids2[0];
						yourlist[i].style.color="";
					}
					
					y = suburblist.length;
				}
				
			}
			
			if (!found) {
				
				var new_values=yourlist[i].value.split('|');
				var new_text=yourlist[i].text.replace(/\([0-9]*\)/,"(0)");
				
				new_values[1]=0;
				
				yourlist[i].value=new_values.join("|");
				yourlist[i].text=new_text;
				yourlist[i].style.color="#CCCCCC";
				
			}
			
		}
	} else if ($(form_id + "suburb_ids_field").value!="") {
	
		var elSel = $(id2);
	
		var ids = suburb_ids_field.value.split('|');
		
		for (var i=0;i<ids.length;i++) {
		
			for(var y=0;y<suburblist.length;y++) {
			
				var ids2 = suburblist[y].value.split('|');
			
				if (ids[i]==ids2[0]) {
				
					TOTAL_PROPERTIES+=parseInt(ids2[1]);
						
					var elOptNew = document.createElement('option');
					elOptNew.text = suburblist[y].text;
					elOptNew.value = suburblist[y].value;
					
					try {
						elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
					}
					catch(ex) {
						elSel.add(elOptNew); // IE only
					}
					
				}
				
			}
			
		}
		
	}
	
	if (TOTAL_PROPERTIES == 0 || TOTAL_PROPERTIES > 150) {
		$(form_id + 'total_prop_display').style.color="#" + NONE_FOUND_NUMBERS_COLOUR;
	} else {
		$(form_id + 'total_prop_display').style.color="#" + FOUND_NUMBERS_COLOUR;
	}
	$(form_id + 'total_prop_display_numbers').innerHTML=TOTAL_PROPERTIES;
	$(form_id + 'COUNT').value=TOTAL_PROPERTIES;

}

/*
function searchSuburbSelect (obj, id) {

	var input=obj.value.toLowerCase();
	var output=$(id).options;
	
	for(var i=0;i<output.length;i++) {
	
		var match_text = output[i].text.toLowerCase();
	
		if(match_text.indexOf(input)==0){
		
			output[i].style.display="";
			
			if (output[i].value=="") {
				i++;
				for (var y=0; (y+i)<output.length; i++) {
					
					if (output[i].value=="") {
						y=output.length;
					} else {
						output[i].style.display="";
					}
					
				}
				
			}
			
		} else {
			output[i].style.display="none";
			output[i].style.visible="hidden";
		}
		
		if(obj.value.value==''){
			output[i].style.display="";
		}
	}
}
*/

var myfilter=false;

function searchSuburbSelect (obj, id) {
	if (!myfilter) {
		myfilter=new filterlist($(id));
	}
	
	if (obj.value=="") {
		myfilter.reset();
	} else {
		myfilter.set(obj.value);
	}

}

/*==================================================*
 $Id: filterlist.js,v 1.3 2003/10/08 17:13:49 pat Exp $
 Copyright 2003 Patrick Fitzgerald
 http://www.barelyfitz.com/webdesign/articles/filterlist/

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *==================================================*/

function filterlist(selectobj) {

  this.selectobj = selectobj;

  this.flags = 'i';

  this.match_text = true;
  this.match_value = false;

  this.show_debug = false;

  this.init = function() {

    if (!this.selectobj) return this.debug('selectobj not defined');
    if (!this.selectobj.options) return this.debug('selectobj.options not defined');

    this.optionscopy = new Array();
    if (this.selectobj && this.selectobj.options) {
    
		for (var i=0; i < this.selectobj.options.length; i++) {
		
			if (selectobj.options[i].value && selectobj.options[i].value !="" && selectobj.options[i].value.indexOf("|") != -1) {
			
				var cnt=0;

				var values=selectobj.options[i].value.split('|');
				
				if (this.isArray(values) && values.length==6) {
					if (this.optionscopy[values[4]]) {
						cnt=this.optionscopy[values[4]].length;
					} else {
						cnt=0;
						this.optionscopy[values[4]] = new Array();
					}
					
					this.optionscopy[values[4]][cnt] = selectobj.options[i];
				}
			
			}

		}
    }
  }

  this.reset = function() {

    this.set('');
  }
  
this.isArray = function(obj) {
	//returns true is it is an array
	if (obj.constructor.toString().indexOf("Array") == -1) {
		return false;
	} else {
		return true;
	}
}

this.isOption = function (obj) {
	//returns true is it is an array
	if (obj.constructor.toString().indexOf("Option") == -1) {
		return false;
	} else {
		return true;
	}
}


  this.set = function(pattern) {

    var loop=0, index=0, regexp, e;

    if (!this.selectobj) return this.debug('selectobj not defined');
    if (!this.selectobj.options) return this.debug('selectobj.options not defined');

    this.selectobj.options.length = 0;

    try {

      regexp = new RegExp("^" + pattern, this.flags);

    } catch(e) {

      if (typeof this.hook == 'function') {
        this.hook();
      }

      return;
    }
    
	var bgcolour1="#C0C0C0";
	var bgcolour2="#C0C0C0";
	var curbgcolour=bgcolour1;
    
	for (var i in this.optionscopy) {
		
		if (this.match_text && regexp.test(i) && this.isArray(this.optionscopy[i])) {
			var option=new Option(i, "", false);
			option.style.backgroundColor=curbgcolour;
			this.selectobj.options[index++] = option;
			
			for (loop=0; loop < this.optionscopy[i].length; loop++) {
			
				var option = this.optionscopy[i][loop];
				this.selectobj.options[index++] = option;
				
			}
		} else {
			
			var town_flag = false;
			
			for (loop=0; loop < this.optionscopy[i].length; loop++) {
			
				var option = this.optionscopy[i][loop];
				
				if (
					option && 
					(
					(this.match_text && regexp.test(option.text)) ||
						(this.match_value && regexp.test(option.value))
						)
						) {
					
					if (!town_flag) {
						var option2=new Option(i, "", false);
						option2.style.backgroundColor=curbgcolour;
						this.selectobj.options[index++] = option2;
						
						town_flag=true;
					}
					
					
					this.selectobj.options[index++] = option;
				}
			}
			
		}
		
		if (curbgcolour==bgcolour1) {
			curbgcolour=bgcolour2;
		} else {
			curbgcolour=bgcolour1;
		}
	}
	/*

	for (loop=0; loop < this.optionscopy.length; loop++) {

	      var option = this.optionscopy[loop];

		if ((this.match_text && regexp.test(option.text)) ||
			(this.match_value && regexp.test(option.value))) {
			
				this.selectobj.options[index++] = option;

				if (option.value=="") {
					
					loop++;
					
					for (var y=0; (y+loop) < this.optionscopy.length; loop++) {
					
						var option = this.optionscopy[loop];
						
						if (option.value!="") {
							this.selectobj.options[index++] = option;
						} else {
							y=this.optionscopy.length;
						}
						
					}
					
				}

			}
	}
	*/

    if (typeof this.hook == 'function') {
      this.hook();
    }

  }


  this.set_ignore_case = function(value) {

    if (value) {
      this.flags = 'i';
    } else {
      this.flags = '';
    }
  }

  this.debug = function(msg) {
    if (this.show_debug) {
      alert('FilterList: ' + msg);
    }
  }

  this.init();

}

function isdefined(variable) {
	if (typeof variable === "undefined") {
		return false;
	} else {
		return true;
	}
}

function areaPageFeaturedAndSeoListingTabbedBox () {
        
        if ($('seo_listing_list').style.display=='none') {
                
                $('seo_listing_list').style.display = 'block';
                $('associated_features_table').style.display = 'none';
                
                $('seo_listing_list_tab').className = 'areaPageActiveTab';
                $('associated_features_table_tab').className = 'areaPageInactiveTab';
                
        } else if ($('associated_features_table').style.display=='none') {
                
                $('seo_listing_list').style.display = 'none';
                $('associated_features_table').style.display = 'block';
                
                $('seo_listing_list_tab').className = 'areaPageInactiveTab';
                $('associated_features_table_tab').className = 'areaPageActiveTab';
                
        }
}

function puslateProvText (elementID) {
        
        if ($(elementID)) {
                $(elementID).style.color="#" + NONE_FOUND_NUMBERS_COLOUR;
                $(elementID).pulsate({ pulses: 5, duration: 5.0 });
                setTimeout("$(\""+elementID+"\").style.color=\"\";", 5000);
                
                // Just incase the opacity changes because of the pulsate function
                setTimeout("$(\""+elementID+"\").opacity=(1);$(\""+elementID+"\").MozOpacity=(1);$(\""+elementID+"\").KhtmlOpacity=(1);$(\""+elementID+"\").filter=\"alpha(opacity=100)\";", 7000);
        }
        
}