//Common JS Function

$.postJSON = function(url,data,callback){
	$.post(url,data,callback,'json');
}
$.fixEvent = function(e){
	var evt = (typeof e == "undefined") ? window.event : e;
	return evt;
}
$.srcElement = function(e)
{
	if (typeof e == "undefined") e = window.event;
  	var src = document.all ? e.srcElement : e.target;
  	return src;
}
$.isTime = function(val)
{
  	var reg = /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;
  	return reg.test(val);
}
$.request = function(url, item)
{
	var sValue=url.match(new RegExp("[\?\&]"+item+"=([^\&]*)(\&?)","i"));
	return sValue?sValue[1]:sValue;
}
$.isNumber = function(val)
{
  	var reg = /^[\d|\.|,]+$/;
  	return reg.test(val);
}

$.isInt = function(val)
{
  	if (val == "")
  	{
   		return false;
  	}
  	var reg = /\D+/;
  	return !reg.test(val);
}


function scrollNews(selector,Entry,time,StartIndex)
{
	var _self=this;
	this.Selector=selector;
	this.Entry=Entry;
	this.time = time;
	this.i=StartIndex||0;
	this.Count=$(this.Selector+" ul li").length;
	$(this.Selector+" ul li").hide();//全部隐藏
	$(this.Selector+" ul li").eq(this.i).show();//第i个显示
	$(this.Selector).bind("mouseenter",function(){
	    	if(_self.sI){clearInterval(_self.sI);}
	}).bind("mouseleave",function(){
			_self.showIndex(_self.i++);
	})
	/*生成激活OL项目*/
	for(var j=0;j<this.Count;j++)
		$(this.Selector+" .activeOL").append('<li><a onclick="'+this.Entry+'.showIndex('+j+');" href="#"><img src="/images/crystal.gif"></a></li>');
	$(this.Selector+" ol li a").eq(this.i).addClass("active");
	this.sI=setInterval(this.Entry+".showIndex(null)",this.time);
	
	this.GetSelector=function(){return this.Selector;}
	this.showIndex=function(index)
	{
		this.i++;//显示下一个
		if(this.sI){clearInterval(this.sI);}
		this.sI=setInterval(this.Entry+".showIndex()",this.time);
		if (index!=null)
		{
			this.i=index;
		}
		if(this.i==this.Count)
			this.i=0;
		$(this.Selector+" ul li").hide();
		$(this.Selector+" ul li").eq(this.i).slideDown();
		$(this.Selector+" ol li a").removeClass("active");
		$(this.Selector+" ol li a").eq(this.i).addClass("active");
	}
}
/**滚动新闻展示效果
code by CssRain--橘子.
转载请注明:http://www.cssrain.cn
// 参数1：ID    		
// 参数2：实例化对象的名称（跟var 后的相同）
// 参数3：间隔时间      
// 参数4：初始化时，默认哪个先显示
**/

function ForDight(Dight)   
{   var How = 4
    Dight = Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);   
    return Dight;   
} 
function ForDight_0(Dight)   
{   var How = 0
    Dight = Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);   
    return Dight;   
}

function len(s) { 
	var l = 0; 
	var a = s.split(""); 
	for (var i=0;i<a.length;i++) { 
	if (a[i].charCodeAt(0)<299) { 
	l++; 
	} else { 
	l+=2; 
	} 
	} 
	return l; 
}

function RndNum(n){
	var rnd="";
	for(var i=0;i<n;i++)
	rnd+=Math.floor(Math.random()*10);
	return rnd;
}
function SetCookie(name,value,day)//两个参数，一个是cookie的名子，一个是值
{
	name = cookiepre+name;
	var argc = SetCookie.arguments.length;
	var argv = SetCookie.arguments;
	var secure = (argc > 5) ? argv[5] : false;
	if(day==null || day==0) day=1;
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + day*24*60*60*1000);
	document.cookie = name + "=" + escape(value) + ("; path=" + cookiepath) + ((cookiedomain == '') ? "" : ("; domain=" + cookiedomain)) + ((secure == true) ? "; secure" : "") + ";expires="+exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
	name = cookiepre+name;
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
	name = cookiepre+name;
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
function CheckInput(This)
{
	if(This.value == '用户名')
	{
		This.value = '';	
	}
	if(This.value == '密码')
	{
		This.style.display = 'none';
		$('#password').show();
		$('#password').focus();
	}
}
function GetInput(This)
{
	if(This.value == '')
	{
		This.value = '用户名';	
	}
}
function GetInput_(This)
{
	if(This.value == '')
	{
		This.style.display = 'none';
		$('#passwordtext').show();
	}
}
 
function checkfstr(This,str)
{
	if(This.value == str)
	{
		This.value = '';	
	}
}
function checkbstr(This,str)
{
	if(This.value == '')
	{
		This.value = str;	
	}
}
function checksearch(formid,wordid,str)
{
	if($('#'+wordid).val() == str)
	{
		$('#'+wordid).val('');
	}
	if($('#'+wordid).val() == '')
	{
		alert(str);
		$('#'+wordid).focus();
		return false;
	}
	$('#'+formid).submit();
}
function bConfirm(This, str)
{
	if(confirm(str))
	{
		This.form.submit();
	}
	else
	{
		return false;	
	}
}
function scaptcha()
{
	$('#captchaimg').attr('src', sitepath+'captcha.php?' + Math.round(Math.random()*10000));
	return true;	
}
function tcaptcha(This)
{
	This.src = sitepath+'captcha.php?' + Math.round(Math.random()*10000);
}
function tCreateCap()
{
	if($('#comment_captcha').val() == '' && !$('#capcode').is(":visible"))
	{
		CreateCap();
	}
}
function CreateCap()
{
	if(scaptcha())
	{
		$('#createcode').hide();
		$('#capcode').show();
	}
}
function lookagreement()
{
	if($('#agreement').is(":visible"))
	{
		$('#agreement').hide();	
	}
	else
	{
		$('#agreement').show();
	}
}
function IniComment(_uid,_uname)
{
	$('#createcode').show();
	$('#capcode').hide();
	$('#comment_content').val('');
	$('#comment_captcha').val('');
	IniLogin(_uid,_uname);
}
function IniLogin(_uid,_uname)
{
	$('#_uid').val(parseInt(_uid));
	$('#_uname').text(_uname);
	if(_uid)
	{
		$('#_toplogin').show();
		$('#_toploginout').hide();
		$('#comment_loginbox').hide();
	}
	else
	{
		$('#_toplogin').hide();
		$('#_toploginout').show();
		if(commentall == 0)
		$('#comment_loginbox').show();
	}
}
function ShowCap()
{
	var captcha = $('#comment_captcha').val();
	if(captcha == '')
	{
		CreateCap();	
	}
}
function closetishi()
{
	$("#tishibox").hide();	
}

function imgresize(ImgD,iwidth,iheight){
    image=new Image();
	image.src=ImgD.attr('src');
		if(image.width>0 && image.height>0){ 
			if(image.width/image.height>= iwidth/iheight){ 
				if(image.width>iwidth){   
					ImgD.attr('width',iwidth); 
					ImgD.attr('height',(image.height*iwidth)/image.width); 
				}else{ 
					ImgD.attr('width',image.width);   
					ImgD.attr('height',image.height); 
				} 
			} 
			else{ 
				if(image.height>iheight){   
					ImgD.attr('height',iheight); 
					ImgD.attr('width',(image.width*iheight)/image.height);   
				}else{ 
					ImgD.attr('width',image.width);   
					ImgD.attr('height',image.height); 
				} 
			} 
		} 
}

function showtab(str1,str2)
{
	$('#'+str2+'title').removeClass();
	$('#'+str1+'title').removeClass();
	$('#'+str1+'title').addClass('TitleLab1');
	$('#'+str2+'title').addClass('TitleLab2');
	
	$('#'+str1+'box').show();
	$('#'+str2+'box').hide();
	
}
function showalltab(total, num, tabbar, tabbox, thisclass, tabclass)
{
	for(var i=1; i<=total; i++)
	{
		$('#'+tabbar+i).removeClass();
		if(tabclass != '') $('#'+tabbar+i).addClass(tabclass);
		$('#'+tabbox+i).hide();
	}
	$('#'+tabbar+num).addClass(thisclass);
	$('#'+tabbox+num).show();
}

function setaction(i,url)
{
	for(var j = 1; j<=4; j++)
	{
		$('#search'+j+'set').removeClass();
	}
	$('#search'+i+'set').addClass('now');
	
	$('#headsearch').attr('action', url);	
	
}
function showshoptab(str)
{
	if(str == '1')
	{
		$('#shop1title').addClass('nowtab');
		$('#shop2title').removeClass();
		$('#shop1box').show();
		$('#shop2box').hide();
	}	
	else
	{
		$('#shop2title').addClass('nowtab');
		$('#shop1title').removeClass();
		$('#shop2box').show();
		$('#shop1box').hide();
	}
}
