/*
//How to use

//ajaxGetFuncHTML('index.php?ajax+run_task+getCities+module/modules/ajax/class.func.php+'+region_id,'city_drop');
//ajaxGetFuncHTML('index.php?ajax+run_task+getCities+module/modules/ajax/class.func.php+'+region_id+'+task_reg_php+city_id','city_drop');
//ajaxGetFuncHTML('index.php?ajax+run_task+[task]+[task_path_location]+'+[task_input],output_id);

//ajaxSQLGetValue('index.php?ajax+run_sql+SELECT title FROM core_structure WHERE structure_id='+region_id,'first_name');
//ajaxSQLGetValue('index.php?ajax+run_sql+[SQL]',output_id);

//ajaxSQLGetArray('index.php?ajax+run_sql_array+SELECT * FROM core_user WHERE user_active_yn=1','city_drop');
//ajaxSQLGetArray('index.php?ajax+run_sql_array+[SQL]',output_id);

//ajaxSQLGetROW('index.php?ajax+run_sql_row+SELECT * FROM core_structure WHERE structure_id='+region_id,'city_drop');
//ajaxSQLGetROW('index.php?ajax+run_sql_row+[SQL]',output_id);


/////////////////////////////////////Paging table
//var sql = '*';
//var db = 'gis_city';
//var where = 'province_id='+province_id;
//var output_id = 'table';
//var pagesize = 15; // default = "10"
//var row_numbers = "off"; // default = "on"
//var pagingtop = ''; // default = "on"
//var pagingbottom = ''; // default = "on"
//var maintablestyle = ''; // default = "width:100%"
//var tablestyle = ''; // default = "width:100%"
//ajaxGetPagingTable(sql,db,where,output_id,pagesize,row_numbers,pagingtop,pagingbottom,maintablestyle,tablestyle);
*/


/*

	******************Returning javascript should be incapsulatyed in script tags**************

	To declare public functions and variables use the following syntax:



	function
	--------

		window.functionname = function(x,y,x)
		{
			alert(x);
		}


	variable
	--------

		window.x = 'Hello World!';
*/

var id_out = '';
var httpObject = null;

function getHTTPObject()
{

	if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else
	{
		alert("Your browser does not support AJAX.");
		return null;
	}

	/*
	try
	{
		// Firefox, Opera 8.0+, Safari
		return new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				return "Your browser does not support AJAX!";

			}
		}
	}
*/

}


function ajaxGetFuncHTML(url,id_output)
{
	//alert(url.length);
	//IE Max length 2083
	httpObject = getHTTPObject();

	if (httpObject != null)
	{
		httpObject.open('POST', url, true);
		if (window.ActiveXObject)
			httpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		else
			httpObject.overrideMimeType('multipart/form-data');
		httpObject.send(null);
		id_out = id_output;
		httpObject.onreadystatechange = setOutputHTML;
	}
}


function execjavascript(html)
{
	var endpos = html.indexOf("</script>");
	var startpos;
	while(endpos!=-1)
	{
		startpos = html.lastIndexOf("<script>",endpos);
		script = html.substring(startpos+8,endpos);
		eval(script);

		html = html.substring(0,startpos)+html.substring(endpos+9);
		endpos = html.indexOf("</script>");
	}
}

function setOutputHTML()
{
	if(httpObject.readyState == 4)
	{
		//document.getElementById(id_out).innerHTML = httpObject.responseText;
		var s = httpObject.responseText;
		document.getElementById(id_out).innerHTML = s;
		execjavascript(s);
	}
}


function ajaxSQLGetValue(url,id_output)
{
	//alert(url.length);
	//IE Max length 2083
	httpObject = getHTTPObject();

	if (httpObject != null)
	{
		httpObject.open('POST', url, true);
		if (window.ActiveXObject)
			httpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		else
			httpObject.overrideMimeType('multipart/form-data');
		httpObject.send(null);
		id_out = id_output;
		httpObject.onreadystatechange = setOutputINPUT;
	}
}

function setOutputINPUT()
{
	if(httpObject.readyState == 4)
	{
		document.getElementById(id_out).value = httpObject.responseText;
	}
}

function ajaxSQLGetArray(url,id_output)
{
	//alert(url.length);
	//IE Max length 2083
	httpObject = getHTTPObject();

	if (httpObject != null)
	{
		httpObject.open('POST', url, true);
		if (window.ActiveXObject)
			httpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		else
			httpObject.overrideMimeType('multipart/form-data');
		httpObject.send(null);
		id_out = id_output;
		httpObject.onreadystatechange = setOutputINPUT;
	}
}

function ajaxSQLGetROW(url,id_output)
{
	//alert(url.length);
	//IE Max length 2083
	httpObject = getHTTPObject();

	if (httpObject != null)
	{
		httpObject.open('POST', url, true);
		if (window.ActiveXObject)
			httpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		else
			httpObject.overrideMimeType('multipart/form-data');
		httpObject.send(null);
		id_out = id_output;
		httpObject.onreadystatechange = setOutputHTML;
	}
}

function ajaxGetPagingTable(sql,db,where,id_output,pagesize,row_numbers,pagingtop,pagingbottom,maintablestyle,tablestyle)
{
	// must change module dir
	var url = 'index.php?ajax+get_pagingtable+getPagingTable+module/modules/ajax/class.func.php+'+sql+'+'+db+'+'+where+'+'+pagesize+'+'+row_numbers+'+'+pagingtop+'+'+pagingbottom+'+'+maintablestyle+'+'+tablestyle+'+'+id_output;

	//alert(url.length);
	//IE Max length 2083
	httpObject = getHTTPObject();

	if (httpObject != null)
	{
		httpObject.open('POST', url, true);
		if (window.ActiveXObject)
			httpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		else
			httpObject.overrideMimeType('multipart/form-data');
		httpObject.send(null);
		id_out = id_output;
		httpObject.onreadystatechange = setOutputHTML;
	}

}

function ajaxGetPagingTablePageNext(sql,db,where,id_output,pagesize,row_numbers,pagingtop,pagingbottom,maintablestyle,tablestyle,position)
{
	// must change module dir
	var url = 'index.php?ajax+get_pagingtable+getPagingTableTabNext+module/modules/ajax/class.func.php+'+sql+'+'+db+'+'+where+'+'+pagesize+'+'+row_numbers+'+'+pagingtop+'+'+pagingbottom+'+'+maintablestyle+'+'+tablestyle+'+'+id_output+'+'+position;
	//alert(url.length);
	//IE Max length 2083
	httpObject = getHTTPObject();
	if (httpObject != null)
	{
		httpObject.open('POST', url, true);
		if (window.ActiveXObject)
			httpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		else
			httpObject.overrideMimeType('multipart/form-data');
		httpObject.send(null);
		id_out = id_output;
		httpObject.onreadystatechange = setOutputHTML;
	}

}