<!--

// ฟังชั่นสำหรับ เปิดหน้าต่าง popup
function winopen(theURL,winName,width,height,scollbar) { //v2.0
var setfocus;
  setfocus = window.open(theURL,winName,'resizable=yes,scrollbars='+ scollbar +',width='+ width +',height='+ height +',top=0,left=0');
  setfocus.focus();
}

// ฟังชั่นสำหรับ เปิดหน้าต่าง popup
function winopenFull(theURL,winName,scollbar) { //v2.0
	var options = 'resizable=1,scrollbars='+scollbar+',menubar=0,titlebar=0,status=1,copyhistory=0,directories=0,location=0';    
	options += ',width=' + (screen.availWidth-20) + ',height=' + (screen.availHeight);    
	options += ',screenX=0,screenY=0,top=0,left=0';	
	var setfocus = window.open(theURL, winName, options);
	setfocus.focus();
}

	function printContentDiv(content){
		var printReady = document.getElementById(content);
		var txt= '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null){
			var txtheadTags = document.getElementsByTagName("head");
			if (txtheadTags.length > 0){
				var str=txtheadTags[0].innerHTML;
				txt += str;	
			}
		}
		txt += '</HEAD>\n<BODY>\n';
		if (printReady != null){
			txt += printReady.innerHTML;
		}
		txt += '\n</BODY>\n</HTML>';
	var printWin = window.open();
		printWin.document.write(txt);
		printWin.document.close();
		printWin.print();

	}



// ฟังชั่นสำหรับ เปิดหน้าต่าง dialog
function opendialog(url,width,height)
{
	window.showModelessDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;");
}

// ฟังชั่นสำหรับ Reload หน้าจอ ของ window.opener โดยการกำหนด เวลา 
function reload_view(t,u) {
//   window.opener.location.reload();
   setTimeout("window.location.href='"+u+"'",(t * 1000));
}

function reload_close(t) {
//   window.opener.location.reload();
   setTimeout("window.close();",(t * 1000));
}

function reload_openerclose() {
   window.opener.location.reload();
   window.close();
}

function fnCloseWindow() {
	if (navigator.appName != "Microsoft Internet Explorer")
	{	// หากไม่ใช่ IE
		window.open('','_parent',''); 
		window.close();
	}else{	// หากเป็น IE
		window.opener=null;
		window.close();
	}
}
// media 
function fnMedia(url,w,h){
	var obj=document.getElementById("objframe");
	obj.src="../modules/mod_media.php?url="+url+"&w="+w+"&h="+h;

}
// gallery
			function changeImg(path,title){
				var imgmain=document.getElementById("img_main");
				var imgtitle=document.getElementById("lblGallery");
				imgmain.src=path;
				imgtitle.innerHTML=title;
			}
 
			function increatImg(){
				var imgmain=document.getElementById("img_main");
				if (imgmain.width >486){
					imgmain.width=450;
				}else{
					imgmain.width=imgmain.width+50;
				}
			}
 
			function decreatImg(){
				var imgmain=document.getElementById("img_main");
				if (imgmain.width < 10){
					imgmain.width=10;
				}else{
					imgmain.width=imgmain.width-50;
				}
			}
				function makevisible(cur,which){
					strength=(which==0)? 1 : 0.2
					
					if (cur.style.MozOpacity)
					cur.style.MozOpacity=strength
					else if (cur.filters)
					cur.filters.alpha.opacity=strength*100
				}

// ===========
function Add_A_Favorite(title) 
{ 
	external.AddFavorite(location.href, title)
// Add the document location and title to the AddFavorite window
}

// ฟังชั่นสำหรับ เช็คฟอร์ม
function Conf(object) {
  if (confirm("Are you sure you want to delete the  record ?") == true)  {
  return true;
  }
  return false;
  }

  // ฟังชั่นสำหรับ confirm ข้อมูล
function Confbuttom(object,txtval) {
  if (confirm(txtval) == true)  {
  return true;
  }
  return false;
  }
//----------------------------------------------------------------------------------------------------------------------------------------
function DisplayIframeMenu(item,frameDetail) {
   var obj=document.getElementById(item);

   var img=document.getElementById(item+"_arrow");
   if (obj.style.display!="none") {
     obj.style.display="none";
     img.src="../images/icon_down.gif";
   } else {
      obj.style.display="block";
      img.src="../images/icon_up.gif";
   }
   parent.autoIframe(frameDetail);
}

function DisplayMenu(item) {
   var obj=document.getElementById(item);
//   var img=document.getElementById(item+"_arrow");
   if (obj.style.display!="none") {
     obj.style.display="none";
//     img.src="resources/images/icon_down.gif";
   } else {
      obj.style.display="block";
//      img.src="resources/images/icon_up.gif";
   }
}

//  resize iframe
	function autoIframe(frameId){
		try{
	  //find the height of the internal page
		  var frame=document.getElementById(frameId);
		  var the_height=frame.contentWindow.document.body.scrollHeight;
		  frame.height= the_height + 20;
		}
		catch(err){
		window.status = err.message;
		}
	}
//  onload="if (window.parent && window.parent.autoIframe) {window.parent.autoIframe('ชื่อ iframe ');}"

// Ajax function
		function createXMLHttpRequest(){
			try { return new ActiveXObject("Msxml2.XMLHTTP");	} catch(e) {} //IE
			try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
			try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
			alert("XMLHttpRequest not supported")
			return null
		}
// function AjaxLoad เป็นฟังชั่นสำหรับใช้เป็นตัวกลางในการรับและส่งค่าตัวแปร ระหว่าง client และ server
// โดยที่จะมี parameter ดังต่อไปนี้
// url = url ที่จะ load ไป
// getMethod = method ที่จะส่งเช่น GET,POST
// param= parameter ที่ต้องการส่งไป หากเป็น GET ให้ส่งค่า null 
// callback = เป็น handlestatechange function 
		function AjaxLoad(url,getMethod,param,callback){
				var objXML = createXMLHttpRequest();
					objXML.open(getMethod,url,true);
					if (getMethod=="POST"){
						objXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					}
					objXML.onreadystatechange=function() {
						callback(objXML);
					}
					objXML.send(param);
		}
		function imgLoading(){
			return "<img src=\"../images/loader.gif\"> Loading...";	
		}
// ฟังชั่นที่ใช้ในการเปลี่ยน style
function InitStyle()
{
	var strCss = getCookie("css");
	if(typeof(strCss) == "undefined")
		strCss = "Normal";
	if(strCss == "Small") $("body").addClass("fs1"); else $("body").removeClass("fs1");
	if(strCss == "Normal") $("body").addClass("fs2"); else $("body").removeClass("fs2");
	if(strCss == "Large") $("body").addClass("fs3"); else $("body").removeClass("fs3");

	return true;
}

function SetStyle(strCss)
{
	if(strCss == "Small") $("body").addClass("fs1"); else $("body").removeClass("fs1");
	if(strCss == "Normal") $("body").addClass("fs2"); else $("body").removeClass("fs2");
	if(strCss == "Large") $("body").addClass("fs3"); else $("body").removeClass("fs3");
	setCookie("css", strCss, 30, "/", null);
}

function UpdateStyle()
{
	var strName;

	strName = getCookie("css")

	if((typeof(strName) != "undefined")&&(strName != null))
		setCookie("css", strName, 30, "/", null);
}


// สร้าง cookie ที่เครื่อง
function setCookie(strName, strValue, intExpire, strPath, strDomain)
{
	var strSetCookieStatement;
	var dateToday = new Date;
	var dateExpires = new Date;

	if((strName != null)&&(typeof(strName) !=" undefined"))
	{
		strSetCookieStatement = escape(strName) + "=";

		if((strValue != null)&&(typeof(strValue) !=" undefined"))
			strSetCookieStatement = strSetCookieStatement + escape(strValue);

		if((intExpire != null)&&(typeof(intExpire) != "undefined")) {
			dateExpires.setTime(dateToday.getTime() + (60 * 60 * 24 * 1000 * intExpire));
			strSetCookieStatement = strSetCookieStatement + "; expires=" + dateExpires.toGMTString();
		}

		if((strPath != null)&&(typeof(strPath) != "undefined")) {
			strSetCookieStatement = strSetCookieStatement + "; path=" + escape(strPath);
		}

		if((strDomain != null)&&(typeof(strDomain) != "undefined")) {
			strSetCookieStatement = strSetCookieStatement + "; domain=" + escape(strDomain);
		}

		strSetCookieStatement = strSetCookieStatement + ";";

		document.cookie = strSetCookieStatement;
	}
}

function setCookieParameter(strName, intExpire, strPath, strDomain)
{
	var strSetCookieStatement;
	var dateToday = new Date;
	var dateExpires = new Date;

	var intOffset, intEnd;
	var strSearch = strName + "=";
	var strValue;

	if((strName != null)&&(typeof(strName) !=" undefined"))
	{
		strSetCookieStatement = escape(strName) + "=";

		if (document.cookie.length > 0) {
			intOffset = document.cookie.indexOf(strSearch);
		 	if (intOffset != -1) {
	 			intOffset += strSearch.length;
	 			intEnd = document.cookie.indexOf(";", intOffset);
		 		if (intEnd == -1)
		 			intEnd = document.cookie.length;
	 			strValue = document.cookie.substring(intOffset, intEnd);
		 	}
		 }

		if((strValue != null)&&(typeof(strValue) !=" undefined"))
			strSetCookieStatement = strSetCookieStatement + strValue;

		if((intExpire != null)&&(typeof(intExpire) != "undefined")) {
			dateExpires.setTime(dateToday.getTime() + intExpire);
			strSetCookieStatement = strSetCookieStatement + "; expires=" + dateExpires.toGMTString();
		}

		if((strPath != null)&&(typeof(strPath) != "undefined")) {
			strSetCookieStatement = strSetCookieStatement + "; path=" + escape(strPath);
		}

		if((strDomain != null)&&(typeof(strDomain) != "undefined")) {
			strSetCookieStatement = strSetCookieStatement + "; domain=" + escape(strDomain);
		}

		strSetCookieStatement = strSetCookieStatement + ";";

		document.cookie = strSetCookieStatement;
	}
}

function getCookie(strName)
{
	var intOffset, intEnd;
	var strSearch = strName + "=";

	 if (document.cookie.length > 0) {
		intOffset = document.cookie.indexOf(strSearch);
	 	if (intOffset != -1) {
	 		intOffset += strSearch.length;
	 		intEnd = document.cookie.indexOf(";", intOffset);
	 		if (intEnd == -1)
	 			intEnd = document.cookie.length;
	 		return unescape(document.cookie.substring(intOffset, intEnd));
	 	}
	 }
}

function getCookieWithKeys(strName, strKey)
{
	var strValue = getCookie(strName);
	var intOffset, intEnd;
	var strSearch = strKey + "=";

	if ((typeof(strValue) != "undefined")&&(strValue != null)&&(strValue.length > 0)) {
		intOffset = strValue.indexOf(strSearch);
	 	if (intOffset != -1) {
	 		intOffset += strSearch.length;
	 		intEnd = strValue.indexOf("&", intOffset);
	 		if (intEnd == -1)
	 			intEnd = strValue.length;
	 		return unescape(strValue.substring(intOffset, intEnd));
	 	}
	 }	
}

//-->
