﻿//经销商登陆
function dealerLogin(){
	if($F('username').trim() == ""){
		$ID('dealerLoginMsg').innerHTML = "请输入您的用户名";
		return;
	}
	if($F('password').trim() == ""){
		$ID('dealerLoginMsg').innerHTML = "请输入您的密码";
		return;
	}
	myAjax.AddKey('username',$F('username'));
	myAjax.AddKey('password',$F('password'));
	myAjax.SendPost(webDomain.url + "app/saleNet/?act=login");
	myAjax.ToDo(function(){},
	function(rs,arg){
		if(rs.responseText == 'dealer'){
			location.href = '/info-center/main.php';
		}else if(rs.responseText == 'media'){
			location.href = '/info-center/main.php';

		}else{
			$ID('dealerLoginMsg').innerHTML = "您的用户名或密码错误";
		}
	}
	);
}
//获取经销商的查询页面
function getDealerCity(id, value, str){
	if(value == "") return;
	$SS(id,"","查询中...");
	$SSF(id,true);
	myAjax.AddKey("province", value);
	myAjax.SendPost(webDomain.url + 'app/saleNet/?act=getCity');
	myAjax.ToDo(function(){},
	function(rs, arg){
		if(rs.responseText != "noData"){
			var arr = new Array();
			var temparr ="0,"+str;
			eval("arr=" + rs.responseText);

			arr.unshift(temparr);

			myAjax.buildSelect(arg, arr);
			$SSF(id,false);
		}else{
              $ID('dealerListDiv').innerHTML = "没有查询结果，请重新查询！";
			}

		myAjax.ClearSet();
	},null,id);

}
//获取经销商列表
function getDealer(id, value, str){
	if(value == "") return;
	$SS(id,"","查询中...");
	$SSF(id,true);
	myAjax.AddKey("city", value);
	myAjax.SendPost(webDomain.url + 'app/saleNet/?act=getDealer');
	myAjax.ToDo(function(){},
	function(rs, arg){
		if(rs.responseText != "noData"){

			var arr = new Array();
			var temparr = "0,"+str;
			eval("arr=" + rs.responseText)
			arr.unshift(temparr);
			myAjax.buildSelect(arg, arr);
			$SSF(id,false);
		}else{
              $ID('dealerListDiv').innerHTML = "没有查询结果，请重新查询！";
			}
		myAjax.ClearSet();
	},null,id);
}
//搜索经销商列表
function getDealerSugg(id, value, str){
	if(value == "") return;
	$SS(id,"","查询中...");
	$SSF(id,true);
	myAjax.AddKey("city", value);
	myAjax.SendPost(webDomain.url + 'app/saleNet/?act=getDealerSugg');
	myAjax.ToDo(function(){},
	function(rs, arg){
		if(rs.responseText != "noData"){

			var arr = new Array();
			var temparr = "0,"+str;
			eval("arr=" + rs.responseText)
			arr.unshift(temparr);
			myAjax.buildSelect(arg, arr);
			$SSF(id,false);
		}else{
              $ID('dealerListDiv').innerHTML = "没有查询结果，请重新查询！";
			}
		myAjax.ClearSet();
	},null,id);
}
//搜索经销商列表,投诉建议使用
//投诉建议 其他生成经销商允许填写
function getOtherDealertext(id,value){
	if(value=='-1'){
		document.getElementById(id).style.display="";
	}else{
		document.getElementById(id).style.display="none";
	}
	
}

function searchDealer(vid){
        var SPECIAL_STR = "￥#$~!@%^&*();'\"?><[]{}\\|,:/=+—“”‘";
        for(i=0;i<$F(vid).length;i++)
            if (SPECIAL_STR.indexOf($F(vid).charAt(i)) !=-1)
            {
                alert("不能包含非法字符("+$F(vid).charAt(i)+")！");
               	$ID(vid).focus();
            return false;
            }
		if($F(vid) != "" && $F(vid) != "请输入关键字"){
			myAjax.AddKey("keyWord", $F(vid));
			myAjax.SendPost(webDomain.url + 'app/saleNet/?act=searchDealer_test');
			myAjax.ToDo(function(){$ID('dealerListDiv').innerHTML =""},
			function(rs, arg){
				if(rs.responseText != "noData"){
					var arr = new Array();
					eval("arr=" + rs.responseText)
					buildDealerList(arr);
				}else{
              $ID('dealerListDiv').innerHTML = "没有查询结果，请重新查询！";
			}
				myAjax.ClearSet();
			},null,null);

		}else{
			$ID(vid).focus();
		}
}
//查找经销商列表
function getDealerInfo(p,c,d,map){
	//alert(p);
	if(map){
		myAjax.AddKey('province',p);
		myAjax.AddKey('map','map');
	}else{
		myAjax.AddKey('province',$S(p));
		myAjax.AddKey('city',$S(c));
		myAjax.AddKey('id',$S(d));
	}

	if($S(p) != ""){
		myAjax.SendPost(webDomain.url + 'app/saleNet/?act=getDealerInfo');
		myAjax.ToDo(function(){$ID('dealerListDiv').innerHTML =""},
		function(rs, arg){
			//alert(rs.responseText);
			if(rs.responseText != "noData"){
				var arr = new Array();
				eval("arr=" + rs.responseText)
				buildDealerList(arr);
			}else{
              $ID('dealerListDiv').innerHTML = "没有查询结果，请重新查询！";
			}
			myAjax.ClearSet();
		});
	} 
	return;
}
//所有经销商列表
function getAllDealer(){
	myAjax.SendGet(webDomain.url + 'app/saleNet/?act=getAllDealer');
	myAjax.ToDo(function(){$ID('dealerListDiv').innerHTML =""},
	function(rs, arg){
		if(rs.responseText != "noData"){
			var arr = new Array();
			eval("arr=" + rs.responseText)
			buildDealerList(arr);
		}else{
              $ID('dealerListDiv').innerHTML = "没有查询结果，请重新查询！";
			}
		myAjax.ClearSet();
	});
	return;
}

//建立经销商列表
function buildDealerList(dealers){
	var dealerList = "";
	for(var i =0;i<dealers.length;i++){
		var str=dealers[i].dealer_name +"~~"+ dealers[i].sale_address +"~~"+ dealers[i].code+"~~"+dealers[i].telephone;
        if(dealers[i].google_url=='' || dealers[i].google_url==null || dealers[i].google_url=='undefined' ){
            map_code='';
        }
        else{
            map_code='&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:openIframe(\''+dealers[i].google_url+'\')"><img src="../dealer/images2011/dealer.gif"  style="vertical-align:middle;border:0;" /><font color="#017AA5">查看地图&gt;</font></a>';
        }
		dealerList += '<table width="710" border="0" cellpadding="0" cellspacing="0">'+
		'  <tr>'+
		'    <th width="10" height="22">&nbsp;</th><th align="left">'+dealers[i].dealer_name+map_code+'</th>'+
        '<th><a class="thickbox" title="发送到手机" href="dealershow.php?height=460&width=500&TB_iframe=true&did='+dealers[i].dealer_id+'&rand='+Math.random()+'" onclick="_gaq.push([\'_trackEvent\', \'dealer\', \'mobile\', \'click\']);" ><img src="../dealer/images2011/tel_ico.jpg"  border="0" align="absmiddle" /> 发送到手机</a></th>'+        
		'  </tr>'+
		'  <tr>'+
		'    <td>&nbsp;</td>'+
		'    <td><table border="0" cellspacing="0" cellpadding="0">';
        if(dealers[i].tag==1)
		{
		dealerList += ''+
		'      <tr>'+
		'        <td height="26" align="left" width="100">维修地址：</td><td width="400" align="left" >'+dealers[i].sale_address+'</td>'+
		'      </tr>';
		}
		else
		{
		dealerList +=
		'      <tr>'+
		'        <td height="26" align="left" width="100">销售地址：</td><td align="left" width="400">'+dealers[i].sale_address+'</td>'+
        '      </tr>';

		}
		dealerList += dealers[i].code!="" ? 
		'      <tr>'+
		'        <td height="26" align="left" width="60">邮编：</td><td align="left">'+dealers[i].code+'</td><td></td>'+
		'      </tr>' : '';
		dealerList += dealers[i].telephone!="" ? 
		'      <tr>'+
		'        <td height="26" align="left" width="60">热线电话：</td><td align="left">'+dealers[i].telephone+'</td><td></td>'+
		'      </tr>' : '';
		dealerList += '<tr>'+
		'        <td height="26" align="left" width="60">&nbsp;</td><td align="left">&nbsp;</td><td></td>'+
		'      </tr>'+
		'    </table></td>'+
		'  </tr>'+
		'</table>';
	}
	$ID('fh').style.height="";
	$ID('dealerListDiv').innerHTML = dealerList;
    TB_launch();
}
