Array.prototype.indexOf=function(ele){var i=0,j=this.length; for(i;i<j;i++) if(this[i]==ele) return i; return false;}
Array.prototype.indexOfKey=function(ele){var i=0,j=this.length; for(i;i<j;i++) if(this[i].id==ele) return i; return false;}
Array.prototype.add=function(ele){ var j=this.length; this[j]=ele; return j; }
String.prototype.ltrim = function() { return this.replace(/^\s+/,""); }
String.prototype.rtrim = function() { return this.replace(/\s+$/,""); }
String.prototype.trim = function() { return this.ltrim().rtrim(); }
String.prototype.y29 = function() { var y=parseInt(this); return (y%4==0); }
String.prototype.isThaiDate = function() {
	var t=this.replace(/\x5c/g,'-'); // ? /  -
	if(t.length!=10||t.search(/(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[0-2])-[0-9]+/) == -1) return false;
	var y29=(''+(parseInt(t.substring(6,4))-543)).y29();
	if(t.search(/3[0-1]-02-/)!=-1||((t.search(/29-02-/)!=-1) && !y29)) return false;
	if(t.search(/30-(0[1-9]|1[0-2])-/)!=-1||t.search(/31-(0[13578]|1[02])-/)!=-1) return true;
	if(t.search(/((0[1-9])|([12][0-9]))-((0[1-9])|(1[0-2]))-/) != -1) return true;
	return false;
}
String.prototype.isYmdHi = function() {
	return (this.length!=16||!this.substring(0,10).isYmd())? false:(this.search(/\s([0-1][0-9]|2[0-3]):[0-5][0-9]/)!=-1);
}
String.prototype.isYmdHis = function() {
	if(this.length!=19) return false;
	if(!this.substring(0,10).isYmd()) return false;
	return (this.search(/\s([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/)!=-1);
}
String.prototype.isYmd = function() {
	var t=this.replace(/\x5c/g,'-');
	if(t.length!=10||t.search(/[0-9]+-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])/)==-1) return false;
	var y29=t.substring(0,4).y29();
	if(t.search(/-02-3[0-1]/)!=-1||((t.search(/-02-29/)!=-1) && !y29)) return false;
	if(t.search(/-(0[1-9]|1[0-2])-30/)!=-1||t.search(/-(0[13578]|1[02])-31/) != -1) return true;
	if(t.search(/-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9])/) != -1) return true;
	return false;
}
String.prototype.isNumber = function() {
	return (this.search(/^[0-9]+$/) != -1?  true : false);
}
String.prototype.isEmail = function() { return (this.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1); }
String.prototype.isMobile = function() { return (this.search(/^08([0-9]{8,8})$/) != -1); }
String.prototype.isPhone = function() { return (this.search(/^0[2-9]([0-9]+)$/) != -1); }
////////////////////////////////////////////////////////////
String.prototype.urlEncode = function() {
	var str = escape(this);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}
String.prototype.urlDecode = function() {
		var str = this.replace(/\+/g, ' ');
		str = unescape(str);
		return str;
}
////////////////////////////////////////////////////////////
String.prototype.toHex = function() {
		var str = '', h='', d=0;
		var ln=this.length;
		for (var i = 0; i<ln; i++){
			d=this.charCodeAt(i);
			h=d.toString(16); h=(h.length==1? '0' : '')+h;
			str+=(h.length==1? '0' : '')+h;
		}
		return str;
}
////////////////////////////////////////////////////////////
function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}
////////////////////////////////////////////////////////////
var CookieValue = '';
var swsound = '';
function set_sound(CookieValue){
	swsound =
	"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "+
	"codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' WIDTH='1' HEIGHT='1'>"+
	"<param name='movie' value='sound/" + CookieValue + ".swf'>"+
	"<param name='quality' value='high'>"+
	"<param name='wmode' value='transparent'>"+
	"<embed src='sound/" + CookieValue + ".swf' quality='high' "+
	"pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='1' height='1'>"+
	"</embed></object>";
}
function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
////////////////////////////////////////////////////////////
function getCookie(Name) {
	var search = Name + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		} else {
			return "";
		}
	}
	return "";
}
////////////////////////////////////////////////////////////
try{
	if(user_name=='xAdministrator'){
		alert('document.getElementById='+typeof(document.getElementById));
		alert('document.getElementByName='+typeof(document.getElementByName));
		alert('document.getElementsByName='+typeof(document.getElementsByName));
		alert('document.all='+typeof(document.all));
		alert('navigator.appName='+navigator.appName+':'+navigator.appVersion);
	}
}catch(e){;}
var IE7 = (typeof(document.all)=='object');
var NS6 = (document.getElementById && !IE7);
var IE = (IE7 && typeof(document.getElementByName)=='object');
var NS = (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=="4");
///////////////////////////////////////////////////////////
var http = Array();
///////////////////////////////////////////////////////////
function new_ajax_2009_02(url, param, ele, callback){
	var j='x_'+http.length;
	http[j]='a';
	if(window.XMLHttpRequest){   //IE7,   Mozilla   ,Firefox   ?????????
		http[j] = new XMLHttpRequest();
	}else if(window.ActiveXObject){ //IE6?IE5
			try{ http[j] = new ActiveXObject( "Msxml2.XMLHTTP ");} catch (e){ ; }
			if( http[j] ==  null) try   { http[j] = new ActiveXObject( "Microsoft.XMLHTTP ");}   catch   (e){; }
	}else{
		alert('not found HttpRequtest'); return false;
	}
	try {
		http[j].open("POST", url, false);
	} catch (e) { alert( "2: Error http.open: \nurl="+url+"\n\n" + e + "\n\n"+ "Click OK to continue.\n\n"); return false; }
	http[j].setRequestHeader("Method", "POST "+url+' HTTP/1.1');
	http[j].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http[j].setRequestHeader("Content-length", param.length);
	http[j].setRequestHeader("Connection", "close");
	http[j].send(param);
	if(http[j].readyState == 4)
		if(http[j].status == 200) {
			var txt=http[j].responseText;
			if(callback !== null) callback.request_ok(txt, ele); 
		}
	http[j] = null;
	return true;
}
/*
///////////////////////////////////////////////////////////////////////////
///////  Below is Function to recieve result from function ale_1(idx).
///////////////////////////////////////////////////////////////////////////
var js_name={
	request_ok: function (rs, ele){
		if(ele=='get_ads') { this.get_ads_rs(rs); } else
		if (ele!='no_alert') alert('22||'+rs);
	},
}
/////////////////////////////////////////////////////////////////////*/
//////////////////////////////////////////////////////////////////////
function ajaxshow(){
	var x=func.q('frame_ajax');
	if(x.width=='0') { x.width='800'; x.style.width=800; x.style.height=120;}else{x.width='0'; x.style.width=0; x.style.height=0;	}
}
///////////////////////////////////////////////////////////
function o_movement(){
}
o_movement.prototype = {
	obj: '',
    is_mousedown: false,
    old_pos: {x: 0, y: 0, w: 0, h: 0},
    old_mouse: {x: 0, Y: 0},
	init: function(obj, idx, lb){
		this.obj=obj;
		if(lb!==null){
			lb.setAttribute('onmousedown', 'hk_movement.obj['+idx+'].mousedown(event)');
			lb.setAttribute('onmouseup', 'hk_movement.obj['+idx+'].mouseup(event)');
			lb.setAttribute('onmousemove', 'hk_movement.obj['+idx+'].mousemove(event)');
		}else{
			this.obj.setAttribute('onmousedown', 'hk_movement.obj['+idx+'].mousedown(event)');
			this.obj.setAttribute('onmouseup', 'hk_movement.obj['+idx+'].mouseup(event)');
			this.obj.setAttribute('onmousemove', 'hk_movement.obj['+idx+'].mousemove(event)');
		}
	},
	mousedown: function(e){
		this.is_mousedown=true;
        this.old_pos=func.get_pos(this.obj);
        this.old_mouse=func.getMousePos(e);
	},
	mouseup: function(e){ this.is_mousedown=false; },
	mousemove: function(e){
		if(this.is_mousedown){
			var cur_mouse = func.getMousePos(e);
			func.div_move(
				this.obj
            	, this.old_pos.x + cur_mouse.x - this.old_mouse.x
            	, this.old_pos.y + cur_mouse.y - this.old_mouse.y
            );
		}
	}
}
var hk_movement = {
	obj: Array(),
	init: function(obj, lb){
		var i=this.obj.add(new o_movement);
		this.obj[i].init(obj, i, lb);
	}
}
/////////////////////////////////////////
function set_mouse_event(tb, st, inc){
	var l=tb.rows.length;
	for (var i=st; i<l; i+=inc){
		var ro=tb.rows[i];
		var f_id=ro.id.substr(4);
		if (f_id!=null){
			if (IE){ var ov='function() { set_over( '+f_id+', '+inc+');}'; var ou='function() { set_out( '+f_id+', '+inc+');}';}
			else{var ov='"set_over( '+f_id+', '+inc+');"'; var ou='"set_out( '+f_id+', '+inc+');"';}
			eval('ro.setAttribute("onmouseover", '+ov+');'); eval('ro.setAttribute("onmouseout", '+ou+');');
			if (inc>1){ var ro=tb.rows[i + 1];
				eval('ro.setAttribute("onmouseover", '+ov+');'); eval('ro.setAttribute("onmouseout", '+ou+');');
			}
		}
	}
}
function set_over(id, inc){
	var obj=func.q('row_'+id);
	if (obj.className.search(/fix/)==-1){
		obj.className += 'hover';
		if(inc>1) {
			var j=1
			for (j;j<inc ;j++ ){
				func.q('row_'+j+'_'+id).className += 'hover';
			}
		}
	}
}
function set_out(id, inc){
	var obj=func.q('row_'+id);
	if (obj.className.search(/fix/)==-1){
		obj.className=obj.className.replace(/hover/g, '');
		if(inc>1) {
			var j=1
			for (j;j<inc ;j++ ){
				x=func.q('row_'+j+'_'+id); x.className=x.className.replace(/hover/g, '');
			}
		}
	}
}
function set_background(tb, st, inc){
	var l=tb.rows.length, c=false, ln=0, x;
	for (var i=st; i<l; i+=inc) {
		c=(parseInt( ln / 2 ) * 2)==ln;
		tb.rows[i].className=c? 'c1': 'c2';
		if (inc>1) for( x=1; x<3; x++) tb.rows[i + x].className=c? 'c1': 'c2';
		ln++;
	}
}
function chk_box_over(obj){
	if(obj.className.search(/Disabled/)==-1)
		if (obj.src.search(/_over/i)==-1) obj.src=obj.src.replace(/\./, '_over.');
}
function chk_box_out(obj){
	if(obj.className.search(/Disabled/)==-1)
		obj.src=obj.src.replace(/_over/ig, '');
}
function chk_box_click(obj){
	var c=obj.className, s=obj.src;
	var ext=s.substr(s.search(/\./));
	if(c.search(/Disabled/)==-1){
		if(obj.title==''){
			obj.title='checked';
			if (s.search(/checked/i)==-1){
				s=s.replace(/_over/, '');
				s=s.replace(/\./, 'checked_over.');
			}else {
				s=s.substr(0, s.search(/check/))+'checked_over'+ext;
			}
		}else{
			obj.title='';
			if (s.search(/checked/i)==-1){
				if(s.search(/_over/)==-1) s=s.substr(0, s.search(/\./))+'_over'+ext;
			}else {
				s=s.substr(0, s.search(/check/))+'_over'+ext;
			}
		} obj.src=s
	}
}
function set_chk_box(t, obj){
	var k=t=='1'? 'checked' : ''; obj.src='../img/chkbox'+k+'.png'; obj.title=k; obj.alt=k; obj.className='chk_Disabled';
}
function chkbox_click(obj){
	var c=obj.src;
	obj.src=(c.search(/checked/)==-1 ?
		c.replace(/\_over/, 'checked_over') : c.replace(/checked/g, ''));
}

