/* START searchbox object */		
if (!searchbox)	var searchbox = {};

searchbox.init = function ()
{
	// add searchbox css for non-safari, dom-capable browsers
	if ( navigator.userAgent.toLowerCase().indexOf('safari') < 0  && document.getElementById )
	{
		this.clearBtn = false;
		
		// add style sheet if not safari
		var dummy = document.getElementById("dummy_css");
		if (dummy)	dummy.href = "Themes/istudio/css/mac_searchbox.css";
	}
}


// called when on user input - toggles clear fld btn
searchbox.onChange = function (fldID, btnID)
{
	// check whether to show delete button
	var fld = document.getElementById( fldID );
	var btn = document.getElementById( btnID );
	if (fld.value.length > 0 && !this.clearBtn)
	{
		btn.style.background = "#ffffff url(Themes/istudio/imgs/srch_r_f2.gif) no-repeat top left";
		btn.fldID = fldID; // btn remembers it's field
		btn.onclick = this.clearBtnClick;
		this.clearBtn = true;



	} else if (fld.value.length == 0 && this.clearBtn)
	{
		btn.style.background = "#ffffff url(Themes/istudio/imgs/srch_r.gif) no-repeat top left";
		btn.onclick = null;
		this.clearBtn = false;
		hide("MainMenu0");	
	}

	if (fld.value.length > 0)
	{
		var	keyword	=	document.getElementById("srch_fld").value;
		ajaxsearch(keyword);
//		display("MainMenu0");
		MM_menu_display(0,this);
	}else{
		hide("MainMenu0");	
	}



}
searchbox.setValue = function(fldID,btnID){
	var fld = document.getElementById( fldID );
	if (fld.value =="")
	{
		fld.value ="Search...";
		hide("MainMenu0");
	}
}

// clears field
searchbox.clearFld = function (fldID,btnID)
{
	var fld = document.getElementById( fldID );
	fld.value = "";
	this.onChange(fldID,btnID);
		hide("MainMenu0");
}

// called by btn.onclick event handler - calls clearFld for this button
searchbox.clearBtnClick = function ()
{
	searchbox.clearFld(this.fldID, this.id);
}

function ajaxsearch(keyword){



	if (document.getElementById("MainMenu0")) {

			document.getElementById("MainMenu0").innerHTML ="<p class=\"img-load\"><img src=\"/Themes/istudio/imgs/icon_search_loading.gif\"/> กำลังค้นหาข้อมูล ...</p>";

			var url_search			="_search_ajax.php?keyword="+keyword;				

			if (keyword !=""){

					xmlhttp2			=newXmlHttp();

					xmlhttp2.open('GET', url_search, true);
					xmlhttp2.onreadystatechange = function(){
						if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
								document.getElementById("MainMenu0").innerHTML =xmlhttp2.responseText;
							}
					}
					xmlhttp2.send(null);
			}

	} 


}



/* END searchbox object */


function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}