var Email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var Empty = /^[ ]{0,}$/;
var PostNum = /^[0-9]{6}$/;

function $(evl){
	return document.getElementById(evl);
}

function $_(evl){
	return document.getElementsByName(evl);
}

function byid(id) {
	return document.getElementById(id);
}

function url_string(s) {
	return encodeURIComponent(s);
}

function num_round(num,length) {
	num = Math.round(num*Math.pow(10,length))/Math.pow(10,length);
	return num;
}

function ajax() {
	var xm,bC=false;
	try{xm=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{xm=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){try{xm=new XMLHttpRequest()}catch(e){xm=false}}}
	if(!xm)return null;this.connect=function(sU,sM,sV,fn){if(!xm)return false;bC=false;sM=sM.toUpperCase();
	try{if(sM=="GET"){xm.open(sM,sU+"?"+sV,true);sV=""}else{xm.open(sM,sU,true);
	xm.setRequestHeader("Method","POST "+sU+" HTTP/1.1");
	xm.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8")}
	xm.onreadystatechange=function(){if(xm.readyState==4&&!bC){bC=true;if(xm.status==200){fn(xm)}else if(xm.status==404){alert("Error 404: resquest page not found on server.")}else{window.status="ajax error status code: "+xm.status}}};
	xm.send(sV)}catch(z){return false}return true};return this;
}

function ajax_out(xm) {
	var s = xm.responseText;
	if (s == "") return {};
	try {eval("var out="+s+";");} catch(e) {alert("Error: "+(s.length>2000 ? (s.substring(0,2000)+" ...") : s));return {};}
	if (typeof(out) != typeof({})) {alert("return value is not an array."); return {};}
	return out;
}

function loadjs(url) {
	var ojs = document.createElement("script");
	ojs.src = url;
	document.getElementsByTagName("head")[0].appendChild(ojs);
	return true;
}

function rand(a,b) {
	if (b > 0) {
		return Math.floor(Math.random()*(b-a)) + a;
	} else {
		var s = Math.ceil(Math.random()*1000000000)+"";
		return s.substring(0, 6);
	}
}

function get_browser() {
	if (navigator.userAgent.indexOf("MSIE")>0) return 1;
	if (isFirefox = navigator.userAgent.indexOf("Firefox")>0) return 2;
	if (isSafari = navigator.userAgent.indexOf("Safari")>0) return 3;
	if (isCamino = navigator.userAgent.indexOf("Camino")>0) return 4;
	if (isMozilla = navigator.userAgent.indexOf("Gecko/")>0) return 5;
	return 0;
}

function get_ie_version() {
	if (window.postMessage) return 8;
	else if (window.XMLHttpRequest) return 7;
	else if (document.compatMode) return 6;
	else if (window.createPopup) return 5.5;
	else if (window.attachEvent) return 5;
	else if (document.all) return 4;
	return 0;
}

function set_center(obj) {
	var objw = obj.offsetWidth;
	var objh = obj.offsetHeight;
	var pscroll = get_scroll();
	var psize = get_size();
	var left = (psize[0] - objw) / 2;
	var top = pscroll[1] + (psize[3] - objh) / 2;
	obj.style.left = left < 0 ? "0px" : left+"px";
	obj.style.top = top < 0 ? "0px" : top+"px";
}

function get_size() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function get_scroll() {
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

function get_position(what, offsettype) {
	var pos = {"left":what.offsetLeft, "top":what.offsetTop};
	var parentEl = what.offsetParent;
	while (parentEl != null) {
		pos.left += parentEl.offsetLeft;
		pos.top += parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
	}
	if (offsettype) {
		return offsettype == "left" ? pos.left : pos.top;
	} else {
		return pos;
	}
}

function on_dom_load(fn) {
	var d = window.document, done = false,
	init = function () {
		if (!done) {
			done = true;
			fn();
		}
	};
	(function() {
		try {
			d.documentElement.doScroll('left');
		} catch (e) {
			setTimeout(arguments.callee, 50);
			return;
		}
		init();
	}) ();
	d.onreadystatechange = function() {
		if (d.readyState == 'complete') {
			d.onreadystatechange = null;
			init();
		}
	};
}

function rand(a,b) {
	if (b > 0) {
		return Math.floor(Math.random()*(b-a)) + a;
	} else {
		var s = Math.ceil(Math.random()*1000000000)+"";
		return s.substring(0, 6);
	}
}

function in_array(s, a) {
	for (var i in a) {
		if (a[i] == s) {
			return true;
		}
	}
	return false;
}

function get_cookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

function set_cookie(name,value,expires,path,domain,secure) {
	expires = expires * 60*60*24*1000;
	var today = new Date();
	var expires_date = new Date( today.getTime() + (expires) );
	var cookieString = name + "=" +escape(value) +
	   ( (expires) ? ";expires=" + expires_date.toGMTString() : "") +
	   ( (path) ? ";path=" + path : "") +
	   ( (domain) ? ";domain=" + domain : "") +
	   ( (secure) ? ";secure" : "");
	document.cookie = cookieString;
}
