var wnd;

function showwnd(url,wnd,width,height)
{
	return window.open(url,'',"width="+width+",height="+height+",left="+((screen.width-width)/2)+",top="+((screen.height-height)/2));
}
function showChatWindow(userid)
{
    var width=600;
    var height=500;
    
    var wnd= window.open("",'chat_'+userid,"width="+width+",height="+height+",left="+((screen.width-width)/2)+",top="+((screen.height-height)/2)+",toolbar=0,location=0,menubar=0,directories=0,resizable=0");
    
    if (wnd.closedchannel!=null) {
        //alert('Már van chat ablak nyitva ezzel a felhasználóval!');
        wnd.focus();
     } else {
        wnd.document.location.href="chat.php?act=newchannel&userid="+userid;
        wnd.focus();
        //window.open("chat.php?act=newchannel&userid="+userid,'chat_'+userid,"width="+width+",height="+height+",left="+((screen.width-width)/2)+",top="+((screen.height-height)/2)+",toolbar=0,location=0,menubar=0,directories=0,resizable=0");
    }
}

function changeCheckBox(control,checked) {
    if (checked==2) {
        var val=document.getElementById(control).checked;
        if (val==true) val=false; else val=true;
    } else {
        val=(checked==0)?false:true;
    }

    document.getElementById(control).checked=val;
    document.getElementById(control+"_img").src="http://static.talalka.hu/"+(val?"checkbox_on.gif":"checkbox_off.gif");
    
}

function changeCheckBox2(control)
{
    var ch = document.getElementById(control).checked;
    document.getElementById(control).checked = (ch)?false:true;
    document.getElementById(control+"_img").src="http://static.talalka.hu/"+((ch)?"checkbox_off.gif":"checkbox_on.gif");
}

function RefreshGemius()
{
   gemius_hit(pp_gemius_identifier.replace('USED_',''));
}


function reload_median() {
	var same=Math.floor(Math.random()*1000000);
	same=same+sameext;
	document.getElementById("median").innerHTML='<!-- Medián WebAudit Mellesleg Network Találka.hu 1/2 --><img style="position:absolute;top:-100px;left:-100px" src="http://audit.median.hu/cgi-bin/track.cgi?uc=11775870501153&dc=1&ui='+same+'" width="1" height="1">';
    RefreshGemius();
}

var usercards=new Array();
var activeUserCard=0;

function showUserCard(userid) {
	if (userid>0) {
		if (usercards[userid]!=null) {
			activeUserCard=userid;
			Element.update('usercardDiv',usercards[userid]);
			TagToTip('usercardDiv',COPYCONTENT,false);
			return;
		}
		$('usercardDiv').innerHTML=$('usercardWaiting').innerHTML;
		activeUserCard=userid;
		TagToTip('usercardDiv', COPYCONTENT, false);
	}
}

function showUserCard_Completed(response) {
	if (response!=null && response.responseXML!=null) {
		card=response.responseXML.getElementsByTagName("card")[0];
        
        if (card!=null) {
            userid=card.getElementsByTagName("userid")[0].firstChild.data;
            data=card.getElementsByTagName("data")[0].firstChild.data;

            if (userid!=null && data!=null) {
				usercards[userid]=data;

				if (activeUserCard==userid) {
					$('usercardDiv').innerHTML=data;
				}
            }
		}
	}
}

var popup_data=null;
/* Megjelenít egy popup ablakot */
function showPopup(url, width, height) {
    if (popup_data!=null) hidePopup();
    
    var dim=getWindowDimension();
    var scroll=window.pageYOffset ? window.pageYOffset : 
		document.documentElement ? document.documentElement.scrollTop : 
		document.body ? document.body.scrollTop : 0;
	var div=NewTag('div',document.body);
    div.style.position='absolute';
    div.style.top='0px';
    div.style.left='0px';
    div.style.width='100%';
    div.style.height=getDocumentHeight()+"px";
    div.style.zIndex=10000;
    div.style.background='black';
    SetOpac(div,60);

    var ifr=NewTag('iframe',document.body);
    ifr.style.position="absolute";
    ifr.style.top=Math.max(0,(scroll+(dim.h-height)/2))+'px';
    ifr.style.left=Math.max(0,((dim.w-width)/2))+'px';
    ifr.style.zIndex=10001;
    ifr.style.width=(width-5)+'px';
    ifr.style.height=(height-5)+'px';
    
    var content=NewTag('div',document.body);
    content.style.position="absolute";
    content.style.top=Math.max(0,(scroll+(dim.h-height)/2))+'px';
    content.style.left=Math.max(0,((dim.w-width)/2))+'px';
    content.style.zIndex=10002;
    content.style.width=width+'px';
    content.style.height=height+'px';
    content.style.background='#503e1e';
    content.style.overflow='hidden';
    content.style.border="1px solid white";
    
    var content2=NewTag('div',content);
    content2.style.width=(width-14)+'px';
    content2.style.height=(height-14)+'px';
    content2.id="popupcontent";
    content2.style.background='white';
    content2.style.overflow='hidden';
    content2.style.margin="2px";
    content2.style.padding= '5px';
    
    popup_data={'backgrnd': div, 'iframe': ifr, 'content': content};
    
    new Ajax.Updater("popupcontent",url,{method: 'get',evalScripts: true});
    reload_median();
}

function hidePopup(callback,param) {
    if (popup_data!=null) {
        document.body.removeChild(popup_data.backgrnd);
        document.body.removeChild(popup_data.iframe);
        document.body.removeChild(popup_data.content);
        delete popup_data;
        popup_data=null;
    }
    if (callback!=null) callback(param);
}


function getWindowDimension() {
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        w = window.innerWidth;
        h = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        w = document.documentElement.clientWidth;
        h = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    return {w:w,h:h};
}

function getDocumentHeight() {
    var htmlheight = document.body.parentNode.scrollHeight; 
    var windowheight = window.innerHeight; 
    if ( htmlheight < windowheight ) { return windowheight; } 
    else { return htmlheight; } 
}

//DOM objektumkezelő függvények
function InsertBefore (pParent, pChild, pBefore)
{
    var a = new Array ();
    var c = pParent.firstChild;
    while (c!=null) {
        if (c == pBefore) break;
        c = c.nextSibling;
    }

    while (c!=null) {
        a[a.length] = c;
        c = c.nextSibling;
    }

    var i = 0;
    for (i = 0; i < a.length; i++) {
        pParent.removeChild(a[i]);
    }
    pParent.appendChild(pChild);
    for (i = 0; i < a.length; i++) {
        pParent.appendChild(a[i]);
    }

    delete a;
}

function RefreshChildren (pParent) {
    var a = new Array ();
    var c = pParent.firstChild;
    while (c!=null) {
        a[a.length] = c;
        c = c.nextSibling;
    }
    var i = 0;
    for (i = 0; i < a.length; i++) {
        pParent.removeChild(a[i]);
    }

    for (i = 0; i < a.length; i++) {
        pParent.appendChild(a[i]);
    }

    delete a;
}

function AddTag(pChild, pParent, pBefore) {
    if(pBefore != undefined) InsertBefore (pParent, pChild, pBefore);
    else pParent.appendChild(pChild);
}

function NewTag(id, pParent, pBefore) {
    var tag = document.createElement(id);
    if(pParent != undefined) AddTag(tag, pParent, pBefore);
    return tag;
}

function NewTextTag(text, pParent, pBefore) {
    var tag = document.createTextNode(text);
    if(pParent != undefined) AddTag(tag, pParent, pBefore);
    return tag;
}

function SetOpac (block,value) {
	block.style.opacity = value/100;
	block.style.filter = 'alpha(opacity=' + value + ')';
}


/* Megjelenít egy képet a képernyő közepén (a többit elsötétíti*/
function showPicture(url) {
    var dim=getWindowDimension();
    var scroll=window.pageYOffset ? window.pageYOffset :
		document.documentElement ? document.documentElement.scrollTop :
		document.body ? document.body.scrollTop : 0;
	var div=NewTag('div',document.body);
    div.style.position='absolute';
    div.style.top='0px';
    div.style.left='0px';
    div.style.width='100%';
    div.style.height=getDocumentHeight()+"px";
    div.style.zIndex=10000;
    div.style.background='black';
    SetOpac(div,60);

    var img=NewTag('img',document.body);
    img.src=url;
    img.style.position='absolute';
    var he=((dim.h-500)/dim.h/2)*100;
    var we=((dim.w-500)/dim.w/2)*100;
    img.style.top=(scroll+(dim.h-500)/2)+'px';
    img.style.left=((dim.w-500)/2)+'px';
    img.style.zIndex=10002;
    img.style.border="1px solid white";

    /*img.style.padding="1px";*/
    img.style.cursor="pointer";
    img.style.margin="auto";
    img.style.width="";
    img.style.height="";


    img.onclick=function() {
        document.body.removeChild(div);
        document.body.removeChild(this);
        document.body.removeChild(ifr);
    }

    img.onload=function() {
    	ifr.style.width=(img.width+2)+'px';
    	ifr.style.height=(img.height+2)+'px';
    	ifr.style.border="0px";
    	ifr.style.background="white";
    	//ifr.style.display="block";
    	img.style.border="1px solid white";
    }

    var ifr=NewTag('iframe',document.body);
    ifr.style.position="absolute";
    ifr.style.top=(scroll+(dim.h-500)/2)+'px';
    ifr.style.left=((dim.w-500)/2)+'px';
    ifr.style.zIndex=10001;
    ifr.style.width=img.width;
    ifr.style.height=img.height;

    //ifr.style.display="none";
    reload_median();
}


function  showPicture2(url)
 {
    var myAjax = new Ajax.Request( url, { method: 'post', onComplete: function(response){
        showPicture(response.responseText)
        } });

 }

/*Képgaléria*/
function openGalleryWithImage(imageid) {
	showwnd('/gallery.php?imageid='+imageid,'', 639,630);
}
function openGalleryWithFolder(folderid) {
	showwnd('/gallery.php?folderid='+folderid,'', 639,630);
}
/*
'style': {
            'position' : 'absolute'
            ,'width' : '100%'
            ,'height' : getDocumentHeight+'px'
            ,'background-color' : '#000000'
            ,'display' : 'none'
        }*/

function showAlert()
{
    var div = new Element('div',{
        id : 'alertPopupDiv'
    });
    div.setStyle({
        backgroundColor : '#000000'
        ,width : '100%'
        ,height : getDocumentHeight()+"px"
        ,position : 'absolute'
        ,top : 0
        ,left : 0
        ,zIndex : 9999
    });
    div.setOpacity(0.5);
    
    var div2 = new Element('div', {
        id : 'contentContainer'
        ,'class' : 'cf'
    });
    div2.setStyle({
        width: '100%'
        ,position: 'absolute'
        ,top:0
        ,left:0
        ,zIndex:10000
    });
    
    var content = new Element('div', {
        id : 'alertPopupContent'
        ,'class' : 'main_infobox'
    });
    content.setStyle({
        margin:"300px auto"
    });
    
    var header = new Element('div', {
        'class' : 'main_infobox_header'
    });
    header.update('PRÉMIUM AKCIÓ!');
    
    var text = new Element('div', {
        'class' : 'main_infobox_item cf'
    });
    
    
    text.setStyle({
         width: '94%'
        ,height: '113px'
        ,textAlign: 'justify'
        ,paddingBottom: '0px'
    });
    text.update("<b>Szia!</b><br>Hallottad már a nagy hírt?<br>Képzeld, a Találkán <b>CSAK 250 Ft+Áfá</b>ba kerül a Prémium tagság egy hónapra! Ennél már csak egy jobb van, az éves előfizetés (1600+Áfa)! Nekem is ilyen van, és képzeld: korlátlanul levelezhetek, flörtölhetek és böngészhetek a felhasználók között! Annyi jó arcot ismertem meg, hogy el sem hinnéd! Gyere, fizess elő Te is");
    
   
    
    
    var alertContainer = new Element('div', {
        id : 'alertContainer'
    });
    
    var closeLink = new Element('a', {
        href: 'javascript:void(0)'
    });
    closeLink.update("Bezár");
    closeLink.setStyle({
        cssFloat: 'right'
        ,marginRight: '20px'
    });
    closeLink.observe('click', closePopup);
    
    content.insert(header);
    content.insert(text);
    content.insert(closeLink);
    div2.insert(content);
    //document.body.appendChild(div);
    //document.body.appendChild(div2);
    $('body').insert(div);
    $('body').insert(div2);
    reload_median();
}

function closePopup(event)
{
    Element.remove('alertPopupDiv');
    Element.remove('contentContainer');
}
