function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return '';
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) 
		end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
function clickHelp() {
	message = '--------------------   HƯỚNG DẪN TÌM KIẾM   --------------------\n\n- Ví dụ: Tìm từ Nokia 8800\n- Bạn gõ từ Nokia 8800\n- Tất cả các bản tin có từ Nokia 8800 sẽ xuất hiện\n- Để xem chi tiết về tìm kiếm xin vui lòng nhấp vào "Hỏi đáp" từ menu chính';
	alert(message);
}
function popup(p,w,h){
	var left = (screen.availWidth/2) - (w/2);
	var top = (screen.availHeight/2) - (h/2);
	window.open(p,'Open','width='+w+',height='+h+',scrollbars=no,status=0, left='+left+', top='+top)
}
function checkForm(f) {
	var user_email = f.user_email.value;
	var err=''
	if (user_email == ''){
		err += "Địa chỉ email không hợp lệ";
		alert(err);
		f.user_email.focus();
		return false;
	}
	if (user_email.indexOf('@') <= 0 || user_email.indexOf('@') == user_email.length -1){
		err += "- Địa chỉ email không hợp lệ\n- Vui lòng nhập vào email chứ không phải là UserName";
	} else {
		var substr = user_email.substring(user_email.indexOf('@'),user_email.length);
		if (user_email.indexOf('.') <= 0) {
			err += "- Địa chỉ email không hợp lệ\n- Vui lòng nhập vào email chứ không phải là UserName";
		}
	}
	if (err != '') {
		alert(err);
		f.user_email.focus();
		return false;
	}
	var pass = f.user_password.value;
	if (pass=='') {
		alert('Vui lòng nhập vào mật khẩu');
		f.user_password.focus();
		return false;
	}
	return true;
}
function showStatus() {
	window.status='http://www.muabanraovat.com';
}
function checkTextBoxSearch (str) {
	var textVal = str.value;	
	if (textVal == '') {
		alert("Vui lòng nhập vào nội dung tìm kiếm");
		str.focus();
		return false;
	}
	return true;
}
function checkPassword(str) {
	var textVal = str.value;	
	if (textVal == '') {
		alert("Vui lòng nhập vào mật khẩu");
		str.focus();
		return false;
	}
	return true;
}
function checkEmail(str){
	var textValue = str.value;
	var err=''
	if (textValue == ''){
		err += "Địa chỉ email không hợp lệ";
		alert(err);
		str.focus();
		return false
	}
	if (textValue.indexOf('@') <= 0 || textValue.indexOf('@') == textValue.length -1){
		err += "- Địa chỉ email không hợp lệ\n- Vui lòng nhập vào email chứ không phải là UserName";		
	} else {
		var substr = textValue.substring(textValue.indexOf('@'),textValue.length);
		if (textValue.indexOf('.') <= 0) {
			err += "- Địa chỉ email không hợp lệ\n- Vui lòng nhập vào email chứ không phải là UserName";
		}
	}
	if (err != '') { 
		alert(err); 
		str.focus();
		return false;
	}
	return true;
}
function fnCategories(s){
	var temp = "";
	var s1   = "";
	var catId = document.frm_main.cat_id.value;
	
	if (catId > 0) {
		temp = temp + "cat_id=" + catId;
	    s1   = "&";
	}	
	var whereId = document.frm_main.where_id.options[document.frm_main.where_id.selectedIndex].value;
	if (whereId > 0) {			
		temp = temp + s1 + "where_id=" + whereId;
	}
	if (temp != "") {
		temp = "?" + temp;
	}		
	var url = s + temp;

	document.location = url;
}
function checkVote(f) {
	var len = f.vote.length;
	var checked = false;
	var value = "";
	for (var i = 0; i< len; i++) {
		if (f.vote[i].checked==true){
			window.open("votes.php?vote=" + f.vote[i].value,"vote","width=350,height=280");
			return true;
		}
	}
	alert("Vui lòng chọn mục mà bạn qua tâm nhất");
	f.vote.focus;
	return false;
}
	/******************************************************/
	function changeVietEng() {		
		var avimOnOff  = getCookie("AVIM_on_off");
		//var avimMethod = getCookie("AVIM_method");
		//alert(avimOnOff);
		//alert(avimMethod);
		if 	(avimOnOff == 0) {
			AVIMObj.setMethod(0);
			if (document.images.imgVietEng !=undefined) {
				document.images.imgVietEng.src = "/images/imgViet.gif";
			}			
			if (document.images.imgVietEngGoogle !=undefined) {
				document.images.imgVietEngGoogle.src = "/images/imgViet.gif";
			}

		} else {
			AVIMObj.setMethod(-1);
			if (document.images.imgVietEng !=undefined) {
				document.images.imgVietEng.src = "/images/imgEng.gif";
			}			
			if (document.images.imgVietEngGoogle !=undefined) {
				document.images.imgVietEngGoogle.src = "/images/imgEng.gif";
			}
		}		
	}
	/******************************************************/
	function showVietEng() {		
		var avimOnOff  = getCookie("AVIM_on_off");		
		if 	(avimOnOff == 0) {			
			if (document.images.imgVietEng !=undefined) {
				document.images.imgVietEng.src = "/images/imgEng.gif";
			}			
			if (document.images.imgVietEngGoogle !=undefined) {
				document.images.imgVietEngGoogle.src = "/images/imgEng.gif";
			}
		} else {
			if (document.images.imgVietEng !=undefined) {
				document.images.imgVietEng.src = "/images/imgViet.gif";
			}			
			if (document.images.imgVietEngGoogle !=undefined) {
				document.images.imgVietEngGoogle.src = "/images/imgViet.gif";
			}
			AVIMObj.setMethod(0);
		}		
	}
	/******************************************************/
		
