
//设置标签
function selectTag(tag){
    //过滤前后空格
    tag =  tag.replace(/(^\s*)|(\s*$)/g, "");
    var obj = document.getElementById("strTags");
    var tags = obj.value;
    tags = tags.replace('，',',');
    var tagArr = tags.split(',');
    var solvedTags = '';
    var exist = false;
    //循环处理，去除已经存在的。同时判断是否存在
	if(tags.length > 1 ){
		for(var i = 0 ; i < tagArr.length ; i ++){
		    if(tagArr[i] == tag ){
				exist = true;
				continue;
			}
			if(tagArr[i].length < 1){
			   continue;
			}
			solvedTags += tagArr[i].replace(/(^\s*)|(\s*$)/g, '');
			
			if(tagArr.length != 1  && tagArr.length - 1 !=  i ){
				if(tagArr[i+1].replace(/(^\s*)|(\s*$)/g, '').length > 0)
				   solvedTags += ',';
			} 
		 }
	 }
    //如果不存在，加一个
    if(!exist){
	   if(solvedTags.replace(/(^\s*)|(\s*$)/g, '').length > 0){
			solvedTags += ','+tag;
	   }else{
		    solvedTags = tag;
	   }
    }
   obj.value=solvedTags;

}

function setColor(color) 
{       

    var obj = document.getElementById('Wish_Preview');

    
    obj.className ="xy"+color;
    
    document.getElementById('styleNum').value = color;  
}




function selectGift(gift){
$('gift').value=gift;
}


function textCounter(field, countfield, maxlimit) 
{        
    if (field.value.length > maxlimit) 
    {
        field.value = field.value.substring(0, maxlimit);
    }        
    else
    {
        countfield.value = maxlimit - field.value.length;
    }     
        
   var obj = document.getElementById('ContentPreview');
    if(obj!=null){
		obj.innerHTML = field.value;
	}
 
}

function writeDay(obj){
           // alert("in writeDay ");
            var strToday = "" ;
                        todayDate = new Date();
                        date = todayDate.getDate();
                        month= todayDate.getMonth() +1;
                        year= todayDate.getYear();
                       if(navigator.appVersion.indexOf("MSIE") == -1){
                         year+=1900;
                       }
                       strToday+=( year ) ;
                        strToday+="\u5e74";
                        strToday+=month;
                        strToday+="\u6708";
                        strToday+=date;
                        strToday+="\u65e5";
               $(obj).innerHTML=strToday;
}


function setName(field){
var obj = document.getElementById('realnameSpan');
if(obj!=null){
    obj.innerHTML = field.value;
}

}

function writeUrl(){
document.getElementById('myUrl').value=window.location.href;
}

//内容复制到 粘贴版上
function copyMyUrl(id){
 if(navigator.appVersion.indexOf("MSIE") == -1){//非IE浏览器
		//暂时什么都不做,
 }else{

	window.clipboardData.setData("Text",document.getElementById(id).value);
	alert('地址复制成功啦，赶快告诉QQ/MSN的好友吧!');
 }
	return false;

}


function sendEmail(){

giveMsg('正在发送...');

var topicId =1;
var emailsValue =document.getElementById('emails').value;

wishmoduleAjaxManager.sendEmail(emailsValue,topicId,sendResult)
}


function giveMsg(content){
var obj = document.getElementById('sendMailMessage');
obj.innerHTML=content+'<br/>';

}

function sendResult(sendStatus){

	if(sendStatus==1){//发送成功
			
		   giveMsg('发送完毕...');
		   setTimeout("giveMsg('')",4000);
		   //giveMsg('');

	}else if(sendStatus == -1){//内容为空
		  giveMsg('请输入邮件地址!');

	}else{//服务器发生了一些逻辑错误的处理,通常是安全性问题,正常情况不会发生
		

	}

}

/**
*@version 2007-09-25
*author 郭一
*<p>发送匿名许愿或者祝福<p/>
*
*/
function switchAnonymous(aform){
    
    anonymousMsgObj = $('anonymousMsg');
    var isAnonymous = $('isAnonymous');
  
    if(isAnonymous.checked==true){
        anonymousMsgObj.style.display="block";
        if(aform.id == 'WishForm'){
             aform.action="/wishmodule/wish_saveAnonymousWish.do";
        }else if(aform.id='BlessForm'){
             aform.action="/wishmodule/bless_saveAnonymousBless.do";
        }
       
    }else if(isAnonymous.checked==false){
         anonymousMsgObj.style.display = "none";
          
          if(aform.id == 'WishForm'){
                 aform.action="/wishmodule/wish_save.do";
           }else if(aform.id='BlessForm'){
                aform.action="/wishmodule/bless_save.do";
           }
         
    }
    
}
function sendWishOrBless(aform,positionId){

		if($('isAnonymous').checked==false){
		    checkLogin(aform,positionId);
		}else if($('isAnonymous').checked==true){
		    aform.submit();
		}
}

