var ajax_file_name_for_js = Array();
var g_file_name_for_js = '';
function tcse_ajax(file_name,id_to_get_result,form_name,method,function_name,time)
{
	
	file_name = file_name+'&ajax=1&';
	if(ajax_file_name_for_js[file_name]==1)
	file_name = file_name+'&js=none&';
	g_file_name_for_js = file_name;
	if(getc('load_mouse_hide')!='true')
	mouse_load(1);
	if(form_name)
	var url=tcse_get_form_data(form_name); 
	
	connection = new tcse_AjaxConnection(file_name,url);
   return connection.tcse_connect(file_name,id_to_get_result,form_name,method,function_name,time);
}

function tcse_AjaxConnection(file_name,url) 
{
   this.tcse_connect=tcse_connect;
   this.file_names=file_name;
   this.uri=url;
} 


function tcse_connect(file_name,id_to_get_result,form_name,method,function_name,time)
        {
			
     this.xmlhttp=tcse_init_object();
	if(method=='')
	method='get';
if(time!='')
var time=parseInt(time,10);
var self = this;
this.xmlhttp.onreadystatechange=function()
  {
  if (self.xmlhttp.readyState==4 && self.xmlhttp.status==200)
    {
		
		if( id_to_get_result!='' && $('#' + id_to_get_result ).length==0)
		{
		}
		else if( id_to_get_result!='' && id_to_get_result!=1 )
        document.getElementById(id_to_get_result).innerHTML=tcse_PaseAjaxResponse(self.xmlhttp.responseText.replace(/^\s*|\s*$/g,''));
		

tcse_function_call(function_name,time);
	mouse_load(0);
    }
  }
		if(id_to_get_result=='')
		var response_key=false;
		else
		var response_key=true;
	
		if(method=='get')
		{
		if(this.uri)
		{
		this.file_names=this.file_names + this.uri;
		}
		this.xmlhttp.open("GET",this.file_names,response_key);
		this.xmlhttp.send();		
		}
		
		else if(method=='post')
		{        
		this.xmlhttp.open("POST",this.file_names,response_key);
		this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.xmlhttp.setRequestHeader("Content-length", this.uri.length);
		this.xmlhttp.setRequestHeader("Connection", "close");
		this.xmlhttp.send(this.uri);
		}
		
  if(id_to_get_result=='')
  {
mouse_load(0);
  return tcse_PaseAjaxResponse(self.xmlhttp.responseText.replace(/^\s*|\s*$/g,''));
  }
  else
  return false;
             
        }
		
function tcse_init_object() {
        var xmlhttp;
        try {
                xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                } catch (oc) {
                        xmlhttp=null;
                }
        }      
        if(!xmlhttp && typeof XMLHttpRequest != "undefined")
                xmlhttp = new XMLHttpRequest();
        if (xmlhttp)
                return xmlhttp;
}		
		
function tcse_get_form_data(form_name)
{
	
  //var url='';
 var form = document.forms[form_name]
    //for (i = 0; i < form.elements.length; i++) {
	//	if(form.elements[i].name!='')
       //     url=url + form.elements[i].name +'='+ form.elements[i].value +'&';
          
   // }

	//return '?&' + url;
	return '&' + $(form).serialize();
}

function tcse_filter_function(function_name,str)
{
	var s1=	function_name.split("(");
for(j=1;j<s1.length;j++)
{
var s2=s1[j].split(")");
for(k=0;k<s2.length;k++)
{
var s3=s2[k].split(",");
for(i=0;i<s3.length;i++)
{
var s4=s3[i].split("'");
if(s4.length==1 && s4[0]!='')
s4[0]=str + "'" + s4[0] + str + "'";
s3[i]=s4.join("'");
}
s2[k]=s3.join(",");
}
s1[j]=s2.join(")");
}
function_name=s1.join("(");
						return function_name;
}
function tcse_function_call(function_name,time_delay){
		function_name =tcse_filter_function(function_name,'');		
		if(function_name!='' && !tcse_validate_number(function_name))
		{
			
			if(time_delay=='')
			time_delay=0;
		setTimeout(function_name,time_delay);
		}
	}

function tcse_PaseAjaxResponse(somemixedcode)
{
var response = somemixedcode;
var title = somemixedcode.split('<title>');
if(title.length>1)
{	
var title = title[1].split('</title>');
document.title = title[0];
}

var source = somemixedcode;
var source1 = somemixedcode;
var scripts = new Array();
var scripts1 = new Array();
while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1)
{
var s = source.indexOf("<script");
var s_e = source.indexOf(">", s);
var e = source.indexOf("</script", s);
var e_e = source.indexOf(">", e);
scripts.push(source.substring(s_e+1, e)); 
source = source.substring(0, s) + source.substring(e_e+1);
} 
for(var x=0; x<scripts.length; x++)
{ 
try 
{ 
  $('head').append('<script type="text/javascript">' + scripts[x] + '</script>');
}
catch(ex)
{
}
}

while(source1.indexOf("<script") > -1 || source1.indexOf("</script") > -1)
{
var s = source1.indexOf("<script");
var s_e = source1.indexOf(">", s);
var e = source1.indexOf("</script", s);
var e_e = source1.indexOf(">", e);
var str = source1.substring(s+1, s_e);
var str_len = str.split('src');
if(str_len.length>1)
{
	str1 = str.split("src=\"");
	str2 = str1[1].split("\"");
scripts1.push(str2[0]); 
}
source1 = source1.substring(0, s) + source1.substring(e_e+1);
} 
for(var x=0; x<scripts1.length; x++)
{ 
try 
{ 
  $('head').append('<script type="text/javascript" src="' + scripts1[x] + '" ></script>');
}
catch(ex)
{
}
}
var rre = response.split('<script');
response = rre[0];
for(i=1;i<rre.length;i++)
{
	var rre1 = rre[i].split('</script>');
	response = rre1[1];
}

if(root_path!='/')
{
cur_url_path = location.pathname.split(root_path);
cur_url_path = cur_url_path[1];
}
else
cur_url_path = location.pathname;

cur_url_path = cur_url_path.split('/');
if(cur_url_path.length>2)
{

		
			var tcse_b_str = response.replaceall("'css/","'"+ root_path +"css/");
			response = tcse_b_str.replaceall('"css/','"'+ root_path +'css/');
			response = response.replaceall('url(css/','url('+ root_path +'css/');
			response = response.replaceall('url("css/','url("'+ root_path +'css/');
			response = response.replaceall("url('css/","url('"+ root_path +"css/");

			if($.browser.msie && $.browser.version.substr(0,1)<7)
	{
ie_png_fix();
	}
	else
	{
				if(ajax_file_name_for_js[g_file_name_for_js]!=1)
			{
				var response11 = $('head').html();
				response11 = response11.replaceall('url(css/','url('+ root_path +'css/');
				response11 = response11.replaceall('url("css/','url("'+ root_path +'css/');
				response11 = response11.replaceall("url('css/","url('"+ root_path +"css/");
				document.getElementsByTagName('head').item(0).innerHTML=response11;
			}	
	}

}
ajax_file_name_for_js[g_file_name_for_js]=1;
return response;

} 
real_path ='';
function mouse_load(val)
{
	if($('#mouse_loading').length==0)
	$('body').append('<div style="position:absolute;display:none;z-index:100002;" id="mouse_loading"></div>');
	
	if(val==1)
	{
	$('#mouse_loading').html('<img  src="'+ tcse_real_path +'ajax-loader.gif" >');
	$('#mouse_loading').show();
	}
	else if(val==0)
	{
		$('#mouse_loading').html('');
	
	$('#mouse_loading').hide();
	}
}

String.prototype.replaceall = function(stringssToFind,stringssToReplace){

    var tcse_tempss = this;

    var tcse_indexss = tcse_tempss.indexOf(stringssToFind);

        while(tcse_indexss != -1){

            tcse_tempss = tcse_tempss.replace(stringssToFind,stringssToReplace);

            tcse_indexss = tcse_tempss.indexOf(stringssToFind);

        }

        return tcse_tempss;

    }
