function externalLinks() {
  //we need getElementsByTagName for this to work
  if (!document.getElementsByTagName) return;
  
  //get all the anchors within the document
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) { //loop through all the anchors
    var anchor = anchors[i];
    
    //check to make sure that we have a href, so its a real hyperlink
    //and make sure that we have a ref and its set to external
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank") {
    
      //assign the dynamic function to the onclick event.
      anchor.onclick = function(x) {
        //store the variable so that we can actually use it within each function
        var p = x;
        return function() {
          var w = window.open(p); //try and open up a new window with the url
          if(!w) { //check to see if the window opened
            //let the user know that a window didnt open
            alert("A popup blocker seems to have blocked the window from opening");
          }
          
          //return false to make sure the browser doesnt navigate away in the current window also
          return false;
        }
      }(anchor.getAttribute("href")); //pass through the href for this anchor
    }
  }
}

//make sure we only set everything up on load
//after the DOM has been inited
window.onload = externalLinks;

function ccss(OID, OCNAME){
	var nodeObj = document.getElementById(OID);
	nodeObj.className = OCNAME;
} 

function ccss3(OID1, OCNAME1, OID2, OCNAME2, OID3, OCNAME3){
	var nodeObj1 = document.getElementById(OID1);
	nodeObj1.className = OCNAME1;
	var nodeObj2 = document.getElementById(OID2);
	nodeObj2.className = OCNAME2;
	var nodeObj3 = document.getElementById(OID3);
	nodeObj3.className = OCNAME3;
} 

function ccss10(OID1, OCNAME1, OID2, OCNAME2, OID3, OCNAME3, OID4, OCNAME4, OID5, OCNAME5, OID6, OCNAME6, OID7, OCNAME7, OID8, OCNAME8, OID9, OCNAME9, OID10, OCNAME10){
	var nodeObj1 = document.getElementById(OID1);
	nodeObj1.className = OCNAME1;
	var nodeObj2 = document.getElementById(OID2);
	nodeObj2.className = OCNAME2;
	var nodeObj3 = document.getElementById(OID3);
	nodeObj3.className = OCNAME3;
	var nodeObj4 = document.getElementById(OID4);
	nodeObj4.className = OCNAME4;
	var nodeObj5 = document.getElementById(OID5);
	nodeObj5.className = OCNAME5;
	var nodeObj6 = document.getElementById(OID6);
	nodeObj6.className = OCNAME6;
	var nodeObj7 = document.getElementById(OID7);
	nodeObj7.className = OCNAME7;
	var nodeObj8 = document.getElementById(OID8);
	nodeObj8.className = OCNAME8;
	var nodeObj9 = document.getElementById(OID9);
	nodeObj9.className = OCNAME9;
	var nodeObj10 = document.getElementById(OID10);
	nodeObj10.className = OCNAME10;
} 

function confirmQ(req){
	if (confirm(req)==true){return true;}
	else{return false;}
}

function AddSmileyIcon(iconCode){
	document.tment.detail.value += iconCode;
	document.tment.detail.focus();
}

function recieve_value(page, field, result){
  	DIM1 = (document.getElementById(field).value)
	//setTimeout("document.form1.submit()",5000);
	doajax(page+DIM1,result)
}

var countword = 0 ;
var lastPage = "";
var lastResult = "";
function recieve_valuedelay(page, field, result){
  	DIM1 = (document.getElementById(field).value)
	countword += 1 ;
	lastPage = page+DIM1 ;
	lastResult  = result;
	setTimeout("callAJAX()", 1000);
}

function callAJAX(){
	if( countword == 1 ){
		countword  -= 1;
		doajax(lastPage ,lastResult );
		ccss('result_suggest', 'pst-ab mt1 sw320 bg-lblack');
	}else{
		countword  -= 1;
	}
}

function fieldblank(action, field, result){
  	DIM1 = (document.getElementById(field).value)
	if (action==1){
		if (DIM1==result){
			document.searchbox.kw.value = '';
		}
	}
	else{
		if (DIM1==""){
			document.searchbox.kw.value = result;
		}
	}
}

// ฟังก์ชั่น backup ของ google map ตัวนี้สามารถใส่ icon แทนได้
    function initialize2() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("gmap"));
        map.setCenter(new GLatLng(12.969096,100.888824), 15);
		var point = new GLatLng(12.969096,100.888824);
		/*
		var blueIcon = new GIcon(G_DEFAULT_ICON);
		blueIcon.iconSize = new GSize(16,16);
		blueIcon.image = "p_hoteldiscount.png";
		markerOptions = { icon:blueIcon };
		var marker = new GMarker(point, markerOptions); 
		*/
		var marker = new GMarker(point); 
		GEvent.addListener(marker , "click", function() {
		   marker.openInfoWindowHtml("<div class=\"fl sw60\"><img class=\"piclist\" src=\"upload/picturet_small/1.jpg\" alt=\"\" /></div><div class=\"fl ml10 fs11\"><span class=\"fs18 fc-blue\">Pattaya</span><br />Thailand</div><br class=\"clear-all\" /><div class=\"space10\"></div><div class=\"fs-ver fs11\"<a class=\"fc-blue\" href=\"#\">Places</a> - <a class=\"fc-blue\" href=\"#\">Hotels</a> - <a class=\"fc-blue\" href=\"#\">Restaurants</a> - <a class=\"fc-blue\" href=\"#\">Shopping</a> - <a class=\"fc-blue\" href=\"#\">Entertainment</a></div>");
		   });
		map.addOverlay(marker);
        map.setUIToDefault();
      }
    }

/* Drag & Drop Sortable List */
var Scriptaculous = {
  Version: '1.8.1',
  require: function(libraryName) {
    // inserting via DOM fails in Safari 2.0, so brute force approach
    document.write('<script type="text/javascript" src="'+libraryName+'"><\/script>');
  },
  REQUIRED_PROTOTYPE: '1.6.0',
  load: function() {
    function convertVersionString(versionString){
      var r = versionString.split('.');
      return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]);
    }
 
    if((typeof Prototype=='undefined') || 
       (typeof Element == 'undefined') || 
       (typeof Element.Methods=='undefined') ||
       (convertVersionString(Prototype.Version) < 
        convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE)))
       throw("script.aculo.us requires the Prototype JavaScript framework >= " +
        Scriptaculous.REQUIRED_PROTOTYPE);
    
    $A(document.getElementsByTagName("script")).findAll( function(s) {
      return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/))
    }).each( function(s) {
      var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,'');
      var includes = s.src.match(/\?.*load=([a-z,]*)/);
      (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each(
       function(include) { Scriptaculous.require(path+include+'.js') });
    });
  }
}

Scriptaculous.load();