var cmtOpt;
function hideTip(ele, msg)
{
	if(obj.home_url == ele && obj.value == 'http://')
		ele.value = "http://";
	if(ele.value == msg && obj.home_url != ele)
		ele.value = "";
}
function showTip(ele, msg)
{
	if(obj.website == ele && obj.website.value == "http://")
		ele.value = 'http://';
	if(ele.value == '')
	{
		ele.value = msg;
	}
}
function hideAllTips()
{
	if(obj.name.value == ALERT_TIP_NAME)
		obj.name.value = '';
	if(obj.email.value == ALERT_TIP_EMAIL)
		obj.email.value = '';
	if(obj.location.value == ALERT_TIP_LOCATION)
		obj.location.value = '';
	if(obj.occupation.value == ALERT_TIP_OCCUPATION)
		obj.occupation.value = '';
	if(obj.home_url.value == 'http://')
		obj.home_url.value = '';
}
//Onmouseover Avatar
function onImg(ele)
{
	if(obj.avatar.value != ele.src) ele.className = 'avatar_o';
}
//Onmouseout Avatar
function offImg(ele)
{
	if(obj.avatar.value != ele.src) ele.className = 'avatar';
}

//Selects avatar
function selImg(ele)
{
	if(obj.currAvatar.value != "" && (imgOld = document.getElementById(obj.currAvatar.value)))
	{
		imgOld.className = 'avatar';
	}
	obj.currAvatar.value = ele.id;
	obj.avatar.value = ele.src;
	ele.className = 'avatar_s';
}

function validateForm(opt)
{
	trimFields();
	cmtOpt = opt;
	if(opt == 'unset')
	{
		if(obj.name.value == "" || obj.name.value == ALERT_TIP_NAME)
		{
			alert(ALERT_ENTER_NAME);
			obj.name.focus();
			return false;
		}

		if(obj.email.value != ALERT_TIP_EMAIL)
		{
			if(obj.email.value != "" && !chkEmail(obj.email.value))
			{
				alert(ALERT_INVALID_EMAIL);
				obj.email.focus();
				obj.email.select();
				return false;
			}
		}
		//Link URL must be a valid URL
		if((obj.home_url.value != "" && obj.home_url.value != 'http://') && !chkURL(obj.home_url.value))
		{
			alert(ALERT_INVALID_URL);
			obj.home_url.focus();
			obj.home_url.select();
			return false;
		}
	}
	if(obj.message.value == "")
	{
		alert(ALERT_ENTER_COMMENT);
		obj.message.focus();
		return false;
	}
	if(obj.message.value.length > 1000)
	{
		alert(ALERT_INVALID_COMMENT_LENGTH);
		obj.message.focus();
		return false;
	}
	if(opt == 'unset')
		hideAllTips();
	obj.btn_submit.disabled = true;
	arrTemp = new Array();
	document.getElementById('loader_blk').innerHTML = '<img src="img/ajax-loader1.gif" alt="Loader" /> Please wait...';
	//Now post via ajax
	var ajax = new AJAX();
	var arrParam = new Array();
	if(opt == 'unset')
	{
		arrParam['name'] = obj.name.value;
		arrParam['email'] = obj.email.value;
		arrParam['home_url'] = obj.home_url.value;
		arrParam['location'] = obj.location.value;
		arrParam['occupation'] = obj.occupation.value;
		arrParam['avatar'] = obj.avatar.value;
	}
	arrParam['message'] = obj.message.value;
	arrParam['article_type'] = obj.article_type.value;
	arrParam['article_text_id'] = obj.article_text_id.value;
	arrParam['opt'] = opt;
	arrParam['cancel_url'] = cancelUrl;
	ajax.postRequest('comment_process.php', arrParam, showCommentResponse)
}
function showCommentResponse(retVal)
{
	if(retVal == 'SUCCESS')
	{
		self.location = cancelUrl+'?comment_post='+Math.floor(Math.random()*1001)+'#last_cmt';
	}
	else if(retVal == 'SPAM')
	{
		self.location = cancelUrl;
	}
	else
	{
		document.getElementById('loader_blk').innerHTML = '<input type="button" id="btn_submit" class="btn3" value="Submit" onclick="javascript:validateForm(\''+cmtOpt+'\')" />&nbsp;&nbsp;&nbsp;<input type="button" id="btn_cancel" value="Cancel" class="btn3" onclick="self.location=\''+cancelUrl+'\'" />';
		self.location = cancelUrl;
	}
}

//Display BBCode Reference window
function showBBCodeRef()
{
	window.open("bbcode_ref.php", "bbcode", "width=350,height=540,toolbar=0,menubar=0,location=0");
}
