var flag=new Array();
var voteflag=0;
var defaultMultipleText="Restaurant Name or City Name";

// Open window method (Macromedia)
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function byAll(){
	set_cookie(0,0,"");
	top.location.href = "/list/search_result.asp";
}
function byFoodStyle(str){
	set_cookie(0,str,0);
	top.location.href = "/list/search_result.asp?foodstyle=" + escape(str);
}
function byArea(str){
	set_cookie(str,0,0);
	top.location.href = "/list/search_result.asp?area=" + escape(str);
}
function byWord(str){
	set_cookie(0,0,str);
	if(str != ""){
		top.location.href = "/list/search_result.asp?name=" + escape(str);
	}else{
		byAll();
	}
}
function byCoupon(){
	top.location.href = "/list/search_result.asp?coupon=1";
}
function byAlph(alph,words){
	top.location.href = "/list/search_result.asp?alph="+alph+"&"+words;
}

function searchWords(){
	byWord(document.searchForm.Search.value);
}
function searchMultiple(){
	var tf=document.searchForm;
	var q_foodstyle=new String("");
	var q_area=new String("");
	var q_name=new String("");
	var q_str=new String("");

	//alert("searchMultiple()");

	if(tf.foodstyle.selectedIndex>0){
		q_foodstyle="foodstyle="+escape(tf.foodstyle.options[tf.foodstyle.selectedIndex].value);
	}
	if(tf.area.selectedIndex>0){
		q_area="area="+escape(tf.area.options[tf.area.selectedIndex].value);
	}
	if(tf.name.value!="" && tf.name.value!=defaultMultipleText){
		q_name="name="+escape(tf.name.value);
	}

	q_str="/list/search_result.asp?";
	q_str+=q_foodstyle;
	if(q_area!="" && q_foodstyle!=""){ q_str+="&"; }
	q_str+=q_area;
	if(q_name!="" && (q_area!="" || q_foodstyle!="")){ q_str+="&"; }
	q_str+=q_name;

	//alert(q_str);

	top.location.href = q_str;
	//リターンキーが押されてonSubmitイベントが起こったときに、本来のsubmitが実行されないようにする
	return false;
}
function initMultipleSearch(){
	var tf=document.searchForm;
	if(tf.name.value==defaultMultipleText){
		tf.name.value="";
	}
}

function turnon(obj,idx){
	document.images[obj+idx].src="images/"+idx+"down.gif";
}
function turnoff(obj,idx){
	if(flag[obj+idx]==true){
		document.images[obj+idx].src="images/"+idx+"down.gif";
	}else{
		document.images[obj+idx].src="images/"+idx+"up.gif";
	}
}
function changeflag(obj,idx){
	var tf=document.voteForm;
	for(i=1;i<6;i++){
		flag[obj+"0"+i]=false;
		if(i==idx){
			flag[obj+"0"+i]=true;
			switch(obj){
			case "t":
				tf.taste.value=i;
				break; 
			case "p":
				tf.price.value=i;
				break; 
			case "s":
				tf.service.value=i;
				break; 
			case "i":
				tf.interior.value=i;
				break; 
			}
		}
		turnoff(obj,"0"+i);
	}
}
function vote(){
	var tf=document.voteForm;
	if(!voteflag){
		voteflag=1;
		tf.action="evaluation.asp";
		tf.method="GET";
		tf.submit();
	}else{
		alert("Don't push a button repeatedly.");
	}
}

function result(){
	var tf=document.voteForm;
	window.open("evaluation_result.asp?restaurantid="+tf.restaurantid.value,"evalresult","width=360,height=220,scrollbars=no");
	window.opener=self;
}

function after_submit(taste,price,service,interior){
	changeflag("t",taste);
	changeflag("p",price);
	changeflag("s",service);
	changeflag("i",interior);
	voteflag=1;
}

function mailtofriend(dir){
	window.open("../mailtofriend/mailform.aspx?dirName="+dir, "mailform", "width=460,height=670,scrollbars=no");
	window.opener=self;
}

function openCoupon(dir){
	window.open("../"+dir+"/coupon/index.html", "coupon", "width=580,height=700,scrollbars=no");
	window.opener=self;
}

function fetch_and_set_cookie(){
	var str=new String(document.location);
	var inputs=new String();
	var ary=new Array();
	var value=new Array();

	//alert(str);

	if(str.indexOf('?')!=-1){
		inputs=str.substring(str.indexOf("?")+1);
		ary=inputs.split("&");
		//alert(inputs+"/"+ary[0]);
		for(var i=0;i<ary.length;i++){
			unset_cookie();
			value=ary[i].split("=");
			//alert(value[0]+"="+value[1]);
			if(value[0]=="area"){
				set_cookie(unescape(value[1]),0,0);
			}else if(value[0]=="foodstyle"){
				set_cookie(0,unescape(value[1]),0);
			}else if(value[0]=="name"){
				set_cookie(0,0,unescape(value[1]));
			}
		}
	}
}

function set_cookie(area, foodstyle, word) {
	document.cookie="areastr="+escape(area);
	document.cookie="foodstylestr="+escape(foodstyle);
	document.cookie="wordstr="+escape(word);
	document.cookie="path=/";
}
function get_cookie(name){
	theName=name+"=";
	theCookie=document.cookie;
	start=theCookie.indexOf(theName);
	if(start!=-1){
		end=theCookie.indexOf(";",start);
		if(end < start+theName.length){
			return "";
		}else{
			return unescape(theCookie.substring(start+theName.length,end));
		}
	}else{
		return 0;
	}
}
function unset_cookie() {
	document.cookie="areastr=0; foodstylestr=0; wordstr=0; expires=1-Jan-1997 00:00:00; ";
}

function track(str){
	var trackstr=new String("");
	var refstr=new String(document.referrer);
	var inputs=new String();
	var ary=new Array();
	var value=new Array();
	var tmpary=new Array();

	var setflag=0;

	//alert(str);

	if(refstr.indexOf('?')!=-1){
		inputs=refstr.substring(refstr.indexOf("?")+1);
		ary=inputs.split("&");
		//alert(inputs+"/"+ary[0]);
		for(var i=0;i<ary.length;i++){
			unset_cookie();
			value=ary[i].split("=");
			//alert(value[0]+"="+value[1]);
			value[1]=unescape(value[1]);
			tmpary=value[1].split('+');
			value[1]=tmpary.join(' ');
			if(value[0]=="area" && value[1]!=""){
				trackstr += "<a href=\"/areamap/index.html\">Area</a>"
					+ "&nbsp;&gt;&nbsp;";
				trackstr += "<a href='javascript:byArea(\"" + value[1] + "\")'>" + value[1] + "</a>";
				setflag=1;
				break;
			}else if(value[0]=="foodstyle" && value[1]!=""){
				trackstr += "<a href=\"/foodstyle/foodstyle.html\">Food Style</a>"
					+ "&nbsp;&gt;&nbsp;";
				trackstr += "<a href='javascript:byFoodStyle(\"" + value[1] + "\")'>" + value[1] + "</a>";
				setflag=1;
				break;
			}else if(value[0]=="coupon"){
				trackstr += "<a href=\"/\">Top</a>"
					+ "&nbsp;&gt;&nbsp;";
				trackstr += "<a href='javascript:byCoupon()'>";
				trackstr += "Coupon";
				trackstr += "</a>";
				setflag=1;
				break;
			}else if(value[0]=="name"){
				trackstr += "<a href=\"/\">Top</a>"
					+ "&nbsp;&gt;&nbsp;";
				trackstr += "<a href='javascript:byWord(\"" + value[1] + "\")'>";
				if(value[1]!=""){
					trackstr += value[1];
				}else{
					trackstr += "All Restaurants";
				}
				trackstr += "</a>";
				setflag=1;
				break;
			}
		}
	}else if(refstr.indexOf('/sp/')!=-1){
		//特集ページから
		var endidx=0;

		if(refstr.indexOf('/index.')!=-1){
			endidx=refstr.indexOf('/index.');
		}else{
			endidx=refstr.length;
		}
		trackstr += "<a href=\"/\">Top</a>"
			+ "&nbsp;&gt;&nbsp;";
		trackstr += "<a href=\"" + refstr + "\">" + refstr.substring(refstr.indexOf('/sp/')+4,endidx) + "</a>";
		setflag=1;
	}
	if(!setflag){
		trackstr += "<a href='javascript:byWord(\"\")'>";
		trackstr += "All Restaurants";
		trackstr += "</a>";
	}

/*	var area=new String("");
	var foodstyle=new String("");
	var word=new String("");

	area=get_cookie("areastr");
	foodstyle=get_cookie("foodstylestr");
	word=get_cookie("wordstr");

	trackstr += "<a href=\"/\">Top</a>"
		+ "&nbsp;&gt;&nbsp;";

	if(area!="0"){
		trackstr += "<a href=\"/areamap/index.html\">Area</a>"
			+ "&nbsp;&gt;&nbsp;";
		trackstr += "<a href='javascript:byArea(\"" + area + "\")'>" + area + "</a>";
	} else if(foodstyle!="0"){
		trackstr += "<a href=\"/foodstyle/foodstyle.html\">Food Style</a>"
			+ "&nbsp;&gt;&nbsp;";
		trackstr += "<a href='javascript:byFoodStyle(\"" + foodstyle + "\")'>" + foodstyle + "</a>";
	} else if(word!="0"){
		trackstr += "<a href='javascript:byWord(\"" + word + "\")'>";
		if(word!=""){
			trackstr += word;
		}else{
			trackstr += "All Restaurants";
		}
		trackstr += "</a>";
	}else{
		trackstr += "<a href='javascript:byWord(\"\")'>";
		trackstr += "All Restaurants";
		trackstr += "</a>";
	}
*/
	trackstr += "&nbsp;&gt;&nbsp;" + str;

	if(document.all){
		//IE
		document.all("track").innerHTML=trackstr;
	}else if(document.getElementById){
		//NN6
		document.getElementById("track").innerHTML=trackstr;
	}else if(document.layers){
		//NN4
		document.layers["track"].document.open();
		document.layers["track"].document.open("<span>");
		document.layers["track"].document.open(trackstr);
		document.layers["track"].document.open("</span>");
		document.layers["track"].document.close();
	}
}

function poll(){
	var tf=document.pollForm;
	var col=0;

	if(!voteflag /*&& get_cookie("poll")!=tf.name.value*/){
		voteflag=1;

		var theDay = 30;
		var setDay = new Date();
		setDay.setTime(setDay.getTime()+(theDay*1000*60*60*24));
		expDay = setDay.toGMTString();
		document.cookie = "poll=" + escape(tf.name.value) + "; expires=" + expDay;

		for(i=0;i<10;i++){
			if(tf.col[i] && tf.col[i].checked){
				col=i+1;
				break;
			}
		}
		window.open("poll_result.asp?name="+tf.name.value+"&col="+col,"poll_result","width=380,height=260,scrollbars=no");

	}else{
		alert("Don't push a button repeatedly.");
	}
}

function deletebbs(num,tuples){
	var tf=document.deleteForm;

	for(i=0;i<tuples;i++){
		if(tf["deletekey_"+i] && tf["deletekey_"+i].value!=""){
			tf.deletekey.value=tf["deletekey_"+i].value;
			break;
		}
	}
	tf.deletenum.value=num;
	tf.action="index.aspx";
	tf.method="POST";
	tf.submit();
}

function jumpPage(num){
	location.href="detail.aspx?start="+num;
}
function jumpTopPage(num){
	location.href="index.aspx?start="+num;
}

