function enlarge(image) {
var i = new Image();
i.src = image;
var x = i.width;
var y = i.height;
// window.status for degugging:
//window.status = image + " = " + x + " x " + y + " pixels";
var z = "toolbar=no, menubar=no,width=" + x + ",height=" + y;//,scrollbars=no,
	//window.open(image,"image",z);
	popwin=window.open("","_blank",z);
	//popwin.document.open()
	popwin.document.write('<html><head><title>Quảng cáo</title><style type="text/css"> BODY { MARGIN: 0px } </style></head><body ><img src="'+image+'"  border="0"></body></html>');
	//popwin.document.close();
}

function sack(file){
	this.AjaxFailedAlert = "Trình duyệt của bạn không hổ trợ các chức năng của website. Vì thế website có thể sẽ không thực hiện đúng các thao táo của bạn.";
	this.requestFile = "process.aspx";
	this.method = "GET";
	this.block_screen=null;
	this.URLString = "";
	this.encodeURIString = true;
	this.execute = false;
	this.filesupload=Array();
	this.onLoading = function() { };
	this.onLoaded = function() { };
	this.onInteractive = function() { };
	this.onCompletion = function() { };
	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			

		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err) {
				this.xmlhttp = null;
			}
		}
		if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
			this.xmlhttp = new XMLHttpRequest();
		if (!this.xmlhttp){
			this.failed = true; 
		}
	};
	
	this.blo_screen = function(){
			//about:blank;
			
			this.iframe = document.createElement("<iframe   height='0' frameborder='0' src='about:blank'>");
			s = this.iframe.style;
			s.position = "absolute";
			s_w=this.block_screen.offsetWidth
			s.width= s_w +"px";
			s_h=this.block_screen.offsetHeight;
			s.height= s_h +"px";
			s_l=offsetLeft(this.block_screen);
			s.left = s_l  +"px";
			s_t =  offsetTop(this.block_screen);
			s.top = s_t +"px";
			//alert(s.width +  " "+ s.height +" " + s.left + " " +s.top);
			s.filter = "Alpha(Opacity="+ 0+")";
			s.zIndex = 6;
			s.display = "";
			document.body.appendChild(this.iframe);
			
			this.aj_screen = document.createElement("DIV");
			this.aj_screen.style.width="300px";
			this.aj_screen.style.height="30px";
			this.aj_screen.style.top= (( s_h-30)/2 + s_t) +"px";
			this.aj_screen.style.left= ((s_w- 300)/2) + s_l + "px";
			this.aj_screen.align="center";
			this.aj_screen.style.position="absolute";
			this.aj_screen.style.padding="3px";
			//this.aj_screen.style.filter = "Alpha(Opacity="+ 0+")";
			this.aj_screen.style.background="#CCCCCC";
			this.aj_screen.style.zIndex="1";
			this.aj_screen.innerHTML ='<b>Vui lòng chờ trong giây lát .</b><br><img src="images/progbar.gif">';
			document.body.appendChild(this.aj_screen);
	
	}
	
	this.setVar = function(name, value){
		if (this.URLString.length < 3){
			this.URLString = name + "=" + value;
		} else {
			this.URLString += "&" + name + "=" + value;
		}
	}
	this.setFile = function(name, value){
		this.filesupload[name] = value;
	}
	this.setVar_from_form = function(theForm){
		
		for (i = 0; i < theForm.length; i++){

			if(theForm.elements[i].type=="radio" || theForm.elements[i].type=="checkbox"){
				if(theForm.elements[i].checked) this.setVar(theForm.elements[i].name,theForm.elements[i].value);
			}
			if(theForm.elements[i].type=="file"){
				this.setFile(theForm.elements[i].name,theForm.elements[i].value);
			}
			else{
				this.setVar(theForm.elements[i].name,theForm.elements[i].value);
			}
				
		}
	}
	this.encVar = function(name, value){
		var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
	return varString;
	}
	
	this.encodeURLString = function(string){
		varArray = string.split('&');
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split('=');
			if (urlVars[0].indexOf('amp;') != -1){
				urlVars[0] = urlVars[0].substring(4);
			}
			varArray[i] = this.encVar(urlVars[0],urlVars[1]);
		}
	return varArray.join('&');
	}
	
	this.runResponse = function(){
		eval(this.response);
	}

	this.runAJAX = function(urlstring){
		
		this.responseStatus = new Array(2);
		if(this.failed && this.AjaxFailedAlert){ 
			alert(this.AjaxFailedAlert); 
		} else {
			if (urlstring){ 
				if (this.URLString.length){
					this.URLString = this.URLString + "&" + urlstring; 
				} else {
					this.URLString = urlstring; 
				}
			}
			if (this.encodeURIString){
				var timeval = new Date().getTime(); 
				this.URLString = this.encodeURLString(this.URLString);
				this.setVar("rndval", timeval);
			}
			if (this.element) { this.elementObj = document.getElementById(this.element); }
			if (this.xmlhttp) {
				
				var self = this;
				if (this.method == "GET") {
					var totalurlstring = this.requestFile + "?" + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
				}
				if (this.method == "POST"){
  					try {
						this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')  ;
						this.xmlhttp.setRequestHeader('Pragma','no-cache')  ;
						} catch (e) {}
				}

				//this.xmlhttp.send(this.URLString);
				if(this.block_screen!=null){
					this.blo_screen();
				}
				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState){
						case 1:
							self.onLoading();
						break;
						case 2:
							self.onLoaded();
						break;
						case 3:
							self.onInteractive();
						break;
						case 4:
							
							if(self.block_screen!=null){
								document.body.removeChild(self.iframe);
								document.body.removeChild(self.aj_screen);
								
							}

							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
							self.onCompletion();
							if(self.execute){ self.runResponse(); }
							if (self.elementObj) {
								var elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							self.URLString = "";
						break;
					}
				};
				this.xmlhttp.send(this.URLString);
			}
		}
	};
this.createAJAX();
}
