var zdn_pages = new Array();

function zdn_page_grab( url , pageno , todiv )
{
	if ( zdn_pages[pageno] == null )
	{
		zcfs_make_request_ex( url );
	}
}

var zdg_http = false;
var zdg_xmlhttp_available = true;

function zdg_open_http()
{
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		zdg_http = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			zdg_http = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			zdg_http = false;
		}
	}
	@end @*/

	if (!zdg_http && typeof XMLHttpRequest!='undefined')
	{
		zdg_http = new XMLHttpRequest();
	}
}

function zdg_get_http()
{
	if ( !zdg_http )
	{
		zdg_open_http();
	}
	
	return zdg_http;
}

function zdg_http_avaiable()
{
	zdg_xmlhttp_available = true;
}

function zdg_make_request( url , func )
{
	zdg_get_http();
	if ( zdg_xmlhttp_available )
	{
		zdg_xmlhttp_available = false;
		zdg_http.open( "GET" , url , true );
		zdg_http.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
		zdg_http.onreadystatechange=func;
		zdg_http.send(null);
	}
	else
	{
		setTimeout( "function() { return zdg_make_request(url , func ); }" , 10 );
	}
}

var zdn_by_type_to_fill = false;
function zdn_by_type_response()
{
	if (zdg_http.readyState==4)
	{
		var resp = zdg_http.responseText;
		var new_values = resp.split( "\n" );
		var elem = document.getElementById( zdn_by_type_to_fill );
		
		for ( var x = elem.length; x >= 0; x--) {
			elem[x] = null;
		}

		for( var key in new_values )
		{
			if( typeof(new_values[key]) == 'function' )
			{
				continue;
			}
			var value = new_values[key].split(",");
			if ( value[1] != undefined )
			{
				elem[elem.length] = new Option( value[1] , value[0] );
			}
		}
		if (elem.length==1) {
			elem.disabled=true;
		}else {
			elem.disabled=false;
		}
		
		setTimeout( "zdg_http_avaiable()" , 10 );
	}
}

function zdn_by_type_on_change( self , base_url, id )
{
	var val = self.value;
	var url = base_url + ((base_url.indexOf('?') != -1)?"&":"?") + self.name + "=" + self.value + "&req_ctrl=" + id;

	zdn_by_type_to_fill = id;
	zdg_make_request( url , zdn_by_type_response );
}

