          Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==). 
        if (this[i] == value) {
            return true;
        }
    }
    return false;
}
     
     Array.prototype.clear = function () {
    this.length = 0;
};
     
     Array.prototype.remove = function (element) {
	var result = false;
	var array = [];
	for (var i = 0; i < this.length; i++) {
		if (this[i] == element) {
			result = true;
		} else {
			array.push(this[i]);
		}
	}
	this.clear();
	for (var i = 0; i < array.length; i++) {
		this.push(array[i]);
	}
	array = null;
	return result;
};     
        
          
          function collectorSelect(selectNodeId,collectorNodeId,inputNodeId) {
          	this.selectNode = document.getElementById(selectNodeId);
          	this.inputNode = document.getElementById(inputNodeId);
          	this.collectorDivNode = document.getElementById(collectorNodeId);
       		this.collectorAr = [];
       		this.newNameAr = [];
       		this.newNameTempCount = 0;
       
       		var self = this;
       		var i;

     
       		this.add = function(obj) {
       			if (!obj) {
       				var selectedIndex = this.selectNode.selectedIndex;
       				optionNode = document.getElementById('szerzotarsak').options[selectedIndex] ;  
       			} else {
					optionNode = obj;
       			}
       			if (!this.collectorAr.inArray(optionNode.value)) {
       				this.collectorAr.push(optionNode.value);       					
       				var newCollectorNode = this.createCollectorItem(optionNode);
       				this.collectorDivNode.appendChild(newCollectorNode);
       				optionNode.style.color = "white";
       				optionNode.style.backgroundColor = "blue";
       				optionNode.selected = true;
       			}
       			
       		}
       		
       		this.addFromInput = function() {
       			var newText = this.inputNode.value;
       			var newTextAr = newText.split(",")
				var optionsAr = this.selectNode.getElementsByTagName("OPTION");
				var vanSelectben = false;
				
				
				for (nameI = 0; nameI < newTextAr.length; nameI++) {
					if (newTextAr[nameI] != "") {
						
       					for (i = 0; i < optionsAr.length; i++) {
     						if (optionsAr[i].text == newTextAr[nameI]) {
     							alert("van ilyen felsorolasban");
								vanSelectben = true;
								this.add(optionsAr[i]);
     						}
       					}

       					if (!vanSelectben) {
       						fakeOptionNode = {value : -1* (++this.newNameTempCount),text:newTextAr[nameI]}

       						if (!this.newNameAr.inArray(fakeOptionNode.text)) {
       							
       							this.newNameAr.push(fakeOptionNode.text); 
       							var newCollectorNode = this.createCollectorItem(fakeOptionNode);
       							this.collectorDivNode.appendChild(newCollectorNode);
       						}
       					}       			
					} 
				} // /for nameI
				this.inputNode.value = "";
				
       		}
       		
       		this.remove = function(collectorNode) {
       			if (collectorNode.optionValue < 0) {
       				this.newNameAr.remove(collectorNode.optionText);	
       			} else {
       				this.collectorAr.remove(collectorNode.optionValue);       				
       			}
       			this.collectorDivNode.removeChild(collectorNode);
       			
       			var optionsAr = this.selectNode.getElementsByTagName("OPTION");
       			for (i = 0; i < optionsAr.length; i++) {
     				if (optionsAr[i].value == collectorNode.optionValue) {
     					optionsAr[i].style.color = "";
     					optionsAr[i].style.backgroundColor = "";
     					optionsAr[i].selected = false;
     				}
       			}
       		}
       		
       		this.createCollectorItem = function(optionNode) {
       			var newNode = document.createElement("DIV");
       			newNode.setAttribute("class","collectorNode");
       			newNode.setAttribute("className","collectorNode");
       			newNode.optionValue = optionNode.value;
       			newNode.optionText = optionNode.text;
       			
       			var newDivNode = document.createElement("DIV");
       			newDivNode.setAttribute("class","collectorNodeText");
       			newDivNode.setAttribute("className","collectorNodeText");
       			var textNode = document.createTextNode(optionNode.text);
				newDivNode.appendChild(textNode);       			
       			
       			var delButtonNode = document.createElement("INPUT");
       			delButtonNode.type = "button";
       			delButtonNode.setAttribute("class","del");       			
       			delButtonNode.setAttribute("className","del");       			
       			delButtonNode.value = "Töröl";
       			delButtonNode.onclick = function() {
       				self.remove(newNode);
       			}

				newNode.appendChild(delButtonNode);       			
				newNode.appendChild(newDivNode);       			

       			return newNode;
       		}
       		
       		this.onload = function() {
				if (this.inputNode.value.indexOf("nincsen") == -1) {
					this.addFromInput();
				
        			var optionsAr = this.selectNode.getElementsByTagName("OPTION");
       				for (i = 0; i < optionsAr.length; i++) {
     					if (optionsAr[i].selected) {
							this.add(optionsAr[i]);    					
     					}
       				}
       			}
       		}
       		
       		this.onsubmit = function() {
				if (
					(this.newNameAr.length == 0 && this.collectorAr.length == 0) &&
					(this.inputNode.value.indexOf("nincsen") == -1)) {
					alert(" A szerző társak mező kitöltése kötelező!\n\n Amennyiben szerzőtársak nincsenek, beírandó '<<nincsenek>>'.\n Ha egy adott munkában a résztvevő szerzőtársak közül valamely restaurátort nem tüntetik fel, és a munkát publikáló kolléga azt észrevételezés esetén sem korrigálja, úgy az érintettek a Restaurátorkamara Etikai Bizottságához fordulhatnak sérelmükkel. A Kamara kötelez a jogsértés megszüntetésére - a jogsértő felhasználó honlapjának hozzáférését mindaddig szünetelteti, míg a bejelentés orvoslást nem nyer.");	
					return false;
				} else {
       				this.inputNode.value = this.newNameAr.join(",");
				
       				var optionsAr = this.selectNode.getElementsByTagName("OPTION");
       				for (i = 0; i < optionsAr.length; i++) {
     					if (this.collectorAr.inArray(optionsAr[i].value)) {
     						optionsAr[i].selected = true;
     					}
       				}
				}

       			

       		}
       		this.onload();
          }








function ocBody(node) {
	var itemNode = node.parentNode.parentNode.parentNode;
	var buttonNode = node.parentNode;
	var childDivs = itemNode.getElementsByTagName("DIV");
	var bodyNode = false;
	for (var i = 0; (i<childDivs.length && bodyNode==false); i++) {
		if (className("check",childDivs[i],"body")) {
			bodyNode = childDivs[i];
		}
	}
	if (className("check",bodyNode,"bodyClose")) {
		className("remove",bodyNode,"bodyClose");
		className("remove",buttonNode,"ocButtonOpen");
	} else {
		className("add",bodyNode,"bodyClose");
		className("add",buttonNode,"ocButtonOpen");	
	}
	
	return false;

}


// http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
function className(a,o,c1,c2)
{
  switch (a){
    case 'swap':
      o.className=!className('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
    break;
    case 'add':
      if(!className('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}



var tags = new Array( 'div','td','tr','p','b','table','strong','emphasis','a','h1','h2','h3','pre','sub','sup','i','th','cp','ul','ol','li','dt','dd','span');
var pixelArray =  new Array('10','12','14');
var emArray =  new Array('0.7','0.9','1.0');
var initSize = 1;

var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function fontSizer(inc,unit) {
	if (!document.getElementById)return;
	var size = initSize;
	size =	parseInt(size)+parseInt(inc);
	if (size < 0 ) {
		size = 0;
	}
	if (size > 2 ) {
		size = 2;
	}
	
	initSize = size;
	getBody = document.getElementsByTagName('body')[0];
	for (i = 0 ; i < tags.length ; i++ ) {
		getallTags = getBody.getElementsByTagName(tags[i]);
		for (k = 0 ; k < getallTags.length ; k++) {
			if (!className("check",getallTags[k],"chapter")) {
				getallTags[k].style.fontSize = (unit=='px') ? pixelArray[size]+unit: emArray[size]+unit;
			}
		}
	}
	SetCookie('FontSize2', size);
}
function meretezo(size,unit) {
	initSize = size;  
	getBody = document.getElementsByTagName('body')[0];
	for (i = 0 ; i < tags.length ; i++ ) {
		getallTags = getBody.getElementsByTagName(tags[i]);
		for (k = 0 ; k < getallTags.length ; k++) {
			if (!className("check",getallTags[k],"chapter")) {
				getallTags[k].style.fontSize = (unit=='px') ? pixelArray[size]+unit: emArray[size]+unit;
			}
		}	
	}
}
function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = "/";
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + value + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((secure == true) ? "; secure" : "");
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1) endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}
