var Site;
Site = {};
Site.getImgUrl = function (seccodeUrl) {
	if(seccodeUrl.indexOf('?') > 0) {
		return seccodeUrl+'&'+ Math.random();
	} else {
		return seccodeUrl+'?'+ Math.random();
	}
}

Site.sendMessage = function () {
	$.weeboxs.open('该功能尚未开放，敬请期待！', {title: '提示',type:'alert', timeout:5});
}

Site.logout = function (url) {
	$.weeboxs.open('您确定要退出商务中心吗？', {title: '提示', 
		width:300,	
		height:30,
		onok:function(){
			window.location.href=url;
			return;
		}
	});
}

Site.AreaTab = function (n) {
	$('.region_title span').removeClass('curr');
	$('.region_title span:eq('+n+')').addClass('curr');
	for(var i=0;i<8;i++) {
		$('#p_'+i).hide();
	}
	$('#p_'+n).show();
}

Site.CheckProvince = function (id,v) {
	var num = 0;
	$("input[name='ret[province][]']").each(function (i) {
		if($(this).attr("checked")==true){
			num++;
		}
	});
	if(num > 5) {
		$('#provinceTip').addClass('onError');
		$('#provinceTip').html('省份最多只能选5个');
		$('#provinceTip').show();
		$('#r_'+id).attr("checked", false); 
		return;
	}
	if(num == 0) {
		$('#provinceTip').addClass('onError');
		$('#provinceTip').html('请至少选择一个省份');
		$('#provinceTip').show();
		$('#r_'+id).attr("checked", false); 
		$('#ex_'+id).remove();
		return;
	}
	if($('#r_'+id).attr("checked") == true) {
		var html = '<div class="region_ok" id="ex_'+id+'">'+v+'<i class="m_icon m_icon_14" onclick="javascript:Site.RemoveProvince('+id+')"></i></div>';
		html = $('#Exprovince').html()+html;
		$('#Exprovince').html(html);
	} else {
		$('#ex_'+id).remove();
	}
}

Site.RemoveProvince = function (id) {
	var num = 0;
	$("input[name='ret[province][]']").each(function (i) {
		if($(this).attr("checked")==true){
			num++;
		}
	});
	$('#r_'+id).attr("checked", false); 
	$('#ex_'+id).remove();
	if(num == 1) {
		$('#provinceTip').addClass('onError');
		$('#provinceTip').html('请至少选择一个省份');
		$('#provinceTip').show();
		return;
	}
}

Site.pihao = function (url,data,db) {
	if(data == '') {
		$.weeboxs.open('请先输入产品通用名然后进行批准文号的查询！', {title: '提示',type:'alert', timeout:3});
		return;
	}
	if(url.indexOf('?') > 0) {
		url = url+'&q='+ encodeURIComponent(data)+'&db='+db;
	} else {
		url = url+'?q='+ encodeURIComponent(data)+'&db='+db;
	}
	$.weeboxs.open(url, {
		title:'查找批准文号', 
		contentType:'ajax',
		width:600,
		showCancel:false,
		showOk:false
	});
}

Site.PiHaoList = function (page) {
	$("#ajaxList").empty().html('<ol><li>正在搜索...</li></ol>');
	$("#ajaxList").load(_url, {page: page, ajax:'1',db:db}); 
}

Site.PiHaoSerach = function () {
	var k = $('#k').val();
	var t = $('#t').val();
	$("#ajaxList").empty().html('<ol><li>正在搜索...</li></ol>');
	$("#ajaxList").load(_Surl, {k: encodeURIComponent(k), t: t, ajax:'1',db:db});
}

Site.SelectCatId = function () {
	var catid = $('#catid').val();
	var catname = $('#catid').find("option:selected").attr("rel");
	$('#currentCat').html(catname.replace('-',' > '));
	$('#cid').val(catid);
}

Site.Addmerchants = function () {
	if($('#cid').val() == '') {
		$.weeboxs.open('请先选择招商产品分类！', {title: '提示',type:'alert', timeout:5});
		return;
	}
	$('#form').submit();
}

Site.quyu = function () {
	var item = $("input[name='quyu']:checked").val();
	$('#regionDetail').hide();
	if(item == 'mall') {
		$('#regionDetail').show();
	}
}

Site.SelectPiHao = function () {
	
	var item = $("input[name='pihao']:checked").val();
	var pihao = $('#n'+item).html();
	//alert(item);
	if(item == undefined) {alert('请选择批准文号！');return;}
	$('#m_pihao').val(pihao);
	$('#m_pihao_id').val(item);
	$.weeboxs.close();
}

Site.SelfInputPiHao = function () {
	
	var item = $("#selfinput").val();
	if(item == '') {alert('请输入批准文号！');return;}
	$('#m_pihao').val(item);
	$('#m_pihao_id').val('0');
	$.weeboxs.close();
}

Site.deletePosts = function (id, ismain, t) {
	if(ismain == '1') {
		var msg= '该留言是主题留言！<br>您确认要删除该主题下的所有留言信息吗？';
	} else {
		var msg= '您确认要删除该留言信息吗?';
	}
	$.weeboxs.open(msg, {title: '提示', 
		width:400,	
		height:40,
		onok:function(){
			$.ajax({
			   type: "POST",
			   url: DeleteMessageurl,
			   data: "id="+id+"&t="+t+"&"+Math.random(),
			   success: function(msg){
			   		var data = eval('('+msg+')');
			   		alert(data.msg);
			   		window.location.href=data.url;
			   		$.weeboxs.close();
			   }
			}); 
			return;
		}
	});
}

Site.reloadAgent = function (id) {
	if(typeof(id) == 'undefined'){
		var id = '';
		$('.l_t_1 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要刷新的信息！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	if(confirm('请确定要刷新该信息吗？')){
		$.ajax({
		   type: "POST",
		   url: reloadAgenturl,
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
		   		alert(msg+'页面将重新载入！');
		   		window.location.reload();
		   }
		}); 
	}
} 

Site.downAgent = function (id) {
	if(typeof(id) == 'undefined'){
		var id = '';
		$('.l_t_1 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要取消发布的信息！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	if(confirm('请确定要取消发布该信息吗？')){
		$.ajax({
		   type: "POST",
		   url: downAgenturl,
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
		   		var data = eval('('+msg+')');
		   		alert(data.msg);
		   		window.location.href=data.url;
		   }
		}); 
	}
}

Site.resetAgent = function (id) {

	if(typeof(id) == 'undefined'){
		var id = '';
		$('.l_t_1 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要重发的信息！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	if(confirm('请确定要重发该信息吗？重发信息无需审核！')){
		$.ajax({
		   type: "POST",
		   url: resetAgenturl,
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
		   		var data = eval('('+msg+')');
		   		alert(data.msg);
		   		window.location.href=data.url;
		   }
		}); 
	}
} 

Site.deleteAgent = function (id) {

	if(typeof(id) == 'undefined'){
		var id = '';
		$('.l_t_1 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要删除的信息！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	if(confirm('请确定要删除该信息吗？删除后无法恢复，请谨慎操作！')){
		$.ajax({
		   type: "POST",
		   url: deleteAgenturl,
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
		   		alert(msg+'页面将重新载入！');
		   		window.location.reload();
		   }
		}); 
	}
}

Site.deleteAttachments = function (id) {
	if(confirm('请确定要删除该附件吗？删除后无法恢复，请谨慎操作！')){
		$.ajax({
		   type: "POST",
		   url: deleteAttachmentsurl,
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
		   		alert(msg);
		   		$('#a'+id).remove();
		   }
		}); 
	}
}

Site.AddShopLinks = function () {
	$.weeboxs.open(AddShopLinkUrl, {
		title:'添加友情链接', 
		contentType:'ajax',
		width:650,
		showCancel:false,
		showOk:false
	});
}

Site.EditShopLinks = function (id) {
	$.weeboxs.open(EditShopLinkUrl+'?id='+id, {
		title:'编辑友情链接', 
		contentType:'ajax',
		width:650,
		showCancel:false,
		showOk:false
	});
}

Site.DeleteShopLinks = function (id) {
	if(typeof(id) == 'undefined'){
		var id = '';
		$('.list_ul_2 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要删除的友情链接信息！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	if(confirm('请确定要删除该友情链接信息吗？删除后无法恢复，请谨慎操作！')){
		$.ajax({
		   type: "POST",
		   url: DeleteShopLinkUrl,
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
			   	$('.list_ul_2 input').each(function(i){
					if($(this).attr("checked")==true){
		    			var row = $(this).attr("value");
		    			$('#link'+row).remove();
		   			}
				});
				$('#link'+id).remove();
		   		alert('友情链接删除成功！');
		   }
		}); 
	}
}

Site.DeleteBanner = function () {
	if(confirm('请确定要删除您的旺铺首页banner图片吗？')){
		$.ajax({
		   type: "POST",
		   url: DeleteShopBannerUrl,
		   data: "p=delete&"+Math.random(),
		   success: function(msg){
			   	$('#outbanner').html('');
			   	$('#deletehref').html('');
			   	alert(msg);
		   }
		}); 
	}
}

Site.DeleteShopHonor = function (id) {
	if(typeof(id) == 'undefined'){
		var id = '';
		$('.list_ul_1 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要删除的资质荣誉证书！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	if(confirm('请确定要删除该资质荣誉证书吗？')){
		$.ajax({
		   type: "POST",
		   url: DeleteShopHonorUrl,
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
			   	$('.list_ul_1 input').each(function(i){
					if($(this).attr("checked")==true){
		    			var row = $(this).attr("value");
		    			$('#honor'+row).remove();
		   			}
				});
				$('#honor'+id).remove();
		   		alert('资质荣誉证书删除成功！');
		   }
		}); 
	}
}

Site.TuijianMerchants = function (v) {
	if(v == '1') {
		var message = '取消推荐';
	} else if(v == '2') {
		var message = '推荐';
	}
	var id = '';
	$('.list_ul_1 input').each(function(i){
		if($(this).attr("checked")==true){
			id += ","+$(this).attr("value");
			}
	});
	if(id == '') {
		alert('请选择您要'+message+'的招商产品信息！');
		return;
	}else{
		id = id.substr(1);
	}	

	if(confirm('请确定要'+message+'该招商产品信息吗？')){
		$.ajax({
		   type: "POST",
		   url: tuijianMerchanturl,
		   data: "v="+v+"&id="+id+"&"+Math.random(),
		   success: function(msg){
			   	var data = eval('('+msg+')');
		   		alert(data.msg);
		   		window.location.href=data.url;
		   }
		}); 
	}
}

Site.DeleteFavorite = function (t,id) {
	if(typeof(id) == 'undefined'){
		var id = '';
		$('.list_ul_1 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要删除的收藏信息！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	if(confirm('请确定要删除该收藏信息吗？')){
		$.ajax({
		   type: "POST",
		   url: DeleteFavoriteUrl,
		   data: "id="+id+"&t="+t+"&"+Math.random(),
		   success: function(msg){
		   		var msg = eval('('+msg+')');
		   		alert(msg.msg);
		   		window.location.href=msg.url;
		   }
		}); 
	}
}

Site.setTabAll = function (name,cursel,n){
	for(i=1;i<=n;i++){
	   if(cursel==i)
	   {
		   $("#"+name+"_"+i).removeClass("disNone");
		  $("#"+name+i).addClass("curr");
	   } 
	   else{
	   $("#"+name+"_"+i).addClass("disNone");
	   $("#"+name+i).removeClass("curr");}
	}
}

Site.AddFavorite  = function (type, id, s) {
	if(currentUid == '') {
		alert('您还没有登录，不能收藏任何信息！');
		return;
	}
	var _url = '';
	if(typeof(s) != 'undefined'){
		var _url = 'smalltype='+s+'&';
	}
	$.ajax({
	   type: "POST",
	   url: AddFavoriteUrl,
	   data: _url+"type="+type+"&id="+id+"&"+Math.random(),
	   success: function(msg){
	   		alert(msg);
	   }
	});
}

Site.addBookmark = function (title,url) {  
	if (window.sidebar) {   
	window.sidebar.addPanel(title, url,"");   
	} else if( document.all ) {  
		try{ 
			window.external.addFavorite(url, title); 
			    }catch (e){ 
			    try{ 
			        window.sidebar.addPanel(title, url, ""); 
			        }catch (e){ 
		        	 
		        	 alert("加入收藏失败，请使用Ctrl+D进行添加");
			        } 
			    } 

	} else if( window.opera && window.print ) {  
	return true;  
	}  
} 


Site.deleteExpo = function (id) {

	if(typeof(id) == 'undefined'){
		var id = '';
		$('.l_t_1 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要删除的信息！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	if(confirm('请确定要删除该信息吗？删除后无法恢复，请谨慎操作！')){
		$.ajax({
		   type: "POST",
		   url: "/index.php?m=home&c=expom&a=delete",
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
		   		alert(msg+'页面将重新载入！');
		   		window.location.reload();
		   }
		}); 
	}
}

Site.addPrint = function (id) {

	if(typeof(id) == 'undefined'){
		var id = '';
		$('#l_t_1 input').each(function(i){
			if($(this).attr("checked")==true){
    			id += ","+$(this).attr("value");
   			}
		});
		if(id == '') {
			alert('请选择您要打印的代理信息！');
			return;
		}else{
			id = id.substr(1);
		}	
    }
	
	if(confirm('请确定要将选中的信息添加到打印嘛？')){
		$.ajax({
		   type: "POST",
		   url: "/index.php?m=home&c=agentprint&a=add",
		   data: "id="+id+"&"+Math.random(),
		   success: function(msg){
		   		alert(msg);
		   		//window.location.reload();
		   }
		}); 
	}
}

Site.emptyPrint = function () {
	if(confirm('请确定要清空选中的打印记录嘛？')){
		$.ajax({
		   type: "POST",
		   url: "/index.php?m=home&c=agentprint&a=empty",
		   data: "id=&"+Math.random(),
		   success: function(msg){
		   		alert(msg);
		   		//window.location.reload();
		   }
		}); 
	}
}
