
function addCommas(_str)
{
	_str += '';
	x = _str.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

function is_ie6 () {
	if (navigator.userAgent.match("MSIE 6")) {
		return true;
	} else {
		return false;
	}
}

function GetElement(strElement)
{
	if (document.getElementById)
	{
		// IE5+, Netscape 6, Mozilla
		return (document.getElementById(strElement));
	}
	else if (document.all)
	{
		// IE4
		return (eval("document.all." + strElement));
	}
	else if (document.layers)
	{
		// Netscape 4
		return (eval("document." + strElement));
	}
	else
	{
		// Crap!
		return (null);
	}
}


if (typeof(lang_areyoucompletesure) == "undefined") {
	var lang_areyoucompletesure  = 'Er du helt sikker på, at du vil:';
}

function fncSikker() {
	var sure = confirm(lang_areyoucompletesure);
	if (sure) {
		return true;
	} else {
		return false;
	}
}

if (typeof(lang_areyousure) == "undefined") {
	var lang_areyousure  = 'Er du sikker på, at du vil:';
}

var confirmMsg  = lang_areyousure;

function confirmLink(theLink, theSqlQuery)
{
    // Confirmation is not required in the configuration file
    if (confirmMsg == '') {
        return true;
    }

    var is_confirmed = confirm(confirmMsg + '\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function


function co(element,mode) {
  if (mode=="in") {
    cursortype = 'hand'
    colorval = '#FA761E'

  } else if (mode=="out") {
    cursortype = ''
    colorval = '#999FAB'

  }
  element.style.background=colorval;
  element.style.cursor=cursortype;
}
function co2(element,mode) {
  if (mode=="in") {
    cursortype = 'hand'
    colorval = '#FA761E'

  } else if (mode=="out") {
    cursortype = ''
    colorval = '#999FAB'

  }
  element.style.background=colorval;
  element.style.cursor=cursortype;
}

function opac(felt,funk) {
	if (navigator.appName == "Microsoft Internet Explorer") {
		if (navigator.appVersion.indexOf("MSIE 5")>-1 || navigator.appVersion.indexOf("MSIE 5.5")>-1) {
			if (funk=="focus") {
				felt.style.background = "#FFFFFF"
			} else {
				felt.style.background = "#DEDEDE"
			}
		}

	}
}

function vindue(fil,bredde,hojde) {
	window.open(fil,'','height='+hojde+',width='+bredde+',status=no');
}

function popup(filNavn, titel) { 

	// LeftPos = (screen.width) ? (screen.width-130)/2 : 0;
	// TopPos = (screen.height) ? (screen.height-130)/2 : 0;
	LeftPos = 20;
	TopPos = 20;
	settings = 'height=130,width=130,top='+TopPos+',left='+LeftPos+',scrollbars=no,resizable=yes';
	imageWin=window.open('',"imageWin",settings);
	imageWin.document.open(); 
	imageWin.document.write( 
	'<html>'+ 
	'<head>'+ 
	'<title>'+ titel + '</title>'+ 
	'<\script language="JavaScript">'+ 
	'function myResize() {'+ 
	'picW = document.images["pic"].width;'+ 
	'picH = document.images["pic"].height;'+ 
	'picW = picW+10;'+
	'picH = picH+25;'+
	'window.resizeTo(picW,picH);'+ 
	'}'+ 
	'<\/script>'+ 
	'</head>'+ 
	'<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="myResize();">'+ 
	'<a href="#" onclick="self.close();">'+
	'<img src="' + filNavn + '" NAME="pic" border="0"></a>'+ 
	'</body>'+ 
	'</html>' ); 
	imageWin.focus();
	imageWin.document.close(); 
} 

function popupz(filNavn) {
	var	LeftPos = (screen.width) ? (screen.width-400)/2 : 0;
	var TopPos = (screen.height) ? (screen.height-500)/2 : 0;
	window.open(filNavn,"imageWin",'height=500,width=400,top='+TopPos+',left='+LeftPos+',scrollbars=no,resizable=yes');
}

function tjeklogin() {
	var f = document.login;

	if (f.loginnavn.value == "")
	{
		alert(lang_pleaseusername);
		f.loginnavn.focus();
		return (false);
	}

	if (f.passwd.value == "")
	{
		alert(lang_pleasepassword);
		f.loginnavn.focus();
		return (false);
	}

	return (true);
}

function billedepop ($id,$type) {
	var $btitle, $bcontent, $bimg;
	if (document.all && document.getElementById) {			//IE5
		$bcontent = document.all($id).style;
	} else if (!document.all && document.getElementById) {	//NS6
		$bcontent = document.getElementById($id).style;
	} else {	// !IE5 && !NS6
		return false;
	}
	if ($type == 'show') {
		$bcontent.display = 'block';
		$bcontent.visibility = 'visible';
	} else {
		$bcontent.display = 'none';
		$bcontent.visibility = 'hidden';
	}
}


// FUNCTIONS FOR COOKIE HANDLING
function setCookie(c_name, value, expiredays) {
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return ""
}

function videoprofil (video, user) {
	window.open('/core/videoprofil.php?video='+video+'&video_user='+user,"videoWin",'height=500,width=400,top=200,left=200,scrollbars=no,resizable=yes');
}

function make_email_link(pre, country) {
	email = pre+'@'+'absi';
	if (country == 'Sverige') {
		email += '.se';
	}else if (country == 'Letland') {
		email += '.lv';
	}else {
		email += '.dk';
	}
	document.write('<a href="mailto:' + email + '">' + email + '</a>');
}

function valid_email(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test(email) == false) {
		return false;
	}
	return true;
}

// FOR USE IN TEXTAREAS
function maxlength(_el, _size) {
	if (_el.value.length > _size) {_el.value = _el.value.substring(0, _size)}
}

var help_subject = "";
function open_helpwin () {
	popupz('http://' + window.location.hostname + '/help.php?subject=' + help_subject)
}


function get_name_from_file(_str) {
	// RETURN THE REMAINING STRING FROM A FILENAME, WHEN PATH AND FILETYPE ARE REMOVED
	_str = _str.replace(/([\w \!\?\.:\b\(\)]+\\)|(\.\w+$)/ig,"")
	_str = _str.replace(/([-_\.])|(\(\d+\))/ig," ")
	_str = _str.slice(0,1).toUpperCase() + _str.slice(1)
	return _str
}

function nissenhit() {
	location.href = '/?p=nissensend';
}
