function isint(str){
	return /^\d+$/.test(str);
}
function isfloat(str){
	return /^(\+|-)?\d+($|\.\d+$)/.test(str);
}
function isdate(str){
	return /^(\d{4})([/|-])(\d{1,2})([/|-])(\d{1,2})$/.test(str);
}
function isemail(str){
	return /^[a-zA-Z0-9_\-]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/.test(str);
}


function reloadCode(obj,name){
	w=obj.width();
	h=obj.height();
	obj.attr('src','/valid.php?n='+name+'&w='+w+'&h='+h+'&amp;t='+Math.round(Math.random()*10000));
}
function copyUrl() {
//	var clipBoardContent = "<a href='" + window.location.href
//			+ "' target=_blank title='" + document.title + "'>"
//			+ document.title + "</a>"
	var clipBoardContent = window.location.href+"\r\n"+document.title;
	copyToClipboard(clipBoardContent);
	alert("复制本站链接成功!");
}
function copyText(text) {
	copyToClipboard(text);
	alert("复制本站链接成功!");
}
function copyToClipboard(txt) {
	if (window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
	} else if (navigator.userAgent.indexOf("Opera") != -1) {
		window.location = txt;
	} else if (window.netscape) {
		try {
			netscape.security.PrivilegeManager
					.enablePrivilege("UniversalXPConnect");
		} catch (e) {
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
		}
		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 printObj(obj) {
	$('#printShow').html(obj.html());
	window.print();
}
function favorite() {
	addfavorite(window.location.href, document.title);
}
function addfavorite(sURL, sTitle) {
	if (document.all) {
		window.external.addFavorite(sURL, sTitle);
	} else if (window.sidebar) {
		window.sidebar.addPanel(sTitle, sURL, "");
	}
}
function showdiv(id, obj) {
	if (obj) {
		var top = ($(obj).offset().top - (-20)) + 'px';
		var left = $(obj).offset().left + 'px';
		$('#' + id).css('position', 'fixed').css('left', left).css('top', top);
	}
	$('#' + id).show(300);
}
function hidediv(id) {
	$('#' + id).hide(100);
}

// 提交表单
function subForm(fid) {
	$('#' + fid).submit();
}
// 把表单变成可以提交用的params,不支持文件
function formToParam(form) {
	var params = {};
	$('#' + form + ' input').each( function() {
		if ($(this).attr('name')) {
			params[$(this).attr('name')] = $(this).val();
		}
	});
	$('#' + form + ' select').each( function() {
		if ($(this).attr('name')) {
			params[$(this).attr('name')] = $(this).val();
		}
	});
	$('#' + form + ' textarea').each( function() {
		if ($(this).attr('name')) {
			params[$(this).attr('name')] = $(this).val();
		}
	});
	$('#' + form + ' button').each( function() {
		if ($(this).attr('name')) {
			params[$(this).attr('name')] = $(this).val();
		}
	});
	return params;
}
// /////////////////////////////////后台部分////////////////////
/*
 * 根据值获得select的Text
 */
function selectText(obj) {
	var val = obj.val();
	var str = '';
	obj.find('option').each( function() {
		if ($(this).attr('value') == val)
			str = $(this).html();
	})
	return str;
}
/*
 * 设定修改表单的数据
 */
function editFunEmpty(obj, formid) {
	var fieldName = '';
	if (!formid)
		formid = '';
	$(formid + ':input').each(
			function() {
				fieldName = $(this).attr('name');
				if (fieldName && obj[fieldName] && !$(this).val()) {
					switch ($(this).attr('type')) {
					case 'radio':
						$(
								formid + ':radio[name="' + fieldName
										+ '"][value="' + obj[fieldName] + '"]')
								.attr('checked', 'checked');
						break;
					case 'file':
						break;
					default:
						$(this).val(obj[fieldName]);
					}
				}
			})
	$(formid + ':checkbox').each( function() {
		fieldName = $(this).attr('name').replace('[]', '');
		var chkObj = $(this);
		var chkVal = obj[fieldName];
		$.each(chkVal, function(key, val) {
			if (chkObj.val() == val) {
				chkObj.attr('checked', 'checked');
			}
		})
	});
}
function editFun(obj, formid) {
	var fieldName = '';
	if (!formid)
		formid = '';
	$(formid + ':input').each(
			function() {
				fieldName = $(this).attr('name');
				if (fieldName && obj[fieldName]) {
					switch ($(this).attr('type')) {
					case 'radio':
						$(
								formid + ':radio[name="' + fieldName
										+ '"][value="' + obj[fieldName] + '"]')
								.attr('checked', 'checked');
						break;
					case 'file':
						break;
					default:
						$(this).val(obj[fieldName]);
					}
				}
			});
	$(formid + ':checkbox').each( function() {
		fieldName = $(this).attr('name').replace('[]', '');
		var chkObj = $(this);
		var chkVal = obj[fieldName];
		$.each(chkVal, function(key, val) {
			if (chkObj.val() == val) {
				chkObj.attr('checked', 'checked');
			}
		})
	});
}
/*
 * 跳转到某个页面
 */
function go(url) {
	window.location.href = url;
}
