var userAgent = navigator.userAgent.toLowerCase();
var is_webtv = userAgent.indexOf('webtv') != -1;
var is_kon = userAgent.indexOf('konqueror') != -1;
var is_mac = userAgent.indexOf('mac') != -1;
var is_saf = userAgent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko' && !is_saf) && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ns = userAgent.indexOf('compatible') == -1 && userAgent.indexOf('mozilla') != -1 && !is_opera && !is_webtv && !is_saf;
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera && !is_saf && !is_webtv) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

/*重载setTimeout*/
var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay) 
{ 
	if(typeof fRef == 'function')
	{  
		var argu = Array.prototype.slice.call(arguments,2);  
		var f = (function(){ fRef.apply(null, argu); });  
		return _st(f, mDelay); 
	} 
	
	return _st(fRef,mDelay);
}




/**
 * 去掉左右空格
 */
function trim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}

/**
 * 对表单数据去左右空格
 */
function common_validate(obj)
{
	for(var i = 0;i<obj.length;i++)
	obj[i].value = trim(obj[i].value);
	return obj;
}
/**
 * 全选表单选择框
 */
function checkAll(obj)
{
	var check =	document.getElementsByName("id[]");
	for(i=0; i<check.length; i++)
	{
		check[i].checked = obj.checked;
	}
}
/**
 * 时间戳转日期格式
 */
function timedate(time)
{
		var time = time+'000';
		var dateObj = new Date(parseInt(time));
		if(((dateObj.getMonth()+1)+'').length ==1) var Month = '0'+((dateObj.getMonth()+1)+''); else var Month = dateObj.getMonth()+1;
		if((dateObj.getDate()+'').length ==1) var date = '0'+(dateObj.getDate()+''); else var date = dateObj.getDate();
		if((dateObj.getHours()+'').length ==1) var hours = '0'+(dateObj.getHours()+''); else var hours = dateObj.getHours();
		if((dateObj.getMinutes()+'').length ==1) var minutes = '0'+(dateObj.getMinutes()+''); else var minutes = dateObj.getMinutes();
		if((dateObj.getSeconds()+'').length ==1) var seconds = '0'+(dateObj.getSeconds()+''); else var seconds = dateObj.getSeconds();
		return (dateObj.getFullYear()+'-'+Month+'-'+date+' '+hours+':'+minutes+':'+seconds);
}
/**
 *删除所选的多个表单项
 */
function Del(obj,msg,link)
{
	if(msg.length >0)
	if(!confirm(msg))
	{
		return false;
	}
	obj.form.action = link;
}

/**
 *跳转到某页
 */
function directurl(url)
{
	window.location.href=url;
}
/**
 *验证email
 */
function check_email(email)
{
	return new RegExp(/^([_a-z0-9]+([\._a-z0-9-]+)*)@[a-z0-9-]{2,}(\.[a-z0-9-]{2,})*(\.[a-z]{2,3}){1,2}$/).test(email);
}

/**
 * 切换
 */
function changer(idx, obj,show)
{
	var m = obj.parentNode.getElementsByTagName("li");
	if(show == 'undefined')
	{
		show = 'show_';	
	}
	for(var i = 0;i<m.length;i++)
	{
		if(m[i] == obj){
			m[i].className = "active";
			document.getElementById(show + idx + "_" + (i + 1)).style.display = "";
		}else
		{
			m[i].className = "";
			document.getElementById(show + idx + "_" + (i + 1)).style.display = "none";
		}
	}
}
/**
 * 重置图片显示大小
 */
function resize_pic(obj,width)
{
	if(obj.width>obj.height)
	{
		if(obj.width >width) 
		{
			obj.resized=true; obj.width=width;
		}
	}
	else
	{
		if(obj.height >width) 
		{
			obj.resized=true; obj.height=width;
		}
	}
}
/**
 * 验证手机
 */
    function check_phone(s){
        var p = /^(013|015|13|15)\d{9}$/;
        if(s.match(p) != null){
           return true;
        }else{
             return false;
        }
    }

		/**
 * ajax的get方法
 */
function ajax_get(url,pars,id)
{
	var myAjax = new Ajax.Request(
		url,
			{
			method: 'get',
			parameters:pars,
			onLoaded:function(originalRequest)
					{
					$(id).innerHTML = '信息正在处理中，请稍等';
					},
			onSuccess:function(originalRequest)
						{
						set_innerHTML(id,originalRequest.responseText);
						},
			onFailure:function(originalRequest)
						{
							$(id).innerHTML = '信息处理错误';
						}
			}
	);
}

/**
 * 验证整数
 */
function check_num(s){
	return parseInt(s);
}

function copy(obj) 
{ 
	var t=document.getElementById(obj); 
	t.select(); 
	window.clipboardData.setData("text",t.createTextRange().text); 
	 alert("复制成功");
}
