﻿function dspInlineTAB() {if(navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Opera")!=-1){return 'table';}return 'inline';}
function dspInlineTD() {if(navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Opera")!=-1){return 'table-cell';}return 'inline';}
function dspInlineTR() {if(navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Opera")!=-1){return 'table-row';}return 'inline';}
function dspInlineBD() {if(navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Opera")!=-1){return 'table-row-group';}return 'inline';}
function setTRVisible(b) {if(b) return dspInlineTR();return 'none';}
String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

/**
 * IMAGE BROWSER CODE
 */
function openIMG(imgid) {
	var url = '/ebl/browse?l={oml:value-of name="base_url"}ebl/show_image?ID='+imgid;
	var win = window.open(url,'full_scale','scrollbars=yes, resizable=yes, width=, height=');
	win.focus();
}

function imgBrowser(did, other, img, showURL) {
	IMAGES = new Array(did.length+other.length);
	IMAGE_INDEX = 0;
	BROWSED_IMAGE = img ;
	SHOW_URL = showURL;
	var i = 0;
	while (i<did.length) {
		IMAGES[i] = did[i++];
	}
	var j = 0 ;
	while (j<other.length) {
		IMAGES[i++] = other[j++];
	}
	//alert(img);

	document.write(
	'<table border="0" cellspacing="0" cellpadding="3" width="100%"><tr><td>'+
	'<a href="javascript:prevImage();"><img src="/estatic/img/spec/zseblap/bt_left.gif" border="0" alt="előző"/></a>'+
	'</td><td>'+
	'<a href="javascript:nextImage();"><img src="/estatic/img/spec/zseblap/bt_right.gif" border="0" alt="következő"/></a></td>'+
	'<td><b id="idx_counter">1/'+IMAGES.length+'</b></td><td width="100%"></td><td>'+
	'<a href="javascript:zoomImage()"><img src="/estatic/img/spec/zseblap/bt_full.gif" border="0" alt="nagyítás"/></a>'+
	'</td></tr></table>');
}

function prevImage() {
	if (IMAGES.length>0) {
	IMAGE_INDEX--;
	if (IMAGE_INDEX<0) {
		IMAGE_INDEX = IMAGES.length-1;
	}
	BROWSED_IMAGE.src = SHOW_URL+IMAGES[IMAGE_INDEX];
	idx_counter.innerHTML = (IMAGE_INDEX+1)+'/'+IMAGES.length;
	}
}

function nextImage() {
	if (IMAGES.length>0) {
		IMAGE_INDEX++;
		if (IMAGE_INDEX>=IMAGES.length) {
			IMAGE_INDEX = 0;
		}
		BROWSED_IMAGE.src = SHOW_URL+IMAGES[IMAGE_INDEX];
		idx_counter.innerHTML = (IMAGE_INDEX+1)+'/'+IMAGES.length;
	}
}

function zoomImage() {
	var url = '/estatic/html/popup/zoom.html?IMAGE_INDEX='+IMAGE_INDEX+'&IMAGES=';
	for (var i=0;i<IMAGES.length;i++) {
		if (i>0) {
			url+=',';
		}
		url+="'"+IMAGES[i]+"'";
	}
	var win = window.open(url,'full_scale','scrollbars=yes, status=no, resizable=no, width=804, height=650');
	win.moveTo(25,25);
	win.focus();
}

/**
 * Utils
 */
function selectAll(id, index) {
	var i;var o;var y=true;var s;
	for (i=1;y;i++) {
		s = id+'_'+i;o=document.getElementById(s);
		if (o!=null) {o.selectedIndex = index ;}
		else {y = false ;}
	}
}

function getOptindexByValue(o, val) {
	for (var i=0;i<o.options.length;i++) {
		if (o.options[i].value==val) {
			return i;
		}
	}
	return 0;
}

function checkAll(id, ch) {
	var i;var o;var y=true;var s;
	for (i=1;y;i++) {
		s = id+'_'+i;o=document.getElementById(s);
		if (o!=null) {o.checked = ch ;}
		else {y = false ;}
	}
}
function invertAllChk(id) {
	var i;var o;var y=true;var s;
	for (i=1;y;i++) {
		s = id+'_'+i;o=document.getElementById(s);
		if (o!=null) {o.checked = !o.checked ;}
		else {y = false ;}
	}
}
function toogleAll(ct,id,chk) {
	var i;var o;var s;
	for (i=0;i<=ct;i++) {
		s = id+'_'+i;o=document.getElementById(s);
		if (o!=null) {
			o.checked = chk;
		}
	}
}

// 0 - false, 1 - true, 2 - invert
function recursiveCheck(id,feedBack,t,oNode) {
	var ct = 0;
	if (oNode) {}	else {oNode = document.getElementById(id);}
	if (oNode.tagName && equalsIgnoreCase(oNode.tagName.toUpperCase(),'INPUT') && equalsIgnoreCase(oNode.type,'checkbox')) {
		if (t==2) {
			oNode.checked = !oNode.checked;
		}
		else {
			oNode.checked = t==1;
		}
		if (oNode.checked) ct++;
	}
	if(oNode.hasChildNodes()){
		for(var i=0; i < oNode.childNodes.length; i++){
			ct+=recursiveCheck(null,feedBack,t,oNode.childNodes[i]);
		}
	}
	if (feedBack) {
		var fb=document.getElementById(feedBack);
		if (fb)	fb.innerHTML = ct;
	}
	return ct;
}
function chkChange(feedBack,chk) {
	var fb = document.getElementById(feedBack);
	if (fb) {
		var ct = parseInt(fb.innerHTML);
		if (chk.checked) {ct++;} else {ct--;}
		fb.innerHTML=ct;
	}
}
function equalsIgnoreCase(a,b) {               
  return a.toLowerCase()==b.toLowerCase();
}

function gotoPage(op,opt,sel) {
	window.location = '?op='+op+'&opt='+opt+'&page='+sel.parentNode.previousSibling.firstChild.value;
}

function getLeft(obj) {
	var r = 0;
	if (obj.offsetParent) {	do {
		r += obj.offsetLeft;
	} while (obj = obj.offsetParent);}
	return r;
}
function getTop(obj) {
	var r = 0;
	if (obj.offsetParent) {	do {
		r += obj.offsetTop;
	} while (obj = obj.offsetParent);}
	return r;
}
function getHeight(id) {
	return document.getElementById(id).offsetHeight;
}
function getWidth(id) {
	return document.getElementById(id).offsetWidth;
}

function showHint(id,cont,x0,y0,up) {
	var d = document.getElementById(id);
	d.style.left = getLeft(cont)+x0;
	d.style.top = getTop(cont)+y0;
	d.style.display = 'block';
	if (up) {
		d.style.top = getTop(cont)+y0-getHeight(id);
	}
}
function hideHint(id) {
	var d = document.getElementById(id);
	d.style.display = 'none';
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function parseXml(xmlText){
	if (typeof DOMParser != "undefined") { 
	    // Mozilla, Firefox, and related browsers 
	    var parser=new DOMParser();
	    var doc=parser.parseFromString(xmlText,"text/xml");
	    //alert(text);
	    return doc; 
	}
	return null;
}


/**
 * AJAX Communication
 */
/*function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/

 /* if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}/**/
function getHTTPObject() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    return xmlhttp;
}
var http=null;
function loadFromServer(url,onResp) {
	if (onResp==undefined) {onResp=null;}
	try {
		if (http==null) {
			//alert('create html');
			http = getHTTPObject(); // We create the HTTP Object
		}
		http.open("GET", url+'&rxq='+(Math.floor(Math.random()*500000)), true);
		http.onreadystatechange = function() {try {if (onResp!=null) {onResp();} else {handleHttpResponse();}}catch (err) {}}
		http.send(null);
	}
	catch (err) {
	}
}


