function boxOpen(_link,_width,_height,_button)
{
	parentDiv = document.createElement("div");
	
	maskDiv = document.createElement("div");
	maskDiv.style.position='absolute';
	maskDiv.style.backgroundColor="grey";
	maskDiv.style.width='100%';
	maskDiv.style.zIndex='1';
	maskDiv.style.opacity='0.5';
	maskDiv.style.height='300%';
	maskDiv.style.overflow='hidden';
	maskDiv.id='popup_mask';
	
	formDiv = document.createElement("div");
	formDiv.id='popup_inner';
	formDiv.style.paddingBottom='15px';
	formDiv.style.left=(getWindowWidth()-_width)/2+'px';
	formDiv.style.top=f_scrollTop()+(getWindowHeight()-_height-35)/2+'px';
	formDiv.innerHTML="<iframe id='popup_iframe' src='"+_link+"' style='width:"+_width+"px; height:"+_height+"px' scrolling='no'></iframe><br/>";
	formDiv.appendChild(boxButton(_button));
	
	document.body.insertBefore(parentDiv, document.body.firstChild);
	document.body.insertBefore(maskDiv, parentDiv);
	document.body.insertBefore(formDiv, maskDiv);
}

function boxButton(_type)
{
	buttonDiv=document.getElementById('popup_button');
	if(!buttonDiv)
	{
		buttonDiv = document.createElement("div");
		buttonDiv.style.textAlign='center';
		buttonDiv.id='popup_button';
	}
	
	switch(_type)
	{
		case 0:
			buttonDiv.innerHTML="";
			break;
		case 1:
			buttonDiv.innerHTML="<input type='button' value='"+BOX_CLOSE+"' onclick='boxClose()'>";
			break;
		case 2:
			buttonDiv.innerHTML="<input type='button' value='"+BOX_SEND+"' onclick='boxSend(150)'>";
			buttonDiv.innerHTML=buttonDiv.innerHTML+"<input style='margin-left: 30px' type='button' value='"+BOX_CANCEL+"' onclick='boxClose()'>";
			break;
	}
	return buttonDiv;
}

function boxSend(_height)
{	
	var myi = document.getElementById("popup_iframe");
	myf = myi.contentWindow.document || myi.contentDocument;
	
	initSrc=myi.src;
	//if(myf.valid_form(myf.getElementById('form_mail')))
		myf.getElementById('form_mail').submit();
	
	boxSent(initSrc,myi,_height);
}

var myTimer;
function boxSent(initSrc,myi,_height)
{
	myf = myi.contentWindow.document || myi.contentDocument;
	
	if(initSrc==myf.location)
		myTimer=setTimeout(function() {boxSent(initSrc,myi,_height);}, 100);
	else
	{
		window.clearTimeout(myTimer);
		myi.style.height=_height+'px';
		boxButton(1);
	}
}
   
function boxClose()
{
	var myChild=document.getElementById('popup_inner');
	if(myChild){
		var myParent=myChild.parentNode;
		myParent.removeChild(myChild);}
	
	var myChild=document.getElementById('popup_mask');
	if(myChild){
		var myParent=myChild.parentNode;
		myParent.removeChild(myChild);}
}



function getWindowHeight() {
    var h = 0;
    if (typeof(window.innerHeight) == 'number') { // Netscape
        h = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        h = document.documentElement.clientHeight;
    } else if (document.body && document.body.offsetHeight) { //client
        h = document.body.offsetHeight;
    }
    return h;
}


function getWindowWidth() {
    var w = 0;
    if (typeof(window.innerWidth) == 'number') { // Netscape
        w = window.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth) {
        w = document.documentElement.clientWidth;
    } else if (document.body && document.body.offsetWidth) { //client
        w = document.body.offsetWidth;
    }
    return w;
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
