﻿//说明：调用生意助手
//'函数名|过程名：gotoHelp(uid)
function gotoHelp(uid)
{
	uid=""+uid+"";
	if(uid.indexOf("_")>=0)
	{
		//调用本地指定的生意助手
		if(parseInt(uid.split("_")[1])>0)
		{
			window.open('http://www.99114.com/syzs/syzs/tqagent_transferpage.htm?uin='+uid.split("_")[1]+'&agentid=970&transferpage=1&tq_bottom_ad_url=http://qtt.tq.cn/post/sendmain.html&tq_right_infocard_url=http://qtt.tq.cn/showcard.do&page=&ispaymoney=1&localurl=http://www.99114.com/&ltype=0',0,'width=598,height=425,location=no,resizable=0,scrollbars=0,status=no,toolbar=no,location=no,menu=no,top=100,left=200')
		}
		else
		{
			alert("用户暂未开通生意助手！");
		}
	}
	else
	{
		//调用远程生意助手
		window.open('http://www.99114.com/syzs/syzs/tqagent_transferpage.htm?uin='+uid+'&agentid=970&transferpage=1&tq_bottom_ad_url=http://qtt.tq.cn/post/sendmain.html&tq_right_infocard_url=http://qtt.tq.cn/showcard.do&page=&ispaymoney=1&localurl=http://www.99114.com/&ltype=0',0,'width=598,height=425,location=no,resizable=0,scrollbars=0,status=no,toolbar=no,location=no,menu=no,top=100,left=200');
	} 
} 
//说明：Email验证函数
//'函数名|过程名：emailIsOK(str)
//返回值：true|false
function emailIsOK(str)
{
	var regE = /^\D\w{1,}@\w{1,}(\.\w{1,}){1,}$/;
	return regE.test(str);
} 
//说明：数字验证函数
//'函数名|过程名：numberIsOK(str)
//返回值：true|false
function numberIsOK(str)
{
	var x = /^(\d{1,}\.\d{1,})|(\d{1,})$/;
	return x.test(str);
} 
//说明：电话验证函数
//'函数名|过程名： telIsOK(str)
//返回值：true|false
function telIsOK(str)
{
	//固定电话
	var regE1 = /^(\d{3}|\d{4})-(\d{7}|\d{8})$/;
	//手机
	var regE2 = /^1(\d{10})$/;
	return (regE1.test(str)|| regE2.test(str));
} 
//说明：传真验证函数
//'函数名|过程名： faxIsOK(str)
//返回值：true|false
function faxIsOK(str)
{
	//固定电话
	var regE1 = /^(\d{3}|\d{4})-(\d{7}|\d{8})(-\d{1,}){0,}$/;	
	return regE1.test(str);
} 
//说明：邮编验证函数
//'函数名|过程名： postIsOK(str)
//返回值：true|false
function postIsOK(str)
{
	var regE = /^(\d{6})$/;
	return regE.test(str);
} 
//说明：日期编验证函数
//'函数名|过程名： dateIsOK(str)
//返回值：true|false
function dateIsOK(str)
{
	var regE = /^\d{4}-\d{1,2}-\d{1,2}$/;
	return regE.test(str);
} 
//说明：时间编验证函数
//'函数名|过程名： timeIsOK(str)
//返回值：true|false
function timeIsOK(str)
{
	var regE = /^\d{2}:\d{1,2}:\d{1,2}$/;
	return regE.test(str);
}
//说明：网址验证函数
//'函数名|过程名： urlIsOK(str)
//返回值：true|false
function urlIsOK(str)
{ 
	var regE = /^http:\/\/(\w|\W){1,}(\.(\w|\W){1,}){1,}$/;	
	return regE.test(str);
}
//说明：JS保留地址栏所有参数并增加新的参数
//'函数名|过程名：getLocationHref(str1,value1)
//参数：str1:参数名称，value1：参数值
//返回值：新的地址
function getLocationHref(str1,value1)
{
	var strResult = "";
	var url=self.location.href;
	var paras = self.location.search;
	var startPos=0;
	var endPos=0;
	if(str1=="" || value1=="")
	{strResult = url;}
	else
	{
		str1 = str1.toLowerCase();
		if(paras=="")
		{strResult = url+"?"+str1+"="+value1;}
		else
		{
			if(paras.indexOf(str1)>=0)
			{
				startPos = paras.indexOf(str1);
				if(parseInt(paras.indexOf("&",startPos+str1.length))<0)
				{
					strResult = paras.substr(0,startPos)+str1+"="+value1;
				}
				else
				{
					endPos = paras.indexOf("&",startPos+str1.length);
					strResult = paras.substr(0,startPos)+str1+"="+value1+paras.substr(endPos);
				}
			}
			else
			{strResult = paras+"&"+str1+"="+value1;}
		}
	}
	return strResult;
}
//说明：页面跳转函数
//'函数名|过程名：pageGoTo(temp,pagecount)
//参数：所输入的页面数值,页面总数
function pageGoTo(n,pagecount)
{
	var obj = document.getElementById("pageskip");
	var temp=0;
	var url = self.location.href;
	if (parseInt(n)==0)
	{			
		if(event.keyCode==13)
		{			
			if(!numberIsOK(obj.value))
				{temp=1+"";}
			else
				{temp=obj.value+"";}
			if(parseInt(temp)>parseInt(pagecount))
				{temp = pagecount;}
			self.location.href=getLocationHref("page",temp);
		}	
	}
	else
		if(parseInt(n)==1){
			if(!numberIsOK(obj.value))
				{temp=1+"";	}
			else
				{temp=obj.value+"";	}
			if(parseInt(temp)>parseInt(pagecount))
				{temp = pagecount;}
			self.location.href=getLocationHref("page",temp);
	}
} 

//全角转半角
function tot(mobnumber){
	while(mobnumber.indexOf("。")!=-1){
		mobnumber = mobnumber.replace("。",".");}
	while(mobnumber.indexOf("．")!=-1){
		mobnumber = mobnumber.replace("．",".");}
	while(mobnumber.indexOf("０")!=-1){
		mobnumber = mobnumber.replace("０","0");}
	while(mobnumber.indexOf("１")!=-1){
		mobnumber = mobnumber.replace("１","1");}
	while(mobnumber.indexOf("２")!=-1){
		mobnumber = mobnumber.replace("２","2");}
	while(mobnumber.indexOf("３")!=-1){
		mobnumber = mobnumber.replace("３","3");}
	while(mobnumber.indexOf("４")!=-1){
		mobnumber = mobnumber.replace("４","4");}
	while(mobnumber.indexOf("５")!=-1){
		mobnumber = mobnumber.replace("５","5");}
	while(mobnumber.indexOf("６")!=-1){
		mobnumber = mobnumber.replace("６","6");}
	while(mobnumber.indexOf("７")!=-1){
		mobnumber = mobnumber.replace("７","7");}
	while(mobnumber.indexOf("８")!=-1){
		mobnumber = mobnumber.replace("８","8");}
	while(mobnumber.indexOf("９")!=-1){
		mobnumber = mobnumber.replace("９","9");}
	return mobnumber;
}
//消除空格，类似与asp中的trim
function trim(inputString) 
{
	return inputString.replace(/^ +/,"").replace(/ +$/,"");
}
//需要用到jquery
//列表展开详细信息函数，可改写有渐进渐出效果。
function ListOpenInfo(strName){ 
	$(strName).css({ display: "" });	
	$(strName).hover(
		function(){},
		function(){$(strName).css({ display: "none"});}
	);
}
 
//设置首页函数
function SetHome(obj,vrl){ 
	try{ obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl); 	} 
	catch(e){ 
		if(window.netscape) { 
			try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } 
			catch (e) { 
					alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); 
			} 
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 
			prefs.setCharPref('browser.startup.homepage',vrl); 
		 } 
	} 
} 
//说明：加入收藏兼容firefox
//参数:URL链接地址，name网站标题
function AddFavorite(url,name){　 // 加入收藏夹   
    if (document.all){   
        window.external.addFavorite(''+url+'', ''+name+'');   
    }else if (window.sidebar){   
        window.sidebar.addPanel(''+name+'', ''+url+'', "");   
    }   
} 

/*全选*/
function SelectAll(flag,DarkName)
{
    var nullregExp =/^\s*$/;

    var NameNull = nullregExp.test(DarkName);

    var objCheckBox=document.getElementsByTagName('input');
    for(var i=0;i<objCheckBox.length;i++)
    {
        if(((objCheckBox[i].type=="checkbox") && objCheckBox[i].id.toUpperCase().indexOf(DarkName.toUpperCase())>=0) || NameNull)
        {
            if(flag)
            {
                switch(flag.toUpperCase())
                {
                    case "ON":
                        objCheckBox[i].checked=true;
                        break;
                    case "OFF":
                        objCheckBox[i].checked=false;
                        break;
                    case "TOGGLE":
                        objCheckBox[i].checked= !objCheckBox[i].checked;
                        break;
                    default:
                        objCheckBox[i].checked= true;
                        break;
                }
            }
        }
    }
}
//Ajax注册协议
function GetEnrollAgree(){			
    $.weeboxs.open("/ajax/EnrollAgree.ashx", {boxid:'dyselbox',title:'注册协议',contentType:'ajax',width:670,height:440,showCancel:false,clickClose:true}); 
}  

//Ajax登陆函数
function GetLogin(){
$.weeboxs.open("/ajax/Login.ashx?action=show", {boxid:'dyselbox',title:'会员登录',contentType:'ajax',width:280,height:100,okBtnName:'确认',onok:function(box){	 
	if ($.trim($("#Ajaxusername").val()) == '') {
			$.weeboxs.open("<center><br/><br/><font size=4><strong>请输入用户名!</strong></font></center>", {title:'提示',width:280,height:100,modal:false,showCancel:false,onclose:function(){$("#Ajaxusername").focus();}});
			return false;
		}
	if ($.trim($("#Ajaxuserpassword").val()) == '') {
			$.weeboxs.open("<center><br/><br/><font size=4><strong>请输入密码!</strong></font></center>", {title:'提示',width:280,height:100,modal:false,showCancel:false,onclose:function(){$("#Ajaxuserpassword").focus();}});
			return false;
		}
	var postdata = 	$('#CheckLogin').serializeArray();	  		
			box.setLoading();
			//alert(postdata);
			$.post('/ajax/Login.ashx?action=submit',postdata, function (data) {		
				
				if ($.trim(data) == "ok") {
					var msg = "登陆成功,三秒钟返回。";								 
				} else {
					var msg = data;	
				}							
				//box.finish("提示", msg, 300);
				$.weeboxs.open("<br/><br/><center><font size=4><strong>"+msg+"</strong></font></center>", {boxid:'dyselbox',title:'提示',width:300,height:100,showCancel:false,timeout:2,showOk:false,onclose:function(){
					location.href=document.URL;
				}});
			 });							
		}	
	}); 
} 

//添加商友
function addCompanyFriend(uid,fcid)
{
    if(uid==0)
    {
       GetLogin();
    }
    else
    {
        $.weeboxs.open("<div><br/><center><img src='/js/box/img/boxloading.gif' /> <font size=4><strong>正在提交,请稍后！</strong></font></div>", {boxid:'dyselbox',title:'',type:"custombox",modal:false,width:300,height:50,showCancel:false,timeout:1,showOk:false,onclose:function(box){  
	        box.setLoading();	
	        var postdata = "";	 							 
	        $.post('/ajax/Friend.ashx?uid='+uid+'&fcid='+fcid,postdata, function (data){	 
		        if ($.trim(data) =="-11") {var msg = "该会员已是您的商友！";} 
		        if ($.trim(data) == "1") {var msg = "成功加为商友！";}
		        if ($.trim(data) == "0") {var msg = "添加失败，请重新添加！";}	 
		        $.weeboxs.open("<br/><center><font size=4><strong>"+msg+"</strong></font></center>", {boxid:'dyselbox',title:'',width:300,height:50,type:"custombox",timeout:2,modal:false,showOk:false,showCancel:false,onclose:function(){
			        if ($.trim(data) == "1") { location.href=document.URL; } 
		        }}); 
	         });							
        }}); 
					 
    }
}

//注销函数
function logOut()
{
   jQuery.ajax({
            url:'/Ajax/Login.ashx',
            type: 'get',
            data: "action=LogOut&time=" + Math.random(),
            timeout: 5000,
            error: function(){
            },
            beforeSend:function(){
            },
            success: function(result){
                if(result=="1")
                {
                  window.location.reload();
                }
                else
                {
                  alert("注销失败");
                }
            }
    });
}

//收藏信息函数
function GetFavoritesInfo(uid,oid,typeid,url){  
    if (uid!=0){
	    $.weeboxs.open("<div><br/><center><img src='/js/box/img/boxloading.gif' /> <font size=4><strong>正在收藏,请稍后！</strong></font></div>", {boxid:'tsName',title:'',type:"custombox",modal:false,width:300,height:50,showCancel:false,timeout:1,showOk:false,onclose:function(box){  
		    //var postdata = $('#ProductOrderFrom').serializeArray();
		    var postdata = "";	 
		    box.setLoading();
		    $.post("/ajax/FavoritesAdd.ashx?userid="+uid+"&oid="+oid+"&typeid="+typeid+"&url='"+url+"'",postdata, function (data) {	
			    if ($.trim(data) == "1") { var msg = "收藏成功，谢谢您的收藏！";}
			    if ($.trim(data) == "0") { var msg = "收藏失败，请确认您未收藏过！";}	
			    if ($.trim(data) == "-1") { var msg = "收藏失败，请重新收藏！";}	 
			    $.weeboxs.open("<br/><center><font size=4><strong>"+msg+"</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:2,modal:false,showOk:false,showCancel:false,onclose:function(){ }}); 
		     });	
	      }}); 	
    }
    else
    { 
       GetLogin();
    }	 
} 
 
//在线询价函数		
function GetSupplyEnquire(sid){			
$.weeboxs.open("/ajax/SupplyEnquire.ashx?action=show&id="+sid, {boxid:'dyselbox',title:'在线询价',contentType:'ajax',width:560,height:360,modal:false,okBtnName:'确认',onok:function(box){	
	 if ($.trim($("#MsgName").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>请输入询价标题！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgName").focus();}});
			return false;
		}
	if ($.trim($("#MsgNumber").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>订货总量不能为空！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgNumber").focus();}});
			return false;
		}
	if ($.trim($("#MsgPrice").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>期望价格不能为空！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgPrice").focus();}});
			return false;
		}
	if ($.trim($("#MsgDetail").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>请输入询价内容！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgDetail").focus();}});
			return false;
		}
	 if ($.trim($("#MsgMan").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>请输入联系人姓名！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgMan").focus();}});
			return false;
		}
	 if ($.trim($("#MsgPhone").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>请输入联系电话！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgPhone").focus();}});
			return false;
		}
	if ($.trim($("#MsgEmail").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>请输入联系邮箱！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgEmail").focus();}});
			return false;
		}
	
	$.weeboxs.open("<div><br/><center><img src='/js/box/img/boxloading.gif' /> <font size=4><strong>正在提交,请稍后！</strong></font></div>", {boxid:'tsName',title:'',type:"custombox",modal:false,width:300,height:50,showCancel:false,timeout:1,showOk:false,onclose:function(box){  
		var postdata = $('#SupplyEnquire').serializeArray();			 
		box.setLoading();
		$.post('/ajax/SupplyEnquire.ashx?action=submit',postdata, function (data) {						
			if ($.trim(data) == "-1") {
				var msg = "验证码不正确，请重填验证码！"; 						 
			} 
			if ($.trim(data) == "1") { 
				var msg = "感谢您的询价，我们会与您联系！";		
			}
			if ($.trim(data) == "0") { 
				var msg = "询价失败，请重新询价！";		
			}	
			msd=data 
			$.weeboxs.open("<br/><center><font size=4><strong>"+msg+"</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){
				if ($.trim(data) == "1") {  
					 location.href=document.URL;
					  
				} 
			}}); 
		});	
	}}); 												
}}); 
} 
//在线订购函数
function GetBuyQuote(bid){
$.weeboxs.open("/ajax/BuyQuote.ashx?action=show&id="+bid, {boxid:'dyselbox',title:'在线报价',contentType:'ajax',width:540,height:290,modal:false,okBtnName:'确认',onok:function(box){	
	 if ($.trim($("#MsgNumber").val()) == '' ) {
			$.weeboxs.open("<br/><center><font size=4><strong>供应数量不能为空！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgNumber").focus();}});
			return false;
		}		
	 if ($.trim($("#MsgPrice").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>所报价格不能为空！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgPrice").focus();}});
			return false;
		}	
	 if ($.trim($("#MsgDetail").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>报价说明不能为空！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgDetail").focus();}});
			return false;
		}				 
	 if ($.trim($("#MsgMan").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>请输入联系人姓名！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgMan").focus();}});
			return false;
		}
	 if ($.trim($("#MsgPhone").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>请输入联系电话！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgPhone").focus();}});
			return false;
		}
	if ($.trim($("#MsgEmail").val()) == '') {
			$.weeboxs.open("<br/><center><font size=4><strong>请输入联系邮箱！</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){$("#MsgEmail").focus();}});
			return false;
		} 
	$.weeboxs.open("<div><br/><center><img src='/js/box/img/boxloading.gif' /> <font size=4><strong>正在提交,请稍后！</strong></font></div>", {boxid:'tsName',title:'',type:"custombox",modal:false,width:300,height:50,showCancel:false,timeout:1,showOk:false,onclose:function(box){  
		var postdata = $('#BuyQuote').serializeArray();			 
		box.setLoading();
		$.post('/ajax/BuyQuote.ashx?action=submit',postdata, function (data) {
			if ($.trim(data) == "1") { 
				var msg = "感谢您报价，我们会与您联系！";		
			}
			if ($.trim(data) == "0") { 
				var msg = "报价失败，请重新报价！";		
			}	
			msd=data 
			$.weeboxs.open("<br/><center><font size=4><strong>"+msg+"</strong></font></center>", {boxid:'tsName',title:'',width:300,height:50,type:"custombox",timeout:1,modal:false,showOk:false,showCancel:false,onclose:function(){
				if ($.trim(data) == "1") {  
					location.href=document.URL;
				} 
			}}); 
		 });	
	  }}); 												
   }}); 
}
 
//查看图片信息
//参数只传路径
function JsLookPic(picPath)
{
    if (picPath==""){
	    $.weeboxs.open("<center>未上传，请选择图片上传!</center>", {title:'提示',width:150,showCancel:false,clickClose:true,onclose:function(){}}); 
    }
    else
    {	
	    if (picPath.split(".")[1] =="swf"){
		    html="<div style='border-width:0px;border-style:solid;width:605px;overflow:auto;cursor:default;'><center><EMBED  pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash src='"+picPath+"'type=application/x-shockwave-flash quality='high' /></center></div>"
	    }
	    else
	    {
		    html="<div style='border-width:0px;border-style:solid;width:605px;height:300px;overflow:auto;cursor:default;'><center><img src='"+picPath+"' /></center></div>"
	    }	
	    $.weeboxs.open(html, {title:'查看图片',width:640,showCancel:false,clickClose:true}); 
    }
}
 
 function friendMessageSend(fun,fuid){	
    $.weeboxs.open("/Member/Friends/FriendMessageSend.aspx?fun="+fun, {boxid:'dyselbox',title:'发送短信息',contentType:'ajax',width:500,height:260,okBtnName:'确认',onok:function(box){	 
    var postdata = $('#FriendMessageSend').serializeArray(); 
    box.setLoading();
    $.post('/ajax/FriendMessageSend.ashx',postdata, function (data) {	 
	    if ($.trim(data) == "ok") {
		    var msg = "发送成功,三秒钟返回。";								 
	    } else {
		    var msg = "发送失败,请重新发送。";
	    }							
	    $.weeboxs.open("<br/><br/><center><font size=4><strong>"+msg+"</strong></font></center>", {boxid:'dyselbox',title:'提示',width:300,height:120,showCancel:false,timeout:2,showOk:false,onclose:function(){
		            location.href= document.URL;
	            }
	        });
        });
      }	 
  }); 
}
