window.onload = initPage;

var searchImageSrc = "";
var AC_FL_RunContent = 0;

function initPage(){	
	resetHeights();
	setupTopMenu();	
	setupSearchMenu();
	try{ selVac(); }catch(e){}
	try{ selRea(); }catch(e){}
}

function setupTopMenu(){
	try{
		var topSpans = document.getElementById("top").getElementsByTagName("span");
		if ( topSpans ){
			for  ( var i = 0; i < topSpans.length; i++){
				var spn = topSpans[i];
				if (spn.className == 'nav') {
					addEventHandler ( spn, "mouseover", topMouseOver);
					addEventHandler ( spn, "mouseout", topMouseOut);
				}
			}
		}		
	}catch(e){
		//window.alert ( "setupTopMenu :" + e ); 
	}
}

function topMouseOver(e){
	var me = getActivatedObject(e);
	me.className = "nav navY";
}

function topMouseOut(e){
	var me = getActivatedObject(e);
	me.className = "nav";
}

function setupSearchMenu(){
	try{
		var searchSpans = document.getElementById("search-menu").getElementsByTagName("span");
		if ( searchSpans ){
			for  ( var i = 0; i < searchSpans.length; i++){
				var spn = searchSpans[i];
				addEventHandler ( spn, "mouseover", searchMouseOver);
				addEventHandler ( spn, "mouseout", searchMouseOut);
			}
		}		
	}catch(e){
		//window.alert ( "setupSearchMenu :" + e ); 
	}
}

function searchMouseOver(e){
	var me = getActivatedObject(e);
	searchImageSrc = me.src;
	searchImageSrc = searchImageSrc.substring(searchImageSrc.indexOf("/images/"));
	
	var iLength = searchImageSrc.length;
	var strOnImgSrc = "-on.jpg"
	var strMeImgSrc = searchImageSrc.substring(iLength-7,iLength);
	if ( strMeImgSrc != "-on.jpg") {
		me.src = searchImageSrc.substring(0, iLength-4) + strOnImgSrc;
	}
}

function searchMouseOut(e){
	var me = getActivatedObject(e);
	me.src = searchImageSrc;
}

function resetHeights(){	
	try{		
		var objFooter = document.getElementById("footer");
		var objLinks = document.getElementById("links");
		var objRightBanner = document.getElementById("right-banner");
		var objContent_section = document.getElementById("content-section");
		
		var iTop = getElemTop("content-section");

		var iContent_Height = getElemHeight ( "content-section" );
		var iLinks_Height = getElemHeight ( "links" );
		var iRight_banner_Height = getElemHeight ( "right-banner" );
		
		var iHeight = 0;
		
		if ( iLinks_Height < iRight_banner_Height ){
			iHeight = iRight_banner_Height + 20;
		}else{
			iHeight = iLinks_Height + 20;
		}

		if ( iHeight < iContent_Height ){
			iHeight = iContent_Height;
		}
		
		objLinks.style.height = iHeight + "px";
		objRightBanner.style.height = iHeight + "px";
		objContent_section.style.height = iHeight + "px";
		
		var iNewTop = iTop + iHeight;		
		objFooter.style.top = iNewTop + "px";
		
		saveHeight(iNewTop);

	}catch(e){
		//window.alert ( "resetHeights :" + e ) ;
	}
}

function saveHeight( topOfFooter ){
	try{
		var data = "cmd=saveHeight"; 
		data = data + "&cid=" + gPageCatId;
		data = data + "&topOfFooter=" + topOfFooter;
		sendRequest( _afterSaveHeight, data, "POST", "/contents/call_category_edit.asp", true );
	}catch(e){
	}
}

function _afterSaveHeight( oj ){
}

function getElemTop( strObjId ){
	
	var selectedPoxX = 0;
	var selectedPoxY = 0;
	var theElem = document.getElementById( strObjId );
	if ( !theElem ) return;
	var theElemHeight = theElem.offsetHeight;
	var theElemWidth = theElem.offsetWidth;
	while(theElem !=null){
		selectedPoxX += theElem.offsetLeft;
		selectedPoxY += theElem.offsetTop;
		theElem = theElem.offsetParent;
	}
	return selectedPoxY;
}

function getElemHeight( strObjId ){
	
	var theElem = document.getElementById( strObjId );
	if ( !theElem ) return;
	var theElemHeight = theElem.offsetHeight;
	return theElemHeight;
}

function selthisWTS( obj ){
	var CatId = obj.options[obj.selectedIndex].value; 

	if (CatId =='17'){
		setNone("div_button_wts");
		setBlock("div_vacation_rentals");		
	}else{
		setNone("div_vacation_rentals");
		setBlock("div_button_wts");
		selthis(obj);
	}
}

function selthis( obj ) {
	try{
		var CatId = obj.options[obj.selectedIndex].value;
		var CatText = obj.options[obj.selectedIndex].text;
		var NoOfSel = '';
		var NameOfSel = '';

		if (CatId !=""){
			NoOfSel = obj.id.substring(7,8);
			NameOfSel = obj.id.substring(4,7);

			var hiddenCatText = "hdnCatId" + NameOfSel;
			document.getElementById(hiddenCatText).value = CatId;
			NoOfSel = eval(NoOfSel);
			for ( var i=5 ; i > NoOfSel ; i--){
				setHidden("div_" + NameOfSel + i);		
			}
		}

		if ( CatText !="All Categories" && CatText !="- Select a Category -"){
			NoOfSel = NoOfSel + 1;
			var data = "cmd=call"; 
			data = data + "&pId=" + CatId;
			data = data + "&nextSelectId=" + "sel_" + NameOfSel + NoOfSel ;
			sendRequest( _afterSelthis, data, "POST", "/contents/call_category_edit.asp", true );
		}else{
		}
	}catch(e){}
}

function _afterSelthis( oj ) {

	try{
		var xmlDoc  = oj.responseXML;	
		
		var nextSelectId = xmlDoc.getElementsByTagName("nextSelectId")[0].firstChild.nodeValue;
			removeOptions(nextSelectId);
		
		var nextDivId = nextSelectId.substring(4,8);

		var optionCount = xmlDoc.getElementsByTagName("optionCount")[0].firstChild.nodeValue;

		if ( eval(optionCount) > 0 ){
		
			var strJOptions = xmlDoc.getElementsByTagName("selectOptions")[0].firstChild.nodeValue;
				eval(strJOptions);
				addOptions( nextSelectId, objJOptions );			
				setVisible ("div_" + nextDivId );
		}else{
				setHidden ("div_" + nextDivId );
		}

	}catch(err){		
		//window.alert ( "_afterSelthis :" + err);
	}
}

function removeOptions( objId ){
	try{
		var elSel = document.getElementById(objId);
		for ( var i = elSel.length; i>=0; i--) {
			elSel.remove(i);
		}
	}catch(e){
	}
}

function addOptions( objId, objVals ){
	try{		
		var elSel = document.getElementById(objId);		
		for ( var i=0; i < objVals.selectOptions.length; i++ ){
			var elOptNew = document.createElement('option');
			elOptNew.text = objVals.selectOptions[i].text;
			elOptNew.value = objVals.selectOptions[i].value;
			try {
				elSel.add(elOptNew, null);
			}
			catch(ex) {
				elSel.add(elOptNew);
			}
		}
	}catch(e){
		//window.alert ("addOptions :" + "\n\r" + "objId: " +  objId + "\n\r" + "objVals :" + objVals + "\n\r" + e);
	}	
}

function setSelectedOption( objId, strSelectedVal ){
	try{
		var elSel = document.getElementById(objId);
		for ( var i=0; i<elSel.length; i++) {
			if (elSel.options[i].value == strSelectedVal){				
				elSel.selectedIndex = i;
			}
		}
	}catch(e){
	}
}

function goSearch( arg ){
	try{
		var strCatId = "hdnCatId" + arg;
		var CatId = document.getElementById( strCatId ).value;
		if (CatId !=''){
			var data = "cmd=goSearch"; 
			data = data + "&pId=" + CatId;
			sendRequest( _afterGoSearch, data, "POST", "/contents/call_category_edit.asp", true );
		}
	}catch(e){
		//window.alert ("goSearch :" + e);
	}
}

function _afterGoSearch( oj ) {

	try{
		var xmlDoc  = oj.responseXML;			
		var searchURL = xmlDoc.getElementsByTagName("searchURL")[0].firstChild.nodeValue;
		if (searchURL != ''){
			document.location = searchURL;
		}
	}catch(err){		
		//window.alert (err);
	}
}

function run_video( aVideo, aWidth, aHeight){

	var srcVideo = '/videos/' + aVideo;
	
	try{
		if (AC_FL_RunContent == 0) {
			alert("This page requires AC_RunActiveContent.js.");
		} else {
			AC_FL_RunContent( 
			'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'name','intro',
			'width',aWidth,
			'height',aHeight,
			'align','middle',
			'id',aVideo,
			'src',srcVideo,
			'quality','high',
			'wmode', 'transparent',
			'allowscriptaccess','sameDomain',
			'allowfullscreen','false',
			'pluginspage','http://www.macromedia.com/go/getflashplayer',
			'movie',srcVideo ); //end AC code
		}
	}catch(e){
		//window.alert ( "run_video :" + e);
	}
}

function selRea() {

	try{
		var vLocation = document.getElementById("selLocation").options[document.getElementById("selLocation").selectedIndex].value;
		var vPropertyType = document.getElementById("selPropertyType").options[document.getElementById("selPropertyType").selectedIndex].value;
		var vBedroom = document.getElementById("selBedroom").options[document.getElementById("selBedroom").selectedIndex].value;
		var vPrice = document.getElementById("selPrice").options[document.getElementById("selPrice").selectedIndex].value;

		setValues(vLocation, vPropertyType, vBedroom, vPrice);
		
		var data = "cmd=call";
		data = data + "&selLocation=" + vLocation;
		data = data + "&selPropertyType=" + vPropertyType;
		data = data + "&selBedroom=" + vBedroom;
		data = data + "&selPrice=" + vPrice;
		
		sendRequest( _afterSelRea, data, "POST", "/contents/call_real_estate_search.asp", true );
	}catch(e){
		//window.alert ( "selRea: " + e ) ;
	}
}

function _afterSelRea( oj ) {

	try{
		var xmlDoc  = oj.responseXML;	
		
		var result = xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue;
		if (result == "ok"){
			
			removeOptions("selLocation");
			var optionCountArea = xmlDoc.getElementsByTagName("optionCountArea")[0].firstChild.nodeValue;
			if ( eval(optionCountArea) > 0 ){		
				var strJOptions = xmlDoc.getElementsByTagName("optionsObjectArea")[0].firstChild.nodeValue;
					eval(strJOptions);
					addOptions( "selLocation", objJOptions );
				var strSelected = xmlDoc.getElementsByTagName("optionSelectedArea")[0].firstChild.nodeValue;
					setSelectedOption( "selLocation", strSelected );
			}

			removeOptions("selPropertyType");
			var optionCountPropertyType = xmlDoc.getElementsByTagName("optionCountPropertyType")[0].firstChild.nodeValue;
			if ( eval(optionCountPropertyType) > 0 ){		
				var strJOptions = xmlDoc.getElementsByTagName("optionsObjectPropertyType")[0].firstChild.nodeValue;
					eval(strJOptions);
					addOptions( "selPropertyType", objJOptions );
				var strSelected = xmlDoc.getElementsByTagName("optionSelectedPropertyType")[0].firstChild.nodeValue;
					setSelectedOption( "selPropertyType", strSelected );
			}

			removeOptions("selBedroom");
			var optionCountPropertyType = xmlDoc.getElementsByTagName("optionCountBedroom")[0].firstChild.nodeValue;
			if ( eval(optionCountPropertyType) > 0 ){		
				var strJOptions = xmlDoc.getElementsByTagName("optionsObjectBedroom")[0].firstChild.nodeValue;
					eval(strJOptions);
					addOptions( "selBedroom", objJOptions );
				var strSelected = xmlDoc.getElementsByTagName("optionSelectedBedroom")[0].firstChild.nodeValue;
					setSelectedOption( "selBedroom", strSelected );
			}

			removeOptions("selPrice");
			var optionCountPropertyType = xmlDoc.getElementsByTagName("optionCountPrice")[0].firstChild.nodeValue;
			if ( eval(optionCountPropertyType) > 0 ){		
				var strJOptions = xmlDoc.getElementsByTagName("optionsObjectPrice")[0].firstChild.nodeValue;
					eval(strJOptions);
					addOptions( "selPrice", objJOptions );
				var strSelected = xmlDoc.getElementsByTagName("optionSelectedPrice")[0].firstChild.nodeValue;
					setSelectedOption( "selPrice", strSelected );
			}

		}
	}catch(e){		
		//window.alert ("_afterSelRea :" + e);
	}
}

function setValues(vLocation, vPropertyType, vBedroom, vPrice){
	
	var obj_location = document.getElementById("hnd_location");
	var obj_propertyType = document.getElementById("hnd_propertyType");
	var obj_bedrooms = document.getElementById("hnd_bedrooms");
	var obj_price = document.getElementById("hnd_price");

	switch(vLocation){
		case "1": obj_location.value = "1 - SEA PINES"; break;
		case "2": obj_location.value = "2 - FOREST BEACH"; break;
		case "3": obj_location.value = "3 - SHIPYARD"; break;
		case "4": obj_location.value = "4 - WEXFORD"; break;
		case "5": obj_location.value = "6 - PALMETTO DUNES/SHELTER COVE"; break;
		case "6": obj_location.value = "7 - FOLLY FIELD"; break;
		case "7": obj_location.value = "5 - LONG COVE"; break;
		case "8": obj_location.value = "12 - SPANISH WELLS"; break;
		case "9": obj_location.value = "11 - INDIGO RUN"; break;
		case "10": obj_location.value = "8 - PORT ROYAL"; break;
		case "11": obj_location.value = "13 - WINDMILL HARBOUR"; break;
		case "12": obj_location.value = "10 - PALMETTO HALL"; break;
		case "13": obj_location.value = "9 - HILTON HEAD PLANTATION"; break;
		case "14": obj_location.value = "15 - DAUFUSKIE ISLAND"; break;
		case "15": obj_location.value = "14 - HH/OFF PLANTATION"; break;
		default : obj_location.value = "%%"; break;
	}

	switch(vPropertyType){
		case "1": obj_propertyType.value = "VIL"; break;
		case "2": obj_propertyType.value = "RES"; break;
		case "3": obj_propertyType.value = "LND"; break;
		default : obj_propertyType.value = "%%"; break;
	}

	switch(vBedroom){
		case "1": obj_bedrooms.value = "1"; break;
		case "2": obj_bedrooms.value = "2"; break;
		case "3": obj_bedrooms.value = "3"; break;
		case "4": obj_bedrooms.value = "4"; break;
		case "5": obj_bedrooms.value = "5"; break;
		case "6": obj_bedrooms.value = "6"; break;
		case "7": obj_bedrooms.value = "7"; break;
		case "8": obj_bedrooms.value = "8"; break;
		default : obj_bedrooms.value = "%%"; break;
	}

	switch(vPrice){
		case "100": obj_price.value = "0-100000"; break;
		case "150": obj_price.value = "100001-150000"; break;
		case "300": obj_price.value = "200001-300000"; break;
		case "400": obj_price.value = "300001-400000"; break;
		case "500": obj_price.value = "400001-500000"; break;
		case "750": obj_price.value = "500001-750000"; break;
		case "1000": obj_price.value = "750001-1000000"; break;
		case "2000": obj_price.value = "1000001-2000000"; break;
		case "3000": obj_price.value = "2000001-3000000"; break;
		case "5000": obj_price.value = "3000001-5000000"; break;
		case "5001": obj_price.value = "5000001-100000000"; break;
		default : obj_price.value = "0-100000000"; break;
	}
}

function selVac() {

	try{
		var vBedroom = document.getElementById("selVacBedroom").options[document.getElementById("selVacBedroom").selectedIndex].value;		
		var vLocation = document.getElementById("selVacLocation").options[document.getElementById("selVacLocation").selectedIndex].value;
		var vView = document.getElementById("selVacView").options[document.getElementById("selVacView").selectedIndex].value;
		
		var data = "cmd=call";
		data = data + "&selVacBedroom=" + vBedroom;
		data = data + "&selVacLocation=" + vLocation;
		data = data + "&selVacView=" + vView;
		
		sendRequest( _afterSelVac, data, "POST", "/contents/call_vacation_rentals_search.asp", true );
	}catch(e){
		//window.alert ( "selVac: " + e ) ;
	}
}

function _afterSelVac( oj ) {

	try{
		var xmlDoc  = oj.responseXML;	
		
		var result = xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue;
		if (result == "ok"){
			
			removeOptions("selVacBedroom");
			var optionCountPropertyType = xmlDoc.getElementsByTagName("optionCountBedroom")[0].firstChild.nodeValue;
			if ( eval(optionCountPropertyType) > 0 ){		
				var strJOptions = xmlDoc.getElementsByTagName("optionsObjectBedroom")[0].firstChild.nodeValue;
					eval(strJOptions);
					addOptions( "selVacBedroom", objJOptions );
				var strSelected = xmlDoc.getElementsByTagName("optionSelectedBedroom")[0].firstChild.nodeValue;
					setSelectedOption( "selVacBedroom", strSelected );
			}

			removeOptions("selVacLocation");
			var optionCountArea = xmlDoc.getElementsByTagName("optionCountLocation")[0].firstChild.nodeValue;
			if ( eval(optionCountArea) > 0 ){		
				var strJOptions = xmlDoc.getElementsByTagName("optionsObjectLocation")[0].firstChild.nodeValue;
					eval(strJOptions);
					addOptions( "selVacLocation", objJOptions );
				var strSelected = xmlDoc.getElementsByTagName("optionSelectedLocation")[0].firstChild.nodeValue;
					setSelectedOption( "selVacLocation", strSelected );
			}

			removeOptions("selVacView");
			var optionCountPropertyType = xmlDoc.getElementsByTagName("optionCountView")[0].firstChild.nodeValue;
			if ( eval(optionCountPropertyType) > 0 ){		
				var strJOptions = xmlDoc.getElementsByTagName("optionsObjectView")[0].firstChild.nodeValue;
					eval(strJOptions);
					addOptions( "selVacView", objJOptions );
				var strSelected = xmlDoc.getElementsByTagName("optionSelectedView")[0].firstChild.nodeValue;
					setSelectedOption( "selVacView", strSelected );
			}

		}
	}catch(e){		
		//window.alert ("_afterSelVac :" + e);
	}
}

function videoOver( i ){

	try{
		var myVideoThumbDiv = document.getElementById( "div_video" + i);
		//var myVideoThumbTop = getElemTop("videoThumb" + i);
		var myVideoThumbTop = getElemTop( "links" );

			myVideoThumbDiv.style.top = myVideoThumbTop + "px";
			myVideoThumbDiv.style.display = "block";
	}catch(e){
		//window.alert ( "videoOver :" + e );
	}
}

function videoOut( i ){

	try{
		var myVideoThumb = document.getElementById("div_video" + i);
			myVideoThumb.style.display = "none";
	}catch(e){
	}
}
