var progressEnd = 27; // set to number of progress <span>'s.
var progressColor = 'red'; // set to progress bar color
var progressInterval = 1000; // set to time between updates (milli-seconds)
var progressAt = progressEnd;
var progressTimer;
var mposx = 10;
var mposy = 10;

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function progress_clear() {
for (var i = 1; i <= progressEnd; i++) document.getElementById('progress'+i).style.backgroundColor = 'transparent';
progressAt = 0;
}
function progress_update() {
document.getElementById('showbar').style.visibility = 'visible';
progressAt++;
if (progressAt > progressEnd) progress_clear();
else document.getElementById('progress'+progressAt).style.backgroundColor = progressColor;
progressTimer = setTimeout('progress_update()',progressInterval);
}
function progress_stop() {
clearTimeout(progressTimer);
progress_clear();
document.getElementById('showbar').style.visibility = 'hidden';
}
col=255;
xfadetime = 13;
function fadetext(id) {
//document.getElementById(id).style.color = "#FFFFFF";
//setTimeout("dofadetext('" + id + "')",8000);
dofadetext(id);
}

function dofadetext(id) { 
//alert(id);
document.getElementById(id).style.color="rgb(" + col + "," + col + "," + col + ")"; col-=5; if(col>0) setTimeout("dofadetext('" + id + "')", xfadetime); 
}


var fadeintime=190; // higher is slower
var fadeouttime=10; // higher is slower
var opacchange=8; // higher is faster (between 2-30 will probably work best)

function fadeindiv(id) 
{ 
document.getElementById(id).style.display="none"
fadeinto=setTimeout("divIn(" + 0 + ",'" + id + "')",fadeintime);
} 

function fadeoutdiv(id) 
{ 
fadeoutto=setTimeout("divOut(" + 100 + ",'" + id + "')",fadeouttime);
} 

pdforglink = "";
function GetPhoneId2(mobid) {
progress_update();
document.location=pdforglink+ "&phoneid=" + mobid;
}

function ManualWithPhoneReq2(pdflink,action,mobid) {
 if (action == 0 && mobid==0) {
    pdforglink = pdflink;
	url = "/manuals/choosephone.asp?callfunc=GetPhoneId";
	newwindow=window.open(url,'ChoosePhone','height=450,width=500');
	newwindow.moveTo(150,150);
	if (window.focus) {newwindow.focus()}
   //alert("choosing phone " + pdflink);
 } else {
	 GetPhoneId2(mobid);
 }
}

function divIn(opacity, id) { 
    opacity+=opacchange;

    var os = document.getElementById(id).style; 
    
    os.opacity = (opacity / 101); 
    os.MozOpacity = (opacity / 101); 
    os.KhtmlOpacity = (opacity / 101); 
    os.filter = "alpha(opacity=" + opacity + ")";
    os.display="inline";
    
    clearTimeout(fadeinto);
    if(opacity<100)
    	{
	fadeinto=setTimeout("divIn(" + opacity + ",'" + id + "')",fadeintime);
    	}
}

function divOut(opacity, id) { 
    opacity-=opacchange;

    var os = document.getElementById(id).style; 
    os.opacity = (opacity / 101); 
    os.MozOpacity = (opacity / 101); 
    os.KhtmlOpacity = (opacity / 101); 
    os.filter = "alpha(opacity=" + opacity + ")";
    
    clearTimeout(fadeoutto);
    if(opacity>0)
    	{
	fadeoutto=setTimeout("divOut(" + opacity + ",'" + id + "')",fadeouttime);
    	}
    else
    	{
	os.display="none";
    	}
} 

function getmousepos(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;

if (e.pageX || e.pageY) 	{
		mposx = e.pageX;
		mposy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		mposx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		mposy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	//mposx = mposx + 80;
	//mposy = mposy -120;
//	document.getElementById("mousedata").innerHTML = "mposx: " + mposx + "<br>mposy: " + mposy + "<br>" + document.getElementById("Help").style.left + "," + document.getElementById("Help").style.top;
	
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
//alert(mposx);
//alert(mposy);
}


function activate(image, act) {
    if (act)
      imagesrc(image, "_default.png", "_active.png");
    else
      imagesrc(image, "_active.png", "_default.png");
}

function imagesrc(image, from, to) {
    if (document[image] == null)
        return;
    if (document[image].src == null) {
        alert(image + " has no src");
        return;
    }
    document[image].src = document[image].src.replace(from, to);
}

function clearIfNot(elem, val) {
    if (elem.value == val ) 
        elem.value = '';
}

function setToIfEmpty(elem, val) {
    if (elem.value =='') 
        elem.value = val;
}
    
function swapInnerHtml(a_id, b_id) {
    var a = document.getElementById(a_id);
    var b = document.getElementById(b_id);
    if (a == null)
        return;
    if (b == null)
        return;
    var bHtml = b.innerHTML;
    b.innerHTML = a.innerHTML;
    a.innerHTML = bHtml;
}

  var appearance = "notShown"
    function show(text)
        {
					//getmousepos();
					//alert(event.clientY + document.body.scrollTop);
					//alert(event.clientX + document.body.scrollLeft );
					
            if (appearance == "notShown")
                {

                   document.getElementById("Help").style.display = "inline";
				    //document.getElementById("Help").style.display = "";
					htmltext = "<div id='SvartText'>";
					htmltext = htmltext + text;
					htmltext = htmltext + "</div>";
					document.getElementById("Help").innerHTML = text;
					//alert(mposx);
//alert(mposy);
					document.getElementById("Help").style.left=mposx;
					document.getElementById("Help").style.top=mposy;
					
                    appearance = "shown";
                }
        }

    function remove()
        {
            document.getElementById("Help").style.display = "none";
            appearance = "notShown";
        }
		
  function remove2()
        {
            document.getElementById("Help").style.display = "none";
            appearance = "notShown";
        }

   function show2(text)
        {
					//getmousepos();
					//alert(event.clientY + document.body.scrollTop);
					//alert(event.clientX + document.body.scrollLeft );
					
            if (appearance == "notShown")
                {

                   document.getElementById("Help").style.display = "inline";
				    //document.getElementById("Help").style.display = "";
					htmltext = "<div id='SvartText'>";
					htmltext = htmltext + text;
					htmltext = htmltext + "</div>";
					document.getElementById("Help").innerHTML = text;
					//alert(mposx);
//alert(mposy);
					document.getElementById("Help").style.left=mposx;
					document.getElementById("Help").style.top=mposy;
					
                    appearance = "shown";
                }
        }

if  (document.getElementById){

(function(){

//Stop Opera selecting anything whilst dragging.
if (window.opera){
document.write("<input type='hidden' id='Q' value=' '>");
}

var n = 500;
var dragok = false;
var y,x,d,dy,dx;

function move(e){
if (!e) e = window.event;
 if (dragok){
  d.style.left = dx + e.clientX - x + "px";
  d.style.top  = dy + e.clientY - y + "px";
  return false;
 }
}

function down(e){
if (!e) e = window.event;
var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
if (temp.tagName != "HTML"|"BODY" && temp.className != "dragclass"){
 temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
 }
if (temp.className == "dragclass"){
 if (window.opera){
  document.getElementById("Q").focus();
 }
 dragok = true;
 temp.style.zIndex = n++;
 d = temp;
 dx = parseInt(temp.style.left+0);
 dy = parseInt(temp.style.top+0);
 x = e.clientX;
 y = e.clientY;
 document.onmousemove = move;
 return false;
 }
}

function up(){
dragok = false;
document.onmousemove = null;
}

document.onmousedown = down;
document.onmouseup = up;

})();
}//End.


checkedid2="";


function ChangeMenuWidth(width) {
	for (i=1;i<=lastitem;i++) {
	    cid = "tnav"+i;
		document.getElementById(cid).style.width = width;
	}
}

function RedrawMenu2(id) {
	for (i=1;i<=lastitem;i++) {
	    cid = "tnav"+i;
		if (id == cid) {
			//document.getElementById(cid).style.background="#EEEEEE";
			//document.getElementById(cid).style.background="#434242";
			
	//		document.getElementById(cid).style.background='url(/img2/button/nmenu_checked.png)';
			document.getElementById(cid).style.color = "#780E0E";
			document.getElementById(cid).style.fontWeight  = "bolder";
			document.getElementById(cid).style.fontStretch = "extra-expanded";
			//menuobj.style.border= "1px solid #e68200";
			//document.getElementById(cid).style.border="2px solid black";
			//document.getElementById(cid).style.border= "none";
			//document.getElementById(cid).style.borderLeft="3px solid gray"; 
			//document.getElementById(cid).style.borderTop="1px solid gray"; 
			//document.getElementById(cid).style.borderBottom="1px solid gray"; 
			//document.getElementById(cid).style.borderTop="3px solid gray";
			//document.getElementById(cid).style.borderRight="1px solid gray"; 
	//		menuobj.style.borderTop="5px solid black"; 
		} else {
	//		document.getElementById(cid).style.background="transparent";
	//		document.getElementById(cid).style.background="";
			document.getElementById(cid).style.fontStretch = "normal";
			document.getElementById(cid).style.fontWeight  = "bold";
			document.getElementById(cid).style.color = "#7696A1";
			document.getElementById(cid).fontWeight  = "normal";
			//document.getElementById(cid).style.border= "none";
			//document.getElementById(cid).style.borderRight="1px solid black"; 
			document.getElementById(cid).style.borderRight="0px solid gray";
			document.getElementById(cid).style.borderLeft="0px solid gray"; 
			document.getElementById(cid).style.borderBottom="0px solid gray"; 
			document.getElementById(cid).style.borderTop="0px solid gray";
			
		}
	}
}

function Printadress(id,name,domain,enddomain) {
	var _rwObsfuscatedHref0 = "mai";
	var _rwObsfuscatedHref1 = "lto";
	var _rwObsfuscatedHref2 = ":";
	var _rwObsfuscatedHref3 = name;
	var _rwObsfuscatedHref4 = "@";
	var _rwObsfuscatedHref5 = domain;
	var _rwObsfuscatedHref6 = ".";
	var _rwObsfuscatedHref7 = enddomain;
	var _rwObsfuscatedHref = _rwObsfuscatedHref0+_rwObsfuscatedHref1+_rwObsfuscatedHref2+_rwObsfuscatedHref3+_rwObsfuscatedHref4+_rwObsfuscatedHref5+_rwObsfuscatedHref6+_rwObsfuscatedHref7; 
	document.getElementById(id).href = _rwObsfuscatedHref;
}


function changemain2(page,otherframe) {
	if (otherframe != "") {
	  //parent.frame[otherframe].src = page;
	  //parent.otherframe.document.location = page;
	  parent.window.frames[otherframe].location = page;
	} else {
	  document.getElementById(frame).src = page;
	}

}


function Hilite2(id,check,url,otherframe) {
if(typeof otherframe == "undefined") { otherframe="";}
menuobj = document.getElementById(id);
if (check == 0 && checkedid2 != id) {
//if (check == 0) {
	//menuobj.style.background='url(img2/button/tmenu_unchecked.png)';
//menuobj.style.background="transparent";
//menuobj.style.background="";
	menuobj.style.color = "#7696A1";
	//menuobj.style.fontWeight  = "normal";
	menuobj.style.fontStretch="normal";
	menuobj.style.fontWeight  = "bold";
	//menuobj.style.border= "none";
	//menuobj.style.border= "none";
	menuobj.style.borderLeft="0px solid gray"; 
	menuobj.style.borderTop="0px solid gray";
	menuobj.style.borderBottom="0px solid gray"; 
	menuobj.style.borderRight="0px solid gray"; 
	
}

if (check == 1 && checkedid2 != id) {
//menuobj.style.background="transparent";
menuobj.style.cursor="pointer";
menuobj.style.color = "#000000";
menuobj.style.fontStretch="normal";
menuobj.style.fontWeight  = "bold";
/*
menuobj.style.borderRight="1px solid gray"; 
menuobj.style.borderLeft="1px solid gray"; 
menuobj.style.borderTop="1px solid gray";
menuobj.style.borderBottom="1px solid gray"; 
*/
menuobj.style.borderRight="0px solid gray"; 
menuobj.style.borderLeft="0px solid gray"; 
menuobj.style.borderTop="0px solid gray";
menuobj.style.borderBottom="0px solid gray"; 


}
if (check == 2) {
//menuobj.style.background='url(img/button/nmenu_unchecked.png)';
//menuobj.style.background='url(/img2/button/tmenu_checked.png)';
menuobj.style.fontWeight  = "bolder";
//menuobj.style.background="#EEEEEE";
menuobj.style.color = "#780E0E";
menuobj.style.cursor="pointer";
menuobj.style.fontStretch="extra-expanded";
//menuobj.style.border="2px solid black";
//menuobj.style.border= "none";
//menuobj.style.borderRight="1px solid gray"; 
//menuobj.style.borderLeft="3px solid gray"; 
//menuobj.style.borderTop="3px solid gray"; 
//menuobj.style.borderBottom="1px solid gray"; 
checkedid2 = id;
RedrawMenu2(id);
}
if (url == 0) { 
}
else {
	changemain2(url,otherframe);
}
}


function pbxconfdisp(vaxel,currentpbxconf,ctuse) {
//alert(vaxel);
//alert(currentpbxconf[0]);
//alert(currentpbxconf[1]);
//alert(currentpbxconf[2]);
//alert(currentpbxconf[3]);
//alert(currentpbxconf[4]);

// Visa
if (currentpbxconf[0] == 1 ) {
document.getElementById("pLineacess").style.display = "";
} else { 
document.getElementById("pLineacess").style.display = "none";
}
if (currentpbxconf[1] == 1 ) {
document.getElementById("pSwitchboard").style.display = "";
} else { 
document.getElementById("pSwitchboard").style.display = "none";
}
if (currentpbxconf[2] == 1 ) {
document.getElementById("pPincode").style.display = "";
} else { 
document.getElementById("pPincode").style.display = "none";
}
if (currentpbxconf[3] == 1 ) {
document.getElementById("pPreEditCode").style.display = "";
} else { 
document.getElementById("pPreEditCode").style.display = "none";
}
if (currentpbxconf[4] == 1 ) {
document.getElementById("pVM").style.display = "";
} else { 
document.getElementById("pVM").style.display = "none";
}
if (currentpbxconf[5] == 1 || ctuse == 1 ) {
document.getElementById("pGSMNumber").style.display = "";
} else { 
document.getElementById("pGSMNumber").style.display = "none";
}

//Tvingande

if (currentpbxconf[6] == 1 ) {
document.getElementById("sl_lineaccess").style.border="3px solid black";
} else { 
document.getElementById("sl_lineaccess").style.border="1px solid black";
}
if (currentpbxconf[7] == 1 ) {
document.getElementById("sl_switchboardnr").style.border="3px solid black";
} else { 
document.getElementById("sl_switchboardnr").style.border="1px solid black";
}
if (currentpbxconf[8] == 1 ) {
document.getElementById("sl_pincode").style.border="3px solid black";
} else { 
document.getElementById("sl_pincode").style.border="1px solid black";
}
if (currentpbxconf[9] == 1 ) {
document.getElementById("precode").style.border="3px solid black";
} else { 
document.getElementById("precode").style.border="1px solid black";
}
if (currentpbxconf[10] == 1 ) {
document.getElementById("pbxvm").style.border="3px solid black";
} else { 
document.getElementById("pbxvm").style.border="1px solid black";
}
if (currentpbxconf[11] == 1 || ctuse == 1) {
document.getElementById("sl_gsmnr").style.border="3px solid black";
} else { 
document.getElementById("sl_gsmnr").style.border="1px solid black";
}

//Default value
document.getElementById("sl_lineaccess").value = currentpbxconf[12];
document.getElementById("sl_switchboardnr").value = currentpbxconf[13];
document.getElementById("sl_pincode").value = currentpbxconf[14];
document.getElementById("precode").value = currentpbxconf[15];
document.getElementById("pbxvm").value = currentpbxconf[16];
document.getElementById("sl_gsmnr").value = currentpbxconf[17];

}


function XCheckValueForm(id,varnocheck,text,alerts,fix) {
obj = document.getElementById(id);
if (fix == 1) {obj.value = XFixString(obj.value);}
if (obj.value == varnocheck) {
if (alerts) { alert(text); }
obj.style.border="3px solid red";
obj.focus();
return 1;
}
obj.style.border="3px solid green";
return 0;
}

function XCheckValueFormCB(id,text,alerts,fix) {
obj = document.getElementById(id);
if (fix == 1) {obj.value = XFixString(obj.value);}
if (!obj.checked) {
if (alerts) { alert(text); }
obj.style.outline="3px solid red";
obj.focus();
return 1;
}
obj.style.outline="3px solid green";
return 0;
}

function XCheckValueFormCBMulti(id,text,alerts,fix,startindex,slutindex) {
for (i = startindex; i <= slutindex; ++ i) {
	obj = document.getElementById(id+i);
	if (obj.checked) {
	 return 0;
	}
}
if (alerts) { alert(text); }
obj.focus();
return 1;
}

function XFixString(value) {
value = value.replace(/-/g, "");
value = value.replace(/ /g, "");
return value;
}



