// JavaScript Document
 	function changeheadima()
	{
		var index = form.headima.options[form.headima.selectedIndex].value;
        document.headimage.src = "ima/headima/"+index+".gif";
	}
	
    function keyjump()
    {
        if(window.event.keyCode == 13)
        {
            jump()
        }
        else
        {
            return;
        }
    }
	
	function jump()
	{
	    var to = jumpto.value;
		this.location.href = "index.php?page="+to;
	}
	
    function getStringLen(str)
    {
        var len;
        var i;
        len = 0;
        for(i = 0; i < str.length; i++)
        {
           if (str.charCodeAt(i) > 255)
			   len += 2;
		   else
			   len++;
        }
        return len;
    }
	
	function checkForm()
	{
	    if(form.name.value == "")
		{
		    alert("请输入姓名！");
			return false;
		}
		if(form.headima.selectedIndex == 0)
		{
		    alert("请选择头像！");
			return false;
		}
		if(form.content.value == "")
		{
		    alert("请输入留言！");
			return false;
		}
		if(getStringLen(form.content.value) > 3000)
		{
		    alert("留言内容的长度不能大于3000字符！");
			return false;
		}

		if (form.post_authcode.value == '' || form.post_authcode.value.length != 4)
		{
		    alert("请输入验证码！");
			form.post_authcode.focus();
			return false;
		}

		return true;
	}
	
	function formSubmit()
	{
		if(!checkForm())
		{
		    return false;
		}
		else
		{
			document.form.postButton.disabled = true;
			document.form.submit();
		}
	}
	
    function inputKeySubmit()
    {
        if(window.event.keyCode == 13)
        {
            formSubmit();
        }
        else
        {
            return;
        }
    }
	
    function areaKeySubmit()
    {
        if(event.ctrlKey && window.event.keyCode == 13)
        {
            formSubmit();
        }
        else
        {
            return;
        }
    }
	
    function viewpicture(pid,x,y)
    {
         picwindow = window.open("viewpicture.php?pid="+pid,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+x+",height="+y+"");
         picwindow.moveTo(0,0);
    }
	
	function insertEmotion(emid)
	{
		 form.content.value = form.content.value + "[:em"+emid+":]";
	}
	
	function showEmotions(total)
	{
	  var emotion_alt = new Array('撇嘴','色','发呆','得意','流泪','害羞','闭嘴','睡'
		                            ,'大哭','尴尬','发怒','调皮','呲牙','微笑','难过','酷'
																,'非典','抓狂','吐','偷笑','可爱','白眼','傲慢','饥饿'
																,'困','惊恐','流汗','憨笑','大兵','奋斗','咒骂','疑问'
																,'嘘','晕','折磨','衰','敲打','再见','惊呀','哼');
    var show = '<table width="200"  border="0" cellspacing="0" cellpadding="1" bgColor="#FFFFFF" class="table_border_emotion_choose">';
    show += '  <tr align="right">';
    show += '            <td colspan="8"><a href="#" onClick="showEmotionSpan.innerHTML = \'\'"><strong>Close</strong></a></td>';
    show += '  </tr>';
		
		var x = 0;
		
		for(var i = 0; i < total/8; i++)
		{
        show += '  <tr align="center" valign="middle">';
		    for(var j = 0; j < 8; j++)
				{
				    x++;
            show += '    <td width="25" height="25"><img src="ima/emotion/em'+x+'.gif" border="0" alt="'+emotion_alt[x-1]+'" onClick="insertEmotion('+x+')" style="cursor:hand"></td>';				
				}
        show += '  </tr>';
		}
		
    show += '  <tr align="center" valign="middle">';
    show += '    <td height="25" colspan="2"><img src="ima/emotion/em41.gif" width="34" height="15" border="0" alt="KISS" onClick="insertEmotion(41)" style="cursor:hand"></td>';
    show += '    <td height="25" colspan="3"><img src="ima/emotion/em42.gif" width="60" height="20" border="0" alt="干杯" onClick="insertEmotion(42)" style="cursor:hand"></td>';
    show += '    <td height="25" colspan="3"><img src="ima/emotion/em43.gif" width="51" height="18" border="0" alt="开火" onClick="insertEmotion(43)" style="cursor:hand"></td>';
    show += '  </tr>';
		
		show += '</table>';
		showEmotionSpan.innerHTML = show;
	}
	
	function showEmotions11()
	{
		
        var show = '<table width="210"  border="0" cellspacing="1" cellpadding="1" bgColor="#EAF2FD" class="table_border_emotion_choose">';
        show += '  <tr align="right">';
        show += '    <td colspan="7"><a href="#" onClick="showEmotionSpan.innerHTML = \'\'"><strong>Close</strong></a></td>';
        show += '  </tr>';
        show += '  <tr align="center" valign="middle">';
        show += '    <td width="30" height="30"><img src="ima/emotion/em1.gif" width="15" height="15" border="0" onClick="insertEmotion(1)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em2.gif" width="15" height="15" border="0" onClick="insertEmotion(2)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em3.gif" width="15" height="15" border="0" onClick="insertEmotion(3)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em4.gif" width="15" height="15" border="0" onClick="insertEmotion(4)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em5.gif" width="15" height="15" border="0" onClick="insertEmotion(5)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em6.gif" width="16" height="15" border="0" onClick="insertEmotion(6)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em7.gif" width="15" height="15" border="0" onClick="insertEmotion(7)" style="cursor:hand"></td>';
        show += '  </tr>';
        show += '  <tr align="center" valign="middle">';
        show += '    <td width="30" height="30"><img src="ima/emotion/em8.gif" width="15" height="15" border="0" onClick="insertEmotion(8)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em9.gif" width="21" height="15" border="0" onClick="insertEmotion(9)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em10.gif" width="16" height="15" border="0" onClick="insertEmotion(10)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em11.gif" width="15" height="15" border="0" onClick="insertEmotion(11)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em12.gif" width="15" height="15" border="0" onClick="insertEmotion(12)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em13.gif" width="25" height="18" border="0" onClick="insertEmotion(13)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em14.gif" width="23" height="15" border="0" onClick="insertEmotion(14)" style="cursor:hand"></td>';
        show += '  </tr>';
        show += '  <tr align="center" valign="middle">';
        show += '    <td width="30" height="30"><img src="ima/emotion/em15.gif" width="29" height="15" border="0" onClick="insertEmotion(15)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em16.gif" width="24" height="15" border="0" onClick="insertEmotion(16)" style="cursor:hand"></td>';
        show += '    <td width="30" height="30"><img src="ima/emotion/em17.gif" width="23" height="15" border="0" onClick="insertEmotion(17)" style="cursor:hand"></td>';
        show += '    <td height="30" colspan="2"><img src="ima/emotion/em18.gif" width="42" height="23" border="0" onClick="insertEmotion(18)" style="cursor:hand"></td>';
        show += '    <td height="30" colspan="2"><img src="ima/emotion/em19.gif" width="34" height="15" border="0" onClick="insertEmotion(19)" style="cursor:hand"></td>';
        show += '  </tr>';
        show += '  <tr align="center" valign="middle">';
        show += '    <td height="30" colspan="3"><img src="ima/emotion/em20.gif" width="60" height="20" border="0" onClick="insertEmotion(20)" style="cursor:hand"></td>';
        show += '    <td height="30" colspan="4"><img src="ima/emotion/em21.gif" width="51" height="18" border="0" onClick="insertEmotion(21)" style="cursor:hand"></td>';
        show += '  </tr>';
        show += '</table>';
		
		showEmotionSpan.innerHTML = show;
	}
	
  function mateLogFormSubmit()
	{
	    if(form_mate_log.username.value == "")
			{
			    alert("请输入用户名！");
					return false;
			}
			if(form_mate_log.password.value == "")
			{
			    alert("请输入密码！");
					return false;
			}
			form_mate_log.mateLogButton.disabled = true;
			form_mate_log.submit();
	}
	
    function mateInputKeySubmit()
    {
        if(window.event.keyCode == 13)
        {
            mateLogFormSubmit();
        }
        else
        {
            return;
        }
    }

	function refreshAuthCode()
	{
		var authcode = document.getElementById("authcode");
		authcode.src = './authcode.php?' + Math.random();
	}