/**
 * Norbert Laposa, 2005, 2008
 *
 */


function nOpenWin(src, width, height) {
	nWixn = window.open(src,'nWin'+unixtime(),'width='+width+',height='+height+',toolbar=0,directories=0,menubar=0,status=no,resizable=1,location=0,scrollbars=1,dialog=0,modal=0');
    nWixn.focus();
}

function openImg(src) {
    url = '/popupimage/' + src;
    nOpenWin(url, 400, 300);
}

function unixtime() {
	var unixtime = new Date().getTime();
	unixtime = unixtime/1000;
	unixtime = parseInt(unixtime);
	return unixtime;
}

function makeAjaxRequest(dom_id, url) {
    $("#" + dom_id).html("<img src='/share/images/ajax-indicator/indicator_verybig.gif' alt='Loading ...'/>").load(url);
}

/*
IE6 BUTTON FIX 
used in 
./component/ecommerce/address_edit.html
./component/ecommerce/basket_edit.html

idea has been given by articel: http://www.peterbe.com/plog/button-tag-in-IE
by Marc Pujol shadow@la3.org
8th February 2006

Modified by Norby, 14/03/2006
Customized for jQuery 16/09/2008
Seems to be still a problem in IE7
*/

//window.onload = button_fix();

function button_fix(onlyInt) {
    if (jQuery.browser.msie) {
        if (parseInt(jQuery.browser.version) < 8) {
            var btns = document.getElementsByTagName('button');
            for(var i=0;i<btns.length;i++) {
                btns[i].onclick = function() {
                    var btns = document.getElementsByTagName('button');
                    for (var i=0;i<btns.length;i++) {
                        if (btns[i] != this) btns[i].disabled = true;
                    }
                    this.style.visibility = "hidden";

                    if (onlyInt == true) this.innerHTML = parseInt(this.className);
                    else this.innerHTML = this.className;
                    return true;
                }
            }
        }
    }
}


/**
 * backoffice
 *
 */
function openEdit(url, el, ajax) {
	if (ajax) {
		openAjaxRequestInDialog(url, '');
	} else {
		nOpenWin(url, 680, 800);
	}
	
}

function openAjaxRequestInDialog(url, title) {
	$('#dialog').dialog( "destroy" );
	$('#dialog').html("<img src='/share/images/ajax-indicator/indicator_verybig.gif' alt='Loading ...'/>").load(url)
	.dialog({
		width: 560, 
		modal: true, 
		overlay: {
			opacity: 0.5, 
			background: 'black'
		}, 
		close: function() {
			$('#dialog').empty()
		},
		title: title
	})
	.dialog('open');
}

function openAjaxRequestInGrowl(url, title) {
	
	$.growl(title, $("#node_properties_edit_result").html("<img src='/share/images/ajax-indicator/indicator_verybig.gif' alt='Loading ...'/>").load(url).html());
	
}



function refreshOpener(orig, id) {
	/*orig = '/{GET.orig}';
	opener.window.location = orig;*/
	newlocation = '/'+orig+'#node_id_'+id;
	opener.window.location.href = newlocation;
	opener.window.location.reload(true);
}

function refreshOpenerAjax(orig, id) {
	if (opener.window.document.getElementById('node_id_'+id)) opener.$('#node_id_'+id).load('/request/node?id=' + id + ' #node_id_'+id+' > *');
	else {
		newlocation = '/'+orig+'#node_id_'+id;
		opener.window.location.href = newlocation;
		opener.window.location.reload(true);
	}
}


$(document).ready(function () {
	$.growl.settings.displayTimeout = 5000;
	$.growl.settings.noticeTemplate = ''
		+ '<div class="nx_messages">'
		+ '<h3>%title%</h3>'
		+ '<p>%message%</p>'
		+ '</div>';
});
