﻿function showBox(html) {
	var fBox=document.getElementById("fBox");
    var shadow=document.getElementById("shadow");
	fBox.innerHTML=html;
    igazit(fBox);
    shadow.style.width = getWidth() + "px";
    var bodyHeight = document.body.offsetHeight
    
    shadow.style.height =  Math.max(bodyHeight, getHeight()) + "px";
	if (fBox.style.visibility=="hidden"){
		fadeIn("fBox",1);
		fadeIn("shadow",0.6);
	}
}

function igazit(elem){
	elem.style.left = (getWidth()-elem.offsetWidth)/2 + "px";
    elem.style.top = (getHeight()-elem.offsetHeight)/2 + getYScroll() + "px";
}
function hideBox(){
	var fBox=document.getElementById("fBox");
    var shadow=document.getElementById("shadow");
	fadeOut("fBox");
	fadeOut("shadow");
}

function fadeIn(elem, to){
	inc=to/3;
	fade(elem, inc, 0, to);
}

function fadeOut(elem){
	from = document.getElementById(elem).style.opacity;
	inc=from/2;
	unfade(elem, inc, from, 0);
}

function fade(elem, inc, start, to){
	if (start < to){
		document.getElementById(elem).style.visibility = "visible";
		currAlpha = start + inc;
		setAlpha(document.getElementById(elem), currAlpha);
		setTimeout("fade('"+elem+"',"+inc+","+currAlpha+","+to+")", 50);
	} else {
		
	}
}

function unfade(elem, inc, start, to){
	if (start > to){
		currAlpha = start - inc;
		setAlpha(document.getElementById(elem), currAlpha);
		setTimeout("unfade('"+elem+"',"+inc+","+currAlpha+","+to+")", 50);
	} else {
		document.getElementById(elem).style.visibility = "hidden";
	}
}

function setAlpha(elem, alpha){
	elem.style.opacity = alpha;
	elem.style.filter = "alpha(opacity=" + (alpha*100) + ")";
}
function getWidth(){
	var scrWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    	scrWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth ) {
    	scrWidth = document.documentElement.clientWidth;
    } else if( document.body && document.body.clientWidth ) { 
    	scrWidth = document.body.clientWidth;
    }
    return scrWidth;
}
function getHeight(){
	var scrHeight = 0;
    if( typeof( window.innerHeight ) == 'number' ) {
    	scrHeight = window.innerHeight;
    } else if( document.documentElement && document.documentElement.clientHeight ) {
    	scrHeight = document.documentElement.clientHeight;
    } else if( document.body && document.body.clientHeight ) { 
    	scrHeight = document.body.clientHeight;
    }
    return scrHeight;
}

function getXScroll(){
	var scrScroll = 0;
    if( typeof( window.pageXOffset ) == 'number' ) {
    	scrScroll = window.pageXOffset;
	} else if( document.body && document.body.scrollLeft ) {
    	scrScroll = document.body.scrollLeft;
	} else if( document.documentElement && document.documentElement.scrollLeft ) {
    	scrScroll= document.documentElement.scrollLeft;
    }
	return scrScroll;
}

function getYScroll(){
	var scrScroll = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
    	scrScroll = window.pageYOffset;
	} else if( document.body && document.body.scrollTop ) {
    	scrScroll = document.body.scrollTop;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
    	scrScroll= document.documentElement.scrollTop;
    }
	return scrScroll;
}

function updateAvatar(){
	for (i=document.getElementById('notMember').pos.length-1; i > -1; i--) {
		if (document.getElementById('notMember').pos[i].checked) {
			valasztott = document.getElementById('notMember').pos[i].value
		}
	}
	document.getElementById('finished').src = server_root+"/generate.php?mode=finished&pos=" + valasztott + "&nc=" + Math.random()
}

function hashToPath(hash){
	rethash= dir_avatars + "/" + hash.charAt(0) + "/" + hash.charAt(1) + "/" + hash + ".jpg";
	return rethash;
}

function showURL(hash){
	
    var text ="<input class='kisbetu' type='text' name='url' value='";
    text += server_root + "/" + hashToPath(hash);
    text += "' style='width:350px;' onClick='javascript:this.focus();this.select()' />";
	text += " <a href='javascript:hideBox()' title='Becsuk'><img src='" + server_root + "/img/icons/cancel.png' alt='Becsuk' width='16' height='16' /></a>";
	showBox(text);
}

function addPublic(hash){
	
	var text = "<div style='text-align:right;'><a href='javascript:hideBox()' title='Becsuk'><img src='" + server_root + "/img/icons/cancel.png' alt='Becsuk' width='16' height='16' /></a></div>";
	text += "<div style='float:left; margin-right:20px;'><img src='" + server_root + "/" + hashToPath(hash) + "' alt='Avatar' width='96' height='96' /></div>";
	text += "Biztos, hogy közzé szeretnéd tenni ezt az avatart?<br /><br /><br />";
	text += "<a href=\"javascript:makeGetRequest('addPublic', '"+hash+"', 1);hideBox()\" title='Igen'>Igen</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href='javascript:hideBox()' title='Mégsem'>Mégsem</a>";

	showBox(text);
}

function removePublic(hash){
	
	var text = "<div style='text-align:right;'><a href='javascript:hideBox()' title='Becsuk'><img src='" + server_root + "/img/icons/cancel.png' alt='Becsuk' width='16' height='16' /></a></div>";
	text += "<div style='float:left; margin-right:20px;'><img src='" + server_root + "/" + hashToPath(hash) + "' alt='Avatar' width='96' height='96' /></div>";
	text += "Biztos, hogy ki szeretnéd venni ezt az avatart a közösből?<br /><br /><br />";
	text += "<a href=\"javascript:makeGetRequest('addPublic', '"+hash+"', 0);hideBox()\" title='Igen'>Igen</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href='javascript:hideBox()' title='Mégsem'>Mégsem</a>";

	showBox(text);
}

function deleteAvatar(hash){
	
	var text = "<div style='text-align:right;'><a href='javascript:hideBox()' title='Becsuk'><img src='" + server_root + "/img/icons/cancel.png' alt='Becsuk' width='16' height='16' /></a></div>";
	text += "<div style='float:left; margin-right:20px;'><img src='" + server_root + "/" + hashToPath(hash) + "' alt='Avatar' width='96' height='96' /></div>";
	text += "Biztos, hogy törölni szeretnéd ezt az avatart?<br />";
	text += "Ha így döntesz, az avatar örökre elvész.<br /><br />";
	text += "<a href=\"javascript:makeGetRequest('delete', '"+hash+"');hideBox()\" title='Törlés'>Törlés</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href='javascript:hideBox()' title='Mégsem'>Mégsem</a>";

	showBox(text);
}

function downloadAvatar(hash){
	window.location = server_root + "/letoltes/" + hash + "/";
}

function showAll(hash){
	var text = "<div style='text-align:right;'><a href='javascript:hideBox()' title='Becsuk'><img src='" + server_root + "/img/icons/cancel.png' alt='Becsuk' width='16' height='16' /></a></div><div style='text-align:center;'><img src='" + server_root + "/img/ajax-loader.gif' alt='töltés' width='32' height='32' /></div>";
	showBox(text);
	makeGetRequest('showAll', hash);
}

function addToBox(hash){
	var text = "<div style='text-align:right;'><a href='javascript:hideBox()' title='Becsuk'><img src='" + server_root + "/img/icons/cancel.png' alt='Becsuk' width='16' height='16' /></a></div><div style='text-align:center;'><img src='" + server_root + "/img/ajax-loader.gif' alt='töltés' width='32' height='32' /></div>";
	showBox(text);
	makeGetRequest('changeBox', hash, "add");
}

function removeFromBox(hash){
	var text = "<div style='text-align:right;'><a href='javascript:hideBox()' title='Becsuk'><img src='" + server_root + "/img/icons/cancel.png' alt='Becsuk' width='16' height='16' /></a></div><div style='text-align:center;'><img src='" + server_root + "/img/ajax-loader.gif' alt='töltés' width='32' height='32' /></div>";
	showBox(text);
	makeGetRequest('changeBox', hash, "rem");
}

function submitTags(hash){
	document.getElementById("pipa").innerHTML = "<img src='" + server_root + "/img/ajax-loader.gif' alt='Töltés...' width='32' height='32' style='vertical-align:middle; margin-left:10px;' />";
	var tags = encodeURI(document.getElementById("tagfield").value);
	makeGetRequest('submitTags', hash, tags);
}

function clearPipa(){
	document.getElementById("pipa").innerHTML = "";
}

function sendIdea(){
	var idea = encodeURI(document.getElementById("idea").value)
	makeGetRequest('sendIdea', idea);
}

function switchUserBar(){
	var userBar1=document.getElementById("userbar1");
	var userBar2=document.getElementById("userbar2");
	
	ub = userBar1.innerHTML;
	userBar1.innerHTML = userBar2.innerHTML;
	userBar2.innerHTML = ub;
	
	document.getElementById("loginbar_user").focus();
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function closeFlashLayer(){
	setCookie("closeHotdog","1",30);
	hotdogDiv = document.getElementById("hotdog");
	hotdogDiv.innerHTML = "";

}

function overstars(num){
	clearTimeout(t)
	for(i=1;i<=5;i++){
		if (i<=num){
			document.getElementById("s" + i).src=server_root +"/img/icons/star.png";
		} else {
			document.getElementById("s" + i).src=server_root + "/img/icons/star_grey.png";
		}
	}
}

function outstars(num){
	t=setTimeout("drawstars()", 200);
}

function drawstars(num){
	for(i=1;i<=5;i++){
		document.getElementById("s" + i).src=server_root + "/img/icons/star.png";
	}
}

function votestar(hash, num){
	document.getElementById("szavazobox").innerHTML="<img src='" + server_root + "/img/ajax-loader-blu.gif' alt='Töltés...' width='32' height='32' style='margin:44px 0 0 134px;' />";
	makeGetRequest('votestar', hash, num);
}
var t;

