//String.prototype.capitalize =	function(){
//function show_hotel_box(box_id,detail_id,box_btn_txt,detail_btn_txt){
//function show_hotel_detail(box_id,detail_id,box_btn_txt,detail_btn_txt){
//function show_add_accmdtn_box(isShow){
//function show_add_style_box(isShow){
//function show_add_location_box(isShow){
//function show_add_promotion_box(isShow){
//function show_edit_promotion_box(isShow,id){
//function sendRequest2BedsOnline(formName){
//function clickArea(area_textbox_id,default_text){
//function blurArea(area_textbox_id,default_text){
//function resetFilterCriteria(formName,argCriteria){
//function reloadFilter(formName,argCriteria){
//function toggleCheckBox(checkboxName,checkboxValue){
//function disableCheckBox(checkboxName,checkboxValue){
//function setCheckBox(checkboxName,checkedBool){
//function toggleAllCheckBox(checkboxName,checkboxStatus){
//function decorStyleCheckboxClick(formName){
//function locationCheckboxClick(formName,ischecked){
//function promotionCheckboxClick(formName,ischecked){
//function decorStyleLabelClick(formName,decor_typeofstay_id){
//function locationLabelClick(formName,decor_typeofstay_id){
//function promotionLabelClick(formName,decor_typeofstay_id){
//function anyDecorStyleClick(formName){
//function enableCheckboxSeries(checkboxName,enable)
//function anyLocationClick(formName){
//function anyLocationClickCheckbox(formName){
//function anyPromotionClick(formName){
//function anyPromotionClickCheckbox(formName){
//function test(text){
//function add2select2(selectId,values)
//function clearOption2(id)
//function insertSelector(str_arg,which_id)
//function generateSEOCode(){
//function chngConfig(sender,lang,currency){
//function gotoHotel(dropdownName)
//function HighlightSearch(docId,	search)
//function doHighlight(source, search, index)
//function hotelshow_hide_section()
//function hotelshow_set_active(id)
//function copyToClipboard(s)
//function switchBetween(id1,id2)
//function setTextBox(id,value)
//function childCheckbox_Click(all)
//function anyCheckbox_Click(all,checkbox)

String.prototype.capitalize	= function(){
   return this.replace(	/(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); }	);
  };
function show_hotel_box(box_id,detail_id,box_btn_txt,detail_btn_txt){
	document.getElementById(box_id).style.display='none';
	document.getElementById(detail_id).style.display='';
	return false;
}
function show_hotel_detail(box_id,detail_id,box_btn_txt,detail_btn_txt){
	document.getElementById(box_id).style.display='';
	document.getElementById(detail_id).style.display='none';
	return false;
}
function show_add_accmdtn_box(isShow){
	if(isShow){
		document.getElementById('add_accmdtn_area').style.display='inline-table';
	} else {
		document.getElementById('add_accmdtn_area').style.display='none';
	}
	document.getElementById('accmdtn_type_name').value='';
	document.getElementById('accmdtn_type_name_th').value='';
	document.getElementById('accmdtn_type_desc').value='';
	document.getElementById('accmdtn_type_desc_th').value='';
	document.getElementById('add_update_accmdtn_label').innerHTML="Add Style";
	return false;
}
function show_add_style_box(isShow){
	if(isShow){
		document.getElementById('add_style_area').style.display='inline-table';
	} else {
		document.getElementById('add_style_area').style.display='none';
	}
	document.getElementById('typeofstay_name').value='';
	document.getElementById('typeofstay_name_th').value='';
	document.getElementById('typeofstay_desc').value='';
	document.getElementById('typeofstay_desc_th').value='';
	document.getElementById('add_update_style_label').innerHTML="Add Style";
	return false;
}
function show_add_location_box(isShow){
	if(isShow){
		document.getElementById('add_location_area').style.display='inline-table';
	} else {
		document.getElementById('add_location_area').style.display='none';
	}
	document.getElementById('location_name').value='';
	document.getElementById('location_name_th').value='';
	document.getElementById('location_desc').value='';
	document.getElementById('location_desc_th').value='';
	document.getElementById('add_update_location_label').innerHTML="Add	Location";
	return false;
}
function show_add_promotion_box(isShow){
	if(isShow){
		document.getElementById('add_promotion_area').style.display='inline-table';
	} else {
		document.getElementById('add_promotion_area').style.display='none';
	}
	document.getElementById('promotion_name').value='';
	document.getElementById('promotion_name_th').value='';
	document.getElementById('promotion_desc').value='';
	document.getElementById('promotion_desc_th').value='';
	document.getElementById('add_update_promotion_label').innerHTML="Add Promotion";
	return false;
}
function show_edit_promotion_box(isShow,id){
	if(isShow){
		document.getElementById(id).style.display='inline-table';
	} else {
		document.getElementById(id).style.display='none';
	}
	return false;
}


//(gadgets.php)
function clickArea(area_textbox_id,default_text){
	var	area_element=document.getElementById(area_textbox_id);
	var	area_value=area_element.value;
	if(area_value==default_text){
		area_element.value="";
	}
	return;
}
function blurArea(area_textbox_id,default_text){
	var	area_element=document.getElementById(area_textbox_id);
	var	area_value=area_element.value;
	if(area_value.trim()==""){
		area_element.value=default_text;
	}
	return;
}

////////////////////
function test(text){
	alert(text);
}

////////////////////
	function addItem2select(selectId,text,values)
	{
		x=selectId;
//		  alert(myAreas[0]);
//		  myAreasHeadTxt=<?php print translate("myAreas[0]+'\'s	Hotel'","'โรงแรมใน'+myAreas[0]");?>;
//		  myAreasHeadTxt='---'+myAreasHeadTxt+'---';
		var	y=document.createElement('option');
		y.text = text;
		y.value	= values;
		add2select2(x,y);
	}

	function add2select2(selectId,values)
	{
		try
		{
			selectId.add(values,null); // standards	compliant
		}
		catch(ex)
		{
			selectId.add(values); // IE	only
		}
	}

	function clearOption2(id)
	{
		if(id.length > 1)
		{
			while(id.length	> 1)
			{
				id.remove(1);
			}
		}
		if(id.length ==	1)
		{
			id.remove(0);
		}
	}

	function insertSelector(str_arg,which_id)
	{
		var	req;
		if (window.XMLHttpRequest)
		{
			// Netscape, FF, and not IE
			req	= new XMLHttpRequest();
		}
		else if	(window.ActiveXObject)
		{
			//IE
			req	= new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			alert("Browser Error");
			return false;
		}
		var	selector;
//		alert("6-"+which_id);
		switch(which_id){
			case "hotel_id":
				if(!document.form_filter.hotel_filter){
					return false;
//					alert("7-"+which_id+':null');
				}
				selector=document.form_filter.hotel_filter;
				break;
			case "des_id":
				if(!document.form_filter.des_filter){
//					alert("7-"+which_id+':null');
					return false;
				}
				selector=document.form_filter.des_filter;
				break;
			case "city_id":
				if(!document.form_filter.city_filter){
//					alert("7-"+which_id+':null');
					return false;
				}
				selector=document.form_filter.city_filter;
				break;
			default:
				return false;
		}
		var	myAreasHeadTxt=selector[0].text;
		req.onreadystatechange = function ()
		{
			if (req.readyState == 4)
			{
				clearOption2(selector);
				var	myAreasTxt,	x;
//				  alert(req.responseText);
				myAreasTxt = req.responseText;
				var	myAreas=myAreasTxt.split("|");
				x=selector;
//				  alert(myAreas[0]);
//				  myAreasHeadTxt=<?php print translate("myAreas[0]+'\'s	Hotel'","'โรงแรมใน'+myAreas[0]");?>;
//				  myAreasHeadTxt='---'+myAreasHeadTxt+'---';
				var	y=document.createElement('option');
				y.text = myAreasHeadTxt;
				y.value	= "all";
				add2select2(x,y);

				if(myAreas.length>1)
				{
					for(i=1;i<myAreas.length;i++)
					{
						var	y=document.createElement('option');
						isplit=myAreas[i].split(";");
						y.text=isplit[0];
						y.value=isplit[1];
						add2select2(x,y);
					}
				}
				else
				{
					var	y=document.createElement('option');
					y.text='Show All';
					y.value='Not found';
					add2select2(x,y);
				}
			}
		}
		x=selector;
		clearOption2(x);
		var	y=document.createElement('option');
		y.text = myAreasHeadTxt;
		y.value	= -3;
		add2select2(x,y);
		var	get_list_url;
		switch(which_id){
			case "hotel_id":
				get_list_url=str_arg+"&get_id=hotel_id&";
				break;
			case "des_id":
				get_list_url=str_arg+"&get_id=des_id&";
				break;
			case "city_id":
				get_list_url=str_arg+"&get_id=city_id&";
				break;
		}
//		  alert(get_list_url);
		req.open("GET",	get_list_url, true);  //return Hotels
		req.send(null);
	}
	function generateSEOCode(input_text){
		input_text=input_text.trim();

		input_text=input_text.toLowerCase();
		input_text=input_text.replace("&","-and-");
		input_text=input_text.replace("@","-at-");
		input_text=input_text.replace(/	+/g," ");
		input_text=input_text.capitalize();
		input_text=input_text.replace(/[^a-z0-9&]+/ig,"-");
		input_text=input_text.replace(/^_/ig,"");
		input_text=input_text.replace(/_$/ig,"");

//		// Capitalize
//		var	input_textArr =	input_text.split("-");
//		if(input_textArr.length>0){
//			var	input_text2="";
//			for(i=0;i<input_textArr.length;i++){
//				if(i>0){
//					input_text2+=",";
//				}
//				input_text2+=input_textArr[i];
//			}
//		}
		return input_text;
	}
	function chngConfig(sender,lang,currency){
		var	url='/local_changer.php?action=2&lang='+lang+'&currency='+currency+'&sender='+sender+'&';
//		alert(url);
		doAJAX(url,null,null,0);
		setTimeout("window.location.reload();",1000);
	}
	function gotoHotel(dropdownName){
		var	url=dropdownName[dropdownName.selectedIndex].value;
//		alert(url);
//		window.location=url;
	}

///
///	Hilight	specified text
///	Usage:
///	window.onload =	function(){
///	   HighlightSearch('content', 'HighlightSearch doHighlight');
///	}
///
function HighlightSearch(docId,	search)	{
   if(search !=	''){
	 var doc = $E(docId);
	 if(doc){
	   var c = doc.innerHTML;
	   var d = search.split(' ');
	   for (var	i =	0; i < d.length; i++) {
		 c = doHighlight(c,	d[i], i);
	   }
	   doc.innerHTML = c;
	}
  }
}

function doHighlight(source, search, index)	{
   var newtext = "";
   var i = -1;
   var lsearch = search.toLowerCase();
   var lsource = source.toLowerCase();
   while (source.length	> 0) {
	 i = lsource.indexOf(lsearch, i+1);
	 if	(i < 0)	{
	   newtext += source;
	   source =	"";
   } else {
	   if (source.lastIndexOf(">", i) >= source.lastIndexOf("<", i)) {
		 if	(lsource.lastIndexOf("/script>", i)	>= lsource.lastIndexOf("<script", i) &&	lsource.lastIndexOf("/style>", i) >= lsource.lastIndexOf("<style", i)) {
		   newtext += source.substring(0, i) + '<span class="search	term' +	(index % 5)	+ '">' + source.substr(i, search.length) + '</span>';
		   source =	source.substr(i	+ search.length);
		   lsource = source.toLowerCase();
		   i = -1;
		 }
	   }
	 }
   };
  return newtext;
}

function hotelshow_hide_section() {
	var arr_nm=new Array();
	arr_nm[0]='overview';
	arr_nm[1]='room';
	arr_nm[2]='facilities';
	arr_nm[3]='gallery';
	arr_nm[4]='map';
	arr_nm[5]='review';
	arr_nm[6]='booking';
	for(i=0;i<arr_nm.length;i++){
		var nm = arr_nm[i];
		var em = document.getElementById(nm);
		var m_em = document.getElementById('m_'	+ nm);
		if(em){
			em.style.display='none';
		}
		if(m_em){
			m_em.className='';
		}
	}
}
function hotelshow_set_active(id) {
	var	em = document.getElementById(id);
	var	m_em = document.getElementById('m_'	+ id);
	if(em){
		em.style.display='block';
	}
	if(m_em){
		m_em.className='active';
	}
}
function hotelshow_data(id,hotel_id,section) {
	var url='/hotelshow_j.php';
	var	em = document.getElementById(id);
	var	m_em = document.getElementById('m_'	+ id);
	if(em){
		url+='?hotel_id='+hotel_id+'&section='+section;
//		alert(url);
		doAJAX(url,id,true,1);
	}
	if(m_em){
		m_em.className='active';
	}
}
function copyToClipboard(s) {
    // ie
    if (window.clipboardData && clipboardData.setData) {
        clipboardData.setData('text', s);
    }
    // others
    else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(s)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
}
function switchBetween(id1,id2){
	var	em1 = document.getElementById(id1);
	var	em2 = document.getElementById(id2);
	if(em1){
		em1.style.display='none';
	}
	if(em2){
		em2.style.display='inline-block';
	}
}
function setTextBox(id,value){
	var	em = document.getElementById(id);
	if(em){
		em.value=value;
	}
}
function fo(id){
	document.getElementById(id).focus();
	document.getElementById(id).select();
}
function permanentLink(area,url){
//	document.write('<div id="p1_"'+area+' onclick="switchBetween(\'p1_'+area+'\',\'p2_'+area+'\');fo(\'p2_txt\');">'+url+'</div>');
//	document.write('<div id="p2_'+area+'" style="display:none;"><input type="text" id="p2_txt" name="p2_txt" value="'+url+'" class="p2" onBlur="setTextBox(\'p2_txt\',\''+url+'\');switchBetween(\'p2_'+area+'\',\'p1_'+area+'\');"></div>');
}
///////////////
var calVis=0;
function showCalendar(){
	if(calVis==0){
		calVis=1;
		document.getElementById('calendar_mode').style.visibility='visible';
	}else{
		calVis=0;
		hideCalendar();
	}
}
function hideCalendar(){
	calVis=0;
	document.getElementById('calendar_mode').style.visibility='hidden';
	var night=document.getElementById('night1')[document.getElementById('night1').selectedIndex].value;
	calDate(night);
}
function dispChildage(){
	return;
}
function print_here(print_id)
{
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
      disp_setting+="scrollbars=yes,width=800, height=485, left=0, top=0";
  var content_vlue = document.getElementById(print_id).innerHTML;

  var docprint=window.open("","",disp_setting);
   docprint.document.open();
   docprint.document.write('<html><head><title>Print Page</title>');
   docprint.document.write('<link href="/styles/hh_style.css" rel="stylesheet" type="text/css">');
   docprint.document.write('<link href="/styles/oh_style.css" rel="stylesheet" type="text/css">');
   docprint.document.write('<link href="/styles/style_home.css" rel="stylesheet" type="text/css">');
   docprint.document.write('<link href="/styles/style_article.css" rel="stylesheet" type="text/css">');
   docprint.document.write('<link href="/styles/style_custom_page.css" rel="stylesheet" type="text/css">');
   docprint.document.write('<link href="/styles/style_hotelshow.css" rel="stylesheet" type="text/css">');
   docprint.document.write('</head><body onLoad="self.print()" style="background:#FFFFFF;text-align:left;">');
   docprint.document.write(content_vlue);
   docprint.document.write('</body></html>');
   docprint.document.close();
   docprint.focus();
}
// new print
var win=null;
function print_here(print_id, title)
{
	win = window.open();
	self.focus();

	win.document.open();
	win.document.write('<'+'html'+'><'+'head'+'><title>' + title.toString() + '</title><'+'style'+'>');
	win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
	win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
	win.document.write(document.getElementById(print_id).innerHTML);
	win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
	win.document.close();
	win.print();
	win.close();
}
// end new print
function say(show,what,id,say){
	var url='/saaay.php';
	doAJAX(url+'?whats_that='+what+'&what_id='+id+'&what_you_say='+say,show,null,null);
	setTimeout('document.getElementById("say_result").innerHTML="";',60*1000);
}
function showToImgBlock(indx){
	var html='';
//	html+='<div><img src="'+imgArr[indx]+'" ></div>';
//	html+='<div>';
//	if(indx<index)
//		html+='<span style="float:right;"><a href="javascript:;" onclick="showToImgBlock('+(indx-1)+')">&raquo;</a></span>';
//	else
//		html+='<span style="float:right;">&raquo;</span>';
//	if(indx>1)
//		html+='<span style="float:left;"><a href="javascript:;" onclick="showToImgBlock('+(indx-1)+')">&lt;&lt;</a></span>';
//	else
//		html+='<span style="float:left;">&lt;&lt;"</span>';
//	html+='</div>';
//
//	var image_show=document.getElementById('image_show');
//	image_show.innerHTML=html;
}
///////////////
function editing(thisID,value){
	if(thisID.value==value){
		thisID.value='editing';
		thisID.style.color='#FFFFFF';
	}
}
function go_ml_link(domain,dot,to,flag)
{
	var a="@";
	var email_txt=to+a+domain+'.'+dot;
	var loc='ma';
	loc+='ilt';
	loc+='o:';
	window.location=loc+email_txt;
}
function preload(images) {
    if (document.images) {
        var i = 0;
        var imageArray = new Array();
        imageArray = images.split(',');
        var imageObj = new Image();
        for(i=0; i<=imageArray.length-1; i++) {
            //document.write('<img src="' + imageArray[i] + '" />');// Write to page (uncomment to check images)
            imageObj.src=images[i];
        }
    }
}
function collapse(_what,_btn) {
	var em=document.getElementById(_what);
	var btn=document.getElementById(_btn);
	if(em.style.position==''){
		em.style.position='absolute';
		em.style.marginLeft='-999em';
		btn.style.backgroundPosition="0 1px";
	}else{
		em.style.position='';
		em.style.marginLeft='0';
		btn.style.backgroundPosition="0 -16px";
	}
}
$(document).ready(function() {
	if($.isFunction($('.fancybox a').fancybox))
		$('.fancybox a').fancybox();
});
function toCSV(checkbox){
	var o = [];
	checkbox.each(function(){
		if($(this).attr('checked')=='checked'){
			o.push($(this).val());
		}
	});
	return o.join(',');
}

