var inputName;

function onLoadFrame(idLoader){
    if ($(idLoader) != null){
            $(idLoader).style.display = "none";
    } else {
        setTimeout("onLoadFrame('loaderID')", 1000);
    }
}

onload = function() {
    var el = document.getElementsByTagName('input');
    if (el.length > 0) {
        for (var i = 0; i < el.length; i++) {
            el[i].onfocus = function() {
                inputName = this.name;
            };
        }
    }
}

function wac_ajax_popup(link, title, close, billingPopup) {
	var frameID = 'wac_ajax_frame';

    var w = 430;
    var h = 240;

    if (billingPopup){
        w = 300;
        h = 390;
    }

    var loaderDiv = new Element('div', {
        id: 'loaderID',
        style:''
    });

    var frameDiv = new Element('div',{
        id: 'frameID',
        style: ''
    });

    var loader = new Element('img',{
		src:"/images/popup-loader.gif",
        id:"popupLoader",
        style:"position:absolute;left:50%;"
    });

    var iframe = new Element('iframe',
        {
			style:'z-index:1000;padding:0;margin:0; background:white; width:' + w + 'px;height:' + h + 'px;overflow: hidden;',
			src: link,
			id: frameID,
			name: frameID,
			border: '0',
			frameborder: '0',
			scrolling: 'no',
			marginwidth: '0',
			marginheight: '0',
            onload: onLoadFrame('loaderID')
    });

    loaderDiv.appendChild(loader);
    frameDiv.appendChild(loaderDiv);
    frameDiv.appendChild(iframe);

    Modalbox.show(frameDiv, {title: title, width: w + 6, height: h + 2, slideDownDuration: 0, slideUpDuration: 0, overlayDuration: 0, resizeDuration: 0}, inputName);
	$('MB_content').setStyle({width: w + 'px'});

	if (close) {
		$('MB_close').update('<span>' + close + '</span>');
	}

	return false;
}
