<!--

function load_idxcontent(div_id, the_url){
	var loading_icon	= '<center><br><img src="images/loading.gif" border="0" title="Đang tải trang"></center>';

	if ( (document.getElementById(div_id).innerHTML == "") || (document.getElementById(div_id).innerHTML == loading_icon) ){
		document.getElementById(div_id).innerHTML	= loading_icon;
		ajaxLoadURL(the_url, div_id);	
	}
}

function show_div(div_id){
 	div_info	= new Array();
 	div_info[1]	= 'Sale';
 	div_info[2]	= 'Job';
 	div_info[3]	= 'Auction';

	for (i=1; i<=3; i++){
		if ( document.getElementById('Div_Menu'+ div_info[i] +'1') && document.getElementById('Div_Menu'+ div_info[i] +'2') && document.getElementById('Div_Content'+ div_info[i]) ){
			if ( div_info[i] == div_id ){
				//Menu
				document.getElementById('Div_Menu'+ div_info[i] +'1').style.display	= 'none';
				document.getElementById('Div_Menu'+ div_info[i] +'2').style.display	= '';
				//Content
				document.getElementById('Div_Content'+ div_info[i]).style.display	= '';
			}
			else{
				//Menu
				document.getElementById('Div_Menu'+ div_info[i] +'1').style.display	= '';
				document.getElementById('Div_Menu'+ div_info[i] +'2').style.display	= 'none';
				//Content
				document.getElementById('Div_Content'+ div_info[i]).style.display	= 'none';
			}
		}
	}

	if ( div_id == 'Sale' ){
		document.getElementById('section').selectedIndex = 0;
	}
	else if ( div_id == 'Job' ){
		document.getElementById('section').selectedIndex = 1;
	}
	else if ( div_id == 'Auction' ){
//		document.getElementById('section').selectedIndex = 2;
	}
	set_cookie('idxTab', div_id, 30);
}

function show_div_record(mdiv_id, sdiv_id){
	if ( document.getElementById(mdiv_id +"_VipRecord") && document.getElementById(mdiv_id +"_ViewedRecord") && document.getElementById(mdiv_id +"_NewRecord") && document.getElementById(mdiv_id +"_HotRecord") ){
		var css_vip		= 'none';
		var css_viewed	= 'none';
		var css_new		= 'none';
		var css_hot		= 'none';

		if ( sdiv_id == 'VipRecord' ){
			css_vip		= '';
		}
		else if ( sdiv_id == 'ViewedRecord' ){
			css_viewed		= '';
		}
		else if ( sdiv_id == 'NewRecord' ){
			css_new		= '';
		}
		else if ( sdiv_id == 'HotRecord' ){
			css_hot		= '';
		}

		document.getElementById(mdiv_id +"_VipRecord").style.display	= css_vip;
		document.getElementById(mdiv_id +"_ViewedRecord").style.display	= css_viewed;
		document.getElementById(mdiv_id +"_NewRecord").style.display	= css_new;
		document.getElementById(mdiv_id +"_HotRecord").style.display	= css_hot;
	}
}

function show_hide_mandatory(the_checked, div_id){
	if ( the_checked == true ){
		document.getElementById(div_id).style.display	= '';
	}
	else{
		document.getElementById(div_id).style.display	= 'none';
	}
}

function rand_int(num) {
	return Math.floor(Math.random()*num);
}

function load_calendar(month_year){
	ajaxLoadURL('ajax.php?act=load_calendar&month='+ month_year, 'Div_Calendar');
}

function check_price(the_field){
	the_field.value = the_field.value.replace(' ', '');
	if ( (the_field.value != "") && !is_numeric(the_field.value) ){
 		alert("Giá không hợp lệ!\nChú ý: chỉ được nhập các số từ 0-9.");
		the_field.focus();
	}
}

function is_numeric(strString){
	var strValidChars	= "0123456789.,";
	var strChar;

	if (strString.length == 0){
		return false;
	}

	//test strString consists of valid characters listed above
	for (i=0; i<strString.length; i++){
		strChar	= strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1){
			return false;;
		}
	}
	return true;
}

function search_all_modules(the_form){
	var module_url	= the_form.smodule.options[the_form.smodule.selectedIndex].value;
	if ( module_url != ""){
		the_form.action	= module_url;
		return true;
	}
	alert("Vui lòng chọn trang cần tìm !");
	return false;
}

//Open normal popup
function open_popup(the_url, the_width, the_height, the_menu) {
	if ( (the_width == 0) || (the_width > screen.width) ){
		the_width	= screen.width;
	}
	if ( (the_height == 0) || (the_height > screen.height) ){
		the_height	= screen.height;
	}

	left_val	= (the_width > 0) ? (screen.width - the_width)/2 : 0;
	top_val		= (the_height > 0) ? (screen.height - the_height)/2 - 30 : 0;
	if (top_val < 0){ top_val	= 0; }
	if (the_menu == ""){ the_menu	= "no";	}

	window.open(the_url, "", "menubar="+ the_menu +", toolbar="+ the_menu +", scrollbars=yes, resizable=yes, width="+ the_width +", height="+ the_height +", top="+ top_val +", left="+ left_val);
}

//Open popup when users submit form
function open_popup_form(the_url, targetName, the_width, the_height){
	left_val	= (the_width > 0) ? (screen.width - the_width)/2 : 0;
	top_val		= (the_height > 0) ? (screen.height - the_height)/2 - 30 : 0;
	if (top_val < 0){ top_val	= 0; }

	window.open(the_url, targetName, "menubar=no, toolbar=no, scrollbars=yes, resizable=yes, width="+ the_width +", height="+ the_height +", top="+ top_val +", left="+ left_val);
}

//Check and open popup when use chose web links
function open_weblink(the_url){
	if ( the_url != "" ){
		window.open(the_url);
	}
}

function select_list(the_value, the_list){
	var option_count = the_list.options.length;
	for (i=0; i<option_count; i++){
		if (the_value == the_list.options[i].value){
			the_list.options[i].selected	= true;
			break;
		}
	}
}

function radio_list(the_value,the_list){
	var name_count = the_list.length;
	for (i=0; i<name_count; i++){
		if (the_value == the_list[i].value){
			the_list[i].checked	= true;
			break;
		}
	}
}


function cart_update(){
	window.document.CARTFORM.submit();
}
function cart_check_login_form(the_form) {
	if ( (the_form.email.value == "") || (the_form.password.value == "") ){
		alert("Vui lòng nhập email và mật khẩu để đăng nhập.")
		return false;
	}
	return true;
}
function cart_check_reg_form(the_form) {
	if ( (the_form.fullname.value == "") || (the_form.address.value == "") || (the_form.phone.value == "") || (the_form.email.value == "") ){
		alert("Vui lòng nhập đầy đủ thông tin yêu cầu.\n\nChú ý: các thông tin có dấu \"*\" là bắt buột.")
		return false;
	}
	return true;
}
function cart_edit_order(the_url){
	var the_form	= window.document.VERIFYFORM;
	the_form.action	= the_url;
	the_form.submit();
}
function cart_copy_shipping_info(the_form){
	if ( the_form.shipping_copy.checked ){
		the_form.shipping_fullname.value	= the_form.fullname.value;
		the_form.shipping_company.value		= the_form.company.value;
		the_form.shipping_address.value		= the_form.address.value;
		the_form.shipping_phone.value		= the_form.phone.value;

		the_form.shipping_fullname.disabled	= true;
		the_form.shipping_company.disabled	= true;
		the_form.shipping_address.disabled	= true;
		the_form.shipping_phone.disabled	= true;
	}
	else{
		the_form.shipping_fullname.disabled	= false;
		the_form.shipping_company.disabled	= false;
		the_form.shipping_address.disabled	= false;
		the_form.shipping_phone.disabled	= false;
	}
}

function insert_remove_www(site_url){
	//Insert/Remove www
	var the_location	= window.location + "";
	if (the_location.indexOf("http://www.") != -1){ //Found www in the browser address
		if (site_url.indexOf("http://www.") == -1){ //Not found www in the ajax link
			site_url	= site_url.replace("http://", "http://www."); //Add www
		}
	}
	else{ //Not found www in the browser address
		if (site_url.indexOf("http://www.") != -1){
			site_url	= site_url.replace("http://www.", "http://"); //Remove www
		}
	}
	return site_url;
}

function show_hide_box(div_id){
	var the_div	= document.getElementById(div_id);
	if ( the_div.style.display == "" ){
		the_div.style.display	= "none";
	}
	else{
		the_div.style.display	= "";
	}
}

function change_picture(img_src){
	document.getElementById('Img_Post').src	= img_src;
	return false;
}

function openImage(the_img, the_width, the_height)
{
	if ( the_width > screen.width ){
    	the_width	= screen.width;
	}
	if ( the_height > screen.height ){
    	the_height	= screen.height;
	}

	winDef = 'status=no,resizable=yes,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes, width='+ the_width +', height='+ the_height;
	winDef = winDef.concat(',top=').concat((screen.height - the_height)/2 - 30);
	winDef = winDef.concat(',left=').concat((screen.width - the_width)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<html><title>Picture</title><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<div align="center"><a href="" onClick="window.close(); return false;"><img src="', the_img, '" alt="Close" border=0 align="center"></a></div>');
	newwin.document.writeln('</body></html>');

	return false;
}

function delete_list(the_url) {
	if (check_selected_items()){
		question = confirm(msg_del_confirm);
		if (question != "0"){
			the_form.action = the_url;
			the_form.submit();
		}
	}
}

function update_list(the_url) {
	if (check_selected_items()){
		question = confirm(msg_update_confirm);
		if (question != "0"){
			the_form.action = the_url;
			the_form.submit();
		}
	}
}

function confirm_action(msg) {
	question = confirm(msg);
	if (question != "0"){
		return true;
	}
	return false;
}

function del_confirm() {
	question = confirm(msg_del_confirm);
	if (question != "0"){
		return true;
	}
	return false;
}

function check_selected_items(){
	var name_count = the_form.length;

	for (i=0;i<name_count;i++){
		if (the_form.elements[i].checked){
			return true;
		}
	}

	alert(msg_choose_record);
	return false;
}

function check_all_box(status) {
	for (i = 0; i < the_form.length; i++) {
		the_form.elements[i].checked = status;
	}
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function show_tip(obj, event){
	var ie	= document.all;
	var ns6	= (document.getElementById && !document.all) ? 1 : 0;
	if (ie || ns6) {
		var tipobj	= document.all ? document.all[obj] : (document.getElementById ? document.getElementById(obj) : "");
		var curX	= (ns6) ? event.pageX : event.x + ietruebody().scrollLeft;
		var curY	= (ns6) ? event.pageY : event.y + ietruebody().scrollTop;
		var rightedge	= (ie && !window.opera) ? ietruebody().clientWidth-event.clientX : window.innerWidth - event.clientX - 16;
		var bottomedge	= (ie && !window.opera) ? ietruebody().clientHeight-event.clientY : window.innerHeight - event.clientY;
		var leftedge	= -1000;

		tipobj.style.display	= "block";

		if ( rightedge < tipobj.offsetWidth ){
			tipobj.style.left	= ie ? ietruebody().scrollLeft + event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset + event.clientX-tipobj.offsetWidth + "px";
		}
		else if (curX<leftedge){
			tipobj.style.left	= "5px";
		}
		else tipobj.style.left	= curX + "px";

		if ( bottomedge < tipobj.offsetHeight ){
			tipobj.style.top	= ie ? ietruebody().scrollTop + event.clientY-tipobj.offsetHeight+16+"px" : window.pageYOffset + event.clientY-tipobj.offsetHeight-16 + "px";
		}
		else{
			tipobj.style.top	= curY + 18 + "px";
			tipobj.style.visibility	= "visible"
			document.body.style.cursor	= "help";
		}
	}
}

function hide_tip(obj){
	var ie	= document.all;
	var ns6	= (document.getElementById && !document.all) ? 1 : 0;
	if (ie || ns6) {
		var tipobj	= document.all ? document.all[obj] : (document.getElementById ? document.getElementById(obj) : "");
		tipobj.style.visibility	= "hidden";
		tipobj.style.left		= "-1000px";
		document.body.style.cursor	= "auto";

		tipobj.style.display	= "none";
	}
}

function set_cookie(c_name, value, expiredays){
	var exdate		= new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie	= c_name +"="+ escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
}

function get_cookie(c_name){
	if ( document.cookie.length > 0 ){
		c_start		= document.cookie.indexOf(c_name + "=");
		if ( c_start != -1 ){
			c_start		= c_start + c_name.length+1;
			c_end		= document.cookie.indexOf(";", c_start);
			if ( c_end==-1 ){
				c_end	= document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}
-->
