function getItem(theId)
{
    return document.getElementById(theId);
}

function setVariable(varName, newValue)
{
    eval(varName + ' = \'' + newValue + '\';');
}

function confirm_del(url, question)
{
    if(confirm(question))
    {
        location.href = url;
    }
}

function addEvent(obj, evType, fn){
	/* adds an eventListener for browsers which support it
	Written by Scott Andrew: nice one, Scott */
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

Array.prototype.max = function () {
	if (this.length == 0) return undefined;
	var n = Number(this[0]);
	for (var i=1; i<this.length; i++) {n = Math.max(n, this[i])};
	return n;
}

function verScroll(dir, spd, lp)
{
    var oDiv, oContent;
    if (typeof dir != "undefined")
        direction = dir;
	
    if (typeof spd != "undefined")
        speed = spd;
	
    if (typeof lp != "undefined")
        loop = lp;
	
    scrolltimer = null;
    oDiv = eval("document.getElementById('contentLayer')");
    oContent = eval("document.getElementById('thumbsTable')");
    if (loop == true)
    {
        if (direction == "dn")
            oDiv.scrollLeft += speed;
        else
            oDiv.scrollLeft -= speed;
        
        window.status = oDiv.offsetWidth + " " + oContent.offsetWidth + " " + oContent.offsetLeft;
        scrolltimer = setTimeout("verScroll(direction,speed,loop)", 1);
        return oContent.offsetLeft;
    }
    return false;
}

function stopScroll() {
    clearTimeout(scrolltimer);
}

function w_open(url)
{
    window.open(url, '', 'height=600,width=800,status=yes,toolbar=no,menubar=no,location=no,top='+(screen.height/2 - 300)+',left='+(screen.width/2 - 400));
}

function in_array(arr, what) {
	var len = arr.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( arr[x] == what ) return true;
	}
	return false;
}

function toggleDiv(theDiv)
{
	if(getItem(theDiv).style.display=='none')
	{
		getItem(theDiv).style.display = '';
	}
	else
	{
		getItem(theDiv).style.display = 'none';
	}
}

function number_format( number, decimals, dec_point, thousands_sep ) {
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

function stripSpaces(input)
{
	var retval = "";
	var firstNull = true;
	for(i=0;i<input.length;i++)
	{
		if((input.charCodeAt(i) >= 48) && (input.charCodeAt(i) <= 57))
		{
			if(input.charCodeAt(i)!=48)
				firstNull = false;
			if(!firstNull)
				retval += input.charAt(i);
		}
	}
	return retval;
}

function formatPrice(obj)
{
	obj.value = number_format(parseInt(stripSpaces(obj.value)), 0, '', ' ');
}

function resize_page_elements()
{
	var leftHeight = getItem("leftcolumn").offsetHeight;
	var centerHeight = getItem("centercolumn").offsetHeight;
	var rightHeight = getItem("rightcolumn").offsetHeight;
	//alert(leftHeight);
	if(leftHeight < 500)
	{
		getItem("leftcolumn").style.height = '500px'
	}
	if(leftHeight > centerHeight)
	{
		getItem("centercolumn").style.height = leftHeight;
		if(leftHeight > rightHeight)
		{
		    getItem("rightcolumn").style.height = leftHeight;
		}
		else
		{
			getItem("centercolumn").style.height = rightHeight;
			getItem("leftcolumn").style.height = rightHeight;
		}
	}
	else
	{
		getItem("leftcolumn").style.height = centerHeight;
		if(leftHeight > rightHeight)
		{
			getItem("rightcolumn").style.height = leftHeight;
		}
	}
}





function setPopup(tipus,allapot)
{
   if (window.XMLHttpRequest)
   {   
      xmlhttp=new XMLHttpRequest();
   }
   else
   {  
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
		
   xmlhttp.onreadystatechange=function()
   {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
         document.getElementById('popup').innerHTML=xmlhttp.responseText;
      }
   }
   
   xmlhttp.open("GET","setPopup.php?tipus="+tipus+"&allapot="+allapot,true);
   xmlhttp.send();
}

function HideDiv(value)
{
    document.getElementById(value).style.display = 'none';
}

function ShowDiv(value)
{
    document.getElementById(value).style.display = 'block';
}

function langflag(value,mode,now)
{
    if(mode == "on")
	document.getElementById('Image'+value).src = 'images/nyelv_'+value+'_on.jpg';
    if(mode == "off" && now != value)
	document.getElementById('Image'+value).src = 'images/nyelv_'+value+'.jpg';
}

