function noErrorMessages () { return true; }
window.onerror = noErrorMessages;

function focusOn(targetElement)
{
	document.getElementById(targetElement).focus();
}
/**
 * Function: Chon toan bo cac checkbox checkall(status)
 **/
function checkall(frm, status){
	if (frm.checkbox){
		var alen = frm.checkbox.length;
		if(alen>0){
			for(var i=0;i<alen;i++){
				if(frm.checkbox[i].disabled==false){
					frm.checkbox[i].checked=status;
				}
			}
		}
		else{
			if(frm.checkbox.disabled==false) frm.checkbox.checked=status;
		}
	}
}
/**
 * Function: note(str)
 * str: string
 **/
function note(str){
	if (confirm(str)==true) return true;
	else return false
}
/**
 * Delete
 **/
function check_checkbox(frm, str){
	var alen = frm.checkbox.length;
	var isChecked=false;
	if(alen>0){
		for(var i=0;i<alen;i++)
	   		if(frm.checkbox[i].checked==true && frm.checkbox[i].disabled==false) isChecked=true;
	}
	else
		if(frm.checkbox.checked==true  && frm.checkbox.disabled==false) isChecked=true;
	if(!isChecked) alert(str);
	return isChecked;
}

function delete_all(frm, str1, str2){
	if (check_checkbox(frm, str1)){
		if (confirm(str2)==true){
			frm.action.value	=	'delete';
			frm.submit();
		}
		else return false
	}
	else return false;
}
//delete, lock, unlock
function action_all_ajax(act, frm, str1, str2, div){
	if (check_checkbox(frm, str1)){
		if (confirm(str2)==true){
			if (act == 0) frm.action.value	=	'movetrash';
			else{
				if (act == 1) frm.action.value	=	'lock';
				else{
					frm.action.value	=	'unlock';
				}
			}
			method_post("index.php", info_post(frm), div, 0);
		}
		else return false
	}
	else return false;
}
function update_all_ajax(frm, str, div){
	if (confirm(str)==true){
		frm.action.value	=	'update';
		method_post("index.php", info_post(frm), div, 0);
	}
	else return false
}
function showid(id, status){
	document.getElementById(id).style.display = status;
}
/////// DHTML /////////
function contractall(lay){
	if (document.getElementById){
		var inc=0
		while (document.getElementById(lay+inc)){
			document.getElementById(lay+inc).style.display="none";
			//document.getElementById(lay+inc).style.height=20;
			inc++
		}
	}
}

function expandone(lay,sid){
	if (document.getElementById){
		contractall(lay);
		if (document.getElementById(lay+sid)){
			document.getElementById(lay+sid).style.display="block";
		}
	}
}

function fclassname(lay,sid,classname){
	if (document.getElementById){
		var inc=0;
		while (document.getElementById(lay+inc)){
			document.getElementById(lay+inc).className = "lar";
			inc++;
		}
		document.getElementById(lay+sid).className = classname;
	}
}

function openfilemanager(id){
	window.open('index.php?s=a&m=upload&f=upload_file&objectid=' + id,'popup','location=0, status=0, scrollbars=0, resizable=0, width=520, height=395');
}

function nulldiv(id){
	document.getElementById(id).innerHTML = '';
	document.getElementById(id).style.display = 'none';
}

function matchid(act){
	document.getElementById('match_0').disabled = act;
	document.getElementById('match_1').disabled = act;
	document.getElementById('match_2').disabled = act;
}

function changeDictionary(dict){
	if (dict == 8){	//chinese dictionary
		document.getElementById('lblHanViet').style.display	=	'';
		document.getElementById('lblPinyin').style.display	=	'';
		document.getElementById('lblPHanViet').style.display=	'';
		document.getElementById('lblNormal').style.display	=	'none';
		document.getElementById('lblBroad').style.display	=	'none';
		document.getElementById('lblFuzzy').style.display	=	'none';
	}
	else{
		document.getElementById('lblHanViet').style.display	=	'none';
		document.getElementById('lblPinyin').style.display	=	'none';
		document.getElementById('lblPHanViet').style.display=	'none';
		document.getElementById('lblNormal').style.display	=	'';
		document.getElementById('lblBroad').style.display	=	'';
		document.getElementById('lblFuzzy').style.display	=	'';
	}
}

//////////// Edit Word
function doEditWord($dict, $word)
{
	window.open('index.php?s=a&m=upload&f=upload_file&objectid=' + id,'popup','location=0, status=0, scrollbars=0, resizable=0, width=520, height=395');
}
/////////// For Language
function doSetCookieLanguage(lang) {
	var exp = new Date(11245711156480).toGMTString();
	document.cookie	=	'language='+lang+';expires='+exp;
	window.location =	'index.php';
}
/////////// Search History
function doSetCookieSearchHistory(countHistory) {
	var exp = new Date(11245711156480).toGMTString();
	document.cookie	=	'countSearchHistory='+countHistory+';expires='+exp;
	window.location =	'index.php';
}
function doClearCookieSearchHistory() 
{
//	cookie_name	=	"searchHistory";
//	var cookie_date = new Date ( );  // current date & time
//  	cookie_date.setTime ( cookie_date.getTime() - 1 );
//  	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
//	window.location =	'index.php';
	var exp = new Date(11245711156480).toGMTString();
	document.cookie	=	'searchHistory=; expires='+exp;
	window.location =	'index.php';
}
