﻿/**
 * 通用方法
 */
function  starryMediaCommon()
{
	/**
	 * 调用地址,参数对象,返回后执行的方法,提示块内容,超时时间,是否异步
	 */
this.post=function(url,data,fn,status,timeout,async)
{
	if(typeof(status)!="undefined"&&$("body").mask)
	{		
	$("body").mask(status+"......");
	}
	$.ajax({
		type: "post",
		url: url,
		dataType: "json",
		data:data,
		async:async,
		success: function(o){	
			if(typeof(status)!="undefined"&&$("body").unmask)$("body").unmask();
			if(o!=null){
				if(o.ajaxcodeid&&o.ajaxcodeid==9){
					StarryMediaCommon.gohome("你尚未登录或登录已过期!请先使用星点通行证登录!");
					return;
				}
				if(fn)fn(o);	
			}
		 },
		 complete:function(){if(typeof(status)!="undefined"&&$("body").unmask)$("body").unmask();},
		 error:function()
		 {  
			 if(typeof(status)!="undefined"&&$("body").unmask)$("body").unmask();
			// StarryMediaCommon.messagebox("调用出现错误","错误",2,1);			
		 },
		 timeout:timeout*1000||30000
		});
	
};
this.gohome=function(content,fn){
	var html="<iframe frameborder=\"0\"  id=\"gohomeDialogframe\" width=580 height=310 style=\"margin:-10px;*width:600px;\"  scrolling=\"no\"   src=\""+baseurl+"loginc/mini?to_url="+encodeURIComponent(location.href)+"\"></iframe>";
	StarryMediaCommon.centerpop(null,html,null,null,"gohomeDialog");	
};

this.get=function(url,data,fn,status,timeout)
{
	if(typeof(status)!="undefined"&&$("body").mask)
	{		
	$("body").mask(status+"......");
	}
	$.ajax({
		type: "GET",
		url: url,
		dataType: "json",
		data:data,
		success: function(o){	
			if(o.ajaxcodeid&&o.ajaxcodeid==9){
				StarryMediaCommon.gohome("你尚未登录或登录已过期!请重新登陆");
				return;
			}
			fn(o);
		 },
		 complete:function(){if($("body").unmask)$("body").unmask();},
		 error:function()
		 {
			 if(typeof(status)!="undefined"&&$("body").unmask)$("body").unmask();
			// StarryMediaCommon.messagebox("调用出现错误",null,2,1); 
		 },
		 timeout:timeout*1000||30000
		});

};
this.gethtml=function(url,data,fn,status,timeout){
	if(typeof(status)!="undefined"&&$("body").mask)
	{		
	$("body").mask(status+"......");
	}
	$.ajax({
		type: "GET",
		url: url,
		dataType:"html",
		data:data,
		success: function(o){
			var json;
			try{
			eval("json="+o);
			if(json.ajaxcodeid&&json.ajaxcodeid==9){
				StarryMediaCommon.gohome("你尚未登录或登录已过期!请重新登陆");
				return;
			}}
			catch(e){}
			fn(o);
		 },
		 complete:function(){if($("body").unmask)$("body").unmask();},
		 error:function()
		 {
			 if(typeof(status)!="undefined"&&$("body").unmask)$("body").unmask();
			// StarryMediaCommon.messagebox("调用出现错误",null,2,1); 
		 },
		 timeout:timeout*1000||30000
		});

};
this.nologin=function (){
	var r=false;
	StarryMediaCommon.post(baseurl+"commondata/islogin",null,function(json){
				if(json.codeid==1){
					StarryMediaCommon.gohome();
					r= false;
				}
				else{
					r= true;
				}
		},"数据提交中",20,false);
	return r;
};
this.thirdlogin=function(id,type){
	if(typeof(type)=="undefined")type=0;
	location.href=baseurl+"commondata/thirdlogin/"+id+"/"+type+"?to_url="+encodeURIComponent(location.href);
};
this.gender={"":"","0":"男","1":"女"};
this.getDateobject=function(time)
 {
	  var date=new Date();
	  date.setTime(time);
	  return {
		  year:date.getFullYear(),
		  month:date.getMonth()+1,
		  date:date.getDate(),
		  day:date.getDay(),
		  hour:date.getHours(),
		  minute:date.getMinutes(),
		  second:date.getSeconds()		  
	  };
 };
 this.getDateString=function(time,type)
{
	  var date=new Date();
	  date.setTime(time);	
	 var temp=date.getFullYear()+"/"+(date.getMonth()+1)+"/"+date.getDate();
	 if(type=="h"||type=="m"||type=="s")
	 {
		  var t=date.getHours();
		  if(t<10)t="0"+t;
		  temp+=" "+t;
	 }
	  if(type=="m"||type=="s")
	  {
		  var t=date.getMinutes();
		  if(t<10)t="0"+t;
		  temp+=":"+t;
	 }
	 if(type=="s")
	{
		  var t=date.getSeconds();
		  if(t<10)t="0"+t;
		  temp+=":"+t;
	}
	 return temp;
};
this.strToDate=function(text){
	var cdate = text.replace(/\-/g, "/");
	var date=new Date();
	try{
		date = new Date(cdate);
	}
	catch(e){
		date=new Date();	
	}
	return {
		  year:date.getFullYear(),
		  month:date.getMonth()+1,
		  date:date.getDate(),
		  day:date.getDay(),
		  hour:date.getHours(),
		  minute:date.getMinutes(),
		  second:date.getSeconds()		  
	  };
};
this.formatDate=function(text){
	var d=new starryMediaCommon();
	var date=d.strToDate(text);
	var d=date.date;
	var y=date.year;
	var m=date.month;
	if(d<10)d="0"+d;
	if(m<10)m="0"+m;
	return y+"-"+m+"-"+d;
};
this.getDateMMDD=function(time,type)
{
	  var date=new Date();
	  date.setTime(time);	
	 var temp=(date.getMonth()+1)+"/"+date.getDate();
	 if(type=="h"||type=="m"||type=="s")
	 {
		  var t=date.getHours();
		  if(t<10)t="0"+t;
		  temp+=" "+t;
	 }
	  if(type=="m"||type=="s")
	  {
		  var t=date.getMinutes();
		  if(t<10)t="0"+t;
		  temp+=":"+t;
	 }
	 if(type=="s")
	{
		  var t=date.getSeconds();
		  if(t<10)t="0"+t;
		  temp+=":"+t;
	}
	 return temp;
};
/*
 * 获取时间差(时间,类型[h,m,s],当前时间)
 */
 this.getTimeDiff=function(time,type)
{
	 var curtime=sysbase.currenttime;
	  var timetype={"Y":31536000000,"M":2592000000,"d":86400000,"h":3600000,"m":60000,"s":1000,"ms":1};
	  var curdate=new Date();	 
	  if(!type)type="m";
	  if(typeof(curtime)!="undefined")
		{
		  curdate.setTime(curtime);
		}	
	    var cur=curdate.getTime();
	    var t=cur-time;	  
	  return Math.round(t/timetype[type]);
};
this.IsOnline=function(time)
{
	var t=this.getTimeDiff(time, "m", sysbase.currenttime);
	 return  (t<sysbase.onlinetime);
};
this.getCNhhmm=function(time,curtime)
{
	if(typeof(curtime)=="undefined"){
	  curtime=sysbase.currenttime;	}
	  var curdate=this.getDateobject(curtime);
	  var date=this.getDateobject(time);
	  var ishour=false;
	  
	  var days=this.getTimeDiff(time, "d", curtime);	
	  var min=0;
	  if(days==0&&date.hour==curdate.hour){
		  ishour=true;
		  min=curdate.minute-date.minute;
		  if(min==0){
		     return (curdate.second-date.second)+"秒前";
		  }
		  else{
			  return   min+"分钟前";
		  }
		  
		  
	  }
	  if(date.minute<10)date.minute="0"+date.minute;
	  if(date.hour<10)date.hour="0"+date.hour;	  
	  if(days<1)
	  {
		  if(days==0){			 
			  return "今天"+date.hour+":"+date.minute;
	  	   }
		  else{
			  return "未来时空"+date.hour+":"+date.minute;;
		  }
       }
	  else{
	   
	     return  date.month+"月"+date.date+"日 "+date.hour+":"+date.minute;
	 }
	  return "";
};
this.getimgurl=function (mid,type)
{
	if(mid==null||typeof(mid)=="undefined")
	{
		return "images/starryHeader.jpg";
		}
	else{
	 var num = mid % 100;
	 return  "face/"+num + "/" + (num % 100) + "/"+ mid+"/"+mid+"_"+type+".jpg";	
	}
};
this.geterrorimgurl=function (type,gender)
{
	var img={"b0":"images/headerMxB.jpg",
	"b1":"images/headerMxG.jpg",
	"m0":"images/headerMB.jpg",
	"m1":"images/headerMG.jpg",
	"s0":"images/headerSB.jpg",
	"s1":"images/headerSG.jpg",
	"all":"images/hpic2.jpg"
	 };	
		if(type==null||typeof(img[type+gender])=="undefined")
		{
			return img["all"];
		}
		else
		{
			return img[type+gender];			
		}
};
this.EnterDown=function(e,fn){var key = window.event ? e.keyCode : e.which;if(key.toString() == "13"){fn();}};
this.messagebox=function(content,title,type,time,fn)
{
	if($&&$.dialog)
	{
		var icon=null;
	 if(typeof(title)=="undefined")title="提示";
	 if(typeof(type)!="undefined"&&type!=null)
		 {
		 icon=(type=="0"?"succeed":"error");
		 }	 
	 if(typeof(time)=="undefined")time=null;
	$.dialog({
	    content:content,
	    title:title,
	    skin: 'facebook',
	    icon:icon,	    		
	    time: time,
	    yesFn: function(){
	    	if(fn)fn();
	        return true;
	    }    
	});
		}
	else
		{
		alert(content);		
		}
};
this.alert=function(content,title,fn)
{
	if($&&$.dialog)
	{
		var icon=null;
	 if(typeof(title)=="undefined")title="提示";	
	$.dialog({
	    content:content,
	    title:title,
	    skin: 'facebook',
	    icon:"alert",	
	    yesFn: function(){	 
	    	 if(fn)fn();
	        return true;
	    }    
	});
	}
	else
		{
		alert(content);		
		}
};
this.msgbox=function(content,time,fn){
	if($&&$.dialog)
	{
		var icon=null;
     	$.dialog({
	    content:content,
	    title:"提示",
	    skin: 'facebook',
	    icon:"alert",
	    time: time,
	    yesFn: function(){	 
	    	 if(fn)fn();
	        return true;
	    }    
	});
	}
	else
		{
		alert(content);		
		}
};
this.popwindow=function(content,title,lock){
	if($&&$.dialog)
	{
		if(typeof(lock)=="undefined")lock=false;	
		if(typeof(title)=="undefined")title="查看";	
		var icon=null;
     	$.dialog({
     	title:title,
	    content:content,
	    lock:lock,
	    skin: 'facebook',
	    noFn: true,
	    noText: "关闭"	    
	});
	}
	else{
		alert("方法不存在");		
	}
};
this.popform=function(content,fn,title,yesText,lock){
	if($&&$.dialog)
	{
		if(typeof(lock)=="undefined")lock=false;	
		if(typeof(title)=="undefined")title="";	
		if(typeof(yesText)=="undefined")yesText="确定";	
		var icon=null;
     	return $.dialog({
     	title:title,
	    content:content,
	    lock:lock,
	    yesText: yesText,
	    noText: "取消",
	    skin: 'facebook',
	    noFn: true,
	 	yesFn: function(){	  
	 	    	 if(fn){
	 	    		 return fn();
	 	    	 }
	 	    	 else{
	 	    		 return true;
	 	    	 }
	 	    }    
	});
	}
	else{
		alert("方法不存在");		
		return null;
	}
};
this.popdiv=function(content,fn,yesText,lock){
	if($&&$.dialog)
	{
		if(typeof(lock)=="undefined")lock=false;	
		if(typeof(yesText)=="undefined")yesText="确定";	
		var icon=null;
     	$.dialog({
     	id:"popdivalert_msg",
	    content:content,
	    title:null,
	    skin: 'facebook',
	    lock:lock,
	    yesText: yesText,
	    noText: "取消",
	    noFn: true,
	 	yesFn: function(){	  
	 	    	 if(fn){
	 	    		 return fn();
	 	    	 }
	 	    	 else{
	 	    		 return true;
	 	    	 }
	 	    }    
	});
	}
	else{
		alert("方法不存在");		
	}
};
this.poptip=function(content,fn,title,yesText,noText,lock){
	if($&&$.dialog)
	{
		if(typeof(lock)=="undefined")lock=false;	
		if(typeof(title)=="undefined")title="";	
		if(typeof(yesText)=="undefined")yesText="确定";	
		if(typeof(noText)=="undefined")noText="关闭";	
		var icon=null;
     	return $.dialog({
     	title:title,
	    content:content,
	    lock:lock,
	    yesText: yesText,
	    noText: noText,
	    skin: 'facebook',
	    noFn: true,
	 	yesFn: function(){	  
	 	    	 if(fn){
	 	    		 return fn();
	 	    	 }
	 	    	 else{
	 	    		 return true;
	 	    	 }
	 	    }    
	});
	}
	else{
		alert("方法不存在");		
		return null;
	}
};

this.confirm=function(content,fn,title,follow,yesText,noText)
{
	if($&&$.dialog)
	{
		var icon=null;
	 if(typeof(title)=="undefined")title="提示";	
	 if(typeof(yesText)=="undefined")yesText="确定";	
	 if(typeof(noText)=="undefined")noText="取消";	
	$.dialog({
	    content:content,
	    title:title,
	    follow:follow,
	    skin: 'facebook',
	    yesText:yesText,
	    noText: noText,
	    icon:"confirm",
	    noFn: true,
	    yesFn: function(){	  
	    	 if(fn)fn();
	        return true;
	    }    
	});
	}
	else
		{
		  if(window.confirm(content))
			{
			  if(fn)fn();
			}
		}
};
this.PostEndMessage=function(o)
{
     StarryMediaCommon.messagebox(o.message,"提示",o.codeid,2);    
};
this.sendmsg=function(uid,name,fn) {	
	if(StarryMediaCommon.nologin()){
	var html="<iframe frameborder=\"0\"  id=\"iframeupload\"  scrolling=\"no\"  width=450 height=250 src=\""+baseurl+"common/message?fn=StarryMediaCommon.centerpopend&amp;name="+encodeURIComponent(name)+"&amp;uid="+uid+"\"></iframe>";
	var title="发私信";
	StarryMediaCommon.centerpop(null,html,title,fn,"starryMediaCommonpop",450);
	}
};
this.getmaplatlng=function(address,fn){
	if(StarryMediaCommon.nologin()){
	 var  html= "<iframe frameborder=\"0\" scrolling=\"no\"  width=620 height=400 src=\""+baseurl+"common/map?fn=StarryMediaCommon.centerpopend&amp;o=" + encodeURIComponent(address) + "\"></iframe>";
     StarryMediaCommon.centerpop(null,html,"地图查找",fn);
	}
},
this.sendmicroblog=function(id,fn) {	
	if(StarryMediaCommon.nologin()){
	var html="<iframe frameborder=\"0\" scrolling=\"no\"  width=450 height=250 src=\""+baseurl+"common/weibo?fn=StarryMediaCommon.centerpopend&amp;id="+id+"\"></iframe>";
	var title="有什么新鲜事想告诉大家？";
	StarryMediaCommon.centerpop(null,html,title,fn,null,450);
	}
};
this.showmap=function(latlng,width,o) {	
	
	if(latlng=="0,0"||latlng==""||latlng==","){
	  return;
	}
	var ary=latlng.split(",");
	if(ary.length!=2){
	  return;
	}
	var lat=parseFloat(ary[0]);
	var lng=parseFloat(ary[1]);
	if(isNaN(lat)||isNaN(lng)){
	 return;
	}
	if(lat>180||lat<-180||lng>180||lng<-180){
		return;
	}
	
	var obj="{content:\"\",title:\"\"}";
	if(o){
	  obj="{content:\""+o.content+"\",title:\""+o.title+"\"}";
	}
	if(StarryMediaCommon.nologin()){
	var html="<iframe frameborder=\"0\"  id=\"iframeupload\"  scrolling=\"no\"  width="+width+" height="+width+" src=\""+baseurl+"common/mapview?ll="+latlng+"&amp;o="+encodeURIComponent(obj)+"&amp;w="+width+"\"></iframe>";
	var title="地图查看";
	StarryMediaCommon.centerpop(null,html,title,null,null,width);
	}
};
this.attentionbrand=function(bid,fn){
	StarryMediaCommon.post(baseurl+"common/followbrand",
			{bid:[bid]},
		        function(json){
			    	if(json.codeid == 0){
			    		if(fn)fn();
					}else{			
						StarryMediaCommon.alert(json.message);
					}});
};
this.attention=function(uid,type,fn){
	StarryMediaCommon.post(baseurl+"common/attention",
			{uid:uid,type:type},
		     function(json){
			    	if(json.codeid == 0){
			    		if(fn)fn(json);
					}else{			
						StarryMediaCommon.alert(json.message);
			}});
};
this.attentionuser=function(uid,fn){
	StarryMediaCommon.post(baseurl+"common/followuser",
			{uid:uid},
		        function(json){
			    	if(json.codeid == 0){
			    		if(fn)fn();
					}else{			
						StarryMediaCommon.alert(json.message);
					}});
};
this.removeattentionuser=function(uid,fn){
	StarryMediaCommon.post(baseurl+"common/canclefollowuser",
			{uid:uid},
		        function(json){
			    	if(json.codeid == 0){
			    		if(fn)fn();
					}else{			
						StarryMediaCommon.alert(json.message);
					}});
};
this.removefans=function(uid,name,fn){
	 var title = "移除粉丝";
	    var html = " <div> " +
	                    " <div class=\"fLeft fontBold\">移除之后将取消他对你的关注,确定要移除" + name + "?</div> " +
	                    " <div class=\"fLeft fluid-input\"> " +
	                    "<input value=\"" + uid + "\" type=\"hidden\" id=\"input_id\"/>" +
	                    "</div><div class=\"clear clearAll\"></div></div>";

	    $.dialog({
	        id: "msgsend",
	        title: title,
	        content: html,
	        skin: "facebook",
	        yesText: "确定",
	        noText: "取消",
	        noFn: true,
	        yesFn: function () {
	            StarryMediaCommon.post(baseurl+"common/removefans", {id:uid},function(json){
	            	if(fn){fn(json);}
	            	else{
	            		StarryMediaCommon.alert(json.message);
	            	}
	            	
	            });
	        }
	    });   
};
this.changelike=function(divid,type){
	 StarryMediaCommon.post(baseurl+"default/getmylikeuser", null,function(json){
		 if(json.codeid==0){
			 $("#"+divid).html(json.html);
		 }
	 });
};
this.supportbrand=function(bid,uid,nick,fn){
	 StarryMediaCommon.post(baseurl+"common/supportbrand", null,function(json){
		 if(json.codeid==0){
			 StarryMediaCommon.popform(json.html, function(){
			 var val=$("#supponickNamertcontent").val();
			var defaultval = $("#supponickNamertcontent").attr("defaultvalue");
			var content = "";
			if(val==defaultval){
				content = defaultval+baseurl+"home/index/uid/"+uid;
			}else{
				content = "我支持了@"+nick+"。"+val+baseurl+"home/index/uid/"+uid;;
			}	
			StarryMediaCommon.post(baseurl+"common/dobrandsupport", {bid:bid,content:content},function(obj){
				StarryMediaCommon.alert(obj.message);
				 if(obj.codeid==0){
					 if(fn){fn(json);}	
				 }
				 else{
					 return false;
				 }
				 
				});				 
			 }, "支持"+nick, "支持", true);
			 $("#supponickNamertcontent").attr("defaultvalue","我支持了@"+nick+"。如果你也喜欢这个品牌的话，就来支持它一下吧");
			 StarryMediaCommon.inputdefault("supponickNamertcontent");				
		 }else{
			 StarryMediaCommon.alert(json.message);
		 }
		 
	 });
	
};
this.surportcoupon=function(id,uid,fn){
	StarryMediaCommon.post(baseurl+"common/createcouponsurport",{id:id,uid:uid},
	        function(json){
				StarryMediaCommon.alert(json.message);
				if(json.codeid==0){if(fn){fn(json);}}
	});
};
this.surportgoods=function(id,uid,fn){
	StarryMediaCommon.post(baseurl+"common/creategoodssurport",{id:id,uid:uid},
	        function(json){
					StarryMediaCommon.alert(json.message);
					if(json.codeid==0){if(fn){fn(json);}}
				});
};
this.typeKeyup=function(ctrlid,maxlen,ctrlcount){
	$("#"+ctrlid).keyup(
			function(event)
			{
				var key = window.event ? event.keyCode : event.which;
				key=key.toString();
				var value=$("#"+ctrlid).val();
				var len=value.length;			
				if(len>maxlen){
					$("#"+ctrlid).val(value.substring(0,maxlen));
					len=maxlen;
				}
				$("#"+ctrlcount).html(len+"/"+maxlen);
				
			}
	);
};
this.ContentCheck=function(ctrlid,maxlen,ctrlcount){
	     $("#"+ctrlid).focus(function(){   	
	    	 $("#"+ctrlid).css("color","#000000");
	    });
	   
	    $("#"+ctrlid).blur(function(){
	    	$("#"+ctrlid).css("color","#999999");
	    });
		$("#"+ctrlid).keyup(
				function(event)
				{
					
					var key = window.event ? event.keyCode : event.which;
					key=key.toString();
					var value=$("#"+ctrlid).val();
					var len=value.length;			
					var n=maxlen-len;
					if(n>0){
						$("#"+ctrlcount).html("你还可以输入<em>"+n+"</em>个字");
					}
					else{
						$("#"+ctrlcount).html("你的输入已经超过<em style=\"color:red;\">"+Math.abs(n)+"</em>个字");
					}
					
					
				}
		);
		$("#"+ctrlid).change(
				function()
				{
					var value=$("#"+ctrlid).val();
					var len=value.length;
					var n=maxlen-len;
					if(n>0){
						$("#"+ctrlcount).html("你还可以输入<font color=green size=3>"+n+"</font>个字");
					}
					else{
						$("#"+ctrlcount).html("你的输入已经超过<font color=red size=3>"+Math.abs(n)+"</font>个字");
					}
				}
		);		
		var v=$("#"+ctrlid).val();
		var len=v.length;
		var n=maxlen-len;
		if(n>0){
			$("#"+ctrlcount).html("你还可以输入<font color=green size=3>"+n+"</font>个字");
		}
		else{
			$("#"+ctrlcount).html("你的输入已经超过<font color=red size=3>"+Math.abs(n)+"</font>个字");
		}
	
};
this.inputdefault=function(ctrlid){
	  $("#"+ctrlid).focus(function(){
	    	if($("#"+ctrlid).val()==$("#"+ctrlid).attr("defaultvalue")){
	    		$("#"+ctrlid).val("");
	    	}	    	
	    	 $("#"+ctrlid).css("color","#000000");
	    });
	   
	    $("#"+ctrlid).blur(function(){
	    	if($("#"+ctrlid).val()==""){
	    		$("#"+ctrlid).val($("#"+ctrlid).attr("defaultvalue"));
	    		$("#"+ctrlid).css("color","#999999");
	    	}
	    	else{
	    		if($("#"+ctrlid).val()!=$("#"+ctrlid).attr("defaultvalue")){
	    			$("#"+ctrlid).css("color","#000000");  
	    		}
	    	}
	    	
	    });
	    if($("#"+ctrlid).val()==""){
    		$("#"+ctrlid).val($("#"+ctrlid).attr("defaultvalue"));
    	}	 
    	$("#"+ctrlid).css("color","#999999");
};

/*
 * (当前页码,总数量,页面大小,翻页方法)
 * 
 */
this.getPageIndex=function(page,total,pagesize,fn){var pagestr="";if(page<1){page=1;}var allpage=1;allpage=parseInt(total/pagesize);allpage=parseInt((total%pagesize)!=0?allpage+1:allpage);allpage=parseInt(allpage==0?1:allpage);var next=page+1;if(next>allpage){next=allpage;}var pre=page-1;if(pre<1){pre=1;}var startcount=(page+3)>allpage?allpage-5:page-2;var endcount=page<5?5:page+3;pagestr+="<span>";if(startcount<1){startcount=1;}if(allpage<endcount){endcount=allpage;}pagestr+=page>1?"<a  href=\"javascript:void(0);\"  class=\"fy\"   onclick=\""+fn+"(1)\"   >&nbsp;首页&nbsp;</a><a href=\"javascript:void(0);\"  class=\"fy\"  onclick=\""+fn+"("+pre+")\" >« 上一页</a>":"";for(var i=startcount;i<=endcount;i++){pagestr+=page==i?"<a onfocus=\"this.blur();\" class=\"fy2\">&nbsp;"+i+"&nbsp;</a>":"<a href=\"javascript:void(0);\"  class=\"fy\"   onclick=\""+fn+"("+i+")\" >&nbsp;"+i+"&nbsp;</a>";}pagestr+=page!=allpage?"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+next+")\"  class=\"fy\" >下一页　»</a><a href=\"javascript:void(0);\"  class=\"fy\" onclick=\""+fn+"("+allpage+")\" >&nbsp;末页&nbsp;</a>":"";return pagestr;};
this.getXPageIndex=function(page,total,pagesize,fn,size){if(typeof size=="undefined"){size=7;}var half=parseInt(size/2);var pagestr="";if(page<1){page=1;}var allpage=1;allpage=parseInt(total/pagesize);allpage=parseInt((total%pagesize)!=0?allpage+1:allpage);allpage=parseInt(allpage==0?1:allpage);if(allpage<2)return "";var next=page+1;if(next>allpage){next=allpage;}var pre=page-1;if(pre<1){pre=1;}var startcount=((page+half)>allpage?allpage-size:page-half);var endcount=(allpage<size?size:page+half);pagestr+="<span>";if(startcount<1){startcount=1;}if(allpage<endcount){endcount=allpage;}pagestr+=page>1?"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+pre+")\" >上一页</a>":"";if(startcount>1)pagestr+="<a  href=\"javascript:void(0);\"   onclick=\""+fn+"(1)\"   >1</a>";if(startcount>2&&allpage>=size){pagestr+="...";}for(var i=startcount;i<=endcount;i++){pagestr+=page==i?"<a onfocus=\"this.blur();\" class=\"cur\" >"+i+"</a>":"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+i+")\" >"+i+"</a>";}if(endcount<allpage-1&&allpage>=size){pagestr+="...";}if(endcount<allpage)pagestr+="<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+allpage+")\" >"+allpage+"</a>";pagestr+=page!=allpage?"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+next+")\" >下一页</a>":"";return pagestr;};
this.getPageIndexSize=function(page,total,pagesize,fn,size){if(typeof size=="undefined"){size=7;}var half=parseInt(size/2);var pagestr="";if(page<1){page=1;}var allpage=1;allpage=parseInt(total/pagesize);allpage=parseInt((total%pagesize)!=0?allpage+1:allpage);allpage=parseInt(allpage==0?1:allpage);if(allpage<2)return "";var next=page+1;if(next>allpage){next=allpage;}var pre=page-1;if(pre<1){pre=1;}var startcount=((page+half)>allpage?allpage-size:page-half);var endcount=(allpage<size?size:page+half);pagestr+="<span>";if(startcount<1){startcount=1;}if(allpage<endcount){endcount=allpage;}pagestr+=page>1?"<a href=\"javascript:void(0);\"  class=\"fy\"  onclick=\""+fn+"("+pre+")\" >« 上一页</a>":"";if(startcount>1)pagestr+="<a  href=\"javascript:void(0);\"  class=\"fy\"   onclick=\""+fn+"(1)\"   >&nbsp;1&nbsp;</a>";if(startcount>2&&allpage>=size){pagestr+="...";}for(var i=startcount;i<=endcount;i++){pagestr+=page==i?"<a onfocus=\"this.blur();\" class=\"fy2\">&nbsp;"+i+"&nbsp;</a>":"<a href=\"javascript:void(0);\"  class=\"fy\"   onclick=\""+fn+"("+i+")\" >&nbsp;"+i+"&nbsp;</a>";}if(endcount<allpage-1&&allpage>=size){pagestr+="...";}if(endcount<allpage)pagestr+="<a href=\"javascript:void(0);\"  class=\"fy\" onclick=\""+fn+"("+allpage+")\" >&nbsp;"+allpage+"&nbsp;</a>";pagestr+=page!=allpage?"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+next+")\"  class=\"fy\" >下一页　»</a>":""; if(allpage>1){ pagestr+="<input type=\"text\" class=\"cuzinput\" value=\"自定义\"  onclick=\"$(this.nextSibling).show();this.value='';this.size=3;\" /><input style=\"display:none;\" value=\"确定\" class=\"cuz\" type=\"button\" onclick=\"$(this).hide();this.previousSibling.size=6;var page=parseInt($(this.previousSibling).val()); if(isNaN(page)){page=1;}if(page>"+allpage+"){page="+allpage+";}"+fn+"(page);\">";}return pagestr;};
this.getminPageIndex=function(page,total,pagesize,fn){var pagestr="";if(page<1){page=1;}var allpage=1;allpage=parseInt(total/pagesize);allpage=parseInt((total%pagesize)!=0?allpage+1:allpage);allpage=parseInt(allpage==0?1:allpage);var next=page+1;if(next>allpage){next=allpage;}var pre=page-1;if(pre<1){pre=1;}var startcount=(page+3)>allpage?allpage-5:page-2;var endcount=page<5?5:page+3;pagestr+="<span>";if(startcount<1){startcount=1;}if(allpage<endcount){endcount=allpage;}pagestr+=page>1?"<a href=\"javascript:void(0);\"  class=\"fy\"  onclick=\""+fn+"("+pre+")\" >« 上一页</a>":"";pagestr+=page!=allpage?"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+next+")\"  class=\"fy\" >下一页　»</a>":"";return pagestr;};
this.getupdownIndex=function(page,total,pagesize,fn){var pagestr="";if(page<1){page=1;}var allpage=1;allpage=parseInt(total/pagesize);allpage=parseInt((total%pagesize)!=0?allpage+1:allpage);allpage=parseInt(allpage==0?1:allpage);var next=page+1;if(next>allpage){next=allpage;}var pre=page-1;if(pre<1){pre=1;}var startcount=(page+3)>allpage?allpage-5:page-2;var endcount=page<5?5:page+3;pagestr+="<span>";if(startcount<1){startcount=1;}if(allpage<endcount){endcount=allpage;}pagestr+=page>1?"<a href=\"javascript:void(0);\"  class=\"fy\"  onclick=\""+fn+"("+pre+")\" >↑上页</a>":"";pagestr+=page!=allpage?"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+next+")\"  class=\"fy\" >下页↓</a>":"";return pagestr;};
this.getpagenav=function(page,total,pagesize,fn){var pagestr="";if(page<1){page=1;}var allpage=1;allpage=parseInt(total/pagesize);allpage=parseInt((total%pagesize)!=0?allpage+1:allpage);allpage=parseInt(allpage==0?1:allpage);var startcount=(page+6)>allpage?allpage-10:page-4;var endcount=page<10?10:page+6;pagestr+="<span>";if(startcount<1){startcount=1;}if(allpage<endcount){endcount=allpage;}pagestr+=page>1?"<a  href=\"javascript:void(0);\"  onclick=\""+fn+"(1)\"  title=\"查看最前页\">&lt;&lt;</a>":"<a onfocus=\"this.blur();\"><b>&lt;&lt;</b></a>";for(var i=startcount;i<=endcount;i++){pagestr+=page==i?"<a onfocus=\"this.blur();\" ><b>"+i+"</b></a>":"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+i+")\" >"+i+"</a>";}pagestr+=page!=allpage?"<a href=\"javascript:void(0);\"  onclick=\""+fn+"("+allpage+")\" title=\"查看最末页\">&gt;&gt;</a>":"<a onfocus=\"this.blur();\"><b>&gt;&gt;</b></a>";return pagestr;};
//↑↓←→
this.getMaxString=function (msg,max){if(msg.length <= max){return msg;}else{return msg.substring(0, max- 1) + "...";}};
this.IsMatch=function (value,txt){if(txt==""){return true;}txt=txt.toUpperCase();if((value+"").toUpperCase().indexOf(txt)>-1){return true;}return false;};
this.copy_clip=function(str) {
    if (window.clipboardData) {
        window.clipboardData.setData("Text", str);
    }
    else {
        if (!document.getElementById("flashcopier")) {
            var d = document.createElement("div");
            d.id = "flashcopier";
            document.body.appendChild(d);
        }
        document.getElementById("flashcopier").innerHTML = "";
        str = '<embed src="'+baseurl+'flash/clipboard.swf" FlashVars="clipboard=' + encodeURIComponent(str) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById("flashcopier").innerHTML = str;
    } 
    return true;
};
this.IsCardID=function(g){var reg=/^(([0-9]{15})|([0-9]{18})|([0-9]{17}(x|X)))$/;if(!reg.test(g)){return false;}else{return true;}  };
this.IsZipcode=function(g){var reg=/[1-9](\d{5})$/;if(!reg.test(g)){return false;}else{return true;}  };
this.IsMobile=function(txt){var reg=/^1(3|5|8|4)\d{9}$/;if(!reg.test(txt)){return false;}else{return true;}};
this.IsEmail=function (mail){var reg=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;return reg.test(mail);};
this.IsPhone=function(g){var reg=/(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/;if(!reg.test(g)){return false;}else{return true;}};
this.IsRealName=function(g){if(new RegExp("^[\u4e00-\u9fa5]{2,6}$").test(g)){return true;}else{if(new RegExp("^[a-z]{2,20}$").test(g)){return true;}else{if(!(new RegExp("[0-9s_><,\\[\\]\\{\\}?/+=|'\\\":;~!@#*$%^&()`\xff00-\xffff]").test(g))){return true;}else{return false;}}}};
this.IsQQ=function(g){if(new RegExp("^[1-9][0-9]{4,11}$").test(g)){return true;}else{if(this.IsEmail(g)){return true}else{return false;}}};
this.IsDate = function (date) {try {var cdate = date.replace(/\-/g, "/");f = new Date(cdate);var y = f.getFullYear();var m = f.getMonth() + 1;var d = f.getDate();var cd = date.split("-");if (cd[1].lenght > 2 || cd[2].lenght > 2) {return false;}if(cd[1].length > 1 && parseInt(cd[1]) != cd[1]) {cd[1] = cd[1].substr(1, 1);}if (cd[2].length > 1 && parseInt(cd[2]) != cd[2]) {cd[2] = cd[2].substr(1, 1);}if (cd[0] == y && cd[1] == m && cd[2] == d) {return true;}else { return false; } } catch (e) {return false;  }};
this.IsDateRange = function (date1,date2) {try {var fdate = date1.replace(/\-/g, "/");var tdate = date2.replace(/\-/g, "/");f = new Date(fdate);t= new Date(tdate); return (f.getTime()<t.getTime()); } catch (e) {return false;  }};
this.IsBrandName=function(name){ var regexp =/^[0-9a-zA-Z\u4e00-\u9fa5_ （）\\&\\(\\)-]*$/; return regexp.test(name);};
this.IsNickName=function(name){	 var regexp =/^[0-9a-zA-Z\u4e00-\u9fa5_]*$/;	 if(name.substring(0,4)=="手机用户"){StarryMediaCommon.alert("昵称不能以“手机用户”开头"); return false;}return regexp.test(name);
};
this.IsUrl=function(url){var regexp=/(https:\/\/|http:\/\/|ftp:\/\/|www\.?|)(([\w-]+\.)+[\w-]+(\/[\w-.\/\?%@&+=:,]*)?)/gi;return regexp.test(url);};
this.setcookie=function(tag,value,day){var d=day||0; var date = new Date();date.setDate(date.getDate()+d);var CookieInfo = tag + "=" +encodeURIComponent(value) + ";"+(d>0?("expires="+date.toGMTString()+" "):"")+"path=/;";document.cookie = CookieInfo;};
this.getcookie=function(tag){var mycookie=document.cookie;var start = mycookie.indexOf(tag + "=");if (start== -1){return null;}else{start=mycookie.indexOf("=",start)+1;var end = mycookie.indexOf(";",start);if (end==-1){end=mycookie.length;}return decodeURIComponent(mycookie.substring(start,end));}};
this.getBLength=function(str) {if(str==null||typeof(str)=="undefined")return 0;	return str.replace(/[^\x00-\xff]/g, 'xx').length;};
this.subBString=function(val, maxLen) {if(val==null||typeof(val)=="undefined")return "";if(this.getBLength(val)<=maxLen){return val;}var len= maxLen-3;maxLen=len;var result = val.substring(0, len);while(this.getBLength(result) > maxLen) {result = result.substring(0, --len);}return result+"...";};
this.centerpopend=function(o){};
this.centerpopdialog=null;
this.centerpop=function(e,html,title,fn,id,width,height,lock){	
	if(typeof(id)=="undefined"||id==null){
	   id="common";
	}
	if(typeof(lock)=="undefined"||lock==null){
		lock=true;
	}
	StarryMediaCommon.centerpopdialog=$.dialog({ 
 	id:id+"_centerpop",
    content:html,
    title:title,
    skin: 'facebook',
    lock:lock,
    yesText: null,
    noText: null,
    closeFn:function(){
    		$("#"+id+"_centerpop iframe").attr("src","about:blank");
    }
    });
 	if(fn&&fn!=null){
		StarryMediaCommon.centerpopend=function(o){StarryMediaCommon.centerpopdialog.close();fn(o);StarryMediaCommon.centerpopdialog=null;};
	}else{
		StarryMediaCommon.centerpopend=function(){StarryMediaCommon.centerpopdialog.close();StarryMediaCommon.centerpopdialog=null;};
	}
 	
};
this.centerpopclose=function(){if(StarryMediaCommon.centerpopdialog){StarryMediaCommon.centerpopdialog.close();StarryMediaCommon.centerpopdialog=null;}};
this.showmenu=function(e,ctrl,mtype,ulname,id,isshow){
	 //head//ulmenu//app//isshow
	if(isshow){
	$("#"+ulname+"_"+id).show();
	}
	else{
		$("#"+ulname+"_"+id).hide();
	}
	
};
this.fixdiv=function(e,html,title,fn,id,width,height){
	if(e)e.cancelBubble = true;
	if(typeof(id)=="undefined"){
		id="starryMediaCommonpop";
	}
	if(width){
	$("#"+id).width(width);
	}
	if(height){
	$("#"+id).height(height);
	}
	$("#"+id+"_content").html(html);
	$("#"+id+"_title").html(title);
	if(fn&&fn!=null){
		StarryMediaCommon.centerpopend=function(o){StarryMediaCommon.centerpopclose();fn(o);};
	}else{
		StarryMediaCommon.centerpopend=function(){StarryMediaCommon.centerpopclose();};
	}
	var loc;
	var windowWidth,windowHeight;
	if (self.innerHeight) {
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	l=windowWidth/2-$("#"+id).width()/2;
	t=windowHeight/2-$("#"+id).height()/2;
	loc={left:l+"px",top:t+"px"};
	$("#"+id).css("z-index","1899").css(loc).css("position","fixed");
	if($.browser.msie && $.browser.version=="6.0"){
		$("#"+id).css("position","absolute");
	};
	$("#"+id).show();
};
this.showtip=function(id){
	var windowWidth,windowHeight;
	if (self.innerHeight) {
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	var t=0+40;
	var l=windowWidth-((windowWidth-1000)/2+$("#"+id).width())-20;
	if(windowWidth<=1000){
	 l=windowWidth-$("#"+id).width()-20;
	}
	loc={left:l+"px",top:t+"px"};
	$("#"+id).css("z-index","1899").css(loc).css("position","fixed");
	if($.browser.msie && $.browser.version=="6.0"){
		$("#"+id).css("position","absolute");
	};
	//$("#"+id).show();
};
this.fixtip=function(id,left){
	var loc;
	if(typeof(left)=="undefined")left=0;
	var windowWidth,windowHeight;
	if (self.innerHeight) {
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientHeight) {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	l=windowWidth/2-$("#"+id).width()/2+left;
	t=windowHeight/2-$("#"+id).height()/2;
	loc={left:l+"px",top:t+"px"};
	$("#"+id).css(loc).css("position","fixed");
	if($.browser.msie && $.browser.version=="6.0"){
		$("#"+id).css("position","absolute");
	};
	$("#"+id).show();
};
this.objtourl=function (o){var str=new Array();for(var name in o){str.push(name+"="+encodeURIComponent(o[name]));}return str.join("&");};
this.objtostring=function (o){var str=new Array();for(var name in o){str.push("\""+name+"\":"+(typeof(o[name])=="string"?("\""+o[name].replace("\"","\\\"")+"\""):o[name]));}return "{"+str.join(",")+"}";},
this.getpostdata=function(post,type){
	  if(typeof(type)=="undefined")type="";
	  for(var name in post){
	   post[name]=$("#"+type+name).val();
	}
};
this.checkboxall=function(chk, crl) { crl = typeof (crl) == "string" ? document.getElementById(crl) : crl; chk = typeof (chk) == "string" ? document.getElementById(chk) : chk; var chks = crl.getElementsByTagName("input"); for (var i = 0; i < chks.length; i++) { if ((chk.checked && !chks[i].checked) || ((!chk.checked && chks[i].checked))) { chks[i].click(); } } };
this.getcheckValues = function (crl, chkname) { crl = typeof (crl) == "string" ? document.getElementById(crl) : crl; var chks; if (crl == document) { chks = crl.getElementsByName(chkname); } else { chks = crl.getElementsByTagName("input"); } var temp = new Array(); for (var i = 0; i < chks.length; i++) { if (chks[i].checked && chks[i].name == chkname) { temp.push(chks[i].value); } } return temp; };
this.gotop=function(){document.body.scrollTop=0;document.documentElement.scrollTop=0;};

//zhanghong
this.IsPositiveInteger=function(v){var reg =/^\+?[1-9][0-9]*$/; if(reg.test(v)){return true;}else{return false;}};
}
starryMediaCommon.prototype.getScroll = function (){var scrollTop = 0, scrollLeft = 0;scrollTop = (document.body.scrollTop > document.documentElement.scrollTop)? document.body.scrollTop:document.documentElement.scrollTop;if( isNaN(scrollTop) || scrollTop <0 ){ scrollTop = 0 ;}scrollLeft = (document.body.scrollLeft > document.documentElement.scrollLeft )? document.body.scrollLeft:document.documentElement.scrollLeft;if( isNaN(scrollLeft) || scrollLeft <0 ){ scrollLeft = 0 ;}return { scrollTop:scrollTop, scrollLeft: scrollLeft};};
starryMediaCommon.prototype.getClient = function (){var isXhtml = true;if( document.documentElement == null || document.documentElement.clientHeight <= 0){if( document.body.clientHeight>0 ){isXhtml = false;}}this.clientHeight = isXhtml?document.documentElement.clientHeight:document.body.clientHeight;this.clientWidth  = isXhtml?document.documentElement.clientWidth:document.body.clientWidth;return {clientHeight:this.clientHeight,clientWidth:this.clientWidth};};
starryMediaCommon.prototype.PopBox = function (e,sObj,divId,l,t){if(e)e.cancelBubble = true;var div=document.getElementById(divId);var dty =div.style;t=t||0;var crl = sObj;var ttop = crl.offsetTop;var thei = crl.clientHeight;var tleft = crl.offsetLeft;var ttyp = crl.type;var twid=crl.clientWidth;while (crl = crl.offsetParent){ttop+=crl.offsetTop;tleft+=crl.offsetLeft;}dty.top = (ttyp=="image")? (ttop+thei)+"px" : (ttop+thei+t)+"px";dty.left =(tleft+twid+l)+"px";div.style.display="";};
starryMediaCommon.prototype.Close = function (divId){var divObj = document.getElementById(divId);if( divObj != null ){divObj.style.display = "none";}};
starryMediaCommon.prototype.addEventListener = function(oTarget, sEventType, fnHandler){if( oTarget.addEventListener ){oTarget.addEventListener( sEventType, fnHandler, false );}else if( oTarget.attachEvent ){oTarget.attachEvent( "on" + sEventType, fnHandler);}};
starryMediaCommon.prototype.getEvent = function(){if( window.event ){return window.event;}else{return this.getEvent.caller.arguments[0];}};
starryMediaCommon.prototype.cancelBubble = function(){if( window.event ){window.event.cancelBubble = true;}else{return this.cancelBubble.caller.arguments[0].cancelBubble = true;}};
var StarryMediaCommon=new starryMediaCommon();


