function in_array(string, array){
   for (var i = 0; i < array.length; i++){
	  if(array[i] == string){
		 return true;
	  }
   }
	return false;
}

function jqueryHash(){
	var hash = window.location.hash;
	hash  = hash.replace('#','');
	if( hash == '' ){
		return 1;
	}else{
		return hash;
	}
}

jQuery.inputHighlight = function(color){  
    $("input[type='text'],input[type='file'],input[type='password'],textarea").each(function(){  
        $(this).focus(function(){  
            $(this).css({"background" : color});  
        });
        $(this).blur(function(){  
            $(this).css({"background" : "white"});  
        }); 
    });  
}

$(document).ready(function(){	
	//$.inputHighlight("#f1fbff");
	$('.navbar li').mouseover(function(){
		$(this).addClass('hover');
		$(this).find('ul:first').slideDown(100);
	}).mouseleave(function(){
		$(this).removeClass('hover');
		$(this).find('ul:first').slideUp(100);
	});
	
	$('.navbar li ul li').mouseover(function(){
		$(this).animate({ backgroundColor: '#fff' }, 200);
	}).mouseleave(function(){
		$(this).animate({ backgroundColor: '#B2D5F6' }, 200);
	});
	
	var arrInputValue = new Array();
	arrInputValue['input_name'] = 'Name';
	arrInputValue['input_email'] = 'Email';
	arrInputValue['input_country'] = 'Form country';
	arrInputValue['input_content'] = 'Content';
	
	$('#input_name, #input_email, #input_country, #input_content').focus(function(){
		var id = this.id;
		if( Trim($(this).val()) == arrInputValue[id] )
			$(this).val('');
	}).blur(function(){
		var id = this.id;
		if( Trim($(this).val()) == '' )
			$(this).val(arrInputValue[id]);
	});
	
	//=============================
	$('.link_list .it').mouseover(function(){
		$(this).addClass('hover');
	}).mouseleave(function(){
		$(this).removeClass('hover');
	});
	
	$('.booking_form td.bg').mouseover(function(){
		$(this).addClass('hover');
		$(this).animate({ backgroundColor: '#f2f8ff' }, 100);
	}).mouseleave(function(){
		$(this).removeClass('hover');
		$(this).animate({ backgroundColor: '#ffffff' }, 1000);
	});
	
	$('#sucuritiy_code_refresh, #sucuritiy_code_img').click(function(){
		$('#sucuritiy_code_img').attr('src', $('#sucuritiy_code_img').attr('src')+'?'+Math.random() )
	});
	
	$('#print').click(function(){
		window.print();						   
	});

	$('#send_to_friends').click(function(){
		var title = $(this).attr('lang').split('|');
		var mar_left = (screen.width-660)/2;
		var link = window.location.href;
		window.open(server+'send_to_friend.php?link='+link+'&title='+title,'aaa','location = 0, width=660, height=657, left='+mar_left);
	});
	
	$('.faq_top').click(function(){
		$('html,body').animate({
			scrollTop: 430
		},1000);
	});
	$('a[rel="hotel_piczoom"]').colorbox({
		overlayClose:true,
		current : "Picture {current}/{total}",
		maxHeight:740
	});
	
	$('#brochure_download').click(function(){
		var brochure_file = $(this).attr('lang');
		if( FileExists('upload/tours/brochure/'+brochure_file) == true )
			window.location.href = server+'upload/tours/brochure/'+brochure_file;
		else
			alert('File not found!');
	});
	
	$('#search_keywords, #msearch_keywords').focus(function(){
		if( Trim( $(this).val() ) == glb_lang['search_keywords'] ){
			$(this).val('');
		}
	}).blur(function(){
		if( Trim( $(this).val() ) == '' ){
			$(this).val( glb_lang['search_keywords'] );
		}else{
			$(this).val( Trim( $(this).val() ) );
		}
	});
	
	$('#head_search_sbumit').click(function(){
		$('#search_submit_head').click();
	});
	
	$('a[rel="_viewImage"]').click(function(){
		window.open( $(this).attr('href'),'_viewImage','width=400, height=400,scrollbars=1');
		return false;
	});
	

	
});


function checkMSearch(form){
	var search_form = document.form;
	alert(search_form);
	if( Trim(search_form.search_keywords.value) == glb_lang['search_keywords'] ){
		alert(  glb_lang['please_check_the_keywords'].replace('&#039;',"'") );
		search_form.search_keywords.focus();
		return false;
	}
}


function FileExists(strURL)
{
    oHttp = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();    
    oHttp.open("GET", strURL, false);
    oHttp.send();
    return (oHttp.status==404) ? false : true;
}


function searchTour(){
	var frm_searchtour = document.frm_searchtour;
	if( frm_searchtour.searchtour_country.value == 0 ){
		alert('Please select Country Tours');
		frm_searchtour.searchtour_country.focus();
		
	/*}else if( frm_searchtour.searchtour_tourtype.value == '' ){
		alert('Please select Type of tours');
		frm_searchtour.searchtour_tourtype.focus();
		
	}else if( frm_searchtour.searchtour_tourduration.value == '' ){
		alert('Please select Duration');
		frm_searchtour.searchtour_tourduration.focus();*/
		
	}else{
		frm_searchtour.submit();
	}
	
}

/*function checkReceived(){
	var received_email = $('#received_email');
	var received_type = $('input[name="received_type"]:checked');
	if( checkMail(received_email.val()) == false ){
		alert('Xin hãy kiểm tra Địa chỉ E-mail.');	
		$('#received_email').focus();		
		return false;
	}
	if( received_type.val() == 2 ){
		if( !confirm('Nếu bạn chắc rằng bạn không nhầm khi chọn Hủy nhận tin với E-mail '+received_email.val()+' thì bấm OK để tiếp tục.') )
			return false;
	}
}*/
