/*
function openCVWindow(vPersonId) {
	var url = 'CV/CVFile'+vPersonId+'.htm';
	alert(url);
	PopUpWin(url, 500, 300);
}
*/
function openCVWindow(vPersonId, vWidth, vHeight) {
	var url = 'CV/CVFile'+vPersonId+'.htm';
	if (typeof(vWidth) == "undefined")
		vWidth = 350;
	if (typeof(vHeight) == "undefined")
		vHeight = 450;		
	var winAr = new Array();
	winAr[1] = url;
	winAr[2] = 'CVWin';
	winAr[3] = vWidth;
	winAr[4] = vHeight;
	winAr[6] = "yes";
	CSSlideNewWindow(winAr);
}

function PopUpWin (url, pheight, pwidth){
   if(document.layers || document.all) {

    var window_left = (screen.width-pwidth)/2;
    var window_top = (screen.height-pheight)/2;
    popUp = window.open(url,'Info','scrollbars,resizable,height='+pheight+',width=' + pwidth +',left=' + window_left + ',top=' + window_top + '')
	popUp.focus();
	}
   else {
      popUp = window.open(url,'Info','scrollbars,resizable,height='+pheight+',width=' + pwidth)
	  popUp.focus();
   }
    
}


function windowopen(jURL,jName,jStyle) 
{
jWindow = window.open(jURL, jName, jStyle);
jWindow.focus();
return;
}


function getValueOf(objectId)
{
	// cross-browser function to get an object's style object given its id
	if(document.getElementById && document.getElementById(objectId))
	{
		// W3C DOM
		return document.getElementById(objectId).value;
	}
	else if (document.all && document.all(objectId))
	{
		// MSIE 4 DOM
		return document.all(objectId).value;
		//alert(document.all(objectId).style.value());
	}
	else if (document.layers && document.layers[objectId])
	{
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId].value;
	}
	else
	{
		return false;
    }
} // getValueOf

function SetWindowStatus(WStatus)
{
if (!WStatus)
WStatus=""
window.status=(WStatus);
}
 

function CSSlideNewWindow(action) {
var wh = ""
if (action[7] || action[8] || action[9] == true) wh=action[4]-125
else wh = action[4]

var wf = "";         
wf = wf + "width=" + action[3];
wf = wf + ",height=" + wh;
wf = wf + ",resizable=" + (action[5] ? "yes" : "no");
wf = wf + ",scrollbars=" + (action[6] ? "yes" : "no");
wf = wf + ",menubar=" + (action[7] ? "yes" : "no");
wf = wf + ",toolbar=" + (action[8] ? "yes" : "no");
wf = wf + ",directories=" + (action[9] ? "yes" : "no");
wf = wf + ",location=" + (action[10] ? "yes" : "no");
wf = wf + ",status=" + (action[11] ? "yes" : "no");              

if(navigator.appVersion.charAt(0) >=4) {
var sw=screen.width-20;
var sh=screen.height;
var newwidth=action[3]; 
var newheight=action[4];
var positionleft=(sw-newwidth)/2;
var positiontop=""
if (action[7] || action[8] || action[9] == true) positiontop=(sh-newheight)/3;
positiontop=(sh-newheight)/2.5;
}

newwindow=window.open(action[1],action[2],wf); 
newwindow.focus()         
if(navigator.appVersion.charAt(0) >=4) {
for(width1 = 1 ; width1 < positionleft ; width1 = width1 + 10)
newwindow.moveTo(width1,positiontop)
}
}

function cb_showhidecontent(theID) {
	var theDiv = document.all.item(theID+"div")
	var theop = document.all.item("op"+theID)

	if (theDiv.style.display == "") {
		theDiv.style.display = "none";
		theop.value = "+"
		return;
	}
	else {
		theDiv.style.display = "";
		theop.value = "-"
	}
}

function OpenReg (pWebProfilFunkId) {
nWidth=550;
nHeight=550;
url='pop.cfm?Fuseaction=creSite&pAction=form&pFormType=DemoFull&pWebProfilFunkId=' + pWebProfilFunkId;
hWind='CreSite';
nScroll=1;

if(document.layers || document.all) {
   var window_left = (screen.width-nWidth)/2;
   var window_top = (screen.height-nHeight)/2;
   var cToolBar = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + nScroll +',left=' + window_left + ',top=' + window_top + ",resizable=0,width=" + nWidth + ",height=" + nHeight
   var popupwin = window.open(url, hWind, cToolBar);
   popupwin.focus();}
}


//function showHideDiv(vName) {
//  if (typeof document.all[vName].style.display != "undefined") {
//    if (document.all[vName].style.display == 'none') {
//	  document.all[vName].style.display = 'block';
//    }
//    else {
//	  document.all[vName].style.display = 'none';
//    }
//  }
//}

function showHideDiv(vName) {
  if (typeof document.getElementById(vName).style.display != "undefined") {
    if (document.getElementById(vName).style.display == 'none') {
	  document.getElementById(vName).style.display = 'block';
    }
    else {
	  document.getElementById(vName).style.display = 'none';
    }
  }
}

function showHideDivId(vName) {
  if (typeof document.getElementById(vName).style.display != "undefined") {
    if (document.getElementById(vName).style.display == 'none') {
	  document.getElementById(vName).style.display = 'block';
    }
    else {
	  document.getElementById(vName).style.display = 'none';
    }
  }
}




function DivVisibility(vName,vView) {
  if (typeof document.all[vName].style.display != "undefined") {
    if (vView == 'visible') {
	  document.all[vName].style.visibility = 'visible';
    }
    else {
	  document.all[vName].style.visibility = 'hidden';
    }
  }
}


function PopUpWindow (url, hWind, nWidth, nHeight, nScroll) {
if(document.layers || document.all || document.getElementById) {
   var window_left = (screen.width-nWidth)/2;
   var window_top = (screen.height-nHeight)/2;
   var cToolBar = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + nScroll +',left=' + window_left + ',top=' + window_top + ",resizable=1,width=" + nWidth + ",height=" + nHeight;
   var popupwin = window.open(url, hWind, cToolBar);
   popupwin.focus();
 }
else {
  var cToolBar = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + nScroll + ",resizable=1,width=" + nWidth + ",height=" + nHeight;
   var popupwin = window.open(url, hWind, cToolBar);
   popupwin.focus();
}
 
}


//setter en egenskap på stilen vStyle på objectet vName (document.all[vName]) til verdien vValue
function setStyle(vName,vStyle,vValue) {
  if (typeof document.all[vName].style[vStyle] != "undefined") 
    {
	  document.all[vName].style[vStyle] = vValue;
    }
  else if (typeof document.all[vName][vStyle] != "undefined") 
    {
	  document.all[vName][vStyle] = vValue;
    }
	return true;
}

function modelesswin(url,mwidth,mheight){
if (document.all&&window.print) //if ie5
eval('window.showModelessDialog(url,"","help:0;resizable:1;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")')
else
eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")')
}

function getkey(e)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

function isInteger(e)
{
	return goodchars(e,'0123456789');
}

function goodchars(e, goods)
{
	var key, keychar;
	key = getkey(e);
	if (key == null) return true;
	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	// check goodkeys
	if (goods.indexOf(keychar) != -1)
		return true;
	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}


/********** Legaliz functions ***********************/

function VisEsaksgang(nofaid){ 
  var Streng; 
  var Hoyde = screen.availHeight - 100; 
  if (Hoyde > 800){ Hoyde  = 700 }; 
  Streng = 'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=781,top=10,height=' + Hoyde; 
  window.open('https://www.legaliz.no/ecase/contractwelcome.asp?KontraktId=' + nofaid + '&PartnerId=2','Saksgang',Streng); 
}

function VisLoginEsaksgang() { 	
  var Streng; 
  var Hoyde = screen.availHeight - 100; 
  if (Hoyde > 800){ Hoyde  = 700; } 
  Streng = 'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=781,top=10,height=' + Hoyde; 
  window.open('https://www.legaliz.no/ecase/login.asp','Saksgang',Streng);	
}

function getObj(objectId)
{
	// cross-browser function to get an object's style object given its id
	if(document.getElementById && document.getElementById(objectId))
	{
		// W3C DOM
		return document.getElementById(objectId);
	}
	else if (document.all && document.all(objectId))
	{
		// MSIE 4 DOM
		return document.all(objectId);
		//alert(document.all(objectId).style.value());
	}
	else if (document.layers && document.layers[objectId])
	{
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
	}
	else
	{
		return false;
    }
} // getObj

function getObjName(objectId) {
	return document.getElementsByName(objectId);
}

function listAppend(list,v,delimiter) {
	if(list.length == 0) list = v;
	else list = list + delimiter + v;
	return list;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while 
			(obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function returnOptions(elementName,mainSep,subSep){
	var objL = document.getElementsByName(elementName);
	var vReturn  = "";
	if(objL.length > 0) {
		for(i=0;i<objL.length;i++){
			if(objL[i].value.length) {
				vTmp = objL[i].title + subSep + objL[i].value;
				vReturn = listAppend(vReturn,vTmp,mainSep);
			}	
		}
	}
	return vReturn;
}

function checkValue(elementName){
	var objL = document.getElementsByName(elementName);
	var vError = false;
	if(objL.length > 0) {
		for(i=0;i<objL.length;i++){
			if(objL[i].value.length == 0) {
				vError = true;
			}	
		}
	}
	return vError;
}

function selectAll(obj, vBool, type) {
	if(typeof(obj.length) == "undefined") {
		if(obj.disabled == false) {
			if(type = "checkbox") {
				obj.checked = vBool;
			}
		}
	}
	else {
		for(i=0;i<obj.length;i++) {
			if(obj[i].disabled == false) {
				if(type = "checkbox") {
					obj[i].checked = vBool;
				}
			}
		}
	}
}

function selectMax(obj, vBool, type, maxSelect) {
	if(typeof(obj.length) == "undefined") {
		if(obj.disabled == false) {
			if(type = "checkbox") {
				obj.checked = vBool;
			}
		}
	}
	else {
		for(i=0; i<obj.length; i++) {
			if(i < maxSelect ) {
				if(obj[i].disabled == false) {
					if(type = "checkbox") {
						obj[i].checked = vBool;
					}
				}
				else {
					maxSelect++;
				}
			}
		}
	}
}

function selectAllByName(n,b) {
	l = document.getElementsByName(n);
	for(i=0; i<l.length; i++) {
		if(!(l[i].disabled)) {
			l[i].checked = b;
		}
	}
}

function disableByName(n,b) {
	l = document.getElementsByName(n);
	for(i=0; i<l.length; i++) {
		l[i].disabled = b;
	}
}

function readOnlyByName(n,b) {
	l = document.getElementsByName(n);
	for(i=0; i<l.length; i++) {
		l[i].readonly = b;
	}
}

function trim(sString)
{
	while (sString.substring(0,1) == ' ')
		sString = sString.substring(1, sString.length);
	while (sString.substring(sString.length-1, sString.length) == ' ')
		sString = sString.substring(0,sString.length-1);
	return sString;
}

function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		//alert("true");   
		return true;
    }else{   
		//alert("false"); 
		return false;
    }
}

function loadUrlRef(u) {
	document.location.href = u;
}

function clearSpace(v) {
	reg = /\s+/gi;
	var out = v.replace(reg,'');
	
	reg = /\xA0/gi;
	out = out.replace(reg,'');

	return out;
}

function makeNumeric(n) {
	n = clearSpace(n);
	reg = /\,/gi;
	var out = n.replace(reg,'.');
	out = parseFloat(out);
	
	return out;
}

function makeInt(n) {
	n = clearSpace(n);
	reg = /\,/gi;
	n = n.replace(reg,'');
	reg = /\./gi;
	var out = n.replace(reg,'');
	out = parseFloat(out / 100);
	return out;
}


function disableIds(idList,b) {
	if(b)
		b=false
	else 
		b = true;
				
	vList = idList.split(",");
	for(i=0;i < vList.length;i++) {
		getObj(vList[i]).disabled = b;
	}
}

function showHideDivs(idList,b) {
	if(b == true || b == 1) {
		b = true;
		n = "";
	}
	else {
		b = false;
		n = "none";
		
	}
				
	vList = idList.split(",");
	for(i=0;i < vList.length;i++) {
		getObj(vList[i]).style.display = n;
	}
}

function IsChecked(objCB) {
	cb = getObjName(objCB);
	if(cb && cb.length > 0) {
		for(i=0;i<cb.length;i++) {
			if(cb[i].checked == true)
				return true;
		}
	}

	return false;
}

function getRand() {
	return Math.floor(Math.random()*10000);
}

/*!
Math.uuid.js (v1.4)
http://www.broofa.com
mailto:robert@broofa.com

Copyright (c) 2010 Robert Kieffer
Dual licensed under the MIT and GPL licenses.
*/

/*
 * Generate a random uuid.
 *
 * USAGE: Math.uuid(length, radix)
 *   length - the desired number of characters
 *   radix  - the number of allowable values for each character.
 *
 * EXAMPLES:
 *   // No arguments  - returns RFC4122, version 4 ID
 *   >>> Math.uuid()
 *   "92329D39-6F5C-4520-ABFC-AAB64544E172"
 * 
 *   // One argument - returns ID of the specified length
 *   >>> Math.uuid(15)     // 15 character ID (default base=62)
 *   "VcydxgltxrVZSTV"
 *
 *   // Two arguments - returns ID of the specified length, and radix. (Radix must be <= 62)
 *   >>> Math.uuid(8, 2)  // 8 character ID (base=2)
 *   "01001010"
 *   >>> Math.uuid(8, 10) // 8 character ID (base=10)
 *   "47473046"
 *   >>> Math.uuid(8, 16) // 8 character ID (base=16)
 *   "098F4D35"
 */
(function() {
  // Private array of chars to use
  var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); 

  Math.uuid = function (len, radix) {
    var chars = CHARS, uuid = [];
    radix = radix || chars.length;

    if (len) {
      // Compact form
      for (var i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
    } else {
      // rfc4122, version 4 form
      var r;

      // rfc4122 requires these characters
      uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
      uuid[14] = '4';

      // Fill in random data.  At i==19 set the high bits of clock sequence as
      // per rfc4122, sec. 4.1.5
      for (var i = 0; i < 36; i++) {
        if (!uuid[i]) {
          r = 0 | Math.random()*16;
          uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
        }
      }
    }

    return uuid.join('');
  };

  // A more performant, but slightly bulkier, RFC4122v4 solution.  We boost performance
  // by minimizing calls to random()
  Math.uuidFast = function() {
    var chars = CHARS, uuid = new Array(36), rnd=0, r;
    for (var i = 0; i < 36; i++) {
      if (i==8 || i==13 ||  i==18 || i==23) {
        uuid[i] = '-';
      } else if (i==14) {
        uuid[i] = '4';
      } else {
        if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0;
        r = rnd & 0xf;
        rnd = rnd >> 4;
        uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
      }
    }
    return uuid.join('');
  };

  // A more compact, but less performant, RFC4122v4 solution:
  Math.uuidCompact = function() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
      return v.toString(16);
    }).toUpperCase();
  };
})();

function navigate(url) {
	document.location.href = url;
}


function cNavigate(url) {
	document.location.href = url;
}



