function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
  }
  if (window.ActiveXObject)
  {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  window.alert ("Kérjük frissítse böngészőjét egy modernebbre!");  
  return null;
}

function ajax_do (url, id, nincsfolyamatban, posthandler) {

  var xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null) return;

  if((id)&&(id!="")&&(!nincsfolyamatban)) {
    var x = document.getElementById(id);
	if (x)
	  x.innerHTML = "folyamatban...";
  }
  
  xmlhttp.onreadystatechange=function()
  {
    if(xmlhttp.readyState==4)
    {
       if(!posthandler) {

	  if((id=="")||(xmlhttp.responseText.match(/(location\s*=|window\.alert)/))) {
        eval(xmlhttp.responseText);
	  } else {
  	        document.getElementById(id).innerHTML = xmlhttp.responseText;	  
	  }
       } else posthandler(xmlhttp.responseText);
    }
  }  

  xmlhttp.open("GET", url);  
  xmlhttp.send(null);

	return true;
}

function setpicstatus(prop, value, ids) {
  var idst = "";
  for (i = 0; i < ids.length; i++) {
    idst += "id"+i+"="+ids[i]+"&";
  }
  var url = "/index.php?op=setpic&type="+prop+"&value="+Number(value)+"&idsc="+ids.length+"&"+idst;
  //alert(url);
  ajax_do(url,"",1);
  alert('Ok.');
}
function setallcheckbox(prop, checked) {
  var e = document.getElementsByName(prop);
  var r = new Array();
  for (i = 0; i < e.length; i++) {
	  e[i].checked = checked;
	  r.push(e[i].value);
  }
  setpicstatus(prop, checked, r);
}
function setswfu(name , value) {
  swfu.addPostParam(name, value);
}

function fileQueueError(file, errorCode, message) {
	try {
		var errorName = "";
		switch (errorCode) {
		case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
		    errorName = "Túl sok fájlt pakoltál be egyszerre!";
			break;
		case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
			errorName = "A(z) "+file.name+" fájl mérete meghaladja a limitet!";
			break;
		}
		
		if (errorName != "")
		  window.alert(errorName);

	} catch (ex) {
		this.debug(ex);
	}

}

function fileDialogComplete(numFilesSelected, numFilesQueued) {
	try {
		if (numFilesQueued > 0) {
		    swfu.setButtonDisabled(true);
			this.startUpload();
		} 
		else
		    swfu.setButtonDisabled(false);		
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadProgress(file, bytesLoaded) {

	try {
		var percent = Math.ceil((bytesLoaded / file.size) * 100);

		var progress = new FileProgress(file,  this.customSettings.upload_target);
		progress.setProgress(percent);
		if (percent === 100) {
			progress.setStatus("Dolgozik a szerver...");
			progress.toggleCancel(false, this);
		} else {
			progress.setStatus("Feltöltés...");
			progress.toggleCancel(true, this);
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadSuccess(file, serverData) {
	try {
	   if(file)
		var progress = new FileProgress(file,  this.customSettings.upload_target);

           var v = document.getElementById("eredmeny");
           if (v) 
              v.innerHTML = serverData + v.innerHTML ;
           v = document.getElementById("eredmenyheader");
           if (v) 
              v.style.display = "";
			v = document.getElementById("plainurls");
			if(v) {
                          v.style.display = "";
  			  var re = new RegExp(/value="([^"]+)"/);
			  var m = re.exec(serverData);
                          var t = m[1];
                          t = t.replace(/&lt;/g, "<" );
                          t = t.replace(/&gt;/g, ">" );
			  v.value += "<p>" + t + "</p>\n";
			}

	} catch (ex) {
		this.debug(ex);
	}
}

function comicLoadImage(url){
			var editor = document.getElementById('editor');
			editor.loadImage(url);
return false;
}

function comicUploadSuccess(file, serverData) {
	try {
			  var re = new RegExp(/img src='([^']+)'/);
			  var m = re.exec(serverData);
                          var t = m[1];
                  comicLoadImage(t);

	} catch (ex) {
		this.debug(ex);
	}
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
  }
  if (window.ActiveXObject)
  {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  window.alert ("Frissitds a browseredet egy modernebbre!");  
  return null;
}

function uploadComplete(file) {
	try {
		/*  I want the next upload to continue automatically so I'll call startUpload here */
		if (this.getStats().files_queued > 0) {
		    swfu.setButtonDisabled(true);		
			this.startUpload();
		} else {
		    swfu.setButtonDisabled(false);		
			var progress = new FileProgress(file,  this.customSettings.upload_target);
			progress.setStatus("Készen is vagyunk!");
			progress.toggleCancel(false);
			progress.setComplete();
                     
                     var v = document.getElementById("email");
                     if((v)&&(v.value != "")) {
                           var xmlhttp=GetXmlHttpObject();
                           if (xmlhttp==null) return;
                           var params = "email="+encodeURIComponent(v.value);
                           xmlhttp.open("POST", "/uploademail.php");  
                           xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                           xmlhttp.setRequestHeader("Content-length", params.length);
                           xmlhttp.setRequestHeader("Connection", "close");
                           xmlhttp.send(params);
                          var e = document.getElementById("eredmeny");
                          if(e) e.innerHTML = e.innerHTML + "<p>Email elment a "+v.value+"-ra!</p>";
                     }
		}
	} catch (ex) {
		this.debug(ex);
	}
}


function uploadError(file, errorCode, message) {
	var progress;
	try {
		progress = new FileProgress(file,  this.customSettings.upload_target);
		progress.setCancelled();
		progress.toggleCancel(false);
		switch (errorCode) {
		case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
			progress.setStatus("Megszakítva");
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
			progress.setStatus("Leállítva");
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
			progress.setStatus("Elérted a feltöltési limitet!");
			break;
		default:
		    progress.setStatus(message);
			break;
		}

	} catch (ex3) {
		this.debug(ex3);
	}

}


function addImage(src) {
	var newImg = document.createElement("img");
	newImg.style.margin = "5px";

	document.getElementById("thumbnails").appendChild(newImg);
	if (newImg.filters) {
		try {
			newImg.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 0;
		} catch (e) {
			// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
			newImg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + 0 + ')';
		}
	} else {
		newImg.style.opacity = 0;
	}

	newImg.onload = function () {
		fadeIn(newImg, 0);
	};
	newImg.src = src;
}

function fadeIn(element, opacity) {
	var reduceOpacityBy = 5;
	var rate = 30;	// 15 fps


	if (opacity < 100) {
		opacity += reduceOpacityBy;
		if (opacity > 100) {
			opacity = 100;
		}

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}

	if (opacity < 100) {
		setTimeout(function () {
			fadeIn(element, opacity);
		}, rate);
	}
}



/* ******************************************
 *	FileProgress Object
 *	Control object for displaying file info
 * ****************************************** */

function FileProgress(file, targetID) {
	this.fileProgressID = "divFileProgress";
	this.fileId = file.id;

	this.fileProgressWrapper = document.getElementById(this.fileProgressID);
	if (!this.fileProgressWrapper) {
		this.fileProgressWrapper = document.createElement("div");
		this.fileProgressWrapper.className = "progressWrapper";
		this.fileProgressWrapper.id = this.fileProgressID;

		this.fileProgressElement = document.createElement("div");
		this.fileProgressElement.className = "progressContainer";

		var progressCancel = document.createElement("a");
		progressCancel.className = "progressCancel";
		progressCancel.href = "#";
		progressCancel.style.visibility = "hidden";
		progressCancel.appendChild(document.createTextNode(" "));
		progressCancel.setAttribute("onClick", "window.alert('hali!')");

		var progressText = document.createElement("div");
		progressText.className = "progressName";
		progressText.appendChild(document.createTextNode(file.name));

		var progressBar = document.createElement("div");
		progressBar.className = "progressBarInProgress";

		var progressStatus = document.createElement("div");
		progressStatus.className = "progressBarStatus";
		progressStatus.innerHTML = "&nbsp;";

		this.fileProgressElement.appendChild(progressCancel);
		this.fileProgressElement.appendChild(progressText);
		this.fileProgressElement.appendChild(progressStatus);
		this.fileProgressElement.appendChild(progressBar);

		this.fileProgressWrapper.appendChild(this.fileProgressElement);

                var targetDiv = document.getElementById(targetID);
                if(targetDiv)
 		  targetDiv.appendChild(this.fileProgressWrapper);
		fadeIn(this.fileProgressWrapper, 0);

	} else {
		this.fileProgressElement = this.fileProgressWrapper.firstChild;
		this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
	}

	this.height = this.fileProgressWrapper.offsetHeight;

}
FileProgress.prototype.setProgress = function (percentage) {
	this.fileProgressElement.className = "progressContainer green";
	this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
	this.fileProgressElement.childNodes[3].style.width = percentage + "%";
};
FileProgress.prototype.setComplete = function () {
	this.fileProgressElement.childNodes[1].innerHTML = "Ennyi!";
	this.fileProgressElement.className = "progressContainer blue";
	this.fileProgressElement.childNodes[3].className = "progressBarComplete";
	this.fileProgressElement.childNodes[3].style.width = "";

};
FileProgress.prototype.setError = function () {
	this.fileProgressElement.className = "progressContainer red";
	this.fileProgressElement.childNodes[3].className = "progressBarError";
	this.fileProgressElement.childNodes[3].style.width = "";

};
FileProgress.prototype.setCancelled = function () {
	this.fileProgressElement.className = "progressContainer";
	this.fileProgressElement.childNodes[3].className = "progressBarError";
	this.fileProgressElement.childNodes[3].style.width = "";

};
FileProgress.prototype.setStatus = function (status) {
	this.fileProgressElement.childNodes[2].innerHTML = status;
};

FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {
	this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
	if (swfuploadInstance) {
		this.fileProgressElement.childNodes[0].onclick = function () {
			swfuploadInstance.cancelUpload();
			return false;
		};
	}
};

function copy(inE)
{
return false;
}

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

