function doSearch(key){
	var url = "/search.do";
	if(key.length > 1){
		url = url+'?k=' + encodeURIComponent(key);
	}else{
		url = "/";
	}
	document.location = url;
}

function setHomepage(obj,url){
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage(url);
}

function loaduser(){
	var url = "/user/ajax/loaduser.do";
	$.get(url,{t:new Date().getTime()},function(data){
		$('#homepageUserBox').html(data);
	});
}


function checkSearchForm(v_form)
{
	if (v_form.k.value.length == 0 || v_form.k.value.length < 2)
	{
		alert("请输入搜索的关键字，最少两个字！");
		v_form.k.focus();
		return false;
	}

	return true;
}

function checksearchHospital(v_form)
{
	if (v_form.k.value.length == 0 || v_form.k.value.length < 2 )
	{
		alert("请输入搜索的关键字，最少两个字！");
		v_form.k.focus();
		return false;
	}

	return true;
}

function checklogin(v_form)
{
	if (v_form.email.value.length == 0 )
	{
		alert("请输入您的email！");
		v_form.email.focus();
		return false;
	}

	if (v_form.password.value.length == 0 )
	{
		alert("请输入您的密码！");
		v_form.password.focus();
		return false;
	}
	
	return true;
}

function checkregister(v_form)
{
	if (v_form.email.value.length == 0 )
	{
		alert("请输入您的email！");
		v_form.email.focus();
		return false;
	}

	if (v_form.password.value.length < 6 )
	{
		alert("请输入您的密码，最少6位长！");
		v_form.password.focus();
		return false;
	}

	if (v_form.nickname.value.length == 0 )
	{
		alert("请输入您的昵称！");
		v_form.nickname.focus();
		return false;
	}

	if (v_form.captcha.value.length < 4 )
	{
		alert("请输入验证码！");
		v_form.captcha.focus();
		return false;
	}
			
	return true;
}

function checkquestion(v_form)
{
	if (v_form.title.value.length < 5 )
	{
		alert("请输入您的问题，最少5个字！");
		v_form.title.focus();
		return false;
	}

	if (v_form.content.value.length < 5 )
	{
		alert("请输入问题的详细描述，最少5个字！");
		v_form.content.focus();
		return false;
	}

	if (v_form.subCatId.value.length == 0 )
	{
		alert("请选择子分类！");
		v_form.subCatId.focus();
		return false;
	}
			
	return true;
}

function checkQuestionTitle(v_form)
{
	if (v_form.k.value.length == 0 || v_form.k.value.length < 5 )
	{
		alert("请输入您的问题，最少5个字！");
		v_form.k.focus();
		return false;
	}

	return true;
}

function checkanswer(v_form)
{

	if (v_form.content.value.length < 5 )
	{
		alert("请输入答案的内容，最少5个字！");
		v_form.content.focus();
		return false;
	}

	if (v_form.captcha.value.length < 4 )
	{
		alert("请输入验证码！");
		v_form.captcha.focus();
		return false;
	}
			
	return true;
}

function checkprofile(v_form)
{

	if (v_form.nickname.value.length < 2 )
	{
		alert("请输入昵称，2-20个字！");
		v_form.nickname.focus();
		return false;
	}
	
	if (!v_form.gender[0].checked && !v_form.gender[1].checked )
	{
		alert("请选择性别！");
		return false;
	}
		
	return true;
}

function showCaptcha()
{
	var captchadiv = document.getElementById("captchadiv");
	var captchadiv2 = document.getElementById("captchadiv2");
	var captchavalue = document.getElementById("captcha");
	if (captchadiv.style.display == "none")
	{
		captchadiv.style.display = "";
		captchadiv2.style.display = "";
		captchavalue.value="";
	}
}

function reply(){
	var content = document.getElementById("postcontent");
	content.focus();
}

function reg(){
	document.location = '/register.do';
}

function login(){
	document.location = '/login.do';
}

function logout(){
	document.location = '/logout.do?f=' + encodeURIComponent(document.URL);
}

function go(url){
	if(url.indexOf("?") == -1){
		url = url+'?f=' + encodeURIComponent(document.URL);
	}else{
		url = url+'&f=' + encodeURIComponent(document.URL);
	}
	
	document.location = url;
}

function nav(url){
	document.location = url;
}

function doRevise(go,h_url,h_title){
	go = go+'?url=' + encodeURIComponent(h_url)+'&title='+encodeURIComponent(h_title);
	document.location = go;
}

function goback(url){
	document.location = decodeURIComponent(url);
}

function addFavorite( title ){
	window.external.addFavorite(document.URL,title);
}

function openPoster(name){
	var posterurl = "/search.do?t=1&k="+name;
	window.open(posterurl);
}	 
	 
function doQuestion(form){
	if (form.k.value.length == 0)
	{
		document.location = "/ask-q-create.do";
	}else{
		form.action = "/ask-q-create.do";
		form.submit();	
	}

}	 
	 
function delQ(url){
	var msg = "确定要删除这个问题？";
	if (confirm(msg)==true){
		document.location = url+'&f=' + encodeURIComponent(document.URL);
	}

}

//跳转到指定页面
function goToPage(page){
	var url = setQueryString('page', page);
	document.location = url;
}

//获取URL中参数值
function getQueryString(fieldName)
{ 
  var urlString = document.location.search;
  if(urlString != null){
       var typeQu = fieldName+"=";
       var urlEnd = urlString.indexOf(typeQu);
       if(urlEnd != -1){
            var paramsUrl = urlString.substring(urlEnd+typeQu.length);
            var isEnd =  paramsUrl.indexOf('&');
            if(isEnd != -1){
                 return paramsUrl.substring(0, isEnd);
            }
            else{
                return paramsUrl;
            }
       }
       else{
            return null;
       }
  }
 else{
    return null;
 }
}

//刷新验证码
function refreshCaptcha(name){
	document.getElementById(name).src = '/service/captcha.do?a='+parseInt(Math.random()*999999);
}

//帖子检查(fck)
function checkAdvancedThread(v_form){
	if (v_form.title.value.length == 0)
	{
		alert("请输入标题");
		v_form.title.focus();
		return false;
	}
	var oEditor = FCKeditorAPI.GetInstance('txtContent') ;
	var content = oEditor.GetHTML(false);
	if(content.length == 0){
		alert("请输入内容");
		oEditor.Focus();
		return false;
	}
	if(v_form.captcha.length == 0){
		alert("请输入验证码");
		v_form.captcha.focus();
		return false;
	}
	return true;

}

//帖子检查
function checkSimpleThread(v_form)
{
	if (v_form.title.value.length == 0 || v_form.title.value.length < 2)
	{
		alert("请输入标题，最少两个字！");
		v_form.title.focus();
		return false;
	}
	if (v_form.content.value.length == 0)
	{
		alert("请输入内容！");
		v_form.content.focus();
		return false;
	}
		
	if (v_form.captcha.value.length == 0)
	{
		alert("请输入验证码！");
		v_form.captcha.focus();
		return false;
	}
	return true;
	
}

//帖子检查
function checkPosterCreate(v_form)
{
	if (v_form.name.value.length == 0)
	{
		alert("请输入名称");
		v_form.name.focus();
		return false;
	}
	if (v_form.desc.value.length == 0)
	{
		alert("请输入描述！");
		v_form.desc.focus();
		return false;
	}
	
	return true;
	
}

function OpenOrClose(){
   if(window.top.document.getElementById("main").cols=="510,12,*")
    {
       window.top.document.getElementById("main").cols="0%,12,*";
       parent.frames['middle'].document.getElementById("ImgArrow").src="/images/ar.gif";
    }
	else
	{
		window.top.document.getElementById("main").cols="510,12,*"
		parent.frames['middle'].document.getElementById("ImgArrow").src="/images/al.gif";
	}
}

function auditPosterUserRequest(url){
	var msg = "确定要通过审核吗？";
	if (confirm(msg)==true){
		document.location = url+'&f=' + encodeURIComponent(document.URL);
	}
}

function confusePosterUserRequest(url){
	var msg = "确定要拒绝审核吗？";
	if (confirm(msg)==true){
		document.location = url+'&f=' + encodeURIComponent(document.URL);
	}
}

function delPosterUser(url){
	var msg = "确定要撤销吧主吗？";
	if (confirm(msg)==true){
		document.location = url+'&f=' + encodeURIComponent(document.URL);
	}
}

function delPosterReply(url){
	var msg = "确定要删除该贴吗？";
	if (confirm(msg)==true){
		document.location = url+'&f=' + encodeURIComponent(document.URL);
	}
}

function delPosterThread(url){
	var msg = "确定要关闭该贴吗？";
	if (confirm(msg)==true){
		document.location = url+'&f=' + encodeURIComponent(document.URL);
	}
}

function checkPhotoUploadForm(v_form){
	
	if(v_form.file.value.length==0){
		alert("请选择源文件！");
		v_form.file.focus();
		return false;
	}
	
	if(v_form.desc.value.length>128){
		alert("简介不能超过128个字符！");
		v_form.desc.focus();
		return false;
	}
	if(v_form.tag.value.length>128){
		alert("不能超过10个标签,不能超过128个字符");
		v_form.tag.focus();
		return false;
	}
	if(v_form.albumid.value == ''){
		alert("请选择一个相册");
		return false;
	}
	
	return true;
} 

function checkAlbumUpdateForm(v_form){
	
	if(v_form.name.value.length==0){
		alert("名称不能为空！");
		v_form.name.focus();
		return false;
	}
	
	if(v_form.name.value.length > 20){
		alert("名称长度不能超过20个字！");
		v_form.name.focus();
		return false;
	}
	
	return true;
}

function checkUserRequest(v_form){
	
	if (v_form.name.value.length == 0)
	{
		alert("请输入真实姓名！");
		v_form.name.focus();
		return false;
	}
	if (v_form.phone.value.length == 0)
	{
		alert("请输入联系电话！");
		v_form.phone.focus();
		return false;
	}
		
	if (v_form.captcha.value.length == 0)
	{
		alert("请输入验证码！");
		v_form.captcha.focus();
		return false;
	}
	
	if (v_form.agreement.checked == false)
	{
		alert("必须接受吧主协议 ！");
		return false;
	}
	return true;
	
}
//设置URL参数中值
function setQueryString(fieldName,fieldValue) {
	 var oUrl = this.location.href.toString();
	 if(getQueryString(fieldName) == null){
		 if(oUrl.indexOf('?') != -1)
			 oUrl = oUrl + '&'+fieldName+'='+fieldValue;
		 else
			 oUrl = oUrl + '?'+fieldName+'='+fieldValue;
	 }
	 var re=eval('/('+ fieldName+'=)([^&]*)/gi');
	 var nUrl = oUrl.replace(re,fieldName+'='+fieldValue);
	 return nUrl;
}

//specify whether contents should be auto copied to clipboard (memory)

//Applies only to IE 4+

//0=no, 1=yes

var copytoclip=1;

function copyToClipboard(theField,isalert) {		

	var tempval=document.getElementById(theField);	

	if (navigator.appVersion.match(/\bMSIE\b/)){

		tempval.select();		

		if (copytoclip==1){

			therange=tempval.createTextRange();

			therange.execCommand("Copy");

			if(isalert!=false)alert("复制成功。现在您可以粘贴（Ctrl+v）到Blog 或BBS中了。");

		}

		return;

	}else{

		alert("您使用的浏览器不支持此复制功能，请使用Ctrl+C或鼠标右键。");

		tempval.select();		

	}

}

