function getBrowserVersion() {
	var browser = {};
	var userAgent = navigator.userAgent.toLowerCase();
	var s;
	(s = userAgent.match(/msie ([\d.]+)/))
			? browser.ie = s[1]
			: (s = userAgent.match(/firefox\/([\d.]+)/))
					? browser.firefox = s[1]
					: (s = userAgent.match(/chrome\/([\d.]+)/))
							? browser.chrome = s[1]
							: (s = userAgent.match(/opera.([\d.]+)/))
									? browser.opera = s[1]
									: (s = userAgent
											.match(/version\/([\d.]+).*safari/))
											? browser.safari = s[1]
											: 0;
	var version = "";
	if (browser.ie) {
		version = 'msie ' + browser.ie;
	} else if (browser.firefox) {
		version = 'firefox ' + browser.firefox;
	} else if (browser.chrome) {
		version = 'chrome ' + browser.chrome;
	} else if (browser.opera) {
		version = 'opera ' + browser.opera;
	} else if (browser.safari) {
		version = 'safari ' + browser.safari;
	} else {
		version = '未知浏览器';
	}
	return version;
}




function in_array(needle, haystack) {
	if(typeof needle == 'string' || typeof needle == 'number') {
	   for(var i in haystack) {
		if(haystack[i] == needle) {
		  return true;
		}
	   }
	}
	return false;
}


function pub_favo(type,appid,app_name,type_cn){
	$.post(APP+"/Pub/favorite",{type:type,appid:appid,app_name:app_name,type_cn:type_cn},function(txt){
	    if(txt == "error") {  alert("不要提交太快!");return;  }
	    if(txt){
			if(txt == "already"){
				Alert("你已经收藏过了!");
			}else{
				Alert("收藏成功!");
			}
	    }else{
			alert("收藏失败,请稍后再试!");
	    }	
	});	
}

function pub_share(type,appid,app_name,type_cn){
	$.post(APP+"/Pub/doShare",{type:type,appid:appid,app_name:app_name,type_cn:type_cn},function(txt){
	    if(txt == "error") {  alert("不要提交太快!");return;  }
	    if(txt){
			if(txt == "already"){
				Alert("你已经分享过了!");
			}else{
				Alert("分享成功!");
			}
	    }else{
			alert("分享失败,请稍后再试!");
	    }	
	});	
}

function pub_jubao(type,appid,app_name){
	var yuanyin = $.trim($("#jubao_yuanyin").val());
	if(!yuanyin) { $("#show_jubao_tip").show(); return; }
	$.post(APP+"/Pub/doJubao",{type:type,appid:appid,app_name:app_name,yuanyin:yuanyin},function(txt){
	    if(txt == "error") {  alert("不要提交太快!");return;  }
	    if(txt){
			if(txt == "already"){
				Alert("你已经举报过了!");
			}else{
				Alert("举报成功!");
			}
	    }else{
			alert("举报失败,请稍后再试!");
	    }	
	});	
}

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

 
//$.cookie("chatlist","["+chatlist+"]",{ path: '/'});
//var ccookie=$.cookie("chatlist");
//$.cookie("chatlist",null,{ path: '/'});//清理cookie
			
			


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};





//$(function(){
//
//	$("img").error(function(){
//		$(this).attr("src",PUBLIC+"/images/default.gif");
//	});
//
//
//});
function strip_tags(stripStr,allowTags){

   var allowArr=[];
   if(!stripStr || stripStr.length==0) return stripStr;
   if (allowTags) allowArr=allowTags.match(/[a-zA-Z]+/gi);
   var matchArr = stripStr.match(/(<\/?[\S][^>]*>)/gi);
   for (var mVal in matchArr){
	   if (isNaN(mVal)) continue; 
	   var matchVal = matchArr[mVal];
	   var allow = false;
	 // alert( matchArr[mVal]);
//	   for (var aVal in allowArr){
//		   if(new RegExp('<\\/?'+allowArr[aVal]+'(?:>| )','i').test(matchVal)){
//			   allow=true
//			   break;
//		   }               
//	   }
	   if (!allow) stripStr=stripStr.split(matchVal).join("");
   }

   return stripStr;
}

function go_url(url){
	location.href = url;
}

/**
 *计算字符串长度的函数
 *
 */
function JHshStrLen(sString)
{
   var sStr,iCount,i,strTemp ;

   iCount = 0 ;
   sStr = sString.split("");
    for (i = 0 ; i < sStr.length ; i ++)
     {
         strTemp = escape(sStr[i]);
          if (strTemp.indexOf("%u",0) == -1)
          {
              iCount = iCount + 1 ;
          }
          else
          {
              iCount = iCount + 2 ;
          }
      }

      return iCount ;
}



/**
 * checkbox选择控制
 *
 */
//按照类来选择
function selectAll(class_name) {   
	//var checked = $("#selectall").attr("checked");   
	   
	$("."+class_name).each(function() {   
		var subchecked = $(this).attr("checked");   
		if (subchecked != true)   
			$(this).click();   
	});   
}   

function unSelectAll(class_name) {   
	//var checked = $("#selectall").attr("checked");   
	   
	$("."+class_name).each(function() {   
		var subchecked = $(this).attr("checked");   
		if (subchecked == true)   
			$(this).click();   
	});   
}   

function getSelectValues(cls) {
	  id = [];
	  var check = cls?"."+cls+" input[type='checkbox']:checked":"input[type='checkbox']:checked";
	  $(check).each(function(){
		  var data = $(this).val();
		  if(!isNaN(data)) id.push(data);
	  });
	  return id.join(',');
}


//最常用的
$(function() {
	$("#checkAll").click(function(){    
		if(this.checked){ 
			$("input[type='checkbox']").each(function(i){
				this.checked=true;
			});
		}else{    
			$("input[type='checkbox']").each(function(i){
				this.checked=false;
			});
		}    
	});  	
});


function escapeHTML(s) {
  return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};


function ReplaceAll(str, sptr, sptr1)
{
	while (str.indexOf(sptr) >= 0)
	{
	   str = str.replace(sptr, sptr1);
	}
	return str;
}


function handlerIframe(){
   // alert(ymPrompt.getPage().contentWindow.document.body.innerHTML);
    ymPrompt.close();
}

//全站统一举报函数
function report(type,url,info){
//    Confirm({message:'确定要举报这个内容？',handler:function(tp){
//            if(tp=='ok'){
//                $.post(TS+"/Public/report",{type:type,url:url,info:info},function(txt){
//                    if(txt){
//                        Alert("举报成功!");
//                    }else{
//                        Alert("你已经举报过了!");
//                    }
//                });
//            }
//            if(tp=='cancel'){
//                ymPrompt.close();
//            }
//            if(tp=='close'){
//                ymPrompt.close();
//            }
//        }});	

url = encode64(url);
Win({message:TS+'/Public/isReport/type/'+type+"/url/"+url+"/info/"+info,width:392,height:220,title:'举报此信息',handler:handlerIframe,autoClose:false,iframe:true,allowRightMenu:true});


}



var keyStr = "ABCDEFGHIJKLMNOP" + 
"QRSTUVWXYZabcdef" + 
"ghijklmnopqrstuv" + 
"wxyz0123456789+/" + 
"=";

function encode64(input)
{ 
input = escape(input); 
var output = ""; 
var chr1, chr2, chr3 = ""; 
var enc1, enc2, enc3, enc4 = ""; 
var i = 0; 

do
{ 
   chr1 = input.charCodeAt(i++); 
   chr2 = input.charCodeAt(i++); 
   chr3 = input.charCodeAt(i++); 
  
   enc1 = chr1 >> 2; 
   enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 
   enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 
   enc4 = chr3 & 63; 
  
   if (isNaN(chr2))
   {
    enc3 = enc4 = 64; 
   }
   else if (isNaN(chr3))
   { 
    enc4 = 64; 
   } 
  
   output = output + 
   keyStr.charAt(enc1) + 
   keyStr.charAt(enc2) + 
   keyStr.charAt(enc3) + 
   keyStr.charAt(enc4); 
   chr1 = chr2 = chr3 = ""; 
   enc1 = enc2 = enc3 = enc4 = ""; 
} while (i < input.length); 

return output; 
}

function decode64(input)
{ 
var output = ""; 
var chr1, chr2, chr3 = ""; 
var enc1, enc2, enc3, enc4 = ""; 
var i = 0; 

// remove all characters that are not A-Z, a-z, 0-9, +, /, or = 
var base64test = /[^A-Za-z0-9\+\/\=]/g; 
if (base64test.exec(input))
{ 
   alert("There were invalid base64 characters in the input text.\n" + 
   "Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" + 
   "Expect errors in decoding."); 
} 
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 

do
{ 
   enc1 = keyStr.indexOf(input.charAt(i++)); 
   enc2 = keyStr.indexOf(input.charAt(i++)); 
   enc3 = keyStr.indexOf(input.charAt(i++)); 
   enc4 = keyStr.indexOf(input.charAt(i++)); 
  
   chr1 = (enc1 << 2) | (enc2 >> 4); 
   chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 
   chr3 = ((enc3 & 3) << 6) | enc4; 
  
   output = output + String.fromCharCode(chr1); 
  
   if (enc3 != 64)
   {
    output = output + String.fromCharCode(chr2); 
   } 
   if (enc4 != 64)
   { 
    output = output + String.fromCharCode(chr3); 
   } 
  
   chr1 = chr2 = chr3 = ""; 
   enc1 = enc2 = enc3 = enc4 = ""; 
} while (i < input.length); 
return unescape(output); 
} 


//上传预览
function getFullPath(obj) 
{ 
	if(obj) 
	{ 
		//ie 
		if (window.navigator.userAgent.indexOf("MSIE")>=1) 
		{ 
			obj.select(); 
			return document.selection.createRange().text; 
		} 
		//firefox 
		else if(window.navigator.userAgent.indexOf("Firefox")>=1) 
		{ 
			if(obj.files) 
			{ 
				return obj.files.item(0).getAsDataURL(); 
			} 
			return obj.value; 
		} 
		return obj.value; 
	} 
} 


//去掉字符串空间调用方式 字符串.trim()    
String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, "");}        
   
//求字符穿真实长度汉字２个字节　字符串.lengthw()    
String.prototype.lengthW = function(){ return this.replace(/[^\x00-\xff]/g,"**").length;}    
   
//判断是否email    
String.prototype.isEmail = function(){ return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this);}     
   
// 字符串中是否包含中文    
String.prototype.existChinese = function(){return /^[\x00-\xff]*$/.test(this);}       
   
//检查url       
String.prototype.isUrl = function(){ return /^http[s]?:\/\/([\w-]+\.)+[\w-]+([\w-./?%&=]*)?$/i.test(this);}    
   
//检查电话号码    
String.prototype.isPhoneCall = function(){ return /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(this);}     
   
//检查整数    
String.prototype.isNum=function(){return /^[0-9]+$/.test(this);}    
   
// 整数转换    
String.prototype.toNumber = function(def){return isNaN(parseInt(this, 10)) ? def : parseInt(this, 10);}       
   
// 小数转换    
String.prototype.toMoney = function(def){return isNaN(parseFloat(this)) ? def : parseFloat(this);}   



//joboto

function checkJsToken(txt) {
        if(txt == 'error'){
                alert('请不要频繁提交');
                return false;
        }
        if(txt == 'fail'){
                alert('说得太快了。休息会吧');
                return false;
        }
        return true;
}

function checkLogin(){
//        delCookie('log_refer');
//        if(0 == MID){
//                var url = location.href;
//                setCookie('log_refer',url,'1000000' );
//                window.location.href = APP+'/Index/login';
//        }
}


function table_mouse_color(){
	try{
		var Ptr=document.getElementById("tab").getElementsByTagName("dd");
		function table_$() {
			  for (i=1;i<Ptr.length+1;i++) {
				Ptr[i-1].className = (i%2>0)?"t1":"t2";
			  }
		}
		window.onload=table_$;
		for(var i=0;i<Ptr.length;i++) {
			  Ptr[i].onmouseover=function(){
				this.tmpClass=this.className;
				 this.className = "t3";
			  };
			  Ptr[i].onmouseout=function(){
			  this.className=this.tmpClass;
			  };
		}	
	}catch(e){
	
	}

	
}


//IE6下PNG透明
function fixPNG(myImage)
{
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if ((version >= 5.5) && (version < 7) && (document.body.filters))
	{
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
		var imgTitle = (myImage.title) ? "title='" + myImage.title   + "' " : "title='" + myImage.alt + "' ";
		var imgStyle = "display:inline-block;" + myImage.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + myImage.width
		+ "px; height:" + myImage.height
		+ "px;" + imgStyle + ";"             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
		myImage.outerHTML = strNewHTML;
	}
}

function Qtip_close(){
	 $('#QC').remove();
}


function check_login() {
	var email = $.trim($("#email").val());
	var pass = $.trim($("#passwd").val());

	if(!email) { Alert("您还没有填写Email!"); return false; }
	if(!pass) { Alert("您还没有填写密码!"); return false; }

	return true;
}

function show_tip(txt,type){
       var span = $('<span class="mini_tip"/>').append(txt);
		span.animate({
			opacity: 0.3
		}, 750).animate({
			opacity: 1
		}, 750);
		window.setTimeout(function(){
			if(type == 1){
				span.removeClass("mini_tip");
			}else{
				$(".mini_tip").remove();
			}
		},1800);
		return span;
}

function show_tip_gz(txt,uid,type,uname){
       var span = $('<span class="mini_tip"/>').append(txt);
		span.animate({
			opacity: 0.3
		}, 750).animate({
			opacity: 1
		}, 750);
		window.setTimeout(function(){
			if(type == 1){
				$(".mini_tip").html('<a href="javascript:follow_ta('+uid+','+uname+')">关注</a>');
			}else{
				$(".mini_tip").html('<a href="###" class="Qconfirm" rel="not_follow_ta('+uid+')" title="确定要取消关注？">已关注</a>');
					Qtip_init();
			}
		
		},1800);
		return span;
}


//search
function check_header_search() {
	var s_key = $.trim($("#header_s_key").val());
	//alert(s_key);
	if(!s_key || s_key == "请输入关键字，搜索你想要的...") { Alert("请输入关键字!"); return false; }
}


function DrawImage(ImgD,iwidth,iheight){    
    //参数(图片,允许的宽度,允许的高度)    
    var image=new Image();    
    image.src=ImgD.src;    
    if(image.width>0 && image.height>0){    
      if(image.width/image.height>= iwidth/iheight){    
          if(image.width>iwidth){      
              ImgD.width=iwidth;    
              ImgD.height=(image.height*iwidth)/image.width;    
          }else{    
              ImgD.width=image.width;      
              ImgD.height=image.height;    
          }    
      }else{    
          if(image.height>iheight){      
              ImgD.height=iheight;    
              ImgD.width=(image.width*iheight)/image.height;            
          }else{    
              ImgD.width=image.width;      
              ImgD.height=image.height;    
          }    
      }    
    }    
}   

//proj add
function do_search(){
	if ($.trim($("#s_time").val()) == '开始日期') {
		$("#s_time").val("");
	}
	if ($.trim($("#e_time").val()) == '结束日期') {
		$("#e_time").val("");
	}
	if ($.trim($("#s_key").val()) == '关键字') {
		$("#s_key").val("");
	}

	var s_key = $.trim($("#s_key").val());
	$("#s_key").val(s_key);
	
	$("#search_form").submit();
}
