// declare public variables
jsB 		= new Object() ;
jsB.init 	= false;
jsB.ajax  	= null; // for ...
jsB.toID	= null; // timeout object
jsB.host	= "hno.th66.com";
var panel1 = new Array ( "Tab1", "Tab2", "Tab3", "Tab4", "Tab5", "Tab6", "Tab7", "Tab8"  );

jsB.cooView = 'historyHNO';
jsB.cooPara = 'paramsR24';
jsB.hno     = '0';
jsB.pv      = '01';
jsB.region  = '';
jsB.loadgif = "<img src='imghotel/imgnearby/loading.gif'>";

var jsCoo	 = []; // paramsR24
jsCoo['cur'] = 'THB';	// currency
jsCoo['hno'] = '0';		// last HNO




// java startup code when page loaded and DOMload not fired
jsB.initpage = function() { 
	if (jsB.init) return false;
	jsB.init = true;
	if (typeof onloading_guide== 'function') 		onloading_guide();	
	if (typeof onloading_landmark == 'function')	onloading_landmark();
	if (typeof onloading_map== 'function') 		onloading_map();	
	if (typeof onloading_sitemap == 'function')  	onloading_sitemap();
	return (jsB.init);
}


function onloading_guide(){
	showpanels('Tab1',panel1);
	var ii=1; while(p = getID('Tab'+(ii))) {  
		p.onmouseover=function(){ showpanels( this.id  , panel1 ) ;  };   
	ii++ ;
	}
}
 
function showpanels (sid,arr) {
var i,p;
	for (i=0; i < arr.length; i++) {
		p = document.getElementById(arr[i]+'box');
		if (p) p.className = 'hidden bangkok-guide-detail'; 
	}
	p = document.getElementById(sid+'box');
	if (p) p.className = 'shown bangkok-guide-detail'; 
	return false;
}
 

function getID(divID) {
    if( document.getElementById ) { //DOM; IE5, NS6, Mozilla, Opera
        return document.getElementById(divID); }
    if( document.all ) { //Proprietary DOM; IE4
        return document.all[divID]; }
    if( document.layers ) { //Netscape layers
        return document.layers[divID]; }
    if( document[divID] ) { //Netscape alternative
        return document[divID]; }
    return false;
}

// fade an object TAG
jsB.setOpacity = function (tag, opacity){
 {	var p = document.getElementById(tag).style; 
		p.opacity = (opacity / 100); 
		p.MozOpacity = (opacity / 100); 
		p.KhtmlOpacity = (opacity / 100); 
		p.filter = "alpha(opacity=" + opacity + ")"; 
		// fix for IE-cleartype: have a background color set
	} //catch (err) {}
} 


// install a javascript file at the end of the HEAD tag
jsB.loadjavafile = function (filename, callback){
	var fileref=document.createElement('script');
	fileref.setAttribute("type","text/javascript");
	if (callback) {
		if (fileref.readyState) { // IE
			fileref.onreadystatechange= function () { 	
				if (fileref.readyState=="complete" || fileref.readyState=="loaded") { fileref.onreadystatechange = null; callback(); }
				};
		} else { // other
			fileref.onload = function () { callback(); };
		}	
	}	
	fileref.setAttribute("src", filename);
	if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref);
}


// install a css stylesheet at the end of the HEAD tag
jsB.loadcssfile = function (filename){
	var fileref=document.createElement("link")
	fileref.setAttribute("rel", "stylesheet")
	fileref.setAttribute("type", "text/css")
	fileref.setAttribute("href", filename)
	if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref)
}


// remove a javascript or stylesheet from HEAD tag
jsB.removejscssfile = function (filename, filetype){
	var targetfile = [];
	if (filename.indexOf("?") < 0) { targetfile[0] = filename; } else { targetfile = filename.split("\?"); } // ignore things after '?'
	var targetelement = (filetype=="js")? "script" : (filetype=="css")? "link" : "none";  //determine element type to create nodelist from
	var targetattr    = (filetype=="js")? "src"    : (filetype=="css")? "href" : "none";  //determine corresponding attribute to test for
	var allsuspects   = document.getElementsByTagName(targetelement);
	for (var fn,i=allsuspects.length; i>=0; i--) 				  //search backwards within nodelist for matching elements to remove
	     if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null) {   
		    fn = allsuspects[i].getAttribute(targetattr);
		if (fn.substr(0,targetfile[0].length) == targetfile[0])
		    allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
//			alert('found '+fn);
	}
}






jsB.map_showhide = function (show) {
	var p = document.getElementById('modlargemap');
	if (p) p.className = show ? 'shown':'hidden'; 
	var p = document.getElementById('gmap');
	if (p) p.className = show ? 'shown':'hidden'; 
	if (show) {
		p = document.getElementById('mapdistance');
		startGoogleMap (jsB.hno, p ? p.value : 1000); 
	}
	return false;
}

//----------------------------------------------------------------------------------//

function ajaxObject(url, callbackFunction) {
  var that=this;      
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(passData,postMethod) { 
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest();              
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (that.AJAX==null) {                             
      return false;                               
    } else {
      that.AJAX.onreadystatechange = function() {  
		if (that.AJAX.readyState==4 || that.AJAX.readyState=="complete") {
          that.updating=false;                
          if (that.AJAX.status == 200) that.callback(that.AJAX.responseText, that.AJAX.responseXML, that.AJAX.status);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();                              
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } else {
        var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}



var DomLoaded = {
	onload: [],
	loaded: function()
	{
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		for (i = 0;i < DomLoaded.onload.length;i++) DomLoaded.onload[i]();
	},
	load: function(fireThis)
	{
		this.onload.push(fireThis);
		if (document.addEventListener) 
			document.addEventListener("DOMContentLoaded", DomLoaded.loaded, null);
		if (/KHTML|WebKit/i.test(navigator.userAgent))
		{ 
			var _timer = setInterval(function()
			{
				if (/loaded|complete/.test(document.readyState))
				{
					clearInterval(_timer);
					delete _timer;
					DomLoaded.loaded();
				}
			}, 10);
		}
	   window.onload = DomLoaded.loaded;
	}
};
window.onload =function() { jsB.initpage(); }
DomLoaded.load(function() { jsB.initpage(); });


