function AddFav(b,a)
{
	try{window.external.addFavorite(b,a)}
	catch(c){try{window.sidebar.addPanel(a,b,"")}
	catch(c){try{createShortcut()}
	catch(c){alert("抱歉，您所使用的浏览器无法完成此操作。\n\n您需要手动将其加入收藏。")}}}
}
function SetHome(c,a)
{
	try{c.style.behavior="url(#default#homepage)";c.setHomePage(a)}
	catch(b){if(window.netscape){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")}
	catch(b){alert("抱歉，此操作被浏览器拒绝！\n\n请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'")}
	}else{
		alert("抱歉，您所使用的浏览器无法完成此操作。\n\n您需要手动将其设置为首页。")
	}
	}
}

function copyCode(){
	var testCode=this.location.href;
	if(copy2Clipboard(testCode)!=false){
		alert("生成的代码已经复制到粘贴板，你可以使用Ctrl+V 贴到需要的地方去了哦！  ");
	}
}
function copyCodeid(id){ 
    var testCode=document.getElementById(id).value; 
    if(copy2Clipboard(testCode)!=false){ 
        alert("生成的代码已经复制到粘贴板，你可以使用Ctrl+V 贴到需要的地方去了哦！ "); 
    } 
}
copy2Clipboard=function(txt){
	if(window.clipboardData){
		window.clipboardData.clearData();
		window.clipboardData.setData("Text",txt);
	}
	else if(navigator.userAgent.indexOf("Opera")!=-1){
		window.location=this.location.href;
	}
	else if(window.netscape){
		try{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}
		catch(e){
			alert("您的firefox安全限制限制您进行剪贴板操作，请打开’about:config’将signed.applets.codebase_principal_support’设置为true’之后重试，相对路径为firefox根目录/greprefs/all.js");
			return false;
		}
		var clip=Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if(!clip)return;
		var trans=Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if(!trans)return;
		trans.addDataFlavor('text/unicode');
		var str=new Object();
		var len=new Object();
		var str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=txt;str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if(!clip)return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
}

	function divshow(tag)
	{
		 var light=document.getElementById(tag);
		 light.style.display='block';
	 }
	 
	function divhide(tag)
	{
		 var light=document.getElementById(tag);
		 light.style.display='none';
	}
	
	function loginshow()
	{
		 var light=document.getElementById('dlg');
		 var fade=document.getElementById('overall');
		 light.style.display='block';
		 fade.style.display='block';
	 }
	 
	function loginhide()
	{
		 var light=document.getElementById('dlg');
		 var fade=document.getElementById('overall');
		 light.style.display='none';
		 fade.style.display='none';
	}
	
	//用户登录
	function submitlogin()
	{
		var iun = document.getElementById('iun');
		var iup = document.getElementById('iup');
		var iuc = document.getElementById('iuc');
		var idbase_weburl = document.getElementById('base_weburl');

		if(iun.value=='')
		{
			alert(' 提 示：用户名不能为空！请输入！');
			iun.focus();
			return false;
		}else if(iup.value=='')
		{
			alert(' 提 示：密码不能为空！请输入！');
			iup.focus();
			return false;
		}	

		if(iuc.value=='')
		{
			alert(' 提 示：验证码不能为空！请输入！');
			iuc.focus();
			return false;
		}
		

		$.post( idbase_weburl.value+"/user/login.php?load=login&act=loginuser",{ use_name: iun.value, use_pwd: iup.value, use_code: iuc.value },function(data) { if(data=='success') { alert('用户登录成功！欢迎你！'); loginhide(); $("#hdivleft").html('欢迎您，<a href="'+idbase_weburl.value+'/user/">'+iun.value+'</a> | <a href="'+idbase_weburl.value+'/user/">用户中心</a> | <a href="'+idbase_weburl.value+'/user/index.php?load=login&act=logout">退出</a>');  }else{  alert(data);  } } );

	}

	//验证码刷新
	function changeImg(webroot_url)
	{
		///var idwebroot_url	=   document.getElementById('webroot_url');
		var idimgCode 	= 	document.getElementById('imgcode');
		idimgCode.src	=	'/user/index.php?load=login&act=get_img_code&time='+Math.random();
 
	}
	
	//字母转换小写
	function tosm( obj )
	{   
		obj.value = obj.value.toLowerCase();   
	}
	//字母转换大写
	function tobg( obj )
	{   
		obj.value = obj.value.toUpperCase();   
	}
	
	//验证邮箱地址是否正确
	function checkemail( obj )
	{
		patn = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
		if(!patn.test(obj.value))
		{
			alert ("提示：\n\nE-mail格式不正确，请输入正确的帐号名称！");
			obj.focus (); 
			return false; 
		}else{
			return true;	
		}
	}
	
	//所填项不能为空！
	function notempty( obj , nameval)
	{
		if(obj.value=='')
		{
			alert ("提示：\n\n"+nameval+"不能为空，请输入！");
			obj.focus (); 
			return false; 
		}else{
			return true;	
		}
	}
	



	//全选操作
	function selectAll(chk,id)
	{
		//var chks = document.getElementsByName(id+'[]');
		var chks = document.getElementsByName(id+'[]');
		for(var i=0; i<chks.length; i++)
		{
		   if(chks[i].type=="checkbox")
		   chks[i].checked=chk.checked;
		}
	}
	
	
	 var isSnum = 0;
	function isSelect(id)
	{
      var chks 	 = document.getElementsByName(id+'[]');
	  var isS 	 = false;
	  var delstr = '';
	 
			for(var i=0; i<chks.length; i++)
			{
			  if(chks[i].type=="checkbox")
			  {
					if(chks[i].checked == true )
					{  
						isS = true ;
						isSnum = isSnum + 1;
						if(isSnum===1){
							delstr = delstr+chks[i].value ; 
						}else{
							delstr = delstr+','+ chks[i].value ; 
						}

					}
				  }
			}
			
			if(isS == false){ alert('提示：\n\n请选择后，再试！'); return false;}
			return delstr;
	}
	
	function arrayDel(id,actstr)
	{
		var idwebroot_url=document.getElementById('webroot_url');
		var delstr = isSelect(id);
		if(delstr){
			if(confirm('你确认要批量删除操作！')) 
			{
			   window.location =idwebroot_url.value+'/index.php?load='+actstr+'&act=del&id='+delstr;  
			}
		}
	}
	
	function arrayShow(id,actstr)
	{
		var idwebroot_url=document.getElementById('webroot_url');
		var delstr = isSelect(id);
		if(delstr){
			if(confirm('你确认要批量显示操作！')) 
			{
			   window.location = idwebroot_url.value+'/index.php?load='+actstr+'&act=show&id='+delstr;  
			}
		}
	}


	function arrayHide(id,actstr)
	{
		var idwebroot_url=document.getElementById('webroot_url');
		var delstr = isSelect(id);
		if(delstr){
			if(confirm('你确认要批量隐藏操作！')) 
			{
			   window.location =idwebroot_url.value+'/index.php?load='+actstr+'&act=hide&id='+delstr;  
			}
		}
	}
	
	//分页排序跳转
	function addOrderBy( listvalval , listtypeval)
	{
		var Url = '';
		if(listvalval !=''){
	     Url += "&listval="+listvalval;
	   }
		if(listtypeval !=''){
	     Url += "&listtype="+listtypeval;
	   }
	   var page_num 	= 1;
	   var PGURLval = document.getElementById("PGURL").value;
	   //urlValue  	= location.pathname;
	   urlValue  	= PGURLval + "&page_num="+page_num ;
	   
	   if(typeof(pageEnter)=="function")
	   {  
		   urlValue += pageEnter();
	   }
	   window.location = urlValue + Url;
	}
	
	//测试是否用户登录状态
	onload = function()
	{
		jQuery.post("/user/index.php?load=login&act=checkuser",{},function(data){ $("#hdivleft").html(data);});
	}
        
        //user/index.php?/login/reg_ajax
        //

	// JavaScript Document
	lastScrollY=0;
	function heartBeat()
	{ 
		var diffY;
		if (document.documentElement && document.documentElement.scrollTop)
			diffY = document.documentElement.scrollTop;
		else if (document.body)
			diffY = document.body.scrollTop
		else
		{/*Netscape stuff*/}

		percent=.1*(diffY-lastScrollY); 
		if(percent>0)percent=Math.ceil(percent); 
		else percent=Math.floor(percent);
		
		if(document.getElementById("lovexin12"))
		document.getElementById("lovexin12").style.top=parseInt(document.getElementById("lovexin12").style.top)+percent+"px";
		
		if(document.getElementById("lovexin14"))
		document.getElementById("lovexin14").style.top=parseInt(document.getElementById("lovexin14").style.top)+percent+"px";
		
		lastScrollY=lastScrollY+percent;
	}
	
	heartleftcode="";
	heartrightcode="";

	//字体大小设置
	function contentZoom(fontval)
	{
		var fontval = fontval; 
		document.getElementById("articlecontentdiv").className = fontval;
	}




//图片按比例缩放
function showImage(ImgD,iwidth,iheight)
{

	var flag=false;
	var image=new Image();
	if(!iwidth)
		iwidth = 100;
	if(!iheight)
		iheight = 80;

	image.src=ImgD.src;
	if(image.width>0 && image.height>0)
	{

		flag=true;
		if(image.width/image.height>= iwidth/iheight)
		{

			if(image.width>iwidth)
			{
				ImgD.style.width=iwidth + "px";
				ImgD.style.height=Math.floor((image.height*iwidth)/image.width) + "px";

			}else{

				ImgD.style.width=image.width + "px"; 
				ImgD.style.height=image.height + "px";

			}

		}else{

			if(image.height>iheight)
			{ 

				ImgD.style.height=iheight + "px";
				ImgD.style.width=Math.floor((image.width*iheight)/image.height) + "px"; 

			}else{

				ImgD.style.width=image.width + "px"; 
				ImgD.style.height=image.height + "px";

			}

		}

	}

}

