function modal_win(title,content,width,height,offset_x,offset_y,classname,fixed)
{
	this.gray=new overlay();
	this.gray.add();
	var uniqiddiv=document.createElement('div');
	this.uid=$(uniqiddiv).identify();
    this.sourceObject;
	
	var d=document.createElement('div');
	$(d).addClassName('modal_win');
	
	if (classname)
		$(d).addClassName(classname);
	
	if (fixed==undefined)
		fixed=true;
	
	if (width==undefined || width=='')
		width=$(d).getStyle('width').sub('px','');
	if (height==undefined || height=='')
		height=$(d).getStyle('height').sub('px','');;
	
	vp=document.viewport.getDimensions();
	if (offset_x==undefined || parseInt(offset_x)==0 || offset_x=='center')
		offset_x=(vp.width-width)/2;
	if (offset_y==undefined || parseInt(offset_y)==0 || offset_y=='center')
		offset_y=(vp.height-height)/2;
	
	vps=document.viewport.getScrollOffsets();
	
	if (offset_x<0)
		offset_x=10;
	if (offset_y<0)
		offset_y=10;
	
	if (!fixed)
	{
		offset_x=vps.left+offset_x;
		offset_y=vps.top+offset_y;
	}
	
	if (!fixed)
	{
		$(d).setStyle({
			top: '0',
			left: '0',
			position:'absolute'});
	} else {
		$(d).setStyle({
			top: offset_y+'px',
			left: offset_x+'px'});
	}
	$(d).setStyle({
		width: width+19+'px',
		height: height+'px'
	});
	
	
	
	
	var ifr=document.createElement('iframe');
	$(ifr).setStyle({
		left: offset_x+'px',
		top: offset_y+'px',
		width: width+19+'px',
		height: height+19+'px',
		zIndex:1,
		border:0,
		opacity: "0.1",
		filter: "alpha(opacity=10)"
	});
	$(ifr).setAttribute('allowtransparency', 'true');

	
	var dc=document.createElement('div');
	$(dc).setStyle({
		left: offset_x+'px',
		top: offset_y+'px',
		width: width+19+'px',
		height: height+19+'px',
		zIndex:findHighestZ()+1,
		position:fixed?'fixed':'absolute'
	});
	$(dc).addClassName('win');
	
	
	

	var tb=document.createElement('div');
	$(tb).setStyle(
	{
		width:width+'px'
	});
	$(tb).addClassName('title_box');
	
	var t=document.createElement('div');
	$(t).addClassName('title');
	$(t).innerHTML=title;
	//padding:5px
	$(t).setStyle({width:width-40+4-5+'px'});
	
	var c=document.createElement('div');
	$(c).addClassName('control');
	var ca=document.createElement('a');
	$(ca).addClassName('close_anchor');
	$(ca).setAttribute('id',this.uid+'_ca');
	
	$(ca).innerHTML='Bezár';
	$(ca).href="#";
	
	$(c).insert($(ca));
	$(tb).insert($(c));
	$(tb).insert($(t));
	///$(d).insert($(tb));
	
	/*var cb=document.createElement('div');
	$(cb).setStyle(
	{
		width: width-19+'px',
		height: height-19,
		overflow: 'hidden'
	});*/
	
	//if (Object.isElement(content))
	///	$(cb).insert(content);
	//$(cb).innerHTML=content;
	///$(d).insert($(cb));
	
	//$(g).insert($(d));
	
	$(dc).insert($(ifr));
	
	//frame
	var frame='\
	<div class="w_tlc"></div>\
	<div class="w_tc" id="'+this.uid+'_w_tc"></div>\
	<div class="w_trc"></div>\
	<div class="w_lc" id="'+this.uid+'_w_lc">\
		<div class="w_rc">\
			<div class="w_cont" id="'+this.uid+'_w_cb">\
				'+$(tb).innerHTML+'\
				<br class="clear">\
				<div id="'+this.uid+'_w_cb2">\
				</div>\
			</div>\
		</div>\
	</div>\
	<div class="w_blc"></div>\
	<div class="w_bc" id="'+this.uid+'_w_bc"></div>\
	<div class="w_brc"></div>';
	
	// end of frame	
	$(d).insert(frame);
	

	
	$(dc).insert($(d));
	
	$(document.body).insert($(dc));
	
	$(this.uid+'_w_cb').setStyle({width:width + 'px'});
	$(this.uid+'_w_tc').setStyle({width:width + 'px'});
	$(this.uid+'_w_bc').setStyle({width:width + 'px'});
	$(this.uid+'_w_cb2').setStyle(
	{
		width: width+'px',
		height: height+'px',
		overflow: 'auto'
	});
    
    if (Object.isElement($(content)))
    {
        this.sourceObject=$(content);
        $(content).show();
    } else
        this.sourceObject=false;
	$(this.uid+'_w_cb2').insert(content);
	$(this.uid+'_w_lc').setStyle({width:width+8 + 'px'});
	
	Event.observe($(this.uid+'_ca'),'click',close_modal_win.bindAsEventListener(this));
	Event.observe(window,'keypress',keypress_win.bindAsEventListener(this));
	
	if (window.openwins==undefined)
		window.openwins=new Array();
	window.openwins.push(this);
	
	
	this.obj=$(dc);
	
	this.close=function() {
		this.obj.hide();
        if (Object.isElement($(this.sourceObject)))
        {
            $(document.body).insert(this.sourceObject);
            this.sourceObject.hide();
        }
		$(this).gray.remove();
		$(this).obj.remove();
		
		index=window.openwins.indexOf(this);
		window.openwins.splice(index,1);
	}
	
	
	
	return this;
	
	
	
}

function close_modal_win(event)
{
	Event.stop(event);
	this.obj.hide();
    
    if (Object.isElement($(this.sourceObject)))
    {
        $(document.body).insert(this.sourceObject);
        this.sourceObject.hide();
    }
	
	$(this).gray.remove();
	$(this).obj.remove();
	
	index=window.openwins.indexOf(this);
	window.openwins.splice(index,1);
}

function keypress_win(event)
{
	if (event.keyCode==27 && event.stopped==undefined)
	{
		Event.stop(event); 
		thisi=window.openwins.pop();
		thisi.obj.hide();
		$(thisi).gray.remove();
		$(thisi).obj.remove();
		
	}
}

function overlay()
{
	this.add=add;
	this.remove=remove;
	
	function add()
	{
		var g=document.createElement('div');
		$(g).addClassName('overlay_gray');
		$(g).setStyle({
			zIndex:findHighestZ()+1});
		$(document.body).insert($(g));
		this.obj=$(g);
	}
	
	function remove()
	{
		this.obj.remove();
	}
}
function findHighestZ(obj){  
    var highestIndex = 0;  
    var currentIndex = 0;  
    var elArray = Array();  
    if(obj){ elArray = obj.getElementsByTagName('*'); }else{ elArray = document.getElementsByTagName('*'); }  
    for(var i=0; i < elArray.length; i++){  
       if (elArray[i].currentStyle){  
          currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);  
       }else if(window.getComputedStyle){  
          currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));  
       }  
       if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }  
    }  
    return(highestIndex);  
}  

function show_layer(obj_id)
{
    if (obj_id=='erdeklodo_urlap')
        title='Bővebb információt kérek';
    else
        title='Jelentkezés';
    new modal_win(title,$(obj_id),500,250,(document.viewport.getWidth()-500)/2 ,(document.viewport.getHeight()-250)/2,'jelentkezes_di',true);
}
function IsEmail(field)
{
 //this is a regular expression
 var expr = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
 
 //Check if regexp matches the value in the field
 if(expr.test(field.value))
  return true;
 return false;
} 
