var _dynaControl;
var _showLoader=true;
var _showErrConlose=false;
var _http_request=false;
var _after;

function makeRequest(url,parameters){
	_http_request=false;
	if(window.XMLHttpRequest){
		_http_request = new XMLHttpRequest();
		if(_http_request.overrideMimneType){
			_http_request = new overrideMimeType("text/html");
		}
	}
	else if(window.ActiveXObject){
		try{
			_http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				_http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}	
		}
	}
	if(!_http_request){
		alert('Cannot make Request');
		return false;
	}
	if(_dynaControl!=false){
		_http_request.onreadystatechange=displayContent;
	}
		_http_request.open("POST",url,true);
		_http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		_http_request.setRequestHeader("Content-length",parameters.length);
		_http_request.setRequestHeader("Connection","close");
		_http_request.send(parameters);
	
}

function displayContent(){	
	var result = '';
	if(_http_request.readyState == 0){
		try{
			document.getElementById('ajaxText').innerHTML = 'Not Initialize';
		}catch(e){}
	}
	if(_http_request.readyState == 1){
		try{
			document.getElementById('ajaxText').innerHTML = 'Prepairing Request';
		}catch(e){}
	}
	if(_http_request.readyState == 2){
		try{
			document.getElementById('ajaxText').innerHTML = 'Sending Request';	
		}catch(e){}
	}
	if(_http_request.readyState == 3){
		try{
			document.getElementById('ajaxText').innerHTML = 'In Process';	
		}catch(e){}
	}
	if(_http_request.readyState == 4){
		if(_http_request.status == 200){ 
			try{
				document.getElementById('ajaxText').innerHTML = 'Complete';
			}catch(e){}
			if(_showLoader==true){ 
				document.getElementById('imgLoader').style.display='none';
				try{
					document.getElementById(_dynaControl).style.opacity=1;
					document.getElementById(_dynaControl).style.filter="alpha(opacity=100)";
				}catch(e){}
			}
			result = _http_request.responseText; 
			if(_dynaControl!='' && result!=''){
				//document.getElementById(_dynaControl+'a').style.visibility = "hidden";
	     		document.getElementById(_dynaControl).innerHTML = result;
				//MM_effectAppearFade(_dynaControl, 1000, 0, 100, false);
				//MM_effectSquish(_dynaControl);
				//MM_effectBlind(_dynaControl, 1000, '0%', '100%', false);
				//document.getElementById(_dynaControl+'a').style.visibility = "visible";
			}
			else{
				alert('Cannot get _dynaControl or result is empty');
			}
			try{
				afterAjax(_after);	
			}catch(e){
				//alert(e);
			}
		}
		else{
			alert('_http_request err');
		}
	}
}

function get(target,postStr,dynaCon,loader,obj){
	_showErrConsole=false;
	if(dynaCon!=''){
		_dynaControl=dynaCon;
	}
	else{
		_dynaControl='';
	}
	_showLoader=loader;
	if(loader==true){
		document.getElementById('imgLoader').style.display='inline';
		try{
			document.getElementById(_dynaControl).style.opacity=.30;
			document.getElementById(_dynaControl).style.filter="alpha(opacity=50)";
		}catch(e){}
	}else if(loader==false){
		
	}else{
		document.getElementById(_dynaControl).innerHTML = loader;
	}
	pathAdj='';
	if(postStr.indexOf("[[")>0){
		startInd=postStr.indexOf("[[")+2; 
		endInd=postStr.indexOf("]]");
		pathAdj=postStr.substring(startInd,endInd);
	}
	_after='';
	if(postStr.indexOf("((")>0){
		startInd=postStr.indexOf("((")+2; 
		endInd=postStr.indexOf("))");
		_after=postStr.substring(startInd,endInd);
	}
	postStr = "filePath="+target+"&"+postStr+"&areaId="+_dynaControl+"&";
	if(obj!=''){
		for(i=0; i<obj.elements.length; i++){
			if(obj.elements[i].type=="text"){
				postStr+=obj.elements[i].name+"="+escape(obj.elements[i].value)+"&";
			}
			else if(obj.elements[i].type=="hidden"){
				postStr+=obj.elements[i].name+"="+escape(obj.elements[i].value)+"&";
			}
			else if(obj.elements[i].type=="checkbox"){
				if(obj.elements[i].checked){
				postStr+=obj.elements[i].name+"="+escape(obj.elements[i].value)+"&";
				}
			}
			else if(obj.elements[i].type=="radio"){
				if(obj.elements[i].checked){
				postStr+=obj.elements[i].name+"="+escape(obj.elements[i].value)+"&";
				}
			}
			else if(obj.elements[i].type=="select-one"){
				sel=obj.elements[i];
				if(sel.selectedIndex<0){
				postStr+=sel.name+"=&";
				}
				else{
				postStr+=sel.name+"="+escape(sel.options[sel.selectedIndex].value)+"&";	
				}
			}
			else if(obj.elements[i].type=="textarea"){
				postStr+=obj.elements[i].name+"="+escape(obj.elements[i].value)+"&";
			}
		}
	}
	//alert(postStr);
	makeRequest(pathAdj+'post.php',postStr);
}

//effects

	function MM_effectAppearFade(targetElement, duration, from, to, toggle)
	{
		Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
	}
	function MM_effectSquish(targetElement)
	{
		Spry.Effect.DoSquish(targetElement);
	}
	function MM_effectBlind(targetElement, duration, from, to, toggle)
	{
		Spry.Effect.DoBlind(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
	}