

var search_tab_active_color = '#FFFFFF';
var search_tab_color = '#F2E9DB';
var search_tab_hover_color = '#B3D34C';
var search_mode_arr = new Array("keyword","map","distance");
var changing = false;
function change_tab(tab_name,dont_reset_main_page){
	if(!changing && tab_name!=cur_search_mode){
		if(tab_name=='keyword'){
			document.getElementById('more_option_title_div').style['display'] = 'none';
			document.getElementById('more_option_div').style['display'] = 'none';
		}else{
			document.getElementById('more_option_title_div').style['display'] = 'block';
		}
		changing = true;
		for(var i=0;i<search_mode_arr.length;i++){
			if(search_mode_arr[i]!=tab_name){
				document.getElementById('search_by_'+search_mode_arr[i]+'_head').style["backgroundColor"] = "#F2E9DB";
				document.getElementById('search_by_'+search_mode_arr[i]+'_head').style["borderBottom"] = "solid 1px #938879";
				document.getElementById('search_by_'+search_mode_arr[i]+'_head').style["paddingBottom"] = "1px";
			}else{
				document.getElementById('search_by_'+search_mode_arr[i]+'_head').style["backgroundColor"] = search_tab_active_color;
				document.getElementById('search_by_'+search_mode_arr[i]+'_head').style["borderBottom"] = "none";
				document.getElementById('search_by_'+search_mode_arr[i]+'_head').style["paddingBottom"] = "2px";
			}
		}
		Effect.toggle_double(cur_search_mode+'_tab',tab_name+'_tab',{duration:0.7});
		cur_search_mode = tab_name;
		set_search_module('by_'+tab_name);
		if(document.getElementById('right_column')) document.getElementById('right_column').innerHTML = '';
		if(document.getElementById('featured_listing_box_content_parent')) document.getElementById('featured_listing_box_content_parent').innerHTML = '';
		if(document.getElementById('information_box_content_parent')) document.getElementById('information_box_content_parent').innerHTML = '';
		if(!dont_reset_main_page) document.getElementById('main_column').innerHTML = '<table width="100%" border="0"><tr><td width="4%"><img src="/images/spacer.gif" width="1" height="70"></td><td width="96%" background="/images/find.png"><span class="contactHeading"><img src="/images/spacer.gif" width="35" height="20">Find your perfect Bed and Breakfast / Inn</span></td></tr><tr><td>&nbsp;</td><td valign="top"><UL><p align="left" class="finddesctext">You can start by simply searching with keywords, map, by the name of Bed Breakfast/Inn, or by searching within a specific distance.</p><p align="left" class="finddesctext">You can also narrow down search by selecting different criteria of your choice.</p><p align="left" class="finddesctext"><strong>Please use options on the left.</strong></p><p align="left" class="briefintro">At BedbreakfastHome.com you can locate your favorite Bed &amp; Breakfast by choosing from over 15,000 B&amp;Bs with more then 200,000 color pictures. Updated daily.<div>&nbsp;<br><img src="/images/2007Bullet.gif" alt="Bullet" width="15" height="8"><span class="bulletsintro">15,000+ Bed &amp; Breakfast to search</span><span class="tks"><br><img src="/images/2007Bullet.gif" alt="Bullet" width="15" height="8"></span><span class="briefintro">Multiple Reservations in one request </span><br><img src="/images/2007Bullet.gif" alt="Bullet" width="15" height="8"><span class="briefintro">Search by birds eye view map </span><br><img src="/images/2007Bullet.gif" alt="Bullet" width="15" height="8"><span class="briefintro">Fastest growing directory with AJAX </span></p></UL></td></tr></table>';
	}
}

function set_search_module(value){
	document.search_form.search_module.value = value;
}
js_search_showLoading = function() {
	document.search_form.SCity.selectedIndex = 0;
	document.search_form.SCity.options[0].text = "Loading...";
};
load_search_city_data = function() {
	var ele = document.search_form.SCityM;
	var eachItem = ele.firstChild;
	while (eachItem)
	{
	   ele.removeChild(eachItem)
	   eachItem = ele.firstChild;
	}
	var myEle = document.createElement('option');
	myEle.value = "";
	myEle.text = "Data Loading...";
	try{
	  ele.add(myEle) ;
	}catch(e){
	  ele.appendChild(myEle) ;
	}
};
finish_load_search_city_data = function() {
}
error_load_search_city_data = function() {
	document.search_form.SStateM.selectedIndex = 0;
	document.search_form.SCityM.options[0].text = "Load Error";
}
js_search_hideLoading = function() {
}
js_search_errorLoading = function() {
	document.search_form.SState.selectedIndex = 0;
	document.search_form.SCity.options[0].text = "Loading error";
	for(var q=document.search_form.SCity.options.length;q>0;q--) document.search_form.SCity.options[q]=null;
}
js_search_errorLoading2 = function() {
	//document.search_form.SCityM.selectedIndex = 0;
	//document.search_form.SLandmark.options[0].text = "Loading error";
	//for(var q=document.search_form.SLandmark.options.length;q>0;q--) document.search_form.SLandmark.options[q]=null;
	document.search_form.SMapCity.selectedIndex = 0;
}

var div_expand_arr = new Array("search_by_keyword_div","search_by_map_div","search_by_location_div","search_by_title_div","search_by_distance_div");
function smooth_expand(div_id, hide_other){
	if(hide_other){
		for(var i=0;i<div_expand_arr.length;i++){
			if(div_expand_arr[i]!=div_id) document.getElementById(div_expand_arr[i]).style["display"] = "none";
		}
		if(div_id!=""){
			document.getElementById("more_option_title_div").style["display"] = "block";
		}else{
			document.getElementById("more_option_title_div").style["display"] = "none";
			document.getElementById("more_option_div").style["display"] = "none";
		}
		Effect.show(div_id,"BLIND",{duration:0.7});
	}else{
		Effect.toggle(div_id,"BLIND",{duration:0.7});
	}
}
function toggle_image(div_id){
	var temp = document.getElementById(div_id).innerHTML;
	if(temp.indexOf('Expand')>=0) document.getElementById(div_id).innerHTML = '<img src="/images/bull_2.png" width="15" height="22" alt="Collapse" align="absmiddle">';
	else document.getElementById(div_id).innerHTML = '<img src="/images/bull_1.png" width="15" height="22" alt="Expand" align="absmiddle">';
}
function show_optional_text(field,checkbox_no_preference_selected,checked,value){
	var form = document.search_form;
	var temp = '';
	var temp1 = '';
	var text_span_id = '';
	if(checkbox_no_preference_selected!=null){
		text_span_id = field+'_text';
		field += '[]';
	}
	if(form.elements[field][0].type=='radio'){
		for(var i=0;i<form.elements[field].length;i++) if(form.elements[field][i].checked) temp = form.elements[field][i].value;
		if(temp=='') temp = '<font color="#333333">No preference</font>';
		document.getElementById(field+'_text').innerHTML = temp;
	}else if(form.elements[field][0].type=='checkbox'){
		if(checked!=null && checked){
			var remove_value = '';
			if(value=='Yes|Yes') remove_value = 'No|No';
			else if(value=='No|No') remove_value = 'Yes|Yes';
			if(remove_value!=''){
				for(var i=0;i<form.elements[field].length;i++){
					if(form.elements[field][i].value==remove_value) form.elements[field][i].checked = false;
				}
			}
		}
		for(var i=0;i<form.elements[field].length;i++) if(form.elements[field][i].checked){
			if(checkbox_no_preference_selected){
				if(form.elements[field][i].value!='') form.elements[field][i].checked = false;
			}else{
				temp1 = form.elements[field][i].value;
				if(temp1!=''){
					temp1 = temp1.split('|');
					if(temp1.length==2) temp += temp1[1] + ', ';
				}else form.elements[field][i].checked = false;
			}
		}
		if(temp=='') temp = '<font color="#333333">No preference</font>';
		else temp = temp.substring(0,temp.length-2);
		document.getElementById(text_span_id).innerHTML = temp;
	}
}
function check_form_search(form){
	try{
	switch(form.search_module.value){
		case 'by_map':
			if (!_JS_hasValue(form.SStateM, "TEXT")){
				document.getElementById("main_column").innerHTML = '<div id="search_alert_table"><table width="100%" border="0"><tr><td width="4%">&nbsp;</td><td width="96%" valign="top"><table width="100%" border="0" bgcolor="#f1f1f1"><tr><td width="15%"><span class="finddesctext"><img src="/images/alert2.png" alt="Alert" width="64" height="64"></span></td><td width="85%"><span class="finddesctext" id="search_alert_msg">Please select Province/State to begin search</span></td></tr></table></td></tr></table></div>';
				form.SStateM.focus();
				return false;
			}
			break;
		case 'by_location':
			if (!_JS_hasValue(form.SState, "TEXT")){
				document.getElementById("main_column").innerHTML = '<div id="search_alert_table"><table width="100%" border="0"><tr><td width="4%">&nbsp;</td><td width="96%" valign="top"><table width="100%" border="0" bgcolor="#f1f1f1"><tr><td width="15%"><span class="finddesctext"><img src="/images/alert2.png" alt="Alert" width="64" height="64"></span></td><td width="85%"><span class="finddesctext" id="search_alert_msg">Please select Province/State to begin search</span></td></tr></table></td></tr></table></div>';
				form.SState.focus();
				return false;
			}
			break;
		case 'by_title':
			if (!_JS_hasValue(form.STitle, "TEXT")){
				document.getElementById("main_column").innerHTML = '<div id="search_alert_table"><table width="100%" border="0"><tr><td width="4%">&nbsp;</td><td width="96%" valign="top"><table width="100%" border="0" bgcolor="#f1f1f1"><tr><td width="15%"><span class="finddesctext"><img src="/images/alert2.png" alt="Alert" width="64" height="64"></span></td><td width="85%"><span class="finddesctext" id="search_alert_msg">Please enter Bed Breakfast or Inn Name to begin your search</span></td></tr></table></td></tr></table></div>';
				form.STitle.focus();
				return false;
			}
			break;
		case 'by_keyword':
			/*if (!_JS_hasValue(form.SQuery, "TEXT")){
				document.getElementById("search_alert_table").style["display"] = "block";
				document.getElementById("search_alert_msg").innerHTML = "Please enter keywords to begin your search";
				form.SQuery.focus();
				return false;
			}*/
			break;
		case 'by_distance':
			if (!_JS_hasValue(form.SZip, "TEXT")){
				document.getElementById("main_column").innerHTML = '<div id="search_alert_table"><table width="100%" border="0"><tr><td width="4%">&nbsp;</td><td width="96%" valign="top"><table width="100%" border="0" bgcolor="#f1f1f1"><tr><td width="15%"><span class="finddesctext"><img src="/images/alert2.png" alt="Alert" width="64" height="64"></span></td><td width="85%"><span class="finddesctext" id="search_alert_msg">Please enter Zip or Postal Code to begin your search</span></td></tr></table></td></tr></table></div>';
				form.SZip.focus();
				return false;
			}
			break;
	}
	document.getElementById("search_alert_table").style["display"] = "none";
	}catch(e){}
	document.search_form.SPage.value = '';
	
	return true;
}

function reset_search_form(){
	var form = document.search_form;
	var tmp_search_mode = form.search_module.value;
	form.reset();
	form.search_module.value = tmp_search_mode;
	document.getElementById('Smoking_Allow_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Handicapped_Accessible_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Pets_Allowed_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Internet_Wireless_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Soft_Adventures_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Active_Adventures_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Romance_and_Relaxation_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Inside_Activities_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Fishing_Adventures_text').innerHTML = '<font color="#333333">No preference</font>';
	document.getElementById('Water_Adventures_text').innerHTML = '<font color="#333333">No preference</font>';
}

function show_criteria_selected(flag){
	document.getElementById('search_form_table').style['display'] = 'none';
	document.getElementById('search_box_title').innerHTML = 'Search B&amp;B / Inn by Map';
	var city_text = '';
	if(document.search_form.SStateM.selectedIndex<61) city_text += 'United States';
	else city_text += 'Canada';
	city_text += ', ' + document.search_form.SStateM.value;
	//if(document.search_form.SCityM.value) city_text += ', ' + document.search_form.SCityM.value;
	if(document.search_form.SMapCity.value) city_text += ', ' + document.search_form.SMapCity.value;
	city_text += '<br>';
	var show_text = '';
	if(document.getElementById('Smoking_Allow_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Smoking ('+document.getElementById('Smoking_Allow_text').innerHTML+'), ';
	if(document.getElementById('Handicapped_Accessible_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Handicapped Accessible ('+document.getElementById('Handicapped_Accessible_text').innerHTML+'), ';
	if(document.getElementById('Pets_Allowed_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Pets Allowed ('+document.getElementById('Pets_Allowed_text').innerHTML+'), ';
	if(document.getElementById('Internet_Wireless_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Internet/Wireless ('+document.getElementById('Internet_Wireless_text').innerHTML+'), ';
	if(document.getElementById('Soft_Adventures_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Soft Adventures ('+document.getElementById('Soft_Adventures_text').innerHTML+'), ';
	if(document.getElementById('Active_Adventures_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Active Adventures ('+document.getElementById('Active_Adventures_text').innerHTML+'), ';
	if(document.getElementById('Romance_and_Relaxation_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Romance and Relaxation ('+document.getElementById('Romance_and_Relaxation_text').innerHTML+'), ';
	if(document.getElementById('Inside_Activities_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Inside Activities ('+document.getElementById('Inside_Activities_text').innerHTML+'), ';
	if(document.getElementById('Fishing_Adventures_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Fishing Adventures ('+document.getElementById('Fishing_Adventures_text').innerHTML+'), ';
	if(document.getElementById('Water_Adventures_text').innerHTML!='<font color="#333333">No preference</font>') show_text += 'Water Adventures ('+document.getElementById('Water_Adventures_text').innerHTML+'), ';
	if(show_text==''){
		show_text = '<font color="#333333">No preference</font>';
	}else show_text = show_text.substring(0,show_text.length-2);
	show_text = city_text + show_text;
	show_text += '<br><a href="javascript:reset_search_form()" class="searchcriterialinks">Reset Search</a> | <a href="javascript:show_criteria_selected(false)" class="searchcriterialinks">Back</a>';
	if(flag){
		document.getElementById('more_option_div').style['display'] = 'none';
		document.getElementById('search_criteria_selected_text').innerHTML = show_text;
	}else{
		document.getElementById('search_form_table').style['display'] = 'block';
		document.getElementById('search_box_title').innerHTML = 'Find your B&amp;B / Inn';
		document.getElementById('search_criteria_selected_text').innerHTML = '';
	}
}

function xajax_search(){
	xajax.loadingFunction = showSearching;
	xajax.doneLoadingFunction = hideSearching;
	xajax.loadingErrorFunction = errorLoading;
	xajax.call('search', arguments, 1);
	on_search_page = true;
}
function xajax_search_cache(){
	xajax.loadingFunction = function(){
		xajaxStatusMessages = false;
		xajaxWaitCursor=false;
	};
	xajax.doneLoadingFunction = function(){
		xajaxStatusMessages = true;
		xajaxWaitCursor=true;
	};
	xajax.loadingErrorFunction = function(){
		xajaxStatusMessages = true;
		xajaxWaitCursor=true;
	};
	xajax.call('search_cache', arguments, 1);
}
errorLoading = function() {
	document.getElementById('top_layer').className = 'top_layer_hide';
	document.getElementById('top_layer_loading').className = 'top_layer_hide';
	if(!right_column_display) document.getElementById('right_column').innerHTML = '';
	else document.getElementById('right_column').innerHTML = right_column_html;
	document.getElementById('main_column').style['display'] = 'block';
	document.getElementById('ajax_loading_error').style['display']='block';
}
showSearching = function() {
	document.getElementById('ajax_loading_error').style['display']='none';
	document.getElementById('main_column').innerHTML='<div align="center" style="height: 100%; width: 100%;"><br><br><br><b>Searching...</b><br><br><img src="/images/wait.gif"></div>';
	document.getElementById('search_by_map_result_frame').src = '/search_by_map_result.php?page=searching';
};
hideSearching = function() {
}

function xajax_include_js(){	
	xajax.call('include_js', arguments, 1);
}
function xajax_load_search_result(){
	xajax.loadingFunction = showLoading;
	xajax.doneLoadingFunction = hideLoading;
	xajax.loadingErrorFunction = errorLoading;
	right_column_display = false;
	xajax.call('load_search_result', arguments, 1);
}

function show_listing_list(type,column){
	/*var detail_function;
	if(!column) column = 'left';
	if(column=='right') detail_function = "parent.load_page_in_frame_start";
	else detail_function = "load_page_in_frame_start";
	switch(type){
		case 'enquiry':
			cookie_name = 'cookie_enquiry_list';			
			submit_button = 'button_enquire_now.png';
			submit_button_alt = 'Enquire Now';
			remove_button_alt = 'Remove this from favourite';
			if(column=='right') submit_url = 'javascript:parent.show_enquiry_window();';
			else submit_url = 'javascript:show_enquiry_window();';
			box_name = 'enquiry_box_content';
			if(document.getElementById(box_name+'_parent')){
				if(enquiry_box_html=='' && document.getElementById(box_name+'_parent')) enquiry_box_html = document.getElementById(box_name+'_parent').innerHTML;
				document.getElementById(box_name+'_parent').innerHTML='';
			}
			break;
		case 'compare':
			cookie_name = 'cookie_compare_list';
			box_name = 'compare_box_content';
			submit_button = 'button_compare_now.png';
			submit_button_alt = 'Compare Now';
			remove_button_alt = 'Remove this from compare list';
			if(column=='right') submit_url = 'javascript:parent.show_compare_page();';
			else submit_url = 'javascript:show_compare_page();';
			if(compare_box_html=='' && document.getElementById(box_name+'_parent')) compare_box_html = document.getElementById(box_name+'_parent').innerHTML;
			break;
	}
	if(document.getElementById(box_name+'_parent')){
	var listing_list = getCookie(cookie_name);
	if(listing_list==null) listing_list = '';
	if(listing_list==''){
		document.getElementById(box_name+'_parent').innerHTML='';
	}else{
		listing_list_arr = listing_list.split('~~~');
		var tmp = '~';
		listing_content = '<table width="100%" border="0">';
		for(var i=0;i<listing_list_arr.length;i++){
			prop_arr = listing_list_arr[i].split('|||');
			listing_content += '<tr><td align="center" valign="top" background="/images/2007_favouriteBox_17.jpg"><img src="'+prop_arr[3]+'" width="60" height="60" alt="'+prop_arr[2]+'"></td><td valign="top" background="/images/2007_favouriteBox_17.jpg" class="favboxcity"><a href="'+get_detail_url(prop_arr[6],prop_arr[1])+'" class="favboxlinks">'+(prop_arr[2].length>20?prop_arr[2].substring(0,20)+'...':prop_arr[2])+'</a><br>BB#: '+prop_arr[1]+' <br>'+prop_arr[4]+', <br>'+prop_arr[5]+'</td><td valign="top" background="/images/2007_favouriteBox_17.jpg"><a onclick="remove_listing('+prop_arr[1]+',\''+type+'\',\''+column+'\')" href="#"><img src="/images/clean_del.gif" alt="'+remove_button_alt+'" width="17" height="17" border="0"></a></td></tr>';
			tmp += prop_arr[1]+'~';
		}
		listing_content += '<tr><td align="center" valign="top" background="/images/2007_favouriteBox_17.jpg">&nbsp;</td><td colspan="2" valign="top" background="/images/2007_favouriteBox_17.jpg" class="favboxcity"><a href="'+submit_url+'"><img src="/images/'+submit_button+'" alt="'+submit_button_alt+'" border="0"></a></td></tr></table>';
		switch(type){
			case 'enquiry':
				if(column=='right'){
					//document.getElementById(box_name+'_parent').innerHTML = right_enquiry_box_html;
					//right_enquiry_box_html = '';
				}else{
					//document.getElementById(box_name+'_parent').innerHTML = enquiry_box_html;
					//enquiry_box_html = '';
				}
				break;
			case 'compare':
				document.getElementById(box_name+'_parent').innerHTML = compare_box_html;
				compare_box_html = '';
				break;
		}
		if(type!='enquiry') document.getElementById(box_name).innerHTML=listing_content;
	}
	}*/
	show_top_cart();
}

function get_detail_url(web_folder,id){
	if(web_folder && web_folder!='') return '/'+web_folder+'/';
	else return '/Detailed/'+id+'_index.html';
}

function show_top_cart(){
	if(document.getElementById('top_cart')){
		var listing_content = '';
		var listing_list = getCookie('cookie_enquiry_list');
		if(listing_list==null) listing_list = '';
		if(listing_list!=''){
			listing_list_arr = listing_list.split('~~~');
			listing_content += '<table id="top_cart_table" width="724" border="0" style="border:#386418 1px solid;padding:5px;background-color:#cff28b;"><tr><td width="38"><img src="/images/success_icon.gif"></td><td width="540"><div class="cartTxt5">Booking Enquiry Cart<div class="cartTxt1">You have added the following listings for a Booking Enquiry. Feel free to add more or click ....</div></td><td><input type="button" class="cartButton" value="Enquire Now" onclick="show_enquiry_window();"></td></tr><tr><td></td><td colspan="2"><table width="552" border="0">';
			for(var i=0;i<listing_list_arr.length;i++){
				prop_arr = listing_list_arr[i].split('|||');
				listing_content += '	<tr><td width="69" class="cartTxt1">BB# '+prop_arr[1]+'</td><td width="184"><A href="'+get_detail_url(prop_arr[6],prop_arr[1])+'" class="cartlink1">'+(prop_arr[2].length>20?prop_arr[2].substring(0,20)+'...':prop_arr[2])+'</A></td>      <td width="91" class="cartTxt1">'+prop_arr[5]+'</td>      <td width="98" class="cartTxt1">'+prop_arr[4]+'</td>      <td width="84"><a href="#" onclick="remove_listing('+prop_arr[1]+',\'enquiry\')"><img src="/images/clean_del.gif" alt="Remove this from your reservation cart" width="17" height="17" border="0"></a></td></tr>';
			}
			listing_content += '  </table></td></tr></table>';
		}
		var listing_list = getCookie('cookie_compare_list');
		if(listing_list==null) listing_list = '';
		if(listing_list!=''){
			if(listing_content!='') listing_content += '<br />';
			listing_list_arr = listing_list.split('~~~');
			listing_content += '<table id="top_cart_table2" width="724" border="0" style="border:#386418 1px solid;padding:5px;background-color:#FB8A6D;"><tr><td width="38"><img src="/images/success_icon1.gif"></td><td width="540"><div class="cartTxt5">Compare List<div class="cartTxt1">You have successfully added the following BB/INN for a Comparison. When you are ready click</div></td><td><input type="button" class="cartButton" value="Compare Now" onclick="show_compare_page();"></td></tr><tr><td></td><td colspan="2"><table width="552" border="0">';
			for(var i=0;i<listing_list_arr.length;i++){
				prop_arr = listing_list_arr[i].split('|||');
				listing_content += '	<tr><td width="69" class="cartTxt1">BB# '+prop_arr[1]+'</td><td width="184"><A href="'+get_detail_url(prop_arr[6],prop_arr[1])+'" class="cartlink1">'+(prop_arr[2].length>20?prop_arr[2].substring(0,20)+'...':prop_arr[2])+'</A></td>      <td width="91" class="cartTxt1">'+prop_arr[5]+'</td>      <td width="98" class="cartTxt1">'+prop_arr[4]+'</td>      <td width="84"><a href="#" onclick="remove_listing('+prop_arr[1]+',\'compare\')"><img src="/images/clean_del.gif" alt="Remove this from your compare list" width="17" height="17" border="0"></a></td></tr>';
			}
			listing_content += '  </table></td></tr></table>';
		}
		document.getElementById('top_cart').innerHTML = listing_content;
		/*if(listing_content!=''){
			if(document.getElementById('landing_flash')){
				if(document.getElementById('top_cart_table')) document.getElementById('top_cart_table').style['width']='100%';
				if(document.getElementById('top_cart_table2')) document.getElementById('top_cart_table2').style['width']='100%';
			}else if(get_screen_width()>1024){
				if(document.getElementById('top_cart_table')) document.getElementById('top_cart_table').style['width']='80%';
				if(document.getElementById('top_cart_table2')) document.getElementById('top_cart_table2').style['width']='80%';
			}else{
				if(document.getElementById('top_cart_table')) document.getElementById('top_cart_table').style['width']='100%';
				if(document.getElementById('top_cart_table2')) document.getElementById('top_cart_table2').style['width']='100%';
			}
		}*/
	}
}

function add_listing(id,title,image,state,city,type,web_folder,column){
	switch(type){
		case 'enquiry':
			cookie_name = 'cookie_enquiry_list';
			alert_cookie_name = 'popup_enquiry_alert';
			alert_div = 'popup_alert_enquiry';
			break;
		case 'compare':
			cookie_name = 'cookie_compare_list';
			alert_cookie_name = 'popup_compare_alert';
			alert_div = 'popup_alert_compare';
			break;
	}
	var temp = '|||'+id+'|||'+title+'|||'+image+'|||'+state+'|||'+city+'|||'+web_folder;
	var listing_list = getCookie(cookie_name);
	if(listing_list==null) listing_list = '';
	if(listing_list!='') temp = '~~~'+temp;
	if(listing_list.indexOf('|||'+id+'|||')<0){
		listing_list += temp;
		setCookie(cookie_name, listing_list, null, null, 'bedbreakfasthome.com');
		if(column=='right'){
			//document.getElementById('listing_added').style['display'] = 'block';
			//alert_message('Listing added successfully to your enquiry cart.');
			show_top_cart();
		}else{
			show_listing_list(type,column);
			/*try{
				var popup_alert = getCookie(alert_cookie_name);
				if(popup_alert==null) popup_alert = 'yes';
				if(popup_alert!='no') createWindow('&nbsp;', 300, '#D6E1F5', alert_div, 0, screen.width/2-173, 110,'background_frame',402,182);
			}catch(e){}*/
		}
	}else if(column=='right'){
		//alert_message('This Listing is already in your enquiry cart.');
	}
}

function alert_message(msg){
	document.getElementById('alert_message_content').innerHTML=msg;
	createWindow('&nbsp;', 300, '#D6E1F5', 'popup_alert_message', 0, screen.width/2-173, 110,'background_frame',402,182);
}

function close_alert_message(){
	js_popup_window.close();
}

function remove_listing(id,type,column){
	if(!column) column = 'left';
	switch(type){
		case 'enquiry':
			cookie_name = 'cookie_enquiry_list';
			break;
		case 'compare':
			cookie_name = 'cookie_compare_list';
			break;
	}
	var listing_list = getCookie(cookie_name);
	if(listing_list==null) listing_list = '';
	if(listing_list!=''){
		listing_list_arr = listing_list.split('~~~');
		listing_list = '';
		for(var i=0;i<listing_list_arr.length;i++){
			if(listing_list_arr[i].indexOf('|||'+id+'|||')<0){
				if(listing_list!='') listing_list += '~~~'+listing_list_arr[i];
				else listing_list += listing_list_arr[i];
			}
		}
		setCookie(cookie_name, listing_list, null, null, 'bedbreakfasthome.com');
		show_listing_list(type,column);
	}
}

function show_search_page(type,show_option){
	if(document.getElementById('left_column')){
		if(type=='') type = 'keyword';
		if(type!='') change_tab(type);
		if(show_option) document.getElementById("more_option_div").style["display"] = "block";
	}else document.location = '/search.html';
}

function do_not_show_alert(type){
	now1 = new Date();
	now1.setTime(now1.getTime() + 7*1000*60*60*24);
	if(type=='enquiry'){
		setCookie('popup_enquiry_alert', 'no', now1, null, 'bedbreakfasthome.com');
		js_popup_window.close();
	}else if(type=='compare'){
		setCookie('popup_compare_alert', 'no', now1, null, 'bedbreakfasthome.com');
		js_popup_window.close();
	}
}

function show_compare_page(){
	var listing_list = getCookie('cookie_compare_list');
	var tmp = '~';
	show_alert = false;
	if(listing_list==null) listing_list = '';
	if(listing_list==''){
		show_alert = true;
	}else{
		listing_list_arr = listing_list.split('~~~');
		if(listing_list_arr.length<=1) show_alert = true;
		else{
			for(var i=0;i<listing_list_arr.length;i++){
				prop_arr = listing_list_arr[i].split('|||');
				tmp += prop_arr[1]+'~';
			}
		}
	}

	if(show_alert){
		alert('Please add more than one listing for comparison.');
	}else{
		show_popup_frame('f_general_popup','f_general_popup_frame','/compare_page.php?listing_id='+tmp,800,500,10,'center');
	}
}

function reload_compare_page(){
	hide_popup_frame('f_general_popup','f_general_popup_frame');
	show_compare_page();
}

function show_enquiry_window(){
	document.location = '/enquiry.php';
	/*var listing_list = getCookie('cookie_enquiry_list');
	var tmp = '~';
	show_alert = false;
	if(listing_list==null) listing_list = '';
	if(listing_list==''){
		show_alert = true;
	}else{
		listing_list_arr = listing_list.split('~~~');
		if(listing_list_arr.length<1) show_alert = true;
		else{
			for(var i=0;i<listing_list_arr.length;i++){
				prop_arr = listing_list_arr[i].split('|||');
				tmp += prop_arr[1]+'~';
			}
		}
	}

	if(show_alert){
		alert('Please add listing for enquiry.');
	}else{
		show_popup_frame('f_general_popup','f_general_popup_frame','/enquiry_page.php?listing_id='+tmp,700,590,10,'center');
	}*/
}

function enlarge_image(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function show_helpdesk_window(){
	show_popup_frame('general_popup','general_popup_frame','/helpdesk_page.php?',528,517,10,'center');
}

function show_login_window(){
	show_popup_frame('general_popup','general_popup_frame','/login_page.php',653,362,100,'center');
}

function show_send_page_window(){
	show_popup_frame('general_popup','general_popup_frame','/popup_send_page.php',528,500,10,'center');
}

function popup_window(url,feature,windowid) {
	if(!windowid) windowid = 'popup_window';
	window.open(url,windowid,feature);
}

function register_listing(){
	document.location = '/package.php';
}

function show_popup_frame(div_id,frame_id,frame_src,w,h,top,left,dont_show_processing){
	document.getElementById(frame_id).src = frame_src;
	var frame_div = document.getElementById(div_id);
	try{
		if(document.all) {
			if(document.documentElement){
				offset_top = document.documentElement.scrollTop;
			}else{
				offset_top = document.body.scrollTop;
			}
		}else{
			offset_top = window.pageYOffset;
		}
	}catch(e){
		offset_top = 0;
	}
	frame_div.style['zIndex'] = 101;
	frame_div.style['width'] = w + 'px';
	frame_div.style['height'] = h + 'px';
	frame_div.style['top'] = (top + offset_top) + 'px';
	if(left=='center') frame_div.style['left'] = (screen.width-w)/2 + 'px';
	else frame_div.style['left'] = left + 'px';
	frame_div.style['display'] = 'block';

	page_height = 0;
	bottom_div_obj = document.getElementById('bottom_div');
	if (bottom_div_obj.offsetParent) {
		page_height = bottom_div_obj.offsetTop
		while (bottom_div_obj = bottom_div_obj.offsetParent) {
			page_height += bottom_div_obj.offsetTop
		}
	}

	document.getElementById('gray_effect_layer').className = 'gray_effect_layer_show';
	if(page_height>0) document.getElementById('gray_effect_layer').style['height'] = page_height+'px';
}

function hide_popup_frame(div_id,frame_id){
	var frame_div = document.getElementById(div_id);
	frame_div.style['display'] = 'none';
	document.getElementById(frame_id).src = '';
	document.getElementById('gray_effect_layer').className = 'gray_effect_layer_hide';
}

function addLoadEvent(func) {
   var oldonload = window.onload;
   if (typeof window.onload != 'function') {
      window.onload = func;
   }
   else {
      window.onload = function() {
		  oldonload();
		  func();
	  }
   }
}

function detail_page_loaded(id){
	show_top_cart();
	check_from_page();
	var listing_list = getCookie('cookie_enquiry_list');
	if(listing_list==null) listing_list = '';
	if(listing_list.indexOf('|||'+id+'|||')>=0) document.getElementById('listing_added').style['display'] = 'block';

	var detail_tabs=new ddtabcontent("listing_detail_tabs")
	detail_tabs.setpersist(true)
	detail_tabs.setselectedClassTarget("link") //"link" or "linkparent"
	ddtabcontent.setCookie("listing_detail_tabs","")
	detail_tabs.init()
}

function about_us(){
	document.location = '/about.html';
}

function HTTP_GET_VARS(s) {
	var rv = {}, decode = window.decodeURIComponent || window.unescape;
	(s === undefined ? location.search : s).replace(
		/([^=&]*?)((?:\[\])?)(?:=([^&]*))?(?=&|$)/g,
		function ($,n,arr,v) {
			if (n == '')
				return;
			n = decode(n);
			v = decode(v);
			n = n.replace('?','');
			if (arr) {
				if (typeof rv[n] == 'object')
					rv[n][rv[n].length] = v;
				else
					rv[n] = [v];
			} else
				 rv[n] = v;
		});
	return rv;
}

function check_from_page(){
	var from_page = getCookie('from_page');
	if(from_page==null) from_page = '';
	var listing_from_page = getCookie('listing_from_page');
	if(listing_from_page==null) listing_from_page = '';
	if(from_page!='' || listing_from_page!=''){
		var _GET = HTTP_GET_VARS();
		if(_GET['from']=='listing' && listing_from_page!=''){
			document.getElementById('detail_bread_crumb').innerHTML = listing_from_page;
		}
		else if(_GET['from']=='search_result' && _GET['page'] && from_page=='search'){
			document.getElementById('detail_bread_crumb').innerHTML = document.getElementById('detail_bread_crumb').innerHTML + '<SPAN class="StPgArrow"> &gt; </SPAN><A class="StPgTraillinks" href="/search.html?SPage='+_GET['page']+'">BACK TO SEARCH RESULTS</A>';
		}
		else if(_GET['from']=='compare_page' && from_page=='compare'){
			var back_page = getCookie('back_page');
			if(back_page==null) back_page = '';
			if(back_page!=''){
				back_page = back_page.replace(/action=show_compare/i, "");
				back_page = back_page.replace(/action=/i, "");
				if(back_page.indexOf('?')>=0) back_page = back_page + '&action=show_compare';
				else back_page = back_page + '?action=show_compare';
				document.getElementById('detail_bread_crumb').innerHTML = document.getElementById('detail_bread_crumb').innerHTML + '<SPAN class="StPgArrow"> &gt; </SPAN><A class="StPgTraillinks" href="'+back_page+'">BACK TO COMPARE PROPERTIES</A>';
			}
		}
	}
}

function end_script(tab,subtab){
	if(document.getElementById('enquiry_box_content_parent')) document.getElementById('enquiry_box_content_parent').innerHTML = '';
	if(document.getElementById('compare_box_content_parent')) document.getElementById('compare_box_content_parent').innerHTML = '';
	if (typeof resize_tab_table == 'function') resize_tab_table();
	var _GET = HTTP_GET_VARS();
	if(_GET['action']=='show_compare'){
		setCookie("from_page", "", null, null, "bedbreakfasthome.com");
		setCookie("back_page", "", null, null, "bedbreakfasthome.com");
		show_compare_page();
	}
	if(_GET['action']=='show_review'){
		if(document.getElementById('tab_Review_id')) document.getElementById('tab_Review_id').onclick();
	}
	if(tab && tab!=""){
		if(document.getElementById(tab)) document.getElementById(tab).onclick();
		if(subtab && subtab!="") if(document.getElementById(subtab)) document.getElementById(subtab).onclick();
	}
	if((_GET['from']=='state' || _GET['from']=='province') && document.getElementById('page_bread_crumb')){
		var tmp = document.getElementById('page_bread_crumb').innerHTML;
		tmp = tmp.split(' &gt; ');
		if(tmp.length==5) document.getElementById('page_bread_crumb').innerHTML = tmp[0] + ' &gt; ' + tmp[1] + ' &gt; ' + tmp[2] + ' &gt; ' + tmp[4].replace('\'.html\';return false;','\'.html?from='+_GET['from']+'\';return false;');
	}
	if(document.getElementById('page_bread_crumb')) setCookie("listing_from_page", document.getElementById('page_bread_crumb').innerHTML, null, null, "bedbreakfasthome.com");
	show_listing_list('enquiry');
	show_listing_list('compare');
	if(review_id_index>0){
		var tmp = '';
		for(var i=0;i<review_id_index;i++) tmp += 'review_id_arr[]='+review_id_arr[i]+'&';
		document.write('<sc'+'ript src="'+'/review_msg.php?'+tmp+'"></sc'+'ript>');
	}
	if(coupon_id_index && coupon_id_index>0){
		var tmp = '';
		for(var i=0;i<coupon_id_index;i++) tmp += 'coupon_id_arr[]='+coupon_id_arr[i]+'&';
		document.write('<sc'+'ript src="'+'/coupon_msg.php?'+tmp+'"></sc'+'ript>');
	}
}

function category_page_loaded(category_name){
	show_listing_list('enquiry');
	show_listing_list('compare');
}

function addbookmark()
{
	url = document.location;
	title = document.title;
	if (window.sidebar) window.sidebar.addPanel(title, url, "");// firefox		
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all) window.external.AddFavorite(url, title);// ie
	else alert('Sorry! Your browser doesn\'t support this function.\nYou can press Ctrl+D to bookmark this page.');
}
