<!--

// ---------------------------------------------------
// Netspirit Custom JavaScript functions
// ---------------------------------------------------

// Author: Krasimir Makaveev | kmakaveev@yahoo.com | 2003
// Modified: 2006
// This script opens a new blank window in the center of the screen. First we must solve really important problem...
//
// For NN the position of the browser's window on the screen depends on "screenX" and "screenY" attributes.
// For IE the position of the browser's window on the screen depends on "top" and "left" attributes.
// Using a "browser-detection"-like function, we first detect the browser and then open the window with the appropriate for the browser attributes.
// So...

function PopWin(url,h,w,scroll_mode)
{
	var sw = screen.width;
	var sh = screen.height;
	
	//Simple mathematical transformations
	var sh_off = (sw - w)/2;
	var sw_off = (sh - h)/2;
	
	if(navigator.appName.indexOf("MSIE"))
	{
		ext_win = window.open(url,"","toolbar=no,copyhistory=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scroll_mode + ",resizeable=no,top="+sw_off+",left="+sh_off+",width="+w+",height="+h+"");
		ext_win.focus();
	}
	else
	{
		ext_win = window.open(url,"","toolbar=no,copyhistory=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scroll_mode + ",resizeable=no,screenX="+sw_off+",screenY="+sh_off+",width="+w+",height="+h+"");
		ext_win.focus();
	}
}

//
// Registration form steps
//

function displayStep(which)
{
	switch(which)
	{
		case "1":
		showStep("reg_step1");
		hideStep("reg_step2");
		hideStep("reg_step3");
		hideStep("reg_step4");
		break;
		
		case "2":
		hideStep("reg_step1");
		showStep("reg_step2");
		hideStep("reg_step3");
		hideStep("reg_step4");
		break;
		
		case "3":
		hideStep("reg_step1");
		hideStep("reg_step2");
		showStep("reg_step3");
		hideStep("reg_step4");
		break;
		
		case "4":
		hideStep("reg_step1");
		hideStep("reg_step2");
		hideStep("reg_step3");
		showStep("reg_step4");
		break;
	}
}

function showStep(which)
{
	document.getElementById(which).style.display = "block";
	document.getElementById(which + "_nav").style.backgroundColor = "#6a7476"; 
}

function hideStep(which)
{
	document.getElementById(which).style.display = "none";
	document.getElementById(which + "_nav").style.backgroundColor = "#999a00";
}

//
// "Accept terms"
//

function acc_terms(theForm)
{
	if(document.user_signup.accept_terms.checked == false)
	{
		alert("Du har glemt at acceptere NetSpirits forretningsbetingelser.");
		return false;
	}
	
	return true;
}

function checkNum(lmnt)
{
	if(isNaN(lmnt.value))
	{
		lmnt.focus();
		lmnt.value = "";
	}
}

function send_frm(event)
{
    if(event.keyCode == 13)
    {
	document.user_login.submit();
    }
}

function jump_to(event)
{
    if(event.keyCode == 13)
    {
	document.user_login.user_pas.focus();
    }
}

function CheckAll(lmnts) {
   for (var i = 0; i < lmnts.elements.length; i++) {
       if( lmnts.elements[i].type == 'checkbox' ) {
           lmnts.elements[i].checked = !(lmnts.elements[i].checked);
       }
   }
}

function confirmAction(msg) {
    return(confirm(msg));
}

/* Show/hide Avatar as image tooltip */

function show_avatar(id,event)
{
	document.getElementById(id).style.top = event.clientY;
	document.getElementById(id).style.left = event.clientX;
	
	document.getElementById(id).style.display = "block";
}

function hide_avatar(id)
{
	document.getElementById(id).style.display = "none";
}

function gotoURL(url)
{
	if(url != "")
	{
		window.location = url;
	}
}

function disable_btn(lmnt)
{
	document.getElementById(lmnt).disabled = true;
}

// tabs, paging

function changeTab(which,tab_num,total)
{
	tabs = GetElementsWithClassName('div','src_all_tabs');
	for (var i = 0; i < tabs.length; i++) {
        tabs[i].style.display = 'none';
    }
    document.getElementById(which).style.display = 'block';
	
	if(tab_num == 1)
	{
		var by = 0;
	}
	else
	{
		var by = tab_num;
	}
	
	var end = 10 * tab_num;
	
	var begin = (end - 10) + 1;
	
	if(end > total)
	{
		end = total;
	}
	
	document.getElementById("from_to").innerHTML = begin + "-" + end;
}

function GetElementsWithClassName(elementName,className) {
    var allElements = document.getElementsByTagName(elementName);
    var elemColl = new Array();
    for (var i = 0; i< allElements.length; i++) {
        if (hasClass(allElements[i], className)) {
            elemColl[elemColl.length] = allElements[i];
        }
    }
    return elemColl;
}

function hasClass(object, className) {
    if (!object.className) return false;
    return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
}

function hide_text(lmnt,txt)
{
	if(lmnt.value == txt)
	{
		lmnt.value = "";
		lmnt.focus();
	}
}

function show_text(lmnt,txt)
{
	if(lmnt.value == "")
	{
		lmnt.value = txt;
	}
}

function points_check_radio()
{
	document.frm_new_q.new_q_points[0].checked = false;
	document.frm_new_q.new_q_points[1].checked = false;
	document.frm_new_q.new_q_points[2].checked = false;
	document.frm_new_q.new_q_points[3].checked = true;
}

// character counter
function textCounter(field, countfield, maxlimit)
{
    if (field.value.length > maxlimit)
    {
		field.value = field.value.substring(0, maxlimit);
    }
    else 
    {
		// countfield.value = maxlimit - field.value.length;
		document.getElementById(countfield).innerHTML = maxlimit - field.value.length;
    }
}

function show_preview(root)
{
	document.frm_new_article.target = "_blank";
	document.frm_new_article.action = root + "pages/preview_article_da.php";
	
	document.frm_new_article.submit();	
	
	document.frm_new_article.target = "_self";
	document.frm_new_article.action = root + "articles/new.php";
}

function showCatBox()
{
	document.getElementById("ctg_box").style.display = "block";
	document.getElementById("postnum_cont").style.display = "none";
}

function hideCatBox()
{
	document.getElementById("ctg_box").style.display = "none";
	document.getElementById("postnum_cont").style.display = "block";
}

function showCertBox()
{
	document.getElementById("cert_box").style.display = "block";
	document.getElementById("postnum_cont").style.display = "none";
}

function hideCertBox()
{
	document.getElementById("cert_box").style.display = "none";
	document.getElementById("postnum_cont").style.display = "block";
}
//-->