/*

function $(var1) { 
	return document.getElementById(var1);	
}
*/

function $(var1) { 
	return document.getElementById(var1);	
} 
function delayHide(elm){
	
	
	elm.onmouseout = function() {
	ta = setTimeout(function hideX() { elm.style.display='none'; },2000);
	}
}

var ta = 1;
function delayGetAjax(url,id,time){ 
	clearTimeout(ta);
	ta = setTimeout(function someX() { getAjax(url,id) },time);
}  

function activateDropMenu(var1,dropid,mainid){
	$(dropid).style.display='block';
	$(mainid).className = 'menu-hover';
	//alert(var1.childNodes[3].href);
	var1.onmouseout = function () {
		$(dropid).style.display = 'none';	
		$(mainid).className = '';
	}
}

function count_content(elm,maxn){
	var content = elm.value;
	
	var chars = new Array();
	
	chars = content.split("");
	
	var numm = chars.length;
	
	if(span = document.getElementById(elm.name+'_count')){
	}
	else {
		
		var parent = elm.parentNode;
		
		newSpan = document.createElement("span");
		newSpan.id = elm.name+"_count";
		
		parent.appendChild(newSpan);
		
	}
	
	   var ms = numm/160;
	   ms =  Math.ceil(ms);
	
	   span.innerHTML = numm+" tegn "+ms+" melding"+(ms>1 ? "er" : "");
	
	if(maxn>0){
	
		span = document.getElementById(elm.name+'_count');
		var Left = maxn-numm;
		span.innerHTML = Left;
		
		if(Left < 1){
		elm.value = elm.value.substr(0,maxn);
		span.innerHTML = '0';
		}
			
	}
	
}
function asf(url,replyto){

	var ta = document.getElementsByTagName('textarea');
	
	var str = "";
	for(i = 0; i < ta.length; i++){
		str += "&"+ta[i].name+"="+escape(encodeURI(ta[i].value));	
	}
	
	var ta = document.getElementsByTagName('input');
	for(i = 0; i < ta.length; i++){
		
		if (ta[i].type == 'checkbox'){
			str += (ta[i].checked == true ?"&"+ta[i].name+"="+escape(encodeURI(ta[i].value)) : '');		
		}
		else {
			str += "&"+ta[i].name+"="+escape(encodeURI(ta[i].value));		
		} 
	}
	
	var ta = document.getElementsByTagName('select');
	for(i = 0; i < ta.length; i++){
		if(ta[i].name.length>1){
		str += "&"+ta[i].name+"="+escape(encodeURI(ta[i].options[ta[i].selectedIndex].value));	
		}
	}
	
	str = str.substring(1);
	
	postAjax(url,str,replyto);
	
}


function asf_limited(url,replyto,formid){

	ta = $(formid).getElementsByTagName("textarea");
	
	var str = "";
	for(i = 0; i < ta.length; i++){
		str += "&"+ta[i].name+"="+escape(encodeURI(ta[i].value));	
	}
	
	ta = $(formid).getElementsByTagName('input');
	for(i = 0; i < ta.length; i++){
		
		if (ta[i].type == 'checkbox'){
			str += (ta[i].checked == true ?"&"+ta[i].name+"="+escape(encodeURI(ta[i].value)) : '');		
		}
		else {
			str += "&"+ta[i].name+"="+escape(encodeURI(ta[i].value));		
		} 
	}
	
	ta = $(formid).getElementsByTagName('select');
	for(i = 0; i < ta.length; i++){
		str += "&"+ta[i].name+"="+escape(encodeURI(ta[i].options[ta[i].selectedIndex].value));	
	}
	
	str = str.substring(1);
	
	postAjax(url,str,replyto);
	
}

function fileSizeConverter(size, dec) {
		if(!dec || dec < 0)
			dec = 2;
		var times = 0;
		var nsize = Number(size);
		var toEval = '';
		var type = Array( 'bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Zb' );
		while( nsize > 1024 ) {
			nsize = nsize / 1024;
			toEval += ' / 1024';
			times++;
		}
		if( times > 0 )
			eval( 'size = ( size' + toEval + ' );' );
		if(dec > 0) {
			var moltdiv = '(';
			while(dec > 0) {
				moltdiv += '10*'; 
				dec--;
			}
			moltdiv = moltdiv.substr(0, (moltdiv.length - 1)) + ')';   
			eval( 'size = Math.round(size * ' + moltdiv + ') / ' + moltdiv + ';' );
		}
		return size + ' ' + type[times];
}
 
