/*
* Functions for user_manager form
* Author: thuanquach
* Date: 09/12/2008
*/
var arrModuleNames = new Array("", "intro", "news", "info", "docs", "complaint_solved", "faqs", "brief_news", "weblinks", "videoclip", "gallery_events", "poller", "advertising", "seminar", "investment_projects", "scroll_news", "regulation");
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 = '';
		document.getElementById('div_editor').style.display = 'none';
	}
	else if ( val == 3 ) {
		document.getElementById('trRoles').style.display = 'none';
		document.getElementById('div_editor').style.display = '';
	}
	else {
		document.getElementById('trRoles').style.display = 'none';
		document.getElementById('div_editor').style.display = 'none';
	}
}
function checkAllFirst() {
	for (i=1; i<17; i++) {
		checkAllselect = false;
		obj = eval(document.getElementById('chkPublish'+i));
		hdRoles = eval(document.getElementById('hdRoles'+i));
		hdRoles.value = arrModuleNames[i]+":,publish,";
		obj.checked = true;			
	}
}
function savePermit() {
	var permit = "";		
	for ( i = 1; i < 17; 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;		
}
function printpage(id) {
	new_win = window.open("printpage.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=830,height=670");
	new_win.focus();
}
function printpage_intro(id) {
	new_win = window.open("printpage_intro.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=830,height=670");
	new_win.focus();
}
function printpage_seminar(id) {
	new_win = window.open("printpage_seminar.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=830,height=670");
	new_win.focus();
}
function printpage_formality(id,group) {
	new_win = window.open("printpage_formality.php?id="+id+"&group="+group,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=830,height=670");
	new_win.focus();
}
function printpage_complaint_solved(id) {
	new_win = window.open("printpage_complaint_solved.php?id="+id,"win1","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=830,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=300,left = 200,top = 100");
	new_win.focus();
}
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]+":,";
	}
}


// Tin moi nhat
function change_cell_news(cell_index) {			
	for ( i = 1; i < 5; i++ ) {
		var cell1 = document.getElementById("cell_news"+i);				
		cell1.className = "cell_news";	
		document.getElementById("news_intro"+i).style.display = "none"
	}
	var cell1 = document.getElementById("cell_news"+cell_index);		
	cell1.className = "cell_news_hover";
	document.getElementById("news_intro"+cell_index).style.display = "block";
	//alert('qqqq');

}
// Tin xem nhieu nhat
function change_cell_news1(cell_index) {		
	for ( i = 1; i < 5; i++ ) {
		var cell1 = document.getElementById("cell_news1"+i);				
		cell1.className = "cell_news";	
		document.getElementById("news_intro1"+i).style.display = "none"
	}
	var cell1 = document.getElementById("cell_news1"+cell_index);		
	cell1.className = "cell_news_hover";
	document.getElementById("news_intro1"+cell_index).style.display = "block";

}

function writeComment() {
	if(document.getElementById("comments").style.display == "") {
		document.getElementById("comments").style.display = "none";
	}
	else {
		document.getElementById("comments").style.display = "";
		//loadEditor();
		document.getElementById("txtFullname").focus();
	}
}

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(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 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 postSeminar(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);
}

/* Posting data to controller page
* Author: thuanquach
* Date created: 15-12-2008 03:03
* Date modified: 15-12-2008 03:16 AM
*/
function postContactInfo(hdID, txtFullname, txtContent, txtEmail, hdCode, txtTitle, txtAddress, txtPhone, txtEmail, links) {
	var params = "mod=post_contact_info";
	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 + "&txtPhone="+txtPhone;
	params = params + "&txtEmail="+txtEmail;	
	params = params + "&hdURL="+encodeURIComponent(links.href);		
	makePOSTRequest('div_comment', 'checkAndSaveData', params);
	document.getElementById('hdCode').value = "";
	return false;
	//makePOSTNoPage("checkAndSaveData.php?mod=post_news_comment", params);
}
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 resetContact() {
	document.getElementById('txtFullname').value = "";
	document.getElementById('txtAddress').value = "";
	document.getElementById('txtEmail').value = "";
	document.getElementById('txtPhone').value = "";
	document.getElementById('cboContact').selectedIndex = 0;
	document.getElementById('txtTitle').value = "";
	tinyMCE.get('txtContent').setContent('');
	document.getElementById('hdCode').value = "";
}

function OWEdit(File, W, H) {
	W += 50;
	H += 50;
	if(W > 780)	W=780;
	if(H > 600)	 H=600;
	Temp="scrollbars=2, resizable=yes, width=" + W + ", height=" + H;
	window.open(File, "FullImage", Temp);
}
