<?php
include("../config.php");
$type = $_GET['type'];
$isrm = ($type == "guestbook")?false:true;
?>

var guestname = "Guest";

var f = $('blog_form'); 
var username = f.username;
var email = f.email;
var email_c = get_email_c(email);

username.value = getcookie("remark_name");
email.value = getcookie("remark_email");

setcookie("is_cookie","aaa");


<?php
if ($isrm)
{
?>

if (username.value == "" || username.value == guestname)
{
	username.value = guestname;
	email_c.style.display = "none";
}
else
{
	email_c.style.display = "";
}

username.onfocus = function ()
{
	if (this.value == guestname) this.value = "";
}

username.onblur = function ()
{
	if (this.value == "")
	{
		this.value = guestname;
		email_c.style.display = "none";
	}
	else
	{
		email_c.style.display = "";
	}
}

username.onkeydown = function (evt)
{
	evt = (evt)?evt:window.event;
	if (evt.keyCode == 9 )
	{
		email_c.style.display = (this.value != "" && this.value != guestname)?"":"none";
	}
}

<?php
}
?>

function checkform(f)
{
	var content = f.content;
	var username = f.username;
	var email = f.email;
	var inblog = f.inblog;
	if (!username.value)
	{
		alert("请输入昵称!");
		return false;
	}
	else
	{
		username.name = "<?php echo get_input("username");?>";
	}
	
	if (email.value != "")
	{
		if (!isEmail(email.value))
		{
			alert("E-mail 格式错误!!");
			return false;
		}
	}

<?php
if (!$isrm)
{
?>	
	if (email.value == "")
	{
		alert('请输入E-mail地址!');
		return false;
	}
<?php
}
?>
	
	email.name = "<?php echo get_input("email");?>";
	
	if(content.value == "")
	{
		alert("请输入内容!!");
		return false;
	}
	else
	{
		content.name = "<?php echo get_input("content");?>";
	}
	
	//记住用户
	setcookie("remark_email",email.value);

	setcookie("remark_name",username.value);
<?php
if ($isrm)
{
?>
	inblog.name = "<?php echo get_input('inblog');?>";
	f.action = "<?php echo $blogurl;?>index.php?do=newremark";
<?php
}
else
{
?>
	f.action = "<?php echo $blogurl;?>index.php?do=newgb";
<?php
}
?>

	var check_dom = document.createElement('input');
	check_dom.name = "<?php echo get_input('check_code');?>";
	check_dom.type = "hidden";
	check_dom.value = "<?php echo get_check_code();?>";
	f.appendChild(check_dom);
	f.submit();
	return false;
}

function get_email_c(o)
{
	var i=0,n = 0;
	var arr = o.parentNode.childNodes;
	for(i=0;i<arr.length;i++)
	{
		if (!arr[i].tagName) continue;
		if (arr[i].tagName.toString().toLowerCase() == "input") n++;
	}
	return (n ==1)?o.parentNode:o;
}