function returnObject (id) {
	if (document.all) {
		return document.all[id];
	} else if (document.getElementById) {
		return document.getElementById(id)
	} else if (document.layers) {
		return document.layers[id];
	}
	return null;
}

function showPopUp(url, title, options) {
	return window.open(url, title, options);
}

function documentWidth () {
	if(typeof(window.innerWidth) == 'number') {
		//Non-IE
	    return parseInt(window.innerWidth);
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	    //IE 6+ in 'standards compliant mode'
    	return parseInt(document.documentElement.clientWidth);
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		return parseInt(document.body.clientWidth);
	}
	
	return 0;
}
	
function documentHeight () {
	if(typeof(window.innerWidth) == 'number') {
		//Non-IE
	    return parseInt(window.innerHeight);
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	    //IE 6+ in 'standards compliant mode'
	    return parseInt(document.documentElement.clientHeight);
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		return parseInt(document.body.clientHeight);
	}
	
	return 0;
}

function showImage (Image, imageWidth, imageHeight, MLS) {
	var url     = 'view_image.php?image=' + Image + '&MLS=' + MLS;
	var title   = 'CREImage';
	var options = 'resizable=yes,status=no,menubar=no,toolbar=no,scrollbars=no,width='+imageWidth+',height='+imageHeight+',top=60,left=60';
	
	return (showPopUp(url, title, options) != null);
}

function showImage2 (Image, imageWidth, imageHeight) {
	var url     = 'view_image2.php?image=' + Image;
	var title   = 'CREImage';
	var options = 'resizable=yes,status=no,menubar=no,toolbar=no,scrollbars=no,width='+imageWidth+',height='+imageHeight+',top=60,left=60';
	
	return (showPopUp(url, title, options) != null);
}

function showGallery (OpenHouse, imageWidth, imageHeight) {
	var url     = 'gallery.php?openhouse=' + OpenHouse;
	var title   = 'CREImageGallery';
	var options = 'resizable=yes,status=no,menubar=no,toolbar=no,scrollbars=no,width='+imageWidth+',height='+imageHeight+',top=60,left=60';
	
	return (showPopUp(url, title, options) != null);
}

function resizePopUpToContents () {
	var docWidth = documentWidth();
	var docHeight = documentHeight();

	var resizeToWidth = parseInt(returnObject('largeImage').offsetWidth);
	var resizeToHeight = parseInt(returnObject('popUpContents').offsetHeight);

	window.resizeTo(resizeToWidth, resizeToHeight);

	docWidth = documentWidth();
	docHeight = documentHeight();
	if ((docWidth < resizeToWidth) || (docHeight < resizeToHeight)) {
		resizeToWidth += resizeToWidth - docWidth;
		resizeToHeight += resizeToHeight - docHeight;
		window.resizeTo(resizeToWidth, resizeToHeight);
	}
}