﻿// JavaScript Document

//get url parameter
function Request(name){
	var pattern = /(\w*)=([a-zA-Z0-9\u4e00-\u9fa5]+)/ig, params = {};//定义正则表达式和一个空对象
	decodeURIComponent(window.location.href, true).replace(pattern, function(a, b, c){ params[b] = c; });
	return params[name] ? params[name] : null;
}


function initCondidate(){
	
	$("country").value = Request("c");
	$("rid").value = Request("rid");
	$("prizeid").value = Request("prizeid");
	var votes = Request("votes");
	if(votes==null || votes=="") votes =0;
	$("votes").innerHTML = votes;	
}

function voteCondidate(){
	var country = $("country").value;
	var rid = $("rid").value;
	var vid = $("prizeid").value;
	
	var voidcids = $.Cookies.get("votecid");
	//vote condidate not only one ,another restaurant  has same condidate prizeid
	var ridvid = rid*1+vid*1;

	if(voidcids!=null){
		if(voidcids.indexOf(ridvid)!=-1){
			$("voteinfo").innerHTML = "You has been vote !";
			return ;
		}		
	}

	$("voteinfo").innerHTML = "Saving... ";
	$.Ajax.get("/form/?type=condidate&rid="+rid+"&c="+country+"&vid="+vid,function(x){
		var info = 	x.responseText;		
		
		if(info>0){
			//location.reload();
			if(voidcids==null){
				$.Cookies.set("votecid",ridvid,1);	
			}else{
				var vArr = voidcids.split(",");	
				if(vArr.length>=5){
					voidcids = voidcids.substring(voidcids.indexOf(",")+1);					
				}
				
				voidcids+=","+ridvid;
				$.Cookies.set("votecid",voidcids,1);								
				
			}
			$("voteinfo").innerHTML = " Saved. Thanks! ";			 
			$("votes").innerHTML = info;			
		}
		else if(info==0){
			$("voteinfo").innerHTML = "You has been vote !";
		}
	});
	
}


function showCat(id){
	var uls = $("menuList").getElementsByTagName("ul");
	for(var i=0,j; j=uls[i]; i++){
		j.style.display = "none";
	}
	$(id).style.display = "block";
	$(id).style.zoom = 1;
}
var handle = null;
function showTab(id,obj){
	var idlist = ["Review","Menu","People","Photos","Video","Map"];
	for(i=0,j; j=idlist[i]; i++){
		if($(j)){$(j).hide();}
	}
	$(id).show();
	var as = obj.parentNode.parentNode.getElementsByTagName("a");
	for(var i=0,j; j=as[i]; i++){
		j.className="";
	}
	obj.className="cur";
	if(id=="Photos"){
		var imgs = $("smallImg").value;
		var ul = $("photoList");
		if(imgs!="" && !ul.firstChild){
			var arr = imgs.split(",");			
			ul.innerHTML = "";
			for(var i=0; i < arr.length-1; i++){
				var li = document.createElement("li");
				li.innerHTML = "<a href=\"javascript:void(0)\" onclick=\"showBigPic('"+arr[i]+"')\"><img src=\""+arr[i]+"_small.jpg\" /></a>";
				ul.appendChild(li);
			}
			handle = setInterval(scrollImgList,60);			
			//$("smallImg").value = "";			
		}
	}
	if(id=="Map"){		
		var url = window.frames["googlemap"].location.href;
		if(url=="about:blank"){
		    window.frames["googlemap"].location.href = "/form/googlemap.html?s="+$V("longitude")+"&t="+$V("latitude")+"&rid="+$V("restid")+"&"+Math.random();
		}
	}
}
function noshow(obj){

}



function setMenubox(obj,id){
    var menuBox = "menubox_"+id;
    //alert(menuBox);
    if($(menuBox).style.display == "none"){
        $(menuBox).style.display = "block";
        obj.src = "http://www.9isp.com/images/collapsed_no.gif";
    }else{
        $(menuBox).style.display = "none";
        obj.src = "http://www.9isp.com/images/collapsed_yes.gif";
    }
}

function showMenubox(obj,id){
    var menuBox = "menubox_"+id;
    //alert(menuBox);
    if($(menuBox).style.display == "none"){
        $(menuBox).style.display = "block";
        obj.style.background = "#F2F2F2 url('http://www.9isp.com/images/down.gif')  no-repeat 6px 13px";
    }else{
        $(menuBox).style.display = "none";
        obj.style.background = "#F2F2F2 url('http://www.9isp.com/images/right_r.gif')  no-repeat 10px 10px";
    }
}



function showScrollHeigth(){
	var scrolldiv = document.getElementById("top_live");  
	var catHeigth = document.getElementById("catListHeigth"); 
	var parent = catHeigth.parentNode;
	var setHeight = 0;
	//&& parent.style.position != 'absolute' 
	while(parent && parent.tagName!='BODY' ){		
		setHeight = setHeight+parent.offsetTop;
		parent = parent.parentNode;		
	}
	
	alert(setHeight);
	/*
	if(document.documentElement.scrollTop &gt;=300){
		$("top_live").style.position = "fixed";
		$("top_live").style.top = "30px";
	}else{
		$("top_live").style.position = "";
	}
	*/
}

function showMenuPhoto(obj,imgPath,imgTitle){
	var bg = document.createElement("div");
	bg.className = "dark";
	bg.id = "dark";	
	var h = Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight);
	bg.style.height = h+ "px";
	bg.onclick = closeMenuPhoto;
	imgPath = imgPath.replace("_Small.jpg","");
	var imgbox = document.createElement("div");
	imgbox.className = "menuphoto";
	imgbox.id = "menuphoto";
	img = new Image();
	img.id = "menuPics";
	img.src=imgPath;
	document.body.appendChild(bg);
	document.body.appendChild(imgbox);
	imgbox.innerHTML="<img src='http://www.9isp.com/images/spinning.gif' align='absmiddle' />  Loading...";
	if(obj.getAttribute("isload")==1){
		showImgInfo(imgbox,imgTitle);
	}else{
		img.onload=function(){
			showImgInfo(imgbox,imgTitle);
			obj.setAttribute("isload",1);
		}
	}
}

function showImgInfo(imgbox,imgTitle){
	imgbox.innerHTML="";
	imgbox.appendChild(img);
	imgbox.innerHTML=imgbox.innerHTML+"<p>"+imgTitle+"</p> <p> <a href='javascript:void(0)' onclick='closeMenuPhoto()'>Close</a></p>";
	
	var b_width = imgbox.clientWidth;
	var b_height = imgbox.clientHeight;	
	var halfHeight = Math.ceil(b_height/2);
	var halfWidth = Math.ceil(b_width/2);		
	imgbox.style.visibility="hidden";	
	//alert(b_height);
	setTimeout(function (){
		imgbox.style.marginLeft="-"+halfWidth+"px";
		imgbox.style.marginTop="-"+halfHeight+"px";
		imgbox.style.visibility="visible";
	},100);
}


function closeMenuPhoto(){		
	$("menuphoto").remove();
	$("dark").remove();
}


function showMenuTabInfo(obj){
	var tipInfo = $("tipsInfo");
	var catheight = $("catheight");	
	var pointer = $("pointer");
	var menuIcon = $("menuIcon");
	
	if(tipInfo.style.display=="none"){
		tipInfo.style.display = 'inline-block';
		catheight.style.display = 'block';
		menuIcon.style.display = 'none';
		pointer.src = 'http://www.9isp.com/images/up.gif';
		menuIcon.style.borderTop="none";
	}else{
		tipInfo.style.display = 'none';
		catheight.style.display = 'none';	
		menuIcon.style.display = 'block';
		pointer.src = 'http://www.9isp.com/images/down.gif';		
		menuIcon.style.borderTop="1px solid #E6E6E6";
	}
}


function showTabInfo(obj){
	//showScrollHeigth();
	var ul = obj.parentNode;
	var lis = ul.getElementsByTagName("LI");
	var len =lis.length;
	var tab = obj.getAttribute("tab");
	var catheight = document.getElementById("catheight");	
	//var menuTab = new Array("hotList","spicyList","veggieList","popularList","healthList");
	var menuTab = new Array();
	for(var i=0;i<len;i++){
		menuTab.push(lis[i].getAttribute("tab"));
	}
	
	

	//alert(len);
	for(var i=0;i<len;i++){
		lis[i].className = "";		
	}	
	
	if(tab!=""){
		for(var j=0,len=menuTab.length;j<len;j++){
			document.getElementById(menuTab[j]).style.display = "none";
		}
		var div = document.getElementById(tab);
		div.style.display = "block";
		//check div is null
		if(div.innerHTML.length<20){
			div.innerHTML = " <div class='nomenu'> No Menu </div>";
		}
	}
	obj.className="sel_item";
}

function showSubCat(obj){
	$(obj).toggleClassName("open");
	var lis = $("menuCat").getElementsByTagName("li");
	for(var i=0,j; j=lis[i]; i++){
		if(j.className != ''){
			j.className = '';
			break;
		}
	}
	$(obj.parentNode).addClassName("cur");
	if($(obj).hasClassName("open")){		
		var ul = obj.parentNode.lastChild;
		if(ul.tagName=="UL"){
			ul.style.display = "block";
		}
	}else{
		var ul = obj.parentNode.lastChild;
		if(ul.tagName=="UL"){
			ul.style.display = "none";
		}
	}	
}
function showBigPic(url){
	var img = new Image();
	img.id = "bigpic";
	img.src = url;
	var handel = setTimeout(function(){
		document.getElementById("picbox").innerHTML = "";
		document.getElementById("picbox").appendChild(img);	
	},30);
}
function menupdf(id){
	var url = "/menu2pdf/?id="+id+"&"+Math.random();
	window.showModalDialog(url,window,"dialogWidth:370px; dialogHeight:300px; help:0");
}
function SImage(callback){
    var img = new Image();
    this.img = img;
    var appname = navigator.appName.toLowerCase();
    if (appname.indexOf("netscape") == -1){
       //ie
        img.onreadystatechange = function(){
            if (img.readyState == "complete"){
                callback(img);
            }
        };
    }else{
       //firefox
        img.onload = function(){
            if(img.complete == true){
                callback(img);
            }
        }
    }
}
SImage.prototype.get = function (url){
    this.img.src = url;
}

var urlName = location.hostname;		
var urls = urlName.split("."); 

window.cm = {
	checklogin : function(){
		var loginfo = $.Cookies.get("dinerpwd");
		if(loginfo!=null && loginfo!=""){
			return true;
		}
		return false;
	},
	darkBackground : function(onlybg){
		var bg = document.createElement("div");
		bg.className = "dark";
		bg.id = "dark";
		var h = Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight);		
		bg.style.height = h + "px";
		document.body.appendChild(bg);
		if(onlybg===1)return;
		cm.showBox();
	},
	showBox : function(){		
		$("popBox").show();		
	},
	closePopup : function(obj){
		$("popBox").hide();
		$("dark").remove();
		//location.reload(false);
	},
	showPhotobox : function(id){
		var bg = document.createElement("div");
		bg.className = "dark";
		bg.id = "dark";
		var h = Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight);		
		bg.style.height = h + "px";
		document.body.appendChild(bg);
		$("photobox").style.display="block";
		cm.photoPosition(id);	
		$("dark").onclick=cm.closePhotobox;
		
	},
	photoPosition : function(id){
		var phototable = $("phototable");
		var pics = phototable.getElementsByTagName("img");	
		var position = $("photoPosition");
		var len = pics.length;
		var previnfo = "";
		var nextinfo = "";
		var current = "";
		var psrc = "";	
		var ptitle ="";
		
		for(var i=0; i<len; i++){
			if(pics[i].getAttribute("id")==id){
				current= i+1;
				psrc= pics[i].getAttribute("src");
				ptitle = pics[i].title;
				break;
			}
		}
		
		$("photosrc").src = psrc.replace("_small.jpg","");		
		$("photoTitle").innerHTML=ptitle;
		var p_prev = $("p_prev");
		var p_next = $("p_next");
		if(current==1){				
			nextinfo = "  <a href='javascript:void(0)' onclick='cm.photoPosition("+pics[current].getAttribute("id")+")'>Next&gt;</a>";
			p_next.innerHTML="<a href='javascript:void(0)' onclick='cm.photoPosition("+pics[current].getAttribute("id")+")' title='Next' class='next'>&gt;</a>";
			p_prev.innerHTML="";
		}else if(current==len){
			previnfo = "<a href='javascript:void(0)' onclick='cm.photoPosition("+pics[current-2].getAttribute("id")+")'>&lt;Prev</a>";
			p_prev.innerHTML="<a href='javascript:void(0)' onclick='cm.photoPosition("+pics[current-2].getAttribute("id")+")' title='Prev' class='prev'>&lt;</a>";
			p_next.innerHTML="";
		}else{
			p_next.innerHTML="<a href='javascript:void(0)' onclick='cm.photoPosition("+pics[current].getAttribute("id")+")' title='Next' class='next'>&gt;</a>";
			p_prev.innerHTML="<a href='javascript:void(0)' onclick='cm.photoPosition("+pics[current-2].getAttribute("id")+")' title='Prev' class='prev'>&lt;</a>";

			previnfo = "<a href='javascript:void(0)' onclick='cm.photoPosition("+pics[current-2].getAttribute("id")+")'>&lt;Prev</a>";
			nextinfo = "<a href='javascript:void(0)' onclick='cm.photoPosition("+pics[current].getAttribute("id")+")'>Next&gt;</a>";
		}	
		
		//alert(" Images "+current+" of "+len+previnfo+nextinfo);
		position.innerHTML=" Images "+current+" of "+len+previnfo+nextinfo;
		
	},	
	closePhotobox : function(){
		$("dark").remove();
		$("photobox").style.display="none";	
	},
	comment : function(){
		cm.darkBackground();
		var country = $V("country");
		if(urls[1]=="menuasian"){
			window.frames["popForm"].location.href = "http://form.menuasian.com/form/writecomment.htm?rid="+$V("restid")+"&country="+country+"&"+Math.random();
		}else{
			window.frames["popForm"].location.href = "http://"+country+".chinesemenu.com/form/writecomment.html?rid="+$V("restid")+"&country="+country+"&"+Math.random();
		}
	},
	commentmenu : function(){
		cm.darkBackground();
		var country = $V("country");
		if(urls[1]=="menuasian"){
			window.frames["popForm"].location.href = "http://form.menuasian.com/form/commentmenu.htm?rid="+$V("restid")+"&menuid="+$V("menuid")+"&country="+country+"&"+Math.random();
		}else{
			window.frames["popForm"].location.href = "http://"+country+".chinesemenu.com/form/commentmenu.html?rid="+$V("restid")+"&menuid="+$V("menuid")+"&country="+country+"&"+Math.random();
		}
	},	
	email : function(){
		cm.darkBackground();		
		window.frames["popForm"].location.href = "/form/emailtofriend.html?rid="+$V("restid")+"&"+Math.random();
	},
	favorites : function(){
		cm.darkBackground();
		var country = $V("country");
		window.frames["popForm"].location.href = "http://"+country+".chinesemenu.com/form/addfavorite.html?rid="+$V("restid")+"&url="+escape(location.href)+"&title="+$V("restname")+"&"+Math.random();
	},
	askquestion : function(){
		cm.darkBackground();
		window.frames["popForm"].location.href = "/form/askquestion.html?rid="+$V("restid")+"&title="+$V("restname")+"&"+Math.random(); //cm.checklogin() ? "/service/post.aspx?toid="+$V("restid")+"&toname="+$V("restname") : "/form/loginfo.html";
	},
	uploadImg : function(){
		cm.darkBackground();
		window.frames["popForm"].location.href = "/form/uploadphoto.html?rid="+$V("restid")+"&"+Math.random();
	},
	rate : function(){
		cm.darkBackground();
		var country = $V("country");	    
		if(urls[1]=="menuasian"){
			window.frames["popForm"].location.href = "http://form.menuasian.com/form/rate.htm?rid="+$V("restid")+"&title="+escape($V("restname"))+"&"+Math.random();	
		}else{
			window.frames["popForm"].location.href = "http://"+country+".chinesemenu.com/form/rate.html?rid="+$V("restid")+"&title="+escape($V("restname"))+"&"+Math.random();
		}

	},
	signin : function(){
		cm.darkBackground();
		var country = $V("country");
		window.frames["popForm"].location.href = "https://"+country+".chinesemenu.com/form/loginfo.html?from="+encodeURIComponent(location.href);
	},
	signout : function(){
		$.Ajax.get("/ajax.aspx?type=signout",function(x){
			if(x.responseText==1){
				location.reload();
			}
		});
	},
	iamtheownner : function(rid){
		cm.darkBackground();
		var country = $V("country");
		window.frames["popForm"].location.href = "http://"+country+".chinesemenu.com/form/iamtheownner.html?rid="+rid;
	},
	showBigPhotos : function(obj,index, total){
		var url = obj.getAttribute("url");
		if(!document.getElementById("dark")){
			cm.darkBackground(1);
		}
		if(document.getElementById("bigImg")){
			document.body.removeChild(document.getElementById("bigImg"));
		}
		setTimeout(function(){
			var div = document.createElement("div");
			div.innerHTML = "loading...";
			div.style.padding = "10px 30px";
			div.id = "bigImg";
			document.body.appendChild(div);
			var img = new Image();
			if($.Browse.isIE()){
				img.onreadystatechange = function(){
					cm.showImage(img,index,total);
				}	
			}else{
				img.onload = function(){
					if(img.complete == true){
             			cm.showImage(img,index,total);
		            }
				}
			}
			img.src = url+"?"+Math.random();
			img.style.visibility = "hidden";
		},10);		
	},
	closeBigPhotos : function(){
		document.body.removeChild(document.getElementById("bigImg"));
		document.body.removeChild(document.getElementById("dark"));
	},
	showImage : function(img,index, total){
		img.style.visibility = "visible";
		var w = img.width;
		var h = img.height;
		if(w>1024){w=1024}
		if(h>768){h=768}
		h+=20;
		document.getElementById("bigImg").innerHTML = "";
		document.getElementById("bigImg").appendChild(img);
		var t = document.createElement("div");
		t.className = "t";
		t.innerHTML = "<a href='javascript:void(0)' class='close' onclick='cm.closeBigPhotos()'>Close</a>"+(index>1?"<a href='javascript:void(0)' onclick=cm.showBigPhotos(document.getElementById('img"+(index-1)+"'),"+(index-1)+","+total+")>Previous</a>":"")+(index==total?"":"<a href='javascript:void(0)' onclick=cm.showBigPhotos(document.getElementById('img"+(index+1)+"'),"+(index+1)+","+total+")>Next</a>");
		document.getElementById("bigImg").appendChild(t);
		document.getElementById("bigImg").style.width = w+"px";
		document.getElementById("bigImg").style.height = h+"px";
		document.getElementById("bigImg").style.marginLeft = (0-w/2)+"px";
		document.getElementById("bigImg").style.marginTop = (0-h/2)+"px";
		document.getElementById("bigImg").style.padding = "0";	
	}
};
// true -> scroll down;  false -> scroll up		
var scrollDirect = true;            	
function scrollImgList(){
	if( (document.getElementById("photoList").scrollHeight - document.getElementById("photoList").clientHeight) < 100 ){clearInterval(handle);return;}
	var sh = document.getElementById("photoList").scrollHeight;
	var ch = document.getElementById("photoList").clientHeight;
	if( (sh - ch) > 0){
		var elem = document.getElementById("photoList");
		if( elem.scrollTop >= (sh-ch)){								
			scrollDirect = false;
		}else if( elem.scrollTop <= 0){
			scrollDirect = true;
		}
		if(scrollDirect){
			elem.scrollTop++;
		}else{		
			elem.scrollTop = elem.scrollTop - 1;
		}
	}
}

function rememberRecentRest(){

    var country = document.getElementById("country").value;
    var id = document.getElementById("restid").value;
    var restname = encodeURIComponent(document.getElementById("restname").value);
    var url = location.href;

    if (url.substring(url.length - 1) != "/" && url.substring(url.lastIndexOf("/")+1) != "index.html") {
        return;
    }    
    setTimeout(function () {
        var ifr = document.createElement("iframe");
        ifr.src = "http://www.chinesemenu.com/ajax.htm?action=recentrest&rid=" + id + "&c=" + country + "&rn=" + restname;
        ifr.width = 0;
        ifr.height = 0;
        ifr.frameBoder = 0;
        ifr.style.display = "none";
        document.body.appendChild(ifr);  
    }, 1500);
}

function showMenuType(type){
	var dd = $("div.cell dl dd");
	var dd_img ="";
	var len = dd.length;
	var len_img = "";
	var divcom  = $("commendmenuList");
	$("menuTable").style.display="none";
	$("commendType").style.display="block";
	$("loadMenu").style.display="block";
	divcom.innerHTML="";
	
	var dl = document.createElement("DL");
	var dd_2 =document.createElement("DD");
	//alert(len+" "+type);
	var num=0;
	setTimeout(function(){
		$("commendTitle").innerHTML=type+"";
		for(var i=0;i<len;i++){
			dd_img = dd[i].getElementsByTagName("IMG");
			len_img = dd_img.length;
			if(len_img>0){
				for(var j=0;j<len_img;j++){
					if(type==dd_img[j].title){
						dd_2=dd[i].cloneNode(true);
						dl.appendChild(dd_2);
						num++;
						break;
					}			
				}
			}
		}
		
		$("loadMenu").style.display="none";
		$("menuTable").style.display="block";
		if(num>0){
			divcom.appendChild(dl);
		}else{
			divcom.innerHTML = " <p class='notfound'> Sorry, Can not find "+type+" !</p>";
		}
		
	},1000);

}

function closeMenulist(){
	$("commendmenuList").innerHTML="";
	$("menuTable").style.display="none";
	$("commendType").style.display="none";
}

function rateMenu(j){
	
	var menuid = $V("menuid");
	var rid = $V("restid");
	var aArr = $("#rating li a");
	var len = aArr.length;
	for(var i=0;i<len;i++){
		aArr[i].remove();		
	}
	//alert($V("rate_score")+"  "+$V("rate_num"));

	if($.Cookies.get("rate_menuid")==menuid){
		$("RateMsg").innerHTML = "You already rating"; 
	}else{	
		var addNum = parseInt($V("rate_num"))+1;
		$("RateCount").innerHTML = addNum;
		var rateVal = ((parseInt($V("rate_score"))+j)/addNum).toString().substring(0,3);
		$("Rate").innerHTML = rateVal;
		$("rateLen").style.width=(parseFloat(rateVal)*30)+"px";
		$.Ajax.post("/form/?type=rateMenu","rid="+rid+"&menuid="+menuid+"&rates="+j,function(x){		
			if(x.responseText==1){				
				$.Cookies.set("rate_menuid",menuid,1);
				//setTimeout(function(){window.location.reload();},50);
				//$("success").style.display = "block";
			}else{
				alert(x.responseText);
				//setTimeout(function(){window.location.reload();},50);
			}
		});

	}

}

function showtop100(obj){
	obj.setAttribute("target","_blank");
	obj.href = "http://top100.chinesemenu.com/us/?p=cat&rootid=3260857&catid=3260858";	
	//setTimeout(function(){ window.open("http://top100.chinesemenu.com/us/?p=cat&rootid=3260857&catid=3260858","top100",""); },100);	
}

function selLang(language){
	var url=location.href;
	var k = url.indexOf("/zh-TW/");
	var l = url.indexOf("/zh-CN/");
	var sel =0;
	var dir = '';
	//alert(language);
	if(language=='en'){
		if(k>0) { sel = k; }							
		if(l>0) { sel = l; }
		if(sel==0){
			url=url;
		}else{
			url=url.replace(/\/zh-TW\/|\/zh-CN\//g,"/");
		}
		$.Cookies.set("typelang","en-US",1,"/","chinesemenu.com");					
	}else{
		if(language=='tw') {
			if(k==-1 && l==-1){
				dir = "/zh-TW/";
			    var m = url.lastIndexOf("/");
				url = url.substring(0,m)+dir+url.substring(m+1,url.length);
			}
			if(k==-1 && l!=-1){
				dir = "/zh-TW/";
			
				url = url.replace(/\/zh-CN\//g,"/zh-TW/");
			}
			 $.Cookies.set("typelang","zh-TW",1,"/","chinesemenu.com"); 
			
		}
		if(language=='cn') {
			if(l==-1 && k==-1){
				dir = "/zh-CN/"; 
				var m = url.lastIndexOf("/");
				url = url.substring(0,m)+dir+url.substring(m+1,url.length);
			}
			if(l==-1 && k!=-1){
				dir = "/zh-CN/";
			
				url = url.replace(/\/zh-TW\//g,"/zh-CN/");
			}
			$.Cookies.set("typelang","zh-CN",1,"/","chinesemenu.com"); 
			
		}
		
	}
	location.replace(url);				
}

function headerdivover(){
	$("x").style.display="block";	
	$("x").className="baroption";
}
function headerdivout(){
	$("x").style.display="none";
}

function googleStatisticCode(){
	
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-18171544-1']);
	_gaq.push(['_setDomainName', '.chinesemenu.com']);
	_gaq.push(['_trackPageview']);
	
	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();	
	
}




function mousePosition(ev){
	
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	}; 
	
} 

function infoMenu(ev,id,type){
	var mid = $("info_"+id);
	//alert(ev.getAttribute("mid"));
	if(type=='hide'){
		mid.style.display="none";	
		
	}else{
		mid.style.display="block";	
	}
}


function showMenuInfo(event,obj){
	var id = obj.getAttribute("mid");
	var infoBox = $("info_"+id);
	infoBox.style.display = "block";
	var scrollTop = Math.max(document.documentElement.scrollTop,document.body.scrollTop);
	var x = event.clientX;
	var y = event.clientY + scrollTop;
	var bWidth = infoBox.offsetWidth;
	var bHeight = infoBox.offsetHeight;
	var menuBoxs = $("menuBoxs");	
	menuBoxs.className = "menuInfobox";
	menuBoxs.innerHTML = infoBox.innerHTML;
	infoBox.style.display = "none";

	if (bWidth > (document.body.offsetWidth - x)) {
		menuBoxs.style.left = x - bWidth - 5 + "px";
	}
	else {
		menuBoxs.style.left = x + 5 + "px";
	}
	if (bHeight > (document.body.offsetHeight - y)) {
		menuBoxs.style.top = y - bHeight - 5 + "px";
	}
	else {
		menuBoxs.style.top = y + 5 + "px";
	}	
	menuBoxs.style.display = "block";
}

function hideMenuInfo(obj){
	var id = obj.getAttribute("mid");
	var infoBox = $("info_"+id);
	$("menuBoxs").style.display="none";	
	infoBox.style.display="none";	
}

function showMenuPic(event,imgsrc){

	var imgBox = $("imgBoxs");
	var x  =  event.clientX;
	var scrollTop = Math.max(document.documentElement.scrollTop,document.body.scrollTop);
	var y = event.clientY+scrollTop;
		
	imgBox.innerHTML = "<img src='"+imgsrc+"'/>";	
	var img = imgBox.getElementsByTagName("img")[0];
	
	if(img.width>(document.body.offsetWidth-x)){
		imgBox.style.left = x - img.width-10+"px";
	}else{
		imgBox.style.left = x + 12 + "px";	
	}
	
	if(img.height > (document.body.offsetHeight - y)){
		imgBox.style.top =  y - img.height-5+"px";
	}else{
		imgBox.style.top = 	y+5+"px";
	}
	
	imgBox.style.display = "block";	
}

function hideMenuPic(){
	$("imgBoxs").style.display = "none";		
}


function setQtyValue(obj){
	//alert(obj.value);
	var qty = parseInt(obj.value);
	if(qty=="" || isNaN(qty)){
		obj.value=1;
	}else{
		obj.value=qty;
	}
}

function GetRealOffset(o)
{        
        var elem = o;
        var leftOffset = elem.offsetLeft;
        var topOffset = elem.offsetTop;
        var parent = elem.offsetParent;
        
        while(parent) 
        {
             leftOffset += parent.offsetLeft;
             topOffset += parent.offsetTop;
            parent = parent.offsetParent;
        }
        var Offsets = new Object();
        Offsets.y = topOffset;
        Offsets.x = leftOffset;        
        return Offsets;
}

function setMenuPic(id,pic){
	$("mp"+id).src=	pic;	
}


function refreshDiv(){
	var StartPoint, EndPoint,intTop;
	var introDiv = document.getElementById("top_live");
	StartPoint = parseInt(introDiv.style.top.replace("px",""));
	///EndPoint = document.body.scrollTop;
	EndPoint = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	if (EndPoint < 0) EndPoint = 0;	
	if (StartPoint != EndPoint ) {
		ScrollAmount = Math.ceil( Math.abs( EndPoint - StartPoint ) / 10 );	
		intTop =parseInt(introDiv.style.top);		
		introDiv.style.top = intTop + ((EndPoint < StartPoint) ? -ScrollAmount : ScrollAmount ) +"px";
	}
	setTimeout("refreshDiv();",20);
	//alert(parseInt(introDiv.style.top) + ((EndPoint < StartPoint) ? -ScrollAmount : ScrollAmount ) +"px");
	
}

function showAllTime(type){
	if(type==1){
		document.getElementById("days").style.display="block";	
	}else{
		document.getElementById("days").style.display="none";			
	}
	
}

function getBusinessHours(){
	var days = document.getElementById("days");
	var dayinfo = document.getElementById("dayinfo");
	var date = new Date();
	var today = date.getDay();
	var arr_week=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	var w = arr_week[today];
	//alert(document.getElementById("days_"+w))
	if(document.getElementById("day_"+w)!=null){
		var g_day = document.getElementById("day_"+w);
		if(g_day.innerHTML.length>8){
			g_day.className = "seltime";
			dayinfo.style.display = "";
			var info = g_day.innerHTML;
			var more = "  <a href='javascript:void(0)' onmoveron=''> More>> </a> ";
			if(info.indexOf("AM")>0 || info.indexOf("PM")>0){
				dayinfo.innerHTML = "Business Hours: &nbsp; "+info;
			}else{
				dayinfo.innerHTML = "Business Hours: &nbsp; "+info.replace("to","");
			}
		}
	}	
}

function text_info(obj){
    var state;
    if(obj.name=="fname"){ 
        state = setTextInfo(obj,"First","first name");                  
    }else if(obj.name=="lname"){
        state = setTextInfo(obj,"Last","last name");        
    }else if(obj.name=="phone"){
        state = setTextInfo(obj,"111-111-1111"," phone ");             
    }else if(obj.name=="email"){
        state = setTextInfo(obj,""," email ");            
    }
    
    return state;
    
}

function setTextInfo(obj,objname,txt){
   // var objName = obj.name;  
    var state = 0; 
    if(obj.value==objname || obj.value==""){
        obj.value = "";
        document.getElementById(obj.name+"_info").style.display = "";
        document.getElementById(obj.name+"_info").innerHTML="Please enter "+txt;              
    }else{
        state = 1;
        document.getElementById(obj.name+"_info").style.display = "none";        
    }
    

    
    if(obj.name=="email" && obj.value!="" ){
        var reg = /^\w+[@]\w+[.][\w]+$/;
        if(!reg.test(obj.value)){
           document.getElementById(obj.name+"_info").style.display = "";
           document.getElementById(obj.name+"_info").innerHTML="please input correct email  ";
           state = 0;
        }else{
           document.getElementById(obj.name+"_info").style.display = "none";
           state = 1;
        }
    }
    
    return state;
      
}

function checkReservation(obj){
    if(text_info(obj.fname)==0){
        return false;
    }
    
    if(text_info(obj.lname)==0){
        return false;
    }
    
    if(text_info(obj.phone)==0){
        return false;
    }
    
    if(text_info(obj.email)==0){
        return false;
    }
    return true;
}









function scroll(p){
  var d = document,dd = d.documentElement,db = d.body,w = window,o = d.getElementById(p.id),ie = /msie/i.test(navigator.userAgent),style;
     if(o){
      o.style.cssText +=";position:"+(p.f&&!ie?'fixed':'absolute')+";"+(p.l==undefined?'right:0;':'left:'+p.l+'px;')+(p.t!=undefined?'top:'+p.t+'px':'bottom:0');
		 if(p.f&&ie){
			o.style.cssText +=';left:expression(body.scrollLeft + '+(p.l==undefined?db.clientWidth-o.offsetWidth:p.l)+' + "px");top:expression(body.scrollTop +'+(p.t==undefined?db.clientHeight-o.offsetHeight:p.t)+'+ "px" );'
			db.style.cssText +=";background-image:url(about:blank);background-attachment:fixed;"
		}else{
			if(!p.f){
			 w.onresize = w.onscroll = function(){
				 var timer,timer1;
				 return function(){
					 if(timer)  clearTimeout(timer);
					 timer = setTimeout(function(){
						 timer1 = setInterval(function(){
							 var st = db.scrollTop,c;
							 c = st  - o.offsetTop + (p.t!=undefined?p.t:(w.innerHeight||db.clientHeight)-o.offsetHeight);
							 if(c!=0){
								  o.style.top = o.offsetTop + Math.ceil(Math.abs(c)/10)*(c<0?-1:1) + 'px';
							 }else{
								  clearInterval(timer1);  
							 }
						 },10)
					 },100)//控制滚动的频率越大频率越慢
				 }
			 }()
			}
	    }
   }  
}
