// IE support
if (window.ActiveXObject && !window.XMLHttpRequest) {
	window.XMLHttpRequest = function() {
		try {return new ActiveXObject("Microsoft.XMLHTTP")}
		catch (e){p('Your Browser does not support XMLHttpRequest: '+e.toString(), '__xmlhttpIE');};
		return null;
	};
}
// Gecko support
if (!window.ActiveXObject && window.XMLHttpRequest) {
	window.ActiveXObject = function(type) {
		return new XMLHttpRequest();
	};
}


// ?????????? HTML

function getObj(n)
{
	if(document.getElementById) return document.getElementById(n);
	if(document.all) return document.all[n];
	return null;
}
// ?? ???function _go(n){return getObj(n);}

// ????/??????
function showDiv(val)
{
	var obj=getObj(val);
	if(obj!=null) obj.style.display = "block";
}

function hideDiv(val)
{
	var obj=getObj(val);
	if(obj!=null) obj.style.display = "none";
}

function ajax_post(url, post, response_func, response_func_param) {
	var req = new XMLHttpRequest();
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState==4 && (req.status == 200 || req.status == 304)) {
				if(response_func_param==null) response_func(req.responseText);
				else response_func(req.responseText, response_func_param);
			}
			if (req.readyState!=4) ajax_loading_func(response_func_param);
		};
		req.open('POST', url);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		req.send(post);
		//alert(req.getAllResponseHeaders());
	}
}

function ajax_get(url, response_func, response_func_param) {

	var req = new XMLHttpRequest();
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState==4 && (req.status == 200 || req.status == 304) ) {
				if(response_func_param==null) response_func(req.responseText);
				else response_func(req.responseText, response_func_param);
			}
			if (req.readyState!=4) ajax_loading_func(response_func_param);
		};
		req.open('GET', url);
		req.send(null);
	}
}

function ajax_load(url) {
	var req = new XMLHttpRequest();
		req.open('GET', url);
		req.send(null);
}

// ???: ?????tml-safe ???unction escape_text(text) {return String(text).replace(/\&/g, "&amp;").replace(/\'/g, "&#039;").replace(/\"/g, '&quot;').replace(/</g, "&lt;").replace(/>/g, "&gt;");}

// ???function unescape_text(text) {return String(text).replace(/\&amp;/g, "&").replace(/\&#039;/g, "'").replace(/\&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">");}


// ?? ??
function trim(s) {return String(s).replace(/^[\s\t]+/g, "").replace(/[\s\t]+$/g, "");}

function openPopup(mypage,myname,w,h,pos,infocus)
{
        if(pos=='random')
                {
                        LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
                        TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
                }
        if(pos=='center')
                {
                        LeftPosition=(screen.width)?(screen.width-w)/2:100;
                        TopPosition=(screen.height)?(screen.height-h)/2:100;
                }
        else
                if((pos!='center' && pos!='random') || pos==null){LeftPosition=100;TopPosition=100;}
                        settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',toolbar=no,status=no,resizable=yes,dependent=yes';
        acePopupWindow=window.open('',myname,settings);
        if(infocus=='back')
        {
                acePopupWindow.blur();
                acePopupWindow.location=mypage;
                acePopupWindow.blur();
        }
        else
                acePopupWindow.location=mypage;
 return false;
}

function GetToJS(vals){
	get = new String(window.location);
	x = get.indexOf('?');
	if(x!=-1)
	{
  		l = get.length;
  		get = get.substr(x+1, l-x);
  		l = get.split('&');
 		x = 0;
  		_GET_Count  = l.length;
		evl_str='var arr={';
		for (i=0;i<_GET_Count;i++){
			get = l[i].split('=');
			evl_str+=get[0]+':"'+get[1]+'"';
			if (i<_GET_Count-1) evl_str+=',';
		}
        evl_str+='}';
        eval(evl_str);
		return arr;
	}
}
