// JavaScript Document
var bbo_poker_tables=new Array();

//bbo_poker_tables[0]=new Array(table_name,description,price,dining_top,upgrade);
bbo_poker_tables[0]=new Array("UPT Jr","Removable Playing Surface",499,"/ultimate_poker_table_jr.html","/poker_tables_images/ultimate_poker_table_jr/1--s.jpg",1,0);
bbo_poker_tables[1]=new Array("V5","Offset Cupholders",549,"/v5series.htm","/poker_tables_images/v5series/1--s.jpg",0,0);
bbo_poker_tables[2]=new Array("UPT","Removable Playing Surface",579,"/ultimate_poker_table.html","/poker_tables_images/ultimate_poker_table/1--s.jpg",1,0);
bbo_poker_tables[3]=new Array("","Pro Blackjack Table",579,"/blackjack_se_table.html","/pokertables/images/BJ.jpg",0,0);
bbo_poker_tables[4]=new Array("Nighthawk","\"55\" Round Card Table",849,"/NightHawk.html","/poker_tables_images/nighthawk/1--s.jpg",0,1);
bbo_poker_tables[5]=new Array("Royale","Furniture Style Custom Table",999,"/royale_poker_table.html","/poker_tables_images/royale/1--s.jpg",1,1);
bbo_poker_tables[6]=new Array("","Casino Grade Poker Table",999,"/Casino_X_Professional_Poker_Table.html","/poker_tables_images/casinox/1--s.jpg",1,0);
bbo_poker_tables[7]=new Array("Rockwell","Removable Playing Surface",1499,"/Rockwell.html","/poker_tables_images/rockwell/1--s.jpg",1,1);
bbo_poker_tables[8]=new Array("Premier","Showpiece Poker Table",1525,"/BBO_Premier.html","/poker_tables_images/bbo_premier/1--s.jpg",1,1);
bbo_poker_tables[9]=new Array("Elite","Furniture Style Custom Table",1579,"/elite_poker_table.html","/poker_tables_images/elite/1--s.jpg",1,1);

bbo_poker_tables[10]=new Array("Albatross","Albatross Leaf Poker Table",1899,"/albatross_poker_table.html","/poker_tables_images/albatross/(15)--s.jpg",1,1);


var bbo_options=new Array();

//bbo_options[0]=new Array("Main Category Name","Multi Or Single");
bbo_options[0]=new Array("Price (Free Shipping)",1);
bbo_options[1]=new Array("Dining / Table Top Cover",0);
bbo_options[2]=new Array("Legs",0);
bbo_options[3]=new Array("Shape",0);
bbo_options[4]=new Array("Features",0);

bbo_options_sub=new Array();

//bbo_options_sub[0]=new Array(Main Caegory,Option_name,Poker_table_ID);
bbo_options_sub[0]=new Array(0,"0 - $600","0|1|2|3");
bbo_options_sub[1]=new Array(0,"$600 - $999","4|5|6");
bbo_options_sub[2]=new Array(0,"$1,000 - $1,899","7|8|9|10");
bbo_options_sub[3]=new Array(1,"Yes","9|8|7|4|10");
bbo_options_sub[4]=new Array(1,"No","0|1|2|3|5|6|4|7|8|9");
bbo_options_sub[5]=new Array(2,"Folding Metal","0|1|2");
bbo_options_sub[6]=new Array(2,"Solid Wood","9|7|6|5|4|8|10");
bbo_options_sub[7]=new Array(2,"Other","3");
bbo_options_sub[8]=new Array(3,"Oval","9|8|6|0|1|2|7|10");
bbo_options_sub[9]=new Array(3,"Round","5|4");
bbo_options_sub[10]=new Array(4,"Removable Playing Surface","9|8|7|4|0|2");
bbo_options_sub[11]=new Array(4,"Removable Armrest","5|6");
bbo_options_sub[12]=new Array(4,"Dealer Spot","1|8|6");



function bbo_poker_tables_search_display()
{
	var html_string="";
	
	html_string+='<div class="bbo_poker_table_search">';	

		html_string+='<div class="options">';
		
			html_string+=bbo_poker_tables_search_options_display();
		
		html_string+='</div>';
		
		html_string+='<div class="right">';
		
			html_string+='<div class="banner">'+bbo_poker_tables_search_banner_display()+'</div>';
			
			html_string+='<div class="module-select-1"><-- Use the selector on the left to find your perfect table!</div>';
				
			//html_string+='<div class="result" id="bbo_poker_table_search_result_1">'+bbo_poker_tables_search_result_initialize()+'</div>';
			html_string+='<div class="result" id="bbo_poker_table_search_result_1"></div>';
			
		html_string+='</div>';
	
	html_string+='</div>';
	
	document.write(html_string);
	
	document.getElementById("check_option_0").checked=true;		
	document.getElementById("check_option_1").checked=true;	
	document.getElementById("check_option_2").checked=true;	
	bbo_poker_tables_search_select_option_result();
}


function bbo_poker_tables_search_options_display()
{
	var html_string="";
	
	for (var i=0;i<bbo_options.length;i++)
	{
		html_string+="<h2>"+bbo_options[i][0]+"</h2>";
		html_string+="<ul>";
		for(var ii=0;ii<bbo_options_sub.length;ii++)
		{
			if(i==bbo_options_sub[ii][0])
			{
				html_string+="<li>";
				html_string+='<input type="checkbox" name="checkbox" id="check_option_'+ii+'" onclick="bbo_poker_tables_search_select_option_ex('+ii+');"/><a href="javascript:bbo_poker_tables_search_select_option('+ii+');">'+bbo_options_sub[ii][1]+'</a>';
				html_string+="</li>";				
			}
		}
		html_string+="</ul>";
	}
	
	return html_string;
}


function bbo_poker_tables_search_banner_display()
{
	var html_string="";
	html_string=$("#search_banner").html();
	return html_string;
}


function bbo_poker_tables_search_result_initialize()
{	
	var html_string="";
	html_string=$("#hide_message").html();
	return html_string;	
}


function bbo_poker_tables_search_select_option(id)
{
	
	var main_option_id;
	
	main_option_id=bbo_options_sub[id][0];
	//alert(main_option_id);
	if (bbo_options[main_option_id][1]==0)
	{
		
		for (var i=0;i<bbo_options_sub.length;i++)
		{
			if(bbo_options_sub[i][0]==main_option_id)
			{
				if(i==id)
				{
					
					//document.getElementById("check_option_"+id).checked=true;
					//alert("test");
					if(document.getElementById("check_option_"+id).checked==true)
					{
						document.getElementById("check_option_"+id).checked=false;	
					}
					else
					{
						document.getElementById("check_option_"+id).checked=true;		
					}
				}
				else
				{
					document.getElementById("check_option_"+i).checked=false;		
				}
			}		
		}
	}
	else
	{	
//		return;
		if(document.getElementById("check_option_"+id).checked==true)
		{
			document.getElementById("check_option_"+id).checked=false;	
		}
		else
		{
			document.getElementById("check_option_"+id).checked=true;		
		}
		//document.getElementById("check_option_"+id).checked=true;		
	}
	
	bbo_poker_tables_search_select_option_result();
	
}


function bbo_poker_tables_search_select_option_ex(id)
{
	var main_option_id;
	
	main_option_id=bbo_options_sub[id][0];

	if (bbo_options[main_option_id][1]==0)
	{
		
		for (var i=0;i<bbo_options_sub.length;i++)
		{
			if(bbo_options_sub[i][0]==main_option_id)
			{
				if(i==id)
				{					
					//document.getElementById("check_option_"+id).checked=true;
				}
				else
				{
					document.getElementById("check_option_"+i).checked=false;		
				}
			}		
		}
	}
	
	bbo_poker_tables_search_select_option_result();
}


function bbo_poker_tables_search_select_option_result()
{
	var result_id="";
	
	var result_array;
	var have_checked=false;
	
	for (var i=0;i<bbo_options.length;i++)
	{
		
		if (bbo_options[i][1]==1)
		{
			for(var ii=0;ii<bbo_options_sub.length;ii++)
			{
				//alert(bbo_options[bbo_options_sub[ii][0]][1]);
				
				if(document.getElementById("check_option_"+ii).checked==true&&bbo_options[bbo_options_sub[ii][0]][1]==1)
				{
					//alert(result_id+"--"+bbo_options_sub[ii][2]);
					have_checked=true;
					result_id=bbo_poker_tables_search_select_option_result_multi(result_id,bbo_options_sub[ii][2]);
				}
				
			}
		}
	}
	
	var multi_unchecked=false;
	//alert(result_id);
	if(!have_checked)
	{
		multi_unchecked=true;
	}

			for(var ii=0;ii<bbo_options_sub.length;ii++)
			{	
				
				if(document.getElementById("check_option_"+ii).checked==true&&bbo_options[bbo_options_sub[ii][0]][1]==0)
				{
					if(multi_unchecked)
					{
						result_id=bbo_poker_tables_search_select_option_result_multi(result_id,bbo_options_sub[0][2]);
						result_id=bbo_poker_tables_search_select_option_result_multi(result_id,bbo_options_sub[1][2]);
						result_id=bbo_poker_tables_search_select_option_result_multi(result_id,bbo_options_sub[2][2]);
						multi_unchecked=false;
					}
					//alert(result_id+"--"+bbo_options_sub[ii][2]);
					result_id=bbo_poker_tables_search_select_option_result_single(result_id,bbo_options_sub[ii][2]);
					//alert(result_id);
				}
			}
	
	
	var no_result="";
	
	if (result_id=="")
	{
		no_result+='<p class="no-result">No Result - Check Options</p>';
		
		no_result+='<p>The best way to find your poker table is to start from a broad property (like Grade), then narrow down each additional option.</p> ';

		no_result+='<p>If you select two conflicting options, your search will return as no result, so it\'s of the highest importance that you choose wisely!</p> ';

		no_result+='<p>We\'re just kidding - we made this so you can have some fun!</p>';

		$("#bbo_poker_table_search_result_1").html(no_result);
		
		return;
	}
	
	//result_id="0|1";
	//$("#bbo_poker_table_search_result_1").html("dddd");
	//alert(result_id);
	//alert(result_id);
	result_array=result_id.split("|");
	
	var html_string="";
	
	html_string+="<ul class=\"list\">";
	
	//result_array.sort();
	
	for (var i=0;i<result_array.length;i++)
	{
			//alert(result_array[i]);
			//document.getElementById("bbo_poker_table_search_result").innerHTML(result_id);
			//alert(typeof(bbo_poker_tables[result_array[i]][0]));
			if(bbo_poker_tables[result_array[i]][0]!="")
			{
				html_string+="<li>";
				
				html_string+="<a href=\""+bbo_poker_tables[result_array[i]][3]+"\">"
				html_string+="<p class=\"image\">"+"<img src=\""+bbo_poker_tables[result_array[i]][4]+"\" width=\"160\" height=\"110\" border=\"0\" alt=\""+bbo_poker_tables[result_array[i]][0]+"\"/>"+"</p>";
				
				html_string+="<p class=\"title\">"+bbo_poker_tables[result_array[i]][0]+"</p>";
				html_string+="<p class=\"description\">\""+bbo_poker_tables[result_array[i]][1]+"\"</p>";
				html_string+="<p class=\"price\">$"+outputMoney(""+bbo_poker_tables[result_array[i]][2])+"</p>";
				html_string+="<p class=\"price\">Free S&amp;H</p>";
				
				html_string+="<p class=\"sign\">"
				
				if(bbo_poker_tables[result_array[i]][5]==1)
				{
					html_string+="<a href=\"javascript:\" title=\"Upgrades Available\"><img src=\"/images/plus.jpg\" style=\"width:15px; padding:0px;margin:5px 5px 0 0px;\" /></a>";
				}
				
				if(bbo_poker_tables[result_array[i]][6]==1)
				{
					html_string+="<a href=\"javascript:\" title=\"Dinng Top Available\"><img src=\"/images/star-2.jpg\"  style=\"width:15px;padding:0px; margin:5px 5px 0 0px;\" /></a>";
				}
				
				html_string+="</p>";			
				
				
				html_string+="</a>"
				
				html_string+="</li>";
			}
	}
	
	html_string+="</ul>";
	
	//get_search_result();
	
	//$("#bbo_poker_table_search_result_1").html(html_string);
	result_output(html_string);
	
}

function get_search_result()
{	
	result_output("<div style=\"text-align:center;font-size:10px;color:#900;\">loading......</div>");
	//$("#loading_word").html("<div style=\"text-align:center;font-size:10px;color:#900;\">loading......</div>");
	//setTimeout(get_after_pasuse_result,800);
}	


function result_output(html)
{
	$("#bbo_poker_table_search_result_1").fadeOut(600,function(){
   	document.getElementById("bbo_poker_table_search_result_1").innerHTML=html;
	$("#bbo_poker_table_search_result_1").fadeIn("slow");
	 });
}

function bbo_poker_tables_search_select_option_result_multi(result_id,current_id)
{
	if (result_id=="")
	{
		result_id=current_id;
		return result_id;	
	}
	
	if (current_id=="")
	{
		return result_id;
	}
	
	
	//var new_string;
	
	var id_array=current_id.split("|");

	
	for (var i=0;i<id_array.length;i++)
	{
		//alert(bbo_poker_tables_search_check(result_id,id_array[i]));
		if(!bbo_poker_tables_search_check(result_id,id_array[i]))
		{
			//alert("exist");
			result_id+="|"+id_array[i];
		}
	}
	
	return result_id;
	
}


function bbo_poker_tables_search_check(result_id,id)
{
	if (result_id=="")
	{
		return false;
	}
	
	var result_array=result_id.split("|");
	var exist=false;

	for (var i=0;i<result_array.length;i++)
	{
		//alert(result_array[i]+"=="+id);
		
		if(result_array[i]==id)
		{
			exist=true;	
		}
	}
	
	if(exist)
	{
		return true;	
	}
	else
	{
		return false;
	}
}


function bbo_poker_tables_search_select_option_result_single(result_id,current_id)
{
	if (result_id=="")
	{
		return "";	
	}
	
	if (current_id=="")
	{
		return result_id;
	}
	
	
	var new_string="";
	
	var id_array=current_id.split("|");
	//alert(result_id+"--"+current_id);
	//alert(
	for (var i=0;i<id_array.length;i++)
	{
		//alert(bbo_poker_tables_search_check(result_id,id_array[i]));
		
		if(bbo_poker_tables_search_check(result_id,id_array[i]))
		{
			//alert("exist");
			if(new_string=="")
			{
				new_string=id_array[i];
			}
			else
			{
				new_string+="|"+id_array[i];
			}
		}
	}
	
	//alert(new_string);
	return new_string;
	
}

