/**
 * @author Mike
 * Updated 2010-08-10 09:00
 */
var ZhuiCN = {
    "availIM":["msn","fetion","skype","gtalk","tylive","qq","mobile"],//通知类型
    "AccountType": "",//账号类型
    "Account": "",//账号
    "UID":"",
    "ZID":"",//订制项ZID
    "SourceID":"",//订制项SID
    "inttime": 100,//倒计时长
    "ServiceName": "",//服务名称
    "U": "",//网址
    "VID":"",
	"buttonType":"",//显示我要追类型(暂未启用)
	"showType":"offset",//显示操作版块类型
	"reSendCode":false,
	"title":"我要追",//标题
	"copyRight":"该服务由<a href='http://www.zhui.cn' target='_blank' style='margin:0 3px;' title='追信'>追信</a>联合提供",//版权
	"ZhuiHeaderBgd":"http://img.zhui.cn/partner/i/ZhuiHeaderBg.gif",
	"ZhuiFooterBgd":"http://img.zhui.cn/partner/i/ZhuiFooterBg.gif",
	"ZhuiCloseBgd":"http://img.zhui.cn/partner/i/ZhuiCloseBg.gif",
	"createButton":function(type,txt,src){
		            switch(type){
						case 0:
						      document.write("<div onclick='ZhuiCN.int(this)'>"+txt+"</div>");
							  break;
						case 1:
							  document.write("<img onclick='ZhuiCN.int(this)' src='"+src+"' alt='"+txt+"' style='cursor:pointer'/>");
						      break;
						default:
						     document.write("<button onclick='ZhuiCN.int(this)'>"+txt+"</button>");	  	    
					}
		            
	},
    "int": function(ele){//初始化
                    if(document.getElementById("Zhui_Div_Wrap")){
						            ZhuiCN.close();
					            }
					var options="";			
					var avail_im=ZhuiCN.availIM;			
					var lenIM=avail_im.length;			
					for(var i=0;i<lenIM;i++){
						switch(avail_im[i]){
							case "mobile":
							options+="<option value='1'>手机短信</option>";
							break;
							case "email":
							options+="<option value='1000'>Email</option>";
							break;
							case "msn":
							options+="<option value='10000'>MSN</option>";
							break;
							case "fetion":
							options+="<option value='10001'>飞信</option>";
							break;
							case "skype":
							options+="<option value='10002'>Skype</option>";
							break;
							case "gtalk":
							options+="<option value='10003'>GTalk</option>";
							break;
							case "tylive":
							options+="<option value='10004'>天翼Live</option>";
							break;
							case "qq":
							options+="<option value='10005'>QQ</option>";
							break;
							default:
							options+="<option value=''>您穿越了</option>";
						}
					}
			        var wrap = document.createElement("div");
			        wrap.setAttribute("id", "Zhui_Div_Wrap");
			        wrap.className = "Zhui_Div_Wrap";
			        wrap.innerHTML = '<div id="Zhui_Div_Close" title="关闭" onclick="ZhuiCN.close()">关闭</div><div id="Zhui_Div_Header">'+ZhuiCN.title+'</div><div id="Zhui_Div_Box" class="Zhui_Div_Box"><div id="Zhui_Div_Select" class="Zhui_Div_Select"><label>请选择通知类型:</label><select id="Zhui_Select_AccountType"  onchange="ZhuiCN.showAccount(this.options[selectedIndex].text)"><option>请选择</option>'+options+'</select></div></div><div id="Zhui_Div_Footer">'+ZhuiCN.copyRight+'</div>';
					var diffStyle;
					var db=document.body;
					var dd=document.documentElement;
					switch(ZhuiCN.showType){
						case "pop":
						        var sTop=db.scrollTop;
								var sTop2=dd.scrollTop;
								var sHeight=db.scrollHeight;
								var sH=dd.scrollHeight;
								var bodyHeight=Math.max(sHeight,sH);
								var bodyTop=Math.max(sTop,sTop2);
								diffStyle="#Zhui_Div_Mask{width:100%;height:"+bodyHeight+"px;position:absolute;left:0;top:0;background:#333;opacity:0.6;filter:alpha(opacity=60);z-index:100000}";
								diffStyle+="#Zhui_Div_Wrap{left:50%;top:"+(bodyTop+100)+"px;margin-left:-150px;}";
								break;
						case "offset":
								var width=ele.offsetWidth;//获取按钮宽度
								var height=ele.offsetHeight;
								var offsetTop=ZhuiCN.getTop(ele);//获取相对上部距离
					    		var offsetLeft=ZhuiCN.getLeft(ele);//获取相对左部距离
                        		var clientWidth=document.body.clientWidth;//获取文档宽度
                        		var clientHeight=document.body.clientHeight;//获取文档高度
                        		//alert(clientHeight);
				    			if(clientWidth-offsetLeft<310){
						 		var offsetRight=clientWidth-offsetLeft-width;	
						   		var offsetPosition='right:'+offsetRight+'px;top:'+Number(offsetTop+height+5)+'px;';
								if(clientHeight-offsetTop<200){
									var offsetPosition='right:'+offsetRight+'px;top:'+Number(offsetTop-125)+'px;';
								}
					     		}else{
						 			var offsetPosition='left:'+offsetLeft+'px;top:'+Number(offsetTop+height+5)+'px;';
									if(clientHeight-offsetTop<200){
									var offsetPosition='left:'+offsetLeft+'px;top:'+Number(offsetTop-125)+'px;';
								}
						 		}
								if(clientHeight<120){
									var offsetPosition='left:'+offsetLeft+'px;top:'+Number(offsetTop+height+5)+'px;';
								}
						 		
								diffStyle="#Zhui_Div_Mask{display:none;}";
								diffStyle+="#Zhui_Div_Wrap{-webkit-box-shadow:0px 0px 4px #666;"+offsetPosition+"}";
								
								break;
					}
					
					diffStyle+="#Zhui_Div_Wrap{z-index:100001;width:310px;border-radius:6px;-webkit-box-shadow:0px 0px 4px #999;background:#fff;height:auto;border:1px solid #49aadd;position:absolute;font-size:12px;}";
					diffStyle+="#Zhui_Div_Box{margin:5px;color:#333;padding:10px;border:1px solid #fff;}"
					diffStyle+="#Zhui_Div_Header{background:url("+ZhuiCN.ZhuiHeaderBgd+") repeat-x;height:15px;padding:5px 5px 5px 10px;color:#fff;font-weight:bold;border-bottom:1px solid #0093dd;}";
					diffStyle+="#Zhui_Div_Footer{background:url("+ZhuiCN.ZhuiFooterBgd+") repeat-x;padding:5px;margin-bottom:1px; text-align:right;color:#444;border-top:1px solid #49aadd;}";
					diffStyle+="#Zhui_Div_Footer a:link,#Zhui_Div_Footer a:visited{color:#ff6600;}";
					diffStyle+="#Zhui_Div_Select{margin-bottom:10px;}";
					diffStyle+="#Zhui_Select_AccountType{width:155px;}";
					diffStyle+="#Zhui_Div_Info{background:#f8f8f8;padding:5px;margin:10px 0 0 0;line-height:1.6}";
					diffStyle+="#Zhui_Div_Close{background:url("+ZhuiCN.ZhuiCloseBgd+") no-repeat left top;font-family:arial;text-indent:-9999px;cursor:pointer;width:21px;height:21px;line-height:21px;text-align:center;color:#000;position:absolute;right:3px;top:2px;}";
					
					wrap.innerHTML+="<style type='text/css'>"+diffStyle+"</style>";
			        var mask=document.createElement("div");
					mask.setAttribute("id","Zhui_Div_Mask");
					mask.className="Zhui_Div_Mask";
					document.body.appendChild(wrap);
					document.body.appendChild(mask);
    },
	"getTop":function(e){
		var offset=e.offsetTop;
		if(e.offsetParent!=null){
			offset+=ZhuiCN.getTop(e.offsetParent);
		}
		return offset;
	},
	"getLeft":function(e){
		var offset=e.offsetLeft;
		if(e.offsetParent!=null){
			offset+=ZhuiCN.getLeft(e.offsetParent);
		}
		return offset;
	},
	"close":function(){
		           if(document.getElementById("Zhui_Div_Wrap")){
				   	document.getElementById("Zhui_Div_Wrap").parentNode.removeChild(document.getElementById("Zhui_Div_Wrap"));
				   }
				   if(document.getElementById("Zhui_Div_Mask")){
				   	document.getElementById("Zhui_Div_Mask").parentNode.removeChild(document.getElementById("Zhui_Div_Mask"));
				   }
	},
    "bind": function(json){//绑定,解析json数据
			        var Status = json.StatusInfo.Status;
			        var ReturnCode = json.StatusInfo.ReturnCode;
			        if (json.VID || json.NeedCode) {
			            var VID = json.VID;
						      ZhuiCN.VID=VID;
			            var NeedCode = json.NeedCode;
			            if (NeedCode) {//如果需要验证
			                document.getElementById("Zhui_Submit_Account").setAttribute("disabled", "disabled");
			                ZhuiCN.showCode();
							document.getElementById("Zhui_Input_Account").onchange=function(){
								document.getElementById("Zhui_Submit_Account").removeAttribute("disabled");
							}
							
			            }
			        }
			        if(Status==1){
			        ZhuiCN.showInfo(ReturnCode,1);
			        }else{
			        ZhuiCN.showInfo(ReturnCode,0);
			        }
    },
	"verify":function(json){
		            var Status = json.StatusInfo.Status;
			        var ReturnCode = json.StatusInfo.ReturnCode;
					if(Status==1){
						//验证成功
						ZhuiCN.showInfo(ReturnCode,1);
						
					}else{
						ZhuiCN.showInfo(ReturnCode,0);
					}
	},
    "showAccount": function(type){//显示账号层
			       
			        //删除重复DIV
			        if (document.getElementById("Zhui_Div_Box").getElementsByTagName("div")) {
			            var hasaccountName = document.getElementById("Zhui_Div_Box").getElementsByTagName("div");
			            for (var i = 0; i < hasaccountName.length; i++) {
			                if (hasaccountName[i].className == "Zhui_Div_Account") {
			                    hasaccountName[i].parentNode.removeChild(hasaccountName[i]);
			                }
							
			            }
						for (var i = 0; i < hasaccountName.length; i++) {
			                if (hasaccountName[i].className == "Zhui_Div_Info") {
			                    hasaccountName[i].parentNode.removeChild(hasaccountName[i]);
			                }
			            }
						for (var i = 0; i < hasaccountName.length; i++) {
			                if (hasaccountName[i].className == "Zhui_Div_Code") {
			                    hasaccountName[i].parentNode.removeChild(hasaccountName[i]);
			                }
			            }
			        }
			        //根据类型改变描述
			        var acctype;
			        switch (type) {
			            case "手机短信":
			                acctype = "手机号码";
			                break;
			            case "Email":
			                acctype = "Email地址";
			                break;
			            case "MSN":
			                acctype = "MSN账号";
			                break;
			            case "飞信":
			                acctype = "飞信账号";
			                break;
			            case "Skype":
			                acctype = "Skype账号";
			                break;
			            case "GTalk":
			                acctype = "GTalk账号";
			                break;
			            case "天翼Live":
			                acctype = "天翼Live账号";
			                break;
			            case "QQ":
			                acctype = "QQ号码";
			                break;
			            default:
			                return false;
			        }
			        var accountName = document.createElement("div");
			        accountName.setAttribute("id", "Zhui_Div_Account");
			        accountName.className = "Zhui_Div_Account";
			        accountName.innerHTML = "<label>请输入" + acctype + ":</label><input id='Zhui_Input_Account' type='text'/><button id='Zhui_Submit_Account'>提交</button>";
			        document.getElementById("Zhui_Div_Box").appendChild(accountName);//添加到窗体
			        document.getElementById("Zhui_Submit_Account").onclick = function(){
						if(document.getElementById("Zhui_Input_Account").value==""){
							ZhuiCN.showInfo("通知账号不能为空",0);
							document.getElementById("Zhui_Input_Account").focus();
							return false;
						}
						ZhuiCN.showInfo("处理中...",2);
			            var accountType = document.getElementById("Zhui_Select_AccountType").value;
			            var accountName = document.getElementById("Zhui_Input_Account").value;
						var url="http://api.zhui.cn/passport/UserVerify.json?AccountType=" + accountType + "&Account=" + accountName + "&UID=" + ZhuiCN.UID + "&ZID=" + ZhuiCN.ZID + "&SourceID=" + ZhuiCN.SourceID + "&ServiceName=" + encodeURI(ZhuiCN.ServiceName) + "&U=" + encodeURI(ZhuiCN.U);
			            ZhuiCN.getJSON(url,ZhuiCN.bind);
						
			        }
    },
    "getJSON": function(url,callback){//载入script标签 跨域 这里还要整合,增加URL参数
                    if(document.getElementById("ZhuiCNScript")){
						var rescript=document.getElementById("ZhuiCNScript");
						rescript.parentNode.removeChild(rescript);
					}
			        var script = document.createElement("script");
			        script.setAttribute("id", "ZhuiCNScript");//生成前判断是否已存在,存在清除
			        script.setAttribute("type", "text/javascript");
					var call="call"+(+new Date());
					url+="&jsoncallback="+call;
			        script.setAttribute("src",url );
					window[call]=callback;
			        document.body.appendChild(script);
    },
    "showCode": function(){//显示验证码层
					if(document.getElementById("Zhui_Div_Code")){
						var rescript=document.getElementById("Zhui_Div_Code");
						rescript.parentNode.removeChild(rescript);
					}
			        var code = document.createElement("div");
			        code.setAttribute("id", "Zhui_Div_Code");
					code.className="Zhui_Div_Code";
					if(ZhuiCN.reSendCode){
					var resendBtn="<button disabled='disabled' id='Zhui_Resend_Code'>重新发送验证码" + ZhuiCN.inttime + "</button>";
					}else{
						var resendBtn="";
					}
			        code.innerHTML = "<label>请输入验证码:</label><input id='Zhui_Input_Code' type='text'/><button id='Zhui_Submit_Code'>验证</button>"+resendBtn;
			        document.getElementById("Zhui_Div_Box").appendChild(code);
					if(ZhuiCN.reSendCode){
			        var i = ZhuiCN.inttime;
			        setInterval(function(){
			            if (i == 0) {
			                document.getElementById("Zhui_Resend_Code").innerHTML = "重新发送验证码";
			                document.getElementById("Zhui_Resend_Code").removeAttribute("disabled");
			                return false;
			            }
			            document.getElementById("Zhui_Resend_Code").innerHTML = "重新发送验证码" + i;
			            i--;
			        }, 1000)
					document.getElementById("Zhui_Resend_Code").onclick=function(){//重新获取验证码
						ZhuiCN.removeInfo();
						ZhuiCN.showCode();
					   }
					}
					document.getElementById("Zhui_Submit_Code").onclick = function(){
						ZhuiCN.showInfo("处理中...",2);
			            var inputValue = document.getElementById("Zhui_Input_Code").value;
						var url="http://api.zhui.cn/passport/UserVerifyCode.json?VID=" + ZhuiCN.VID + "&Vcode=" + inputValue;
			            ZhuiCN.getJSON(url,ZhuiCN.verify);
			        }
					
    },
    "showInfo": function(msg,type){//type 1成功   0失败 2加载中 
				   ZhuiCN.removeInfo();
				   var wrap = document.createElement("div");
			        wrap.setAttribute("id", "Zhui_Div_Info");
			        wrap.className = "Zhui_Div_Info";
			        
					wrap.style.fontWeight="bold";
					var fontColor;
					switch(type){
						case 0:
						    fontColor="#f00";
						    break;
						case 1:
						    fontColor="#080";
							break;
						case 2:
							fontColor="#666";
							break
						default:
							fontColor="#666";
					}
					wrap.style.color=fontColor;
					wrap.style.border = "1px solid "+fontColor;
			        wrap.innerHTML = msg;
			        document.getElementById("Zhui_Div_Box").appendChild(wrap);
    },
	"removeInfo":function(){
		        if(document.getElementById("Zhui_Div_Info")){//去除已存在标签
				 	var ZhuiInfo=document.getElementById("Zhui_Div_Info");
					ZhuiInfo.parentNode.removeChild(ZhuiInfo);
				 }
	}
};





