var iframeopened=0;
var floatboxopened=0;
var iframeheight=0;
var lastopenedfloatbox='';
function createoverflowbox(bwidth, bheight, bpositionx, bpositiony, content, showdirectcont){
	var divnamesadd='';
	if(bwidth=='big'){
		if(lastopenedfloatbox!='big'){
			closefloatbox();
			lastopenedfloatbox='big';
		}
		divnamesadd='big';
	}
	else{
		if(lastopenedfloatbox!='sm'){
			closefloatbox();
			lastopenedfloatbox='sm';
		}
	}
    var floatboxcont=document.getElementById("floatboxcontent"+divnamesadd);
    var dialogbody=document.getElementById("dialogbody"+divnamesadd);
    var height;
    if(bheight=='') bheight=500;
	
    var floatbox=document.getElementById("floatbox"+divnamesadd);
    if(bpositiony!=undefined && bpositiony!=''){
    	if(bpositiony>150) bpositiony=bpositiony-150;
		floatbox.style.top=bpositiony;
	}
    floatbox.style.visibility="visible";
    floatboxopened=1;
    var outp ='';
    var poststr = content;

    if(content.search(/tp=ifr/)>=0){
        if(content.search(/maps/)>0){
		    if(iframeopened==1){
		        var floatboxiframe=document.getElementById("floatboxiframe"+divnamesadd);
	            if(floatboxiframe.src==content) return false;
			}
        }
        var iframeurl='';
        var iframew='520';
        if(bheight=='') var iframeh='500';
        else var iframeh=bheight;
        if(bwidth=='big'){
            iframew='881';
            iframeh='544';
        }
        var floatbox=document.getElementById("floatboxcontainer"+divnamesadd);
        floatbox.style.height=bheight;
        dialogbody.style.height=bheight;
        iframeheight=bheight;
        
        if(content.search(/userdetails/)>0 || content.search(/editprofile/)>0 || content.search(/userfriends/)>0){
        	var scrolling='auto';
        	if(content.search(/editprofile/)>0 || content.search(/userfriends/)>0){
            	iframeh='504';
        	}
       	}
        else var scrolling='no';
        
        if(content.search(/http/)>=0 || content.search(/maps/)>0 || content.search(/userdetails/)>0){
            iframeurl=content;
        }
        else{
        	if(content.search(/usethis/)>=0){
	        	var theurl=content.match(/usethis\:(.*?)$/i);
	        	iframeurl='/?'+theurl[1];
	        }
        	else if(content.search(/usethispath/)>=0){
	        	var theurl=content.match(/usethispath\:(.*?)$/i);
	        	iframeurl=theurl[1];
	        }
	        else{
	            var shm=content.match(/shm=(.*?)&/i);
	            var op=content.match(/op=(.*?)&/i);
	            var reason='';            
	            var mainwurl=escape(self.location.href);
	            if(content.match(/reason=(.*?)&/i)){
	                var reasonmatch=content.match(/reason=(.*?)&/i);
	                reason='&reason='+reasonmatch['1'];
	            }
	            if(content.match(/ac=(.*?)&/i)){
	                var acmatch=content.match(/ac=(.*?)&/i);
	                reason=reason+'&ac='+acmatch['1'];
	            }
	            if(content.match(/send2user=(.*?)&/i)){
	                var send2usermatch=content.match(/send2user=(.*?)&/i);
	                reason=reason+'&send2user='+send2usermatch['1'];
	            }
	            iframeurl='/?globalm='+shm['1']+'&op='+op['1']+reason+'&outptp=ifr&vpos='+bpositiony+'&mainwurl='+mainwurl+'';
	        }   
        }
        
        floatboxcont.innerHTML='<iframe id="floatboxiframe'+divnamesadd+'" src="'+iframeurl+'" allowtransparency="true" width="'+iframew+'" height="'+iframeh+'" scrolling="'+scrolling+'" frameborder=0></iframe>';
        
        iframeopened=1;
    }
    else if(showdirectcont!= undefined && showdirectcont!=''){
    	iframeopened=0;
    	floatboxcont.innerHTML='';
    	floatboxcont.style.height=bheight;
    	dialogbody.style.height=bheight;
    	floatbox.style.height=bheight;
    	floatbox.style.maxHeight=bheight;
    	floatboxcont.style.maxHeight=bheight;
    	floatboxcont.innerHTML=showdirectcont;
    }
    else{
		var browserName=navigator.appName; 
 		if (browserName=="Microsoft Internet Explorer"){
 			bheight=Math.ceil(bheight)+50;
		}
    	iframeopened=0;
    	floatboxcont.innerHTML='';
    	floatboxcont.style.height=bheight;
    	dialogbody.style.height=bheight;
    	floatbox.style.height=bheight;
    	floatbox.style.maxHeight=bheight;
    	floatboxcont.style.maxHeight=bheight;
        makePOSTRequest('/js/getcontentent.php', poststr);
    }   
    return false;
}

function changeiframesize(newheight){
    var floatboxiframe=document.getElementById("floatboxiframe");
    var dialogbody=document.getElementById("dialogbody");
    if(floatboxiframe!=undefined) floatboxiframe.style.height=newheight;
    var floatbox=document.getElementById("floatboxcontainer");
    floatbox.style.height=newheight;
    dialogbody.style.height=newheight;
    iframeheight=newheight;
}

function changefloatboxsize(newheight){
    var dialogbody=document.getElementById("dialogbody");
    dialogbody.style.height=newheight;
}

function closefloatbox(){
	var divadd='';
	if(lastopenedfloatbox=='big') divadd='big';
	else if(lastopenedfloatbox=='sm') divadd='';
	else return;
    var floatbox=document.getElementById("floatbox"+divadd);
    floatbox.style.visibility="hidden";
    floatboxopened=0;
    
    var floatboxcont=document.getElementById("floatboxcontent");
    floatboxcont.innerHTML='';
    
    return false;
}
function getverticalPosition(who){
    var T= 0,L= 0;
    while(who){
        T+= who.offsetTop;
        who= who.offsetParent;
    }
    return T;    
}



var http_request = false;

function makePOSTRequest(url, parameters, alertstr) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1251");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      if(alertstr==1){
    	alert(parameters);
   	}
      http_request.send(parameters);
}

function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            //alert(result);
            eval(result);            
         } else {
            alert('There was a problem with the request.');
         }
      }
}

function checkifvisibleandscroll(elem)
{
    var docViewTop = document.body.scrollTop;
    var divpos=getverticalPosition(elem);
    if(divpos<docViewTop) self.scrollTo(0, divpos-30);    
    
    var docViewBottom = docViewTop + document.body.clientHeight;
    var divbottompos = divpos + elem.offsetHeight;
    if(divbottompos>docViewBottom) self.scrollTo(0, docViewTop+(divbottompos-docViewBottom+20));
}
function closetmpmsgbox(){
    var tmpmsgbox=document.getElementById("tmpmsgbox");
    tmpmsgbox.style.display="none";
	return false;	
}
function htmlspecialchars(vartext){
	vartext = encodeURIComponent(vartext);
    return vartext.replace(/&/g,'%26').replace(/\+/,'%2B').replace(/</g,escape('<')).replace(/>/g,escape('>'));
}
function undohtmlspecialchars(vartext) {
    return vartext.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
}
function openuserdet(userid){
    var tmpmsgbox=document.getElementById("userdets"+userid);
    tmpmsgbox.style.visibility="visible";
	return false;	
} 
function closeuserdet(userid){
    var tmpmsgbox=document.getElementById("userdets"+userid);
    tmpmsgbox.style.visibility="hidden";
	return false;	
}

function shownewsmaplayer(cposdiv, mapid){
    var verticalposition=getverticalPosition(cposdiv);
    createoverflowbox('big', '545', '', verticalposition, "/maps/newsmap.html?globalm=maps&outptp=ifr&mapid="+mapid+"&rand="+maprandcode);
	miniprofileopened=0;
	opennonusermap=1;
	return false;
}
function hidemaplayer(){
	var srcray=document.getElementById("maplayer");
	srcray.style.display="none";
	mapopened=0;
	if(opennonusermap==undefined || opennonusermap!=0) setcplace('refreshmenu');
	if(miniprofileopened==2){
		showminiprofileedit();
	}
	return false;
}

/* trqbva da se ipravi za da bachka png transiton-a

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
    document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
    window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
    var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
    var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

    for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
        if (itsAllGood && img.src.match(/\.png$/i) != null) {
            fnFixPng(img);
            img.attachEvent("onpropertychange", fnPropertyChanged);
        }
        img.style.visibility = "visible";
    }

    var nl = document.getElementsByTagName("INPUT");
    for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
        if (e.className && e.className.match(/\bimage\b/i) != null) {
            if (e.src.match(/\.png$/i) != null) {
                fnFixPng(e);
                e.attachEvent("onpropertychange", fnPropertyChanged);
            }
            e.style.visibility = "visible";
        }
    }
}

function fnPropertyChanged() {
    if (window.event.propertyName == "src") {
        var el = window.event.srcElement;
        if (!el.src.match(/img\/spacer\.gif$/i)) {
            el.filters.item(0).src = el.src;
            el.src = "http://i.id24.bg/img/spacer.gif";
        }
    }
}

function dbg(o) {
    var s = "";
    var i = 0;
    for (var p in o) {
        s += p + ": " + o[p] + "\n";
        if (++i % 10 == 0) {
            alert(s);
            s = "";
        }
    }
    alert(s);
}

function fnFixPng(img) {
    var src = img.src;
    img.style.width = img.width + "px";
    img.style.height = img.height + "px";
    img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
    img.src = "img/spacer.gif";
}

*/



/**
* DD_belatedPNG: Adds IE6 support: PNG images for CSS background-image and HTML <IMG/>.
* Author: Drew Diller
* Email: drew.diller@gmail.com
* URL: http://www.dillerdesign.com/experiment/DD_belatedPNG/
* Version: 0.0.8a
* Licensed under the MIT License: http://dillerdesign.com/experiment/DD_belatedPNG/#license
*
* Example usage:
* DD_belatedPNG.fix('.png_bg'); // argument is a CSS selector
* DD_belatedPNG.fixPng( someNode ); // argument is an HTMLDomElement
**/

/*
PLEASE READ:
Absolutely everything in this script is SILLY.  I know this.  IE's rendering of certain pixels doesn't make sense, so neither does this code!
*/