/**************************************
*   (c) Andrew Zaitsew, 2005 - 2009   *
*       Aranea web-design studio      *
*           www.aranea.com.ua         *
*               custom.js             *
*      front-end custom javascript    *
***************************************/

function PopupImage(imgPath, title) {
	var win = window.open('','araneapreview',
	'width=50,height=50,left=0,top=0,screenX=0,screenY=0,resizable=1');

	if (title == undefined) title = VIEW_IMAGE;
	var content = '<html><head><title>' + title + '</title>' +
					'<style>body { background:#000000; color:#ffffcc; margin:0px; padding:0px; } #div-image { padding:2px; overflow:auto; } img { border:0; text-align:center; } form { margin:0px; padding:0px; } #header { text-align:center; margin:0px; padding:5px; font-size:14px; font-weight: bold; }</style>' +
					'</head><body><div id="all"><div id="header">' + title + '</div><div id="div-image" align="center"><a href="javascript:self.close()">' +
					'<img alt="' + CLOSE_WINDOW + '" id="image" src="' + imgPath + '" /></a></div></div></body></html>'
	win.document.write(content);

	win.document.body.onload = function() {
    	var obj = win.document.getElementById('image');
    	var w = obj.width, h = obj.height;
    	var iHeight= document.body.clientHeight, iWidth = self.innerWidth;

    	var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
    	var top =  (self.opera ? iHeight : screen.availHeight)/2 - h/2;

		if (w + 25 > screen.availWidth) {
			left = 0;
			w = screen.availWidth;
		} else {
			w += 25;
		}

		if (h + 120 > screen.availHeight) {
			top = 0;
			h = screen.availHeight;
		} else {
			h += 120;
		}
	
		win.resizeTo(w, h);	
		win.moveTo(left, top);
    }
    win.onload = win.document.body.onload; // special for Mozilla
    
    win.document.close();
    win.focus();
}

function showAJAXicon(_item, _mode) {
	if ( document.getElementById(_item) ) {
		if ( _mode == 0 ) {
			document.getElementById(_item).innerHTML = '<div style="clear:both; margin:5px 0 10px 0;"><img src="' + site_url + 'images/icon-ajax.gif" width="31" height="31" alt="-" /></div>';
		}
		if ( _mode == 1 ) {

			setSelected(_item);
//			document.getElementById(_item).innerHTML = '<div style="clear:both; margin:0;"><img src="' + site_url + 'images/icon-ajax-small.gif" width="16" height="16" alt="-" /></div>';
		}
		if ( _mode == 2 ) {
			document.getElementById(_item).innerHTML = '<div align="center" style="clear:both; margin:0px;"><img src="' + site_url + 'images/icon-ajax-bg.gif" width="31" height="31" alt="-" /></div>';
		}
		if ( _mode == 3 ) {
			document.getElementById(_item).innerHTML = '<div style="clear:both; margin:0;"><img src="' + site_url + 'images/icon-ajax-small.gif" width="16" height="16" alt="-" /></div>';
		}
	}
}

function hideAJAXicon(_item, _mode) {
	if ( document.getElementById(_item) ) {
		if ( _mode == 1 ) {
			unsetSelected(_item);
		} else {
			document.getElementById(_item).innerHTML = '';
		}
	}
}

function updateMessageForm(req) {
	Spry.Utils.setInnerHTML('message-content', req.xhRequest.responseText);
}

function changePrice(_gid) {
	_str = _gid;
	if ( document.getElementById('product_includeId') ) {
		_str = _str + '&pincId=' + document.getElementById('product_includeId').value;
	}
	if ( document.getElementById('product_sizeId') ) {
		_str = _str + '&psizeId=' + document.getElementById('product_sizeId').value;
	}
	showAJAXicon('product_price', 0);
	Spry.Utils.updateContent('product_price', site_url + 'module/ajax/action_price.php?gid=' + _str);
}
