// JavaScript Document
function popup(url,width,height) 
{
	OpenWin = this.open(url,"_blank", "toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resize=no,resizable=yes,width="+width+",height="+height+",top=100,left=100'");
}
function rShowHide(id){
	var d=document.getElementById(id);
	if(d){
		if(d.style.display!='block'){
			$('#'+id).show("slow");
		}else{
			$('#'+id).hide("slow");			
		}
	}
}
function select_position(id_tour,title_tour)
{
//	opener.frm_contact.Tour_name.value = title_tour;
	parent.document.forms['dat_quang_cao'].elements['Vi_Tri_Quang_Cao'].value = title_tour;
	parent.document.getElementById("chon_vitri").innerHTML = title_tour;
	parent.tb_remove();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

function div_toggle(div_id)
{
	$(div_id).toggle('slow');
	//$('#rSearchForm').toggle('slow');
	/*
	if(div_id.style.display == "none")
		div_id.style.display = "block";
	else
		div_id.style.display = "none";
	*/
}

function div_toggle_and_switch_img(div_id,img)
{
	if(div_id.style.display == "none")
	{
		img.src = 'images/arrow1.gif';
		img.title = "<?=$lang['thunho']?>";
	}
	else
	{
		img.src = 'images/arrow2.gif';
		img.title = "<?=$lang['morong']?>";
	}
	$(div_id).toggle('fast');
}


function switch_2div(div_open,div_close, obj_1, obj_2)
{
	//document.getElementById(obj_2).style.backgroundColor = '#006699';
	//document.getElementById(obj_1).style.backgroundColor = '#990000';
	$('#'+div_close).hide('fast');
	$('#'+div_open).show('slow');
	
	//document.getElementById().style.display = "inline";
	//document.getElementById().style.display = "none";
	
	/*document.getElementById(div_open + '_on').style.display = "block";
	document.getElementById(div_open + '_off').style.display = "none";
	document.getElementById(div_close + '_on').style.display = "none";
	document.getElementById(div_close + '_off').style.display = "block";*/
	
	//document.forms['frm_rent'].btn_hd.background = '#FFFFFF';
	//document.forms['frm_rent'].btn_dl.backgroundcolor = '#FFFFFF';
	document.forms['frm_rent'].dichvu.value = div_open;
	document.forms['frm_rent'].test.value = div_open;
}

function menu_jump(url)
{
	if (url.substring(0,5) != "")
	{
		window.location=url;
	}
	else return false;
}

function add_car(cat, id)
{
	$.get('addcar.php?cat=' + cat + '&id=' + id, function(r) {
			document.getElementById('hinh_chonxe1').innerHTML = r;
			document.getElementById('hinh_chonxe2').innerHTML = r;
			document.frm_rent.chonxe1.value=cat;
			document.frm_rent.chonxe2.value=cat;
		});
}
function rUpdateDate(month) {
   /*
   * Edited by Cao Phong
   * www.JavaScriptBank.com
   */
	text = document.getElementById('ngay_bd').value;
	if(!text) {
		
	}
	if(!month) {
		month = 0;
	}
	date = text.split('/');
   month = parseInt(month);
   curMonth = parseInt(date[1]);
	curYear =  parseInt(date[2]);
   if( month >= 12 )
   {
      val_month = date[1];
      val_year = curYear + month/12;
   }
   else
   {
       val_month = curMonth + month;
       if( val_month > 12 )
       {
           val_month %= 12;
           val_year = curYear + 1;
       }
       else
       {
           val_month = curMonth + month;
           val_year = curYear;
       }
   }	
	date2 = date[0] + '/' + val_month + '/' + val_year;
	document.getElementById('ngay_kt').value = date2;
}

function validate_frm_login(lang)
{
	if(lang=='_en')
	{
		if (frm_login.username.value == "")
		{	alert("Please fill in all required fields (marked *)");
			frm_login.username.focus();
			return false;}
		if (frm_login.password.value == "")
		{	alert("Please fill in all required fields (marked *)");
				frm_login.password.focus();
			return false;}
		else return true;
	}
	else
	{
		if (frm_login.username.value == "")
		{	alert("Xin vui lòng điền tên tài khoản của bạn");
			frm_login.username.focus();
			return false;}
		if (frm_login.password.value == "")
		{	alert("Xin vui lòng nhập password đúng");
				frm_login.password.focus();
			return false;}
		else return true;
	}
}
function only_toggle(id, div)
{
   //alert(document.getElementById('cauhinhsx_' + id + '_detail_' + div).id);
   var arr = new Array('kithuat', 'tiennghi', 'antoan');
   for(var i = 0; i < arr.length; i++)
   {
      document.getElementById('cauhinhsx_' + id + '_detail_' + arr[i]).style.display = 'none';
   }
   eval("div_toggle(" + document.getElementById('cauhinhsx_' + id + '_detail_' + div).id + ");");
}
function only_toogle_detail(div_id)
{
   var arr = new Array('cauhinhchitiet_detail', 'cauhinhchitiet_an_toan', 'cauhinhchitiet_amthanh', 'cauhinhchitiet_tien_nghi', 'cauhinhchitiet_cua_xo', 'cauhinhchitiet_ghe_ngoi');
   
   for(var i = 0; i < arr.length; i++)
   {
      document.getElementById(arr[i]).style.display = 'none';
   }
   eval("div_toggle(" + document.getElementById(div_id).id + ");");
}
