<!--
var Locations = Array( 'prov_code', 'amp_code', 'tam_code', 'moo_code' );
/*
var Taxonomys = Array( 'king_code', 'phylum_code', 'subphy_code', 'class_code', 'subclass_code', 'order_code', 'suborder_code', 'spfamily_code', 'family_code', 'subfam_code', 'tribe_code', 'subtribe_code', 'genus_code', 'subgenus_code', 'species_code', 'subspec_code' );
var Taxonomys1 = Array( 'king', 'phylum', 'subphy', 'class', 'subclass', 'order', 'suborder', 'spfamily', 'family', 'subfam', 'tribe', 'subtribe', 'genus', 'subgenus', 'species', 'subspec' );
var Taxonomys_plant = Array( 'king_code', 'subking_code', 'division_code', 'subdivision_code', 'class_code', 'subclass_code', 'superorder_code', 'order_code', 'suborder_code', 'family_code', 'subfamily_code', 'tribe_code', 'subtribe_code', 'genus_code', 'subgenus_code', 'section_code', 'subsection_code', 'series_code', 'species_code', 'subspecies_code', 'variety_code', 'subvariety_code', 'form_code' );
var Taxonomys_plant1 = Array( 'king', 'subking', 'division', 'subdivision', 'class', 'subclass', 'superorder', 'order', 'suborder', 'family', 'subfamily', 'tribe', 'subtribe', 'genus', 'subgenus', 'section', 'subsection', 'series', 'species', 'subspecies', 'variety', 'subvariety', 'form' );
*/
function confirmLink(theLink, Msg){
    if (Msg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(Msg + ' \n');
    if (is_confirmed) {
        theLink.href;
    }

    return is_confirmed;
} 

function confirmAction(){
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(confirmMsg + ' \n');

    return is_confirmed;
} 

function openwin(url, w, h) {
		if (w==0 && h==0){
			var width = 450;
			var height = 300;
		}else{
			var width = w;
			var height = h;
		}
		var Digital=new Date();
		var nameWin = "Win"+Digital.getHours()+""+Digital.getMinutes()+""+Digital.getSeconds();
		var top = (screen.availHeight/2)-(height/2);
		var left = (screen.availWidth/2)-(width/2);

var newWin = window.open(url, nameWin, "channelmode=no,scrollbars=yes,resizable=yes,status=1,toolbar=no,directories=no,width="+width+",height="+height+",top="+top+",left="+left)

}

function oPenWinPrint(url, w, h) {
		if (w==0 && h==0){
			var width = 450;
			var height = 300;
		}else{
			var width = w;
			var height = h;
		}
		var top = (screen.availHeight/2)-(height/2);
		var left = (screen.availWidth/2)-(width/2);

		var newWin = window
		newWin.open(url,null,"channelmode=no,scrollbars=yes,resizable=no,status=no,toolbar=no,directories=no,width="+width+",height="+height+",top="+top+",left="+left)
}

function showDialog(url, width, height, obj, frm) {
	var left = (screen.availWidth/2)-(width/2);
	var top = (screen.availHeight/2)-(height/2);

	var Win = window.open(url+"?obj="+obj+"&frm="+frm,"Win","margin=0,channelmode=no,scrollbars=yes,resizable=yes,status=no,toolbar=no,directories=no,width="+width+",height="+height+",top="+top+",left="+left);
}

function Popup(pname,purl,w,h,s){
	LeftPosition = (screen.width) ? (screen.width-w-8)/2 : 0;
	TopPosition = (screen.height) ? ((screen.height-h)/2)-10 : 0;
	//myWinName = window.open(purl,pname,"width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+",scrollbars="+s+",resizable=no");
	myWinName = window.open(purl,pname,"width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+",scrollbars=1,status=1,resizable=yes");
	if (parseInt(navigator.appVersion) >= 4) {
		myWinName.window.focus();
	}
	return myWinName;
}

function Pprint(purl,w,h){
	LeftPosition = (screen.width) ? (screen.width-w-8)/2 : 0;
	TopPosition = (screen.height) ? 0 : 0;
	myWinName = window.open('../libs/print.php?url='+urlencode(purl)+'&mode=print','',"width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+",scrollbars=1,status=1,resizable=yes");
	if (parseInt(navigator.appVersion) >= 4) {
		myWinName.window.focus();
	}
	return myWinName;
}

function PPprint(purl,w,h){
	LeftPosition = (screen.width) ? (screen.width-w-8)/2 : 0;
	TopPosition = (screen.height) ? 0 : 0;
	myWinName = window.open('webengine/libs/print.php?url='+urlencode(purl)+'&mode=print','',"width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+",scrollbars=1,status=1,resizable=yes");
	if (parseInt(navigator.appVersion) >= 4) {
		myWinName.window.focus();
	}
	return myWinName;
}

function showDialog(sURL, vArguments, sFeatures){
	//vReturnValue = window.showModalDialog(sURL, vArguments, sFeatures);
	//vReturnValue = window.showModelessDialog(sURL, vArguments, sFeatures);
	vReturnValue = window.showModelessDialog(sURL, vArguments, sFeatures);
}

function printPage()
{
    // Do print the page
    if (typeof(window.print) != 'undefined') {
		alert("กรุณาตรวจสอบการตั้งค่าหน้ากระดาษก่อนการพิมพ์ว่าเหมาะสมกับเอกสารที่จะพิมพ์            ");
        window.print();
    }
}

function removeN(tag){ 
	var tags = document.getElementsByTagName(tag); 
    for (var i=tags.length-1;i>=0;i--){ 
    var root = tags[i].parentNode; 
    var kids = tags[i].childNodes; 
    var eSpan = document.createElement('span') 
        for(var j=0;j<kids.length;j++){ 
        clon = kids[j].cloneNode(true); 
        eSpan.appendChild(clon) 
        } 
    root.replaceChild(eSpan,tags[i]) 
    } 
}

function show(){
	var Digital=new Date()
	var hours=Digital.getHours()
	var minutes=Digital.getMinutes()
	var seconds=Digital.getSeconds()
	var dn="AM" 
	if (hours>=12)
		dn="PM"
	if (hours>12)
		hours=hours-12
	if (hours==0)
		hours=12
	if (minutes<=9)
		minutes="0"+minutes
	if (seconds<=9)
		seconds="0"+seconds
	window.status=hours+":"+minutes+":"+seconds+" "+dn
	setTimeout("show()",1000)
}

function ML(F){
	for(var i=0; i<F.grpOut.length; i++)
		if(F.grpOut.options[i].selected==true)	{
				newOption=F.grpOut.options[i];
				F.grpOut.options[i]=null;
				F.grpIn.add(newOption, F.grpIn.length);
				i=-1;
		}
}

function MR(F){
	for(var i=0; i<F.grpIn.length; i++)
		if(F.grpIn.options[i].selected==true){
				newOption=F.grpIn.options[i];
				F.grpIn.options[i]=null;
				F.grpOut.add(newOption, F.grpOut.length);
				i=-1;
		}
}

function setCheckboxes(the_form, do_check){
	if (typeof(document.forms[the_form].elements['sel[]']) != 'undefined')	{
		var elts      = document.forms[the_form].elements['sel[]'];
		var elts_cnt  = (typeof(elts.length) != 'undefined') ? elts.length : 0;

		if (elts_cnt>0) {
			for (var i = 0; i < elts_cnt; i++) {
				elts[i].checked = do_check;
			} 
		} else {
			elts.checked = do_check;
		}

		return true;
	}
	return false;
} 

function setCheckAll(the_form, do_check){
    var elts      = document.forms[the_form].elements['sel[]']
    var elts_cnt  = (typeof(elts.length) != 'undefined') ? elts.length : 0;
	var s = 0;
    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            if(elts[i].checked==true) {s++}
        }
		if (s==elts_cnt)	{
			document.forms[the_form].selall.checked = 1;
		}else{
			document.forms[the_form].selall.checked = 0;
		}
    } else {
        document.forms[the_form].selall.checked = elts.checked;
    } 
}
	function checksel(F){
		var D = eval("document.forms." + F);

		if (typeof(D['sel[]']) != 'undefined'){
			var s = 0;
			var elts_cnt  = (typeof(D['sel[]'].length) != 'undefined') ? D['sel[]'].length : 1;
			if (typeof(D['sel[]'].length) != 'undefined'){
				for(var i =0; i < elts_cnt; i++){
					if(D['sel[]'][i].checked==true){ s++}
				}
			}else{
				if(D['sel[]'].checked==true) s++
			}
			
			if (s==0){
				alert("กรุณาเลือกรายการที่จะลบด้วยค่ะ     ");
				return false;
			}
			return true;
		}else{
			alert("ไม่มีรายการที่จะลบค่ะ     ");
			return false;
		}
	}

	function checkselprint(F){
		var D = eval("document.forms." + F);

		if (typeof(D['sel[]']) != 'undefined'){
			var s = 0;
			var elts_cnt  = (typeof(D['sel[]'].length) != 'undefined') ? D['sel[]'].length : 1;
			if (typeof(D['sel[]'].length) != 'undefined'){
				for(var i =0; i < elts_cnt; i++){
					if(D['sel[]'][i].checked==true){ s++}
				}
			}else{
				if(D['sel[]'].checked==true) s++
			}
			
			if (s==0){
				alert("กรุณาเลือกรายการที่จะพิมพ์ด้วยค่ะ     ");
				return false;
			}
			return true;
		}else{
			alert("ไม่มีรายการที่จะพิมพ์ค่ะ     ");
			return false;
		}
	}

    function deleteme(F, ID){
		if (confirmAction())		{
			var D = eval("document.forms." + F);
			if(ID>=0) {
				if (typeof(D['sel[]'][ID]) != 'undefined'){
					D['sel[]'][ID].checked=1;
				}else{
					D['sel[]'].checked=1;
				}
			}
			D.mode.value="delete";
			D.submit();
		}else return false;
	}

    function PrintBarcode(F, ACT, TG){
		var D = eval("document.forms." + F);
		D.mode.value = "print";
		D.method = "get";
		D.action = ACT;
		D.target = TG;
		D.submit();
	}

	function PBarcode(F, ACT, w, h){
		if( checkselprint(F) ) {
			Popup('PrintBarcode', '../libs/print.php?url=about:blank&mode=print', w, h, 'yes,status=yes');
			PrintBarcode(F, ACT, 'contents');
		}
	}

	function setDisableFields(oElm, strTagName, LookUPvalue){
		var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
		LookUPvalue = LookUPvalue.replace(/-/g, "\-");
		var oRegExp = new RegExp("(^|\s)" + LookUPvalue + "(\s|$)");
		for(var i=0; i<arrElements.length; i++){
			/*
			if(arrElements[i].name && arrElements[i].type){
				retrieve_field(arrElements[i])
			}
			*/
			if(oRegExp.test(arrElements[i].value)){
				arrElements[i].disabled = true;
			}
		}
	}
	function Popupiframe(pname,purl,w,h,s,callback){
		var html = '<html>';
		html += '<head>';
		html += '<title></title>';
		html += '<meta http-equiv="Content-Type" content="text/html; charset=windows-874">';
		html += '<script type="text/javascript">';
		html += '	window.onbeforeunload  = function(){';
		//html += '	alert("test");';
		//html += '		window.opener.location.reload();';
		html += '		eval("window.opener.'+callback+'");';
		html += '	}';
		html += '</script>';
		html += '</head>';
		html += '<frameset rows="0,*" frameborder="NO" border="0" framespacing="0">';
		html += '  <frame src="water" name="topFrame" frameborder="no" >';
		html += '  <frame src="' + purl + '" name="mainFrame">';
		html += '</frameset>';
		html += '<noframes><body>';
		html += '</body></noframes>';
		html += '</html>';

		LeftPosition = (screen.width) ? (screen.width-w-8)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h-50)/2 : 0;
		myWinName = window.open('about:blank', pname,"width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+",scrollbars=1,status=1,resizable=yes");
		myWinName.window.document.write(html);
		if (parseInt(navigator.appVersion) >= 4) {
			myWinName.window.focus();
		}
		return myWinName;

	}

	window.onload = function(){
		//alert(document.cookie);
		setDisableFields(document, '*', 'hidden');
	}


	function checkutm(cValue, UTMType, oText) {
		//var UTMS = new Array(new Array(315992, 1216763), new Array(636031, 2254143));
		var UTMS = new Array(new Array(200000, 2000000), new Array(400000, 2500000));
		var UTM = UTMType=='x' ? UTMS[0] : UTMS[1];
		var cObjectName = UTMType=='x' ? 'E' : 'N';
		var cValue = parseFloat(cValue);
		oText = oText || "ค่า %name (%value) ควรอยู่ในช่วง %min ถึง %max      "
		oText = oText.replace('%name', cObjectName);
		oText = oText.replace('%value', cValue);
		oText = oText.replace('%min', UTM[0]);
		oText = oText.replace('%max', UTM[1]);
		if(cValue < UTM[0]){
			alert(oText);
			return -1;
		}else if(cValue > UTM[1]){
			alert(oText);
			return 1;
		}else{
			return 0;
		}
	}

	location.querystring = (function() {   
		var result = {};   
		var querystring = location.search;   

		if (!querystring)  {
			return result;
		}

		var pairs = querystring.substring(1).split("&");   
		var splitPair;   

		for (var i = 0; i < pairs.length; i++) {   
			splitPair = pairs[i].split("=");   
			result[splitPair[0]] = splitPair[1];   
		}   

		return result;   
	})();

	location.get_querystring = function(qrs) {
		var result = Array();
		var n = 0;
		if (qrs != null)  {
			qrs = location.querystring
		}

		for (var key in qrs) {
			result[n++] = key + "=" + qrs[key];
		}
		return result.join('&');
	};

// {{{ urldecode
function urldecode( str ) {
    // Decodes URL-encoded string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urldecode/
    // +       version: 809.1713
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);

    return ret;
}// }}}

// {{{ urlencode
function urlencode( str ) {
    // URL-encodes string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/
    // +       version: 809.1713
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                                     
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}// }}}
//-->