var dv_ajax_debug_mode = false;
		
function dvajax_debug(text) {
	if (dv_ajax_debug_mode)
	alert("RSD: " + text);
}

function dvajax_init_object() {
	dvajax_debug("dvajax_init_object() called..");	
	var RetValue;
	try {
			RetValue = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
		RetValue = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
		RetValue = null;
		}
	}
	if(!RetValue && typeof XMLHttpRequest != "undefined")
		RetValue = new XMLHttpRequest();
		if (!RetValue)
			dvajax_debug("Could not create connection object.");
		return RetValue;
}

function dvajax_run(func_name,func_obj, args) {
	var i, x, n;
	var uri;
	var post_data;
	uri = "ajax_check.asp";
	if (dvajax_request_type == "GET") {
		if (uri.indexOf("?") == -1) 
			uri = uri + "?rs=" + func_name;
		else
			uri = uri + "&rs=" + func_name;
			for (i = 0; i < args.length-1; i++) 
				uri = uri + "&rsargs[]=" + args[i];
				uri = uri + "&rsrnd=" + new Date().getTime();
				post_data = null;
	} else {
				post_data = "rs=" + func_name;
				for (i = 0; i < args.length-1; i++) 
					post_data = post_data + "&rsargs[]=" + urlencode(args[i]);
	}
			
			x = dvajax_init_object();
			x.open(dvajax_request_type, uri, true);
			if (dvajax_request_type == "POST") {
				x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
				x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			x.onreadystatechange = function() {
				if (x.readyState != 4) 
					return;
				dvajax_debug("received " + x.responseText);				
				var status;
				var data;
				status = x.responseText.charAt(0);
				datacache = x.responseText.substring(0);
				data = unescape(datacache);
				if (status == "-") 
					alert("Error: " + data);
				else  
					args[args.length-1](func_obj,data);
			}
	x.send(post_data);
	dvajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
	dvajax_debug(func_name + " waiting..");
	delete x;
}

function obj_getbyid(id) {
	itm = null;
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all)	{
		itm = document.all[id];
	} else if (document.layers) {
		itm = document.layers[id];
	}
	return itm;
}

function dv_ajaxcheck(seltype,objid){
        var objname = obj_getbyid(objid).value;
		if (objname){
			x_checkdata(seltype,objid,objname,checkuser_cb);
		}
}

function checkuser_cb(c_type,data){
	var isok_username = obj_getbyid("isok_"+c_type);
	if (isok_username)
	{
		isok_username.innerHTML = "&nbsp;"+data;
	}
}

function x_checkdata(x_seltype,x_obj) {
	dvajax_run(x_seltype,x_obj,x_checkdata.arguments);
}

function urlencode(text){
	text = text.toString();
	var matches = text.match(/[\x90-\xFF]/g);
	if (matches)
	{
		for (var matchid = 0; matchid < matches.length; matchid++)
		{
			var char_code = matches[matchid].charCodeAt(0);
			text = text.replace(matches[matchid], '%u00' + (char_code & 0xFF).toString(16).toUpperCase());
		}
	}
	return escape(text).replace(/\+/g, "%2B");
}

function check_pass(p1,p2,imgurl,msg){
	var password = obj_getbyid(p1).value;
	var passwordconfirm = obj_getbyid(p2).value;
	if (password != passwordconfirm) {
		obj_getbyid("isok_password").innerHTML = "<img src='"+imgurl+"/note_error.gif' border='0'/> <span class='redfont'>"+msg+"</span>";
	} else {
		obj_getbyid("isok_password").innerHTML = "<img src='"+imgurl+"/note_ok.gif' border='0'/>";
	}
}

function re_queryly(){


}