// JavaScript Document
var ajax = new sack();
function validate_articles_form()
{
	var frm = document.getElementById("frm_submit_articles");
	var titleReg = /^([A-Za-z0-9-_ ]+)$/;
	if(frm.slct_category.value == 0)
	{
		alert("Please select article category.");
		frm.slct_category.focus();
		return false;
	}
	if(frm.slct_subcategory.value == 0)
	{
		alert("Please select article subcategory.");
		frm.slct_subcategory.focus();
		return false;
	}
	if(GenValidation(frm.article_title,"article title.","","")=="")
		return false;
	if(titleReg.test(document.getElementById("article_title").value)==false)
	{
		alert("Special characters are not allowed.");
		document.getElementById("article_title").focus();
		return false;
	}
}
function populateSubcategory(catId)
{
	ajax.requestFile = "../shared-ajax/articles_ajax.php?ajax_id=ajx111&catId="+catId;
	ajax.onCompletion = dispResponse;
	ajax.runAJAX();
}
function tellAFriend(name,email,message,articleId)
{
	ajax.requestFile = "../../shared-ajax/articles_ajax.php?ajax_id=ajx123&name="+name+"&email="+email+"&message="+message+"&articleId="+articleId;
	ajax.onCompletion = dispResponse;
	ajax.runAJAX();
}
function reportAbuse(name,email,message,articleId)
{
	ajax.requestFile = "../../shared-ajax/articles_ajax.php?ajax_id=ajx124&name="+name+"&email="+email+"&message="+message+"&articleId="+articleId;
	ajax.onCompletion = dispResponse;
	ajax.runAJAX();
}
function dispResponse()
{
	//alert(ajax.response);
	eval(ajax.response);
}
function pagination(pageid)
{
	document.getElementById('page_no').value=pageid;
	document.frm_our_article_member.submit();
}
function pagination_admin(pageid)
{
	document.getElementById('page_no_admin').value=pageid;
	document.frm_our_article_admin.submit();
}
// id ==1 mean post comment Div
// id ==2 mean view comment Div
// id ==3 mean tell a friend div
// id ==4 mean report abuse Div
function hideDispDiv(divId)
{
	var i = 1;
	if(document.getElementById("div_"+divId).style.display == "")
		document.getElementById("div_"+divId).style.display = "none";
	else
	{
		for(i=1; i<=4; i++)
		{
			if(document.getElementById("div_"+i) != null)
				document.getElementById("div_"+i).style.display = "none";
		}
		document.getElementById("div_"+divId).style.display = "";
		document.getElementById("div_"+divId).focus();
	}
}
function validatePostomment()
{
	if(document.getElementById("textarea_comment").value == "")
	{
		alert("Please write your comment.");
		document.getElementById("textarea_comment").focus();
		return false;
	}
}
function validateTellAFriend(articleId)
{
	var name = document.getElementById("tellAFriend_name").value;
	var email = document.getElementById("tellAFriend_email").value;
	var message = document.getElementById("tellAFriend_message").value;
	if(name == "")
	{
		alert("Please write your friend name.");
		document.getElementById("tellAFriend_name").focus();
		return false;
	}
	if(email == "")
	{
		alert("Please write your friends email.");
		document.getElementById("tellAFriend_email").focus();
		return false;
	}
	if(EmailValidation(document.getElementById("tellAFriend_email"))=="")
		return false;
	tellAFriend(name,email,message,articleId);
}
function validateReportAbuse(articleId)
{
	var name = document.getElementById("reportAbuse_name").value;
	var email = document.getElementById("reportAbuse_email").value;
	var message = document.getElementById("reportAbuse_message").value;
	if(name == "")
	{
		alert("Please write your name.");
		document.getElementById("reportAbuse_name").focus();
		return false;
	}
	if(email == "")
	{
		alert("Please write your email.");
		document.getElementById("reportAbuse_email").focus();
		return false;
	}
	if(EmailValidation(document.getElementById("reportAbuse_email"))=="")
		return false;
	reportAbuse(name,email,message,articleId);
}
function validate_editArticles_form()
{
	var titleReg = /^([A-Za-z0-9-_ ]+)$/;
	if(document.getElementById("article_title").value=="")
	{
		alert("Please enter article.");
		document.getElementById("article_title").focus();
		return false;
	}
	if(titleReg.test(document.getElementById("article_title").value)==false)
	{
		alert("Special characters are not allowed.");
		document.getElementById("article_title").focus();
		return false;
	}
}