var new_image = false;
var cur_image;

function TradeImage(old_img_place,new_img_place) {

	if(new_image != false) {
		return;
	}
	
	cur_image = $(new_img_place);
	new_image = $(old_img_place);

	var params = "path=" + encodeURIComponent( new_image.getProperty('src') );
					
	var url = "ajax/a_image_size.php";
	var mime = "application/json";
	
	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			// set mime type accordingly
			httpRequest.overrideMimeType(mime);
		}
	}
	else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	if (!httpRequest) {
		//alert('Create XMLHTTPRequest failed.');
		return false;
	}
	
	httpRequest.open('POST', url, true);
	httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	httpRequest.onreadystatechange = function() {
		if (httpRequest.readyState == 4) {
			if (httpRequest.status == 200) {
				if(httpRequest.responseText != "0") {
					//alert(httpRequest.responseText);
					
					var img_size = eval("(" + httpRequest.responseText + ")");
					
					var link = new_image.getProperty('src');
					new_image.setProperty('src', cur_image.getProperty('src'));
					cur_image.setProperty('src', link);
					new_width = Math.min(320,img_size[0]);
					cur_image.setStyle('width',new_width);
					
					new_image = false;
					cur_image = false;
				}
			}
		}
	};
	
	httpRequest.send(params);
	return true;
}

var popwin = null;
function PopupImage(link,wtitle,w,h) {
if (popwin) popwin.close();
popwin = window.open("",'popwindow','toolbar=no,location=no,directories=no,status=no,menubar=no,width='+w+',height='+h+',scrollbars=yes,resizable=no,screenX=50,screenY=50,left=50,top=50');
popwin.document.write('<HTML><HEAD><TITLE>' + wtitle + '</TITLE><body bgcolor="#FFFFFF" onLoad="self.focus()">');
if (wtitle) popwin.document.write('<CENTER><FONT SIZE="3" FACE="lucida grande, sans serif"><B>' + wtitle + '</B></FONT></CENTER><BR>');
popwin.document.write('<CENTER><IMG SRC="' + link + '" BORDER="0" ALT="' + wtitle + '"></CENTER>');
popwin.document.write('<BR><CENTER><A HREF="javascript: self.close();"><FONT SIZE="2" FACE="Lucida Grande, sans serif">Close Window</FONT></A></CENTER>');
popwin.document.write('</BODY></HTML>');
popwin.document.close() ;
//popwin.location.href = link;
//popwin.focus();
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
