function checkEmail(email){
	var re = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	if (!re.test(email)){
		return false;
	} else {
		return true;
	}
}
function checkAll(inputName, isChecked){
	var boxes = document.getElementsByName(inputName);
	if(boxes){
		for(var i = 0; i < boxes.length; i++){
			if(boxes[i].disabled){
				continue;
			}
			boxes[i].checked = isChecked ? true : false;
		}
	}
}
function checkBoxSelected(inputName){
	var boxes = document.getElementsByName(inputName);
	if(boxes){
		for(var i = 0; i < boxes.length; i++){
			if(boxes[i].checked){
				return true;
			}
		}
	}
	return false;
}

function screenDark() {
	var screen = document.getElementById("screen");
	if (!screen) {
		screen = document.createElement("div");
		document.body.appendChild(screen);
	}
	screen.id = "screen";
	screen.style.cssText = "position:absolute;top:0px;left:0px;background:#000000;";
	var a = (document.documentElement.scrollHeight == 0) ?	document.body.scrollHeight : document.documentElement.scrollHeight;
	screen.style.width = document.documentElement.scrollWidth + "px";
	screen.style.height = a + "px";
	screen.style.zIndex = "100";
	$('#screen').css('opacity','0.7');
	setAllSelectDisabled(true);
}

function closeDark(){
	$('#screen').remove();
	setAllSelectDisabled(false);
}

function setAllSelectDisabled(isDisabled) {
	var selects = document.getElementsByTagName("select");
	for (var i = 0; i < selects.length; i++) {
		selects[i].disabled = isDisabled;
	}
}

function showDialog(id,html,width,height){
	$('#'+id).remove();
	var dialog = document.createElement('div');
	dialog.id = id;
	dialog.innerHTML = html;

	document.body.appendChild(dialog);

	var st,cw,ch;
	cw = document.body.clientWidth;
	if (document.body.scrollTop == 0){
		ch = document.documentElement.clientHeight;
		st = document.documentElement.scrollTop;
	}else{
		ch = document.body.clientHeight;
		st = document.body.scrollTop;
	}
	var left = (cw - width) / 2;
	var top = (ch - height) / 2 + st;
	dialog.style.position = "absolute";
	dialog.style.left = left + "px";
	dialog.style.top = top + "px";

	dialog.style.zIndex = '1110';
}
function showModalDialog(id,html,width,height){
	screenDark();
	showDialog(id,html,width,height);
}
function closeModalDialog(id){
	$('#'+id).remove();
	closeDark();
}
function getPreviewImageUrl(img_url){
	if (img_url.indexOf('attachments') < 0){
		return img_url.replace(/\.(jpg|png|gif)/,'_small.\$1');
	}else{
		return img_url.replace(/\.(jpg|png|gif)/,'.thumb.\$1');
	}
}
function showFlash(url,width,height){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,65,0" width="'+width+'" height="'+height+'" align="middle">');
	document.write('<param name="movie" value="'+url+'" />'); document.write('<param name="quality" value="high" />'); document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="'+url+'" quality="high" width="'+width+'" height="'+height+'" align="middle" swLiveConnect="true" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
function deleteConfirm(title,message,url){
	var method = "window.location.href='"+url+"'";
	confirmDialog(title,message,method);
}
function confirmDialog(title,message,method){
	var id = 'dialog_confirm';
	var html = '<div class="main"><div class="maincenter"><div class="tit"><span class="close"><a href="javascript:closeModalDialog(\''+id+'\');"><img src="/resource/image/sys_btn_close.gif" alt="close" title="close" border="0" /></a></span>';
	html += title + '</div><div class="maintext"><p>' + message + '</p><br />';
	html += '<input type="button" value="确定" class="btn_darkgrey_l2" onclick="'+method+'" /><input type="button" value="取消" class="btn_darkgrey_l2" onclick="closeModalDialog(\''+id+'\');" /></div></div></div>';
	showModalDialog(id,html,460,190);
}
function alertDialog(title,message){
	var id = 'dialog_alert';
	var html = '<div class="main"><div class="maincenter"><div class="tit"><span class="close"><a href="javascript:closeModalDialog(\''+id+'\');"><img src="/resource/image/sys_btn_close.gif" alt="close" title="close" border="0" /></a></span>';
	html += title + '</div><div class="maintext"><p>' + message + '</p><br />';
	html += '<input type="button" value="确定" class="btn_darkgrey_l2" onclick="closeModalDialog(\''+id+'\');" /></div></div></div>';
	showModalDialog(id,html,460,190);
}
function addReport(url){
	var id = 'dialog_post_report';
	var html = '<div class="main"><div class="maincenter"><div class="tit"><span class="close"><a href="javascript:closeModalDialog(\''+id+'\');"><img src="/resource/image/sys_btn_close.gif" alt="close" title="close" border="0" /></a></span>';
	html += '投诉</div><form method="post" action="/report/add_submit.html"><div class="maintext">';
	html += '<table><tr><td>投诉地址：<input class="box_danhang230" type="text" name="url" value="'+url+'" readonly /></td></tr><tr><td>投诉内容：<textarea name="content" class="box_duohang230"></textarea></td></tr></table>';
	html += '<br /><input type="submit" value="提交" class="btn_darkgrey_l2" /><input type="button" value="取消" class="btn_darkgrey_l2" onclick="closeModalDialog(\''+id+'\');" /></div></form></div></div>';
	showModalDialog(id,html,460,290);
}
function showLogin(type,uid){
	var id = 'login';
	var html = '<iframe width="468" height="224" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" bordercolor="#F8FFDF" src="/user/login_iframe.html?type='+type+'&fid='+uid+'"></iframe>';
	showModalDialog(id,html,468,224);
}
function resizeImg(img,x){
	img.resized=true;
	if (img.width > img.height){
		if (img.width > x){
			img.width = x;
		}
	}else{
		if (img.height > x){
			img.height = x;
		}
	}
}