﻿function calculatePasswordStrength(password) {
  var score = 0;

  // Length at least 8 chars long
  if (password.length >= 8)
    score++;

  // both lower and uppercase chars
  if (password.match(/[a-z]/) && password.match(/[A-Z]/))
    score++;

  // at least one num char
  if (password.match(/[0-9]+/))
    score++;

  // at least one special char
  if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)-]/))
    score++;

  // Length at least 12 chars long
  if (password.length >= 12)
    score++;

  return score;
}

function simplifiedPasswordStrength(password) {
  var score = 0;

  // Length at least 6 chars long
  if (password.length >= 6)
    score++;

  return score;
}


function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posY = 0; oElement; oElement = oElement.offsetParent ) {
        if (oElement.offsetTop)
            posY += oElement.offsetTop;
    }
    return  posY ;
  } else {
    return oElement.y;
  }
}
function findMargin( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0; oElement; oElement = oElement.offsetParent ) {
        if (oElement.offsetLeft)
            posX += oElement.offsetLeft;
    }
    return  posX ;
  } else {
    return oElement.x;
  }
}
var treeDivID = '';
var footerText = '';

function resizeContentTable()
{
//return;
  height = 0;
  width = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    height = window.innerHeight;
    width = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    height = document.documentElement.clientHeight;
    width = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    height = document.body.clientHeight;
    width = document.body.clientWidth;
  }
  if (height > 0)
  {
    footerCellHeight = 0;
    if (footerText.length > 0)
       footerCellHeight = 50;
    else
    {
      footerDiv = document.getElementById('footerCell');
      footerDiv.style.display = 'none';
    }
   element1 = document.getElementById('treeCell');
   treewidth = 250;
   loadDivVisibility('treeCell');    
   if(element1 != null &&  typeof(element1) != 'undefined' ) {
    //height = height - findPosition(element1);
    element1.style.height = (height - findPosition(element1)) +'px';
    if (element1.clientWidth != null && element1.clientWidth > 0)
        treewidth = element1.clientWidth;
    if (element1.style.display=='none')
      treewidth = 0
   }
   else
   {
      treewidth = 0
   }
   element3 = document.getElementById('subContent');
   if( element3 != null && typeof(element3) != 'undefined' ) 
   {
     pos3 = findPosition(element3);
     if (pos3 + footerCellHeight > height)
      pos3 = 0;
     element3.style.height = (height - pos3 - footerCellHeight) + 'px';
     if (treewidth - 20 < width)
        element3.style.width = (width - treewidth - 20)+'px';   
   }      
   
   element2 = document.getElementById('contentCell');
   if(element2 != null &&  typeof(element2) != 'undefined' ) 
   {
     pos2 = findPosition(element2);
     if (pos2 > height)
      pos2 = 0;
     element2.style.height = (height - pos2)+'px';   
     if (treewidth - 20 < width)     
        element2.style.width = (width - treewidth  - 20)+'px';   
   }

   element4 = document.getElementById(treeDivID);
   if(element4 != null && typeof( element4) != 'undefined' ) 
   {
     pos4 = findPosition(element4);
     if (pos4 > height)
      pos4 = 0;   
     element4.style.height = (height - pos4)+'px';   
   }
  }
}
function resizeContentFF()
{
//return;
  height = 0;
  width = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    height = window.innerHeight;
    width = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    height = document.documentElement.clientHeight;
    width = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    height = document.body.clientHeight;
    width = document.body.clientWidth;
  }
  if (height > 0)
  {
    footerCellHeight = 0;
    if (footerText.length > 0)
       footerCellHeight = 50;
    else
    {
      footerDiv = document.getElementById('footerCell');
      footerDiv.style.display = 'none';
    }
   element1 = document.getElementById('treeCell');
   treewidth = 245;
   loadDivVisibility('treeCell');
   if(element1 != null &&  typeof(element1) != 'undefined' ) {
    //height = height - findPosition(element1);
    element1.style.height = (height - findPosition(element1)) +'px';
    if (element1.clientWidth != null && element1.clientWidth > 0)
        treewidth = element1.clientWidth;
    if (element1.style.display=='none')
      treewidth = 0        
   }
   else
   {
      treewidth = 0        
   }
   element2 = document.getElementById('contentCell');
   if(element2 != null &&  typeof(element2) != 'undefined' ) 
   {
     pos2 = findPosition(element2);
     if (pos2 > height)
      pos2 = 0;
     element2.style.height = (height - pos2)+'px';   
     if (treewidth - 10 < width)     
        element2.style.width = (width - treewidth - 10)+'px';   
   }
   element3 = document.getElementById('subContent');
   if( element3 != null && typeof(element3) != 'undefined' ) 
   {
     pos3 = findPosition(element3);
     if (pos3 + footerCellHeight > height)
      pos3 = 0;
     element3.style.height = (height - pos3 - footerCellHeight) + 'px';
     if (treewidth - 10 < width)
        element3.style.width = (width - treewidth - 10)+'px';   
   }   
   element4 = document.getElementById(treeDivID);
   if(element4 != null && typeof( element4) != 'undefined' ) 
   {
     pos4 = findPosition(element4);
     if (pos4 > height)
      pos4 = 0;   
     element4.style.height = (height - pos4)+'px';   
   }
  }
}
function loadTreePosition()
{
    loadDivPosition(treeDivID);
}
function loadDivPosition(divID) 
{
   var tvDiv = document.getElementById(divID);
   if(tvDiv != null &&  typeof(tvDiv) != 'undefined' ) 
   {
       tvDiv.scrollTop = getCookie(divID + "yPos");
   }
}
function setDivPosition(divID)
{
  var divPanel = document.getElementById(divID);
  if(divPanel != null &&  typeof(divPanel) != 'undefined' ) 
  {
    var intY = divPanel.scrollTop;
    document.cookie = divID+"yPos=" + intY ;
  }
}
      
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 printdiv(printpage)
{
    var headstr = "<html><head><title></title></head><body>";
    var footstr = "</body></html>";
    var myDiv = document.getElementById(printpage);
    var newstr = document.body.innerHTML;
    if(myDiv != null &&  typeof(myDiv) != 'undefined' ) 
    {
      newstr = myDiv.innerHTML;
    }
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = headstr+newstr+footstr;
    window.print();
    document.body.innerHTML = oldstr;
return false;
}
function loadDivVisibility(divID) 
{
   var tvDiv = document.getElementById(divID);
   if(tvDiv != null &&  typeof(tvDiv) != 'undefined' ) 
   {
     tvDiv.style.display = getCookie(divID+"display");
   }
}
 function hideMenu()
 {
   element1 = document.getElementById('treeCell');
   if(element1 != null &&  typeof(element1) != 'undefined' ) {
    element1.style.display = 'none';
    document.cookie = "treeCelldisplay=none";
   }
 }
 function showMenu()
 {
   element1 = document.getElementById('treeCell');
   if(element1 != null &&  typeof(element1) != 'undefined' ) {
    element1.style.display = 'block';
    document.cookie = "treeCelldisplay=inline";
   }
 }
 
function charCounter(textId, lblId, totalchar) 
{
  var textbox = document.getElementById(textId);
  var lbl = document.getElementById(lblId);  

  if(textbox != null &&  typeof(textbox) != 'undefined' && lbl != null &&  typeof(lbl) != 'undefined' ) 
  {
    if (textbox.value.length > totalchar) 
    {
      textbox.value = textbox.value.substring(0, totalchar);
    }
    lbl.innerHTML = textbox.value.length + "/" + (totalchar - textbox.value.length);
  }
}
