﻿

	var params;

	var req;

	var theView;

	//var theView_helpyear;

		 

	function retrieveURL(url, view) {

		if (window.XMLHttpRequest) { // Non-IE browsers

	      req = new XMLHttpRequest();

	      req.onreadystatechange = processStateChange;

	      try {

			req.open("GET", url, true);

	      } catch (e) {

	        alert(e);

	      } // catch

	      req.send(null);

	    } else if (window.ActiveXObject) { // IE

	      req = new ActiveXObject("Microsoft.XMLHTTP");

	      if (req) {

	        req.onreadystatechange = processStateChange;

	        req.open("GET", url, true);

	        req.send();

	      } // if

	    } // else if

	} // retrieveURL()

	

	function processStateChange() {

	    if (req.readyState == 4) { // Complete

	      if (req.status == 200) { // OK response

			if (theView) {

				 theView.innerHTML = req.responseText;

			} else {

				alert("NULL");

			} // else

	      } else {

	        alert("Problem : " + req.statusText);

	      } // else

	    } // if

	 } // processStateChange()

	 

	function loadURL(url, view) {		

		//alert("url: " + url + "view: " + view);

		theView = document.getElementById(view);

//		if (theView.innerHTML) {

			theView.innerHTML = '<img src="image/loading.gif"><br><span class="txt"> Đang đọc dữ liệu</span>';		

			var Html = retrieveURL(url,view);

			return true;

//		} else {

			//setTimeout("loadURLByAjax('" + url + "','" + view + "')", 500);

//			return false;

//		} // else

	} // loadURLByAjax()

	function dragDiv(){

		var theHandle = document.getElementById("subWindowHandle");

		var theRoot   = document.getElementById("windowRefresh");

		Drag.init(theHandle, theRoot);

	}

	

	var theUrlRefresh;

	var theViewRefresh;

	function showWindow(url, width, height, title, urlRefresh) {

			//alert("url: " + url);

			theUrlRefresh = urlRefresh;

			theViewRefresh = '';

			document.getElementById('closeWindowPopup').value = 'ON';

			document.getElementById("windowRefresh").style.visibility='';	

			document.getElementById("titleWindowRefresh").innerHTML = title;	

			document.getElementById("windowRefreshContent").innerHTML = "<IFRAME frameborder=no SRC='"+url+"' WIDTH="+width+" HEIGHT="+height+">Unsuppor IFrame</IFRAME>";

			checkCloseWindow();

			return true;

	}



	function showWindow(url, width, height, title, urlRefresh, theView){

			theUrlRefresh = urlRefresh;

			theViewRefresh = theView;

			document.getElementById('closeWindowPopup').value = 'ON';

			document.getElementById("windowRefresh").style.visibility='';	

			document.getElementById("titleWindowRefresh").innerHTML = title;	

			document.getElementById("windowRefreshContent").innerHTML = "<IFRAME frameborder=no SRC='"+url+"' WIDTH="+width+" HEIGHT="+height+">Unsuppor IFrame</IFRAME>";

			checkCloseWindow();

			return true;

	}

	

	function checkCloseWindow()

	{

		var value = document.getElementById('closeWindowPopup').value;

		if (value=='OFF') {				

			closeWindow();

		}

		else {

			setTimeout("checkCloseWindow()",500);

		}

	}

		

	function closeWindow() {		

		document.getElementById('closeWindowPopup').value = 'OFF';

		document.getElementById("windowRefreshContent").innerHTML = "";

		document.getElementById("windowRefresh").style.visibility='hidden';

		if ((theUrlRefresh !=null) && (theUrlRefresh.length > 0)) {

			if ((theViewRefresh !=null) && (theViewRefresh.length > 0)) {

				loadURLByAjax(theUrlRefresh, theViewRefresh);

			} else {

				window.location.href = theUrlRefresh;

			} // else			

		} // if

	}
