// declare new variables for each new div that you add, and link to the div by ID
// var region_div = document.getElementById("region_div");
var doc = null;

function ajax() {
	// Make a new XMLHttp object
	if (typeof window.ActiveXObject != 'undefined' ) doc = new ActiveXObject("Microsoft.XMLHTTP");
	else doc = new XMLHttpRequest();
}

function GetUrl(url){
	ajax();
	if (doc){
	//	doc.onreadystatechange = function() {
	//		if (doc.readyState == 4) {
	//			alert( doc.responseText);
	//		}
	//	}
		doc.open("GET", url, false);
		doc.send(null);
	}else{
	}
}

var req = null;

function InitXMLHttpRequest() {
	// Make a new XMLHttp object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
//	if (typeof window.ActiveXObject != 'undefined' ) req = new ActiveXObject("Microsoft.XMLHTTP");
//	else req = new XMLHttpRequest();
}

function RunJS(dest, response){
	if (response.search(/<script/) == -1){
		dest.innerHTML=response;
		return false;
	}
	//Check user browser
	var agent=(window.navigator.appName=='Netscape')?'Firefox':'IE';
	if(agent=='IE'){
		///place &nbsp; before <scrript> tag
		dest.innerHTML=response;
		var arr_scripts = dest.getElementsByTagName("script");
		for(i in arr_scripts){
			var src = arr_scripts[i].src;
			if(null!=src){
				var has_question = (src.indexOf('?', 1)>0 ? true : false);
				if(0==src.length)
					arr_scripts[i].setAttribute('src', '');
				else
					arr_scripts[i].setAttribute('src', arr_scripts[i].src + (has_question==true ? '&' : '?') + '1=1');
			}
		}
	}else{
		//Mozilla
		var d=dest.parentNode;
		var d_new=document.createElement('div');

		//Set same attributes as original
		var attributes=dest.attributes;
		var len=attributes.length;

		d_new.innerHTML=response;
		for(var i=0; i<len; i++){
			d_new.setAttribute(attributes[i].name, attributes[i].value);
		}

		d.replaceChild(d_new, dest);
	}
}

function ajaxRequest(file_name, str, destination_odj, tmp_text, anisochronous){
	if (str != '') {
		str = str+'&ajax=1';
		InitXMLHttpRequest();
		// Load the result from the response page
		if (req) {
			if (anisochronous){
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						//destination_odj.innerHTML = req.responseText;
						RunJS(destination_odj,req.responseText);
					} else {
						destination_odj.innerHTML = tmp_text;
					}
				}
			}
			req.open("POST", file_name+'?rnd='+Math.random(), anisochronous);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8 ');
			req.setRequestHeader("Content-length", str.length);
      		req.setRequestHeader("Connection", "close");
			req.send(str);
			if (!anisochronous) RunJS(destination_odj,req.responseText);
		} else {
			destination_odj.innerHTML = 'Browser unable to create XMLHttp Object';
		}        
	} else {
		destination_odj.innerHTML = "no string";
	}
}
opacity = 0;
i1 = 0;
i2 = 0;
t1 = 0;
function noticeCode(code){
	//if(code == '') return false;
	addNoticeDiv(code);
	divTag = document.getElementById('notice_div');
	opacity = 0;
	i1 = setInterval('increaseOpacity(divTag);',2);
}

function increaseOpacity(divTag){
	opacity++;
	if (opacity >= 100){
		clearInterval(i1);
		setTimeout("i2 = setInterval('decreaseOpacity(divTag)',5)",3000);
		return false;
	}
	setOpacity(divTag,opacity);
}

function decreaseOpacity(divTag){
	opacity = opacity-10;
	if (opacity <= 1){
		clearInterval(i2);
		clearTimeout(t1);
		document.body.removeChild(divTag);
		return false;
	}
	setOpacity(divTag,opacity);
}
function setOpacity(divTag,i){
	divTag.style.filter = 'alpha(opacity='+i+')';
	divTag.style.opacity = i/100;
}
function addNoticeDiv(code){
	if (document.getElementById('notice_div')){
		clearInterval(i1);
		clearInterval(i2);
		clearTimeout(t1);
		divTag = document.getElementById('notice_div');
		if (divTag) document.body.removeChild(divTag);
	}
	
	var divTag = document.createElement("div"); 
  
	divTag.id = 'notice_div'; 
	divTag.setAttribute('align','center'); 
	divTag.style.margin = '0px auto'; 
	divTag.style.border = '1px solid #000000';
	divTag.style.background = '#ffffff';
	divTag.style.padding = '15px'
	
	if (navigator.appName == 'Microsoft Internet Explorer'){
		divTag.style.position = 'absolute';
		divTag.style.top = document.body.scrollTop+10;
	}else{	
		divTag.style.position = 'fixed';
		divTag.style.top = '10px';
	}
	divTag.style.left = '10px';
	
	divTag.style.filter = 'alpha(opacity=1)';
	divTag.style.opacity = '0.01';
	
	divTag.className ="dynamicDiv"; 
	divTag.innerHTML = code;
	document.body.appendChild(divTag);	
}
