/*
* Functions for user_manager form
* Author: thuanquach
* Date: 09/12/2008
*/
var arrModuleNames = new Array("", "intro", "news", "achievement", "rooms_news", "formality", "documents", "docs", "brief_news", "scroll_news", "gallery_events", "advertising", "weblinks");
function checkMember(user) {	
	if ( user != "" ) {	
		var params = "txtUsername="+user;
		//alert(params);
		makePOSTNoPage("../checkAndSaveData.php?mod=check_userexist", params);
	}
}
function applyRole(checked, role, hdID) {		
	hdRoles = eval(document.getElementById('hdRoles'+hdID));
	hdRolesValue = hdRoles.value;					
	if ( checked == true ) {
		if ( hdRolesValue.indexOf(role) == -1 ) {
			hdRoles.value += role+",";
		}
	}
	else {					
		hdRoles.value = hdRolesValue.replace(role+",", "");
	}				
}
function showRoles(val) {
	if ( val == 2 ) {
		document.getElementById('trRoles').style.display = '';
	}
	else {
		document.getElementById('trRoles').style.display = 'none';
	}
}
function checkAllFirst() {
	for (i=1; i<13; i++) {
		checkAllselect = false;
		obj = eval(document.getElementById('chkPublish'+i));
		hdRoles = eval(document.getElementById('hdRoles'+i));
		hdRoles.value = arrModuleNames[i]+":,publish,";
		obj.checked = true;			
	}
}
function checkAll(n, checked) {
	objView = eval(document.getElementById('chkPublish'+n));
	objAdd = eval(document.getElementById('chkAdd'+n));
	objEdit = eval(document.getElementById('chkEdit'+n));
	objDelete = eval(document.getElementById('chkDelete'+n));
	
	hdRoles = eval(document.getElementById('hdRoles'+n));
	hdRolesValue = hdRoles.value;
	
	objView.checked = checked;
	objAdd.checked = checked;
	objEdit.checked = checked;
	objDelete.checked = checked;
	if ( checked == true ) {
		hdRoles.value = "";
		hdRoles.value = arrModuleNames[n]+":,";
		hdRoles.value += "publish,add,edit,delete,";}
	else {
		hdRoles.value = arrModuleNames[n]+":,";
	}
}
function savePermit() {
	var permit = "";		
	for ( i = 1; i < 13; i++ ) {
		hdRoles = eval(document.getElementById('hdRoles'+i));
		hdRolesValue = hdRoles.value;
		hasRoles = hdRolesValue.substr(hdRolesValue.indexOf(':')+2, hdRolesValue.length);
		if ( hasRoles != "" ) {
			permit += hdRolesValue+";"; 
		}
	}
	//alert(permit);
	document.frmUsers.hdPermit.value = permit;		
}
<!--Author Nhan le-->
<!--Date: 06/10/2008-->
<!--Function support for index-->
function printpage(id, tbl) {
	new_win = window.open("printpage.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=990,height=670");
	new_win.focus();
}
function printpage_intro(id, tbl) {
	new_win = window.open("printpage_intro.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=990,height=670");
	new_win.focus();
}
function printpage_formality(id, tbl) {
	new_win = window.open("printpage_formality.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=990,height=670");
	new_win.focus();
}
function printpage_documents(id, tbl) {
	new_win = window.open("printpage_documents.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=990,height=670");
	new_win.focus();
}
function printpage_docs(id, tbl) {
	new_win = window.open("printpage_docs.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=990,height=670");
	new_win.focus();
}
function mailtofriendnews(links) {
	new_win = window.open("mail2friendnews.php?url="+encodeURIComponent(links.href),"win2","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=265,left = 200,top = 100");
	new_win.focus();
}

function postComment(hdID, txtFullname, txtContent, txtEmail, hdCode, txtTitle, txtAddress, links, mod) {
	var params = "mod="+mod;
	params = params + "&hdID="+hdID;
	params = params + "&txtFullname="+txtFullname;
	params = params + "&txtContent="+txtContent;	
	params = params + "&txtEmail="+txtEmail;	
	params = params + "&hdCode="+hdCode;	
	params = params + "&txtTitle="+txtTitle;	
	params = params + "&txtAddress="+txtAddress;	
	params = params + "&hdURL="+encodeURIComponent(links.href);	
	makePOSTRequest('div_comment', 'checkAndSaveData', params);
	document.getElementById('hdCode').value = "";
	//makePOSTNoPage("checkAndSaveData.php?mod=post_news_comment", params);
}

function displayNews() {
	if(document.getElementById("div_news").style.display == "inline") {
		document.getElementById("div_news").style.display = "none";
	}
	else {
		document.getElementById("div_news").style.display = "inline";
	}
}
function displayIntro() {
	if(document.getElementById("div_intro").style.display == "inline") {
		document.getElementById("div_intro").style.display = "none";
	}
	else {
		document.getElementById("div_intro").style.display = "inline";
	}
}
function displayAchievement() {
	if(document.getElementById("div_achie").style.display == "inline") {
		document.getElementById("div_achie").style.display = "none";
	}
	else {
		document.getElementById("div_achie").style.display = "inline";
	}
}
function displayRooms() {
	if(document.getElementById("div_rooms").style.display == "inline") {
		document.getElementById("div_rooms").style.display = "none";
	}
	else {
		document.getElementById("div_rooms").style.display = "inline";
	}
}
function displayDocuments() {
	if(document.getElementById("div_doc").style.display == "inline") {
		document.getElementById("div_doc").style.display = "none";
	}
	else {
		document.getElementById("div_doc").style.display = "inline";
	}
}

function loadEditor() {
		tinyMCE.init({
			mode : "textareas",
			theme : "advanced",
			plugins : "inlinepopups,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
			language: 'vi',
			theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink,emotions",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
		});
}


function checkImage() {
	if(trim(document.getElementById('hdCode').value)!='') {	
		if (document.getElementById('hdCode').value.length==6) {	
			document.getElementById('check_image').innerHTML = "Đang kiểm tra mã bảo vệ...";
			sendRequest("checkImage.php?param="+ document.getElementById('hdCode').value,'check_image');	
		}
  }
}
function checkfbProducts(links)
{			
	var contentlist = tinyMCE.get('txtContent');
	if(trim(document.getElementById('txtFullname').value)==""){
		alert("Vui lòng nhập họ tên!");
		document.getElementById('txtFullname').focus();
		return false;
	}
	if(trim(document.getElementById('txtEmail').value)==""){
		alert("Vui lòng nhập địa chỉ email!");
		document.getElementById('txtEmail').focus();
		return false;
	}
	if(!isEmail(document.getElementById('txtEmail').value)){
		alert("Địa chỉ mail không chính xác, vui lòng nhập lại!");
		document.getElementById('txtEmail').focus();
		return false;
	}
	if(trim(document.getElementById('txtTitle').value)==""){
		alert("Vui lòng nhập vào tiêu đề!");
		ddocument.getElementById('txtTitle').focus();
		return false;
	}
	if(contentlist.getContent() == "") {
		alert("Vui lòng nhập vào nội dung!");
		contentlist.focus();
		return false;
	}
	if (trim(document.getElementById('hdCode').value)=="") {
		alert("Vui lòng nhập mã bảo vệ!");
		document.getElementById('hdCode').focus();
	return false;
	}	
	if (document.getElementById('check_image').innerHTML.indexOf('accept')==-1) {
			alert("Mã bảo vệ không chính xác, mời bạn nhập lại!");
			document.getElementById('hdCode').focus();
			return false;
	}
	else{
		hdID = document.getElementById('hdID').value;
		txtFullname = document.getElementById('txtFullname').value;
		txtContent = contentlist.getContent();
		txtEmail = document.getElementById('txtEmail').value;
		hdCode = document.getElementById('hdCode').value;
		txtTitle = document.getElementById('txtTitle').value;
		txtAddress = document.getElementById('txtAddress').value;
		
		postNewsComment(hdID, txtFullname, txtContent, txtEmail, hdCode, txtTitle, txtAddress, links);
	}
}
function postNewsComment(hdID, txtFullname, txtContent, txtEmail, hdCode, txtTitle, txtAddress, links) {
	var params = "hdID="+hdID;
	params = params + "&txtFullname="+txtFullname;
	params = params + "&txtContent="+txtContent;	
	params = params + "&txtEmail="+txtEmail;	
	params = params + "&hdCode="+hdCode;	
	params = params + "&txtTitle="+txtTitle;	
	params = params + "&txtAddress="+txtAddress;	
	params = params + "&hdURL="+encodeURIComponent(links.href);		
	//alert(params);
	makePOSTNoPage("checkAndSaveData.php?mod=post_news_comment", params);
}

function writeComment() {
	if(document.getElementById("comments").style.display == "inline") {
		document.getElementById("comments").style.display = "none";
	}
	else {
		document.getElementById("comments").style.display = "inline";
	}
}

function checkContact() {
	if(trim(document.frmContact.txtFullname.value)==""){
		alert("Vui lòng nhập họ tên!");
		document.frmContact.txtFullname.focus();
		return false;
	}
	if(checkScript(trim(document.frmContact.txtFullname.value))){
		alert("Họ tên không chính xác. Vui lòng nhập lại!");
		document.frmContact.txtFullname.focus();
		return false;
	}
	if(trim(document.frmContact.txtEmail.value)==""){
		alert("Vui lòng nhập địa chỉ email!");
		document.frmContact.txtEmail.focus();
		return false;
	}
	if(!isEmail(document.frmContact.txtEmail.value)){
		alert("Địa chỉ email không chính xác. Vui lòng nhập lại!");
		document.frmContact.txtEmail.focus();
		return false;
	}
	if(!isEmail(document.frmContact.txtEmail.value)){
		alert("Địa chỉ email không chính xác. Vui lòng nhập lại!");
		document.frmContact.txtEmail.focus();
		return false;
	}
	if(trim(document.frmContact.txtSubject.value)==""){
		alert("Vui lòng nhập tiêu đề của câu hỏi!!");
		document.frmContact.txtSubject.focus();
		return false;
	}
	if(trim(document.frmContact.txtContent.value)==""){
		alert("Vui lòng nhập nội dung của câu hỏi!!");
		document.frmContact.txtContent.focus();
		return false;
	}
	else{
		return true;
	}
}
function search_edocs() {
		if ( document.getElementById('tr_box_edoc_search').style.display == 'none' ) {	
			document.getElementById('tr_box_edoc_search').style.display = '';
			document.getElementById('tr_edoc_search').style.display = 'none';
		}
		else {
			document.getElementById('tr_box_edoc_search').style.display = 'none';
			document.getElementById('tr_edoc_search').style.display = '';
		}
}
function viewAttributes() {
		if ( document.getElementById('tr_display').style.display == 'none' ) {	
			document.getElementById('tr_display').style.display = '';			
		}
		else {
			document.getElementById('tr_display').style.display = 'none';			
		}
}
function doEnter(evt){
	// IE					// Netscape/Firefox/Opera
	var key;
	if(evt.keyCode == 13 || evt.which == 13){
		onSearch(evt);
	}
}