var request = createRequestObject();
var dataReturn='';
var ajaxTimeout='';
var enterChecker=false;

function createRequestObject()
{
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

function makeRequest (url, fun)
{
	enterChecker=false;
	request.open('get', url);
	request.onreadystatechange = function() { handleResponse(fun); }
	request.send(null);
}

function handleResponse(fun) {

	if(request.readyState < 4)
	{
		ajaxTimeout=setTimeout('handleResponse(\''+fun+'\')',10);
	}
	else if(request.readyState == 4 && !enterChecker)
	{
		enterChecker=true;
		var response = request.responseText;
		dataReturn=response;
        
		if(fun!='')
			ajaxTimeout=setTimeout(fun+'()', 200);
	}
}

function stopAjax()
{
	clearTimeout(ajaxTimeout);
	ajaxTimeout='';
}

//post ajax functions

var ajaxIframesAmount=0;

function showAjaxForm(formName, w, h, funcToCall)
{
	var fObj=document.forms[formName];
	if(fObj.getAttribute('method')==null)
		alert('Developer error: METHOD should be set to a form');
	if(!fObj.getAttribute('action')==null)
		alert('Developer error: ACTION should be set to a form');
	if(!fObj.getAttribute('enctype')==null)
		alert('Developer error: ENCTYPE should be set to a form');
	if(funcToCall.match('"'))
		alert('Developer error: " symbol is not allowed in funcToCall variable value');
		
	var formContent=fObj.innerHTML;
	
	if(funcToCall!='')
		funcToCall=funcToCall+';';
	
	formContent='<style>*{font-family:arial; font-size:12px;}</style><form action="'+fObj.getAttribute('action')+'" method="'+fObj.getAttribute('method')+'" enctype="'+fObj.getAttribute('enctype')+'" name="'+formName+'">'+formContent+'<br /><br /><center><input type="submit" value="Submit Form" onclick="parent.preloadTop(true)"></center><input type="hidden" name="func_to_call" value="'+funcToCall+'parent.preloadTop(false)" /></form>';
	
	var formIframe='<iframe name="ajaxFrameName'+ajaxIframesAmount+'" id="ajaxFrameId" width="'+(w-30)+'" height="'+(h-45)+'" frameborder="0"></iframe>';
	
	document.getElementById('contentDiv').innerHTML=formIframe;
	var toReturn=window.frames['ajaxFrameName'+ajaxIframesAmount];
	
	window.frames['ajaxFrameName'+ajaxIframesAmount].document.write(formContent);
	
	if(window.stop)
		window.stop();
	else
		document.execCommand('stop');
	
	showMessage('mDiv', w, h);
	
	ajaxIframesAmount++;
	
	return toReturn;
}

function testIt()
{
	//alert('a');
 	//document.frames['ajaxFrameId'].document.innerHTML
}

function appendBody(appObj)
{
 	bodyObj = document.getElementsByTagName('body');
 	bodyObj = bodyObj[0];
 	bodyObj.appendChild(appObj); 
}

function preloadTop(showPreloader)
{
	p=document.getElementById('preloaderTopId');
	if(showPreloader)
		p.className='visible';
	else                    
		p.className='displaynone';
}