sLT=new Array(2);

sLT[0] = new Array('please fill out all fields','password strength has to be at least weak','please fill out all fields correctly');
sLT[1] = new Array('wype&#322;nij wszystkie pola','hasło nie jest bezpieczne','prosimy wypełnić pola prawidłowo');


function wr(hs){
 document.write(hs);
}

function getObj(nm) {
 var obj;
 try{
   obj=document.getElementById(nm);
   if(!obj){
     obj=document.all(nm);
   }
 } catch(e) {}

 return obj;
}

function SetAlphaObj(nm,val) {
  var obj = getObj(nm);
  if (obj) {
    SetAlpha(obj,val);
   // alert('1');
  } else {
  //  alert('2');
  }
}

function SetAlpha(obj,val) {
 if (obj) {
  if (val == 0 || val == 100) {
    if (!val) {
      obj.style.filter = 'alpha(opacity=0)';
      obj.style.opacity = '0';
      obj.style["-moz-opacity"] = '0';
    //  obj.style.visibility = 'hidden';
    }
    else {
      obj.style.visibility = 'visible';
      obj.style.filter = 'alpha(opacity=100)';
      obj.style.opacity = '1';
      obj.style["-moz-opacity"] = '1';
    }
  } else {
    obj.style.filter = 'alpha(opacity='+val+')';
    obj.style["-moz-opacity"] = '.'+val;
    obj.style.opacity = '.'+val;
  }
 }
}

function ChangeAlpha(nm) {
 var obj = getObj(nm);

 if (obj && obj.alphaAdd) {
   obj.alpha += obj.alphaAdd;
   obj.steps --;
   if (obj.steps>0 && obj.style.visibility == 'visible') {
     SetAlpha(obj,parseInt(obj.alpha));
     setTimeout("ChangeAlpha('"+nm+"')",50);
   } else {
     if (obj.alphaAdd<0) SetAlpha(obj,0);
       else SetAlpha(obj,obj.maxA);
   }
 }
}

function ElementVis(nm, val, steps, maxalpha) {  // if steps>0 - fade
 var obj = getObj(nm);

 if (obj) {
  if (!steps || steps == 1) {  // no fade
   if (val) {
    SetAlpha(obj,100);
   } else {
    SetAlpha(obj,0);
    obj.alphaAdd = 0;
   }
  }
  else {  // fade
   obj.steps = steps;
   obj.alphaAdd = maxalpha/steps;
   obj.maxA = maxalpha;

   if (val) {
     obj.alpha = 0;
     SetAlpha(obj,0);
     obj.style.visibility = 'visible';
   } else {
     obj.alphaAdd = - obj.alphaAdd;
     SetAlpha(obj,100);
   }

    setTimeout("ChangeAlpha('"+nm+"')",50);
  }

 } else {
      //  setTimeout("ElementVis('"+nm+"', '"+val+"', '"+steps+"', '"+maxalpha+"')",500);
    setTimeout("SetAlphaObj('"+nm+"','100')",500);
 }

}

var VisibleLayer = 0;

function showLayer(id, stp, maxAlph) {
  if (!stp) {stp = 6; }
  if (!maxAlph) {maxAlph = 100; }

  if (VisibleLayer) {
    if (id != VisibleLayer) {
      ElementVis('mm'+VisibleLayer, false);
    }
  }

  VisibleLayer = id;
  ElementVis('mm'+VisibleLayer, true, stp, maxAlph);
}


function buttons(lic) {
  var $stl = 'style="width:60px;"';
  for (hj=1; hj<=lic; hj++) {
    wr('<input type="button" value="mm' + hj + '" onClick="showLayer(\''+hj+'\')" ' + $stl + '>');
  }
}

function myConfirm(myMsg)
{
  var decis = confirm(myMsg);

  if (decis) { return true; }
        else { return false; }
}

function checkTxt(fNm,eNm1,eNm2) {

  txt1 = document.forms[fNm].elements[eNm1].value;
  txt2 = document.forms[fNm].elements[eNm2].value;

  if (txt1 != txt2 || !txt2) {
    getObj(eNm2+'Txt').style.color = '#FF8585';
    return 1;
  } else {
    getObj(eNm2+'Txt').style.color = '#F9F9E9';
    return 0;
  }
}

function checkInput(fNm,eNm,len,dontChCol) {
  if (!len) { len = 2; }

  if (document.forms[fNm].elements[eNm].value.length < len) {
    if (!dontChCol)
      getObj(eNm+'Txt').style.color = '#FF8585';
    return 1;
  } else {
    if (!dontChCol)
      getObj(eNm+'Txt').style.color = '#F9F9E9';
    return 0;
  }
}

function checkSelect(fNm,eNm) {
  if (document.forms[fNm].elements[eNm].selectedIndex < 1) {
    getObj(eNm+'Txt').style.color = '#FF8585';
    return 1;
  } else {
    getObj(eNm+'Txt').style.color = '#F9F9E9';
    return 0;
  }
}

function checkMail(fNm,eNm) {
  mail = document.forms[fNm].elements[eNm].value;
  var Vmail = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z])+$/;

	if (!Vmail.test(mail)) {
    getObj(eNm+'Txt').style.color = '#FF8585';
    return 1;
  } else {
    getObj(eNm+'Txt').style.color = '#F9F9E9';
    return 0;
  }
}

function setFocus(nm) {
  if (nm) {
    var foc = getObj(nm);
    if (foc) { foc.focus(); }
  }
}

function setAttr(nm,attr,val) {
  var obj = getObj(nm);
  if (obj) { obj.setAttribute(attr,val); }
}

function changeClassTxt(Elem, myClass, myTxt, doFocus) {
  var elem = getObj(Elem);

  if(elem) {
    if(myClass) elem.className = myClass;
    elem.innerHTML = myTxt;
    setFocus(doFocus);
  }
}

function showGenWin(Elem, myClass, myTxt) {
  var elem = getObj(Elem);

  if(elem) {
    if(myClass) elem.className = myClass;
    elem.innerHTML = myTxt+'...<br><br><center><img src="/imgs/wait.gif" alt="'+myTxt+'"></center><br>';
    setFocus(doFocus);
  }
}


function checkR1Form(langID) {
  if (langID == undefined) langID = 0;
  err    = 0;
  formNm = 'sub';

  err += checkInput(formNm,'r_famName');
  err += checkInput(formNm,'r_firName');
  err += checkSelect(formNm,'r_reg');
  err += checkMail(formNm,'r_mail');
  err += checkInput(formNm,'r_idnr',5);

  if (err>0) {
    changeClassTxt('mc1','warn',sLT[langID][0]);
  } else {
    document.forms[formNm].submit();
  }
}

function checkR2Form(langID) {
  if (langID == undefined) langID = 0;
  err    = 0;
  formNm = 'sub';

  err += checkInput(formNm,'r_mailCode',32);
  err += checkInput(formNm,'r_userNm',6);
  err += checkInput(formNm,'r_userP1',6);
  err += checkInput(formNm,'r_userP2',6);
  err += checkTxt(formNm,'r_userP1','r_userP2');

  if ( 1 > checkPS(getObj('r_userNm').value,getObj('r_userP1').value) )
   { err += 20; }

  if (err>0) {
     if (err==20) {
       changeClassTxt('mc1','warn',sLT[langID][1]);
     } else {
       changeClassTxt('mc1','warn',sLT[langID][2]);
     }
  } else {
    document.forms[formNm].submit();
  }
}

function rand(nr) {
  return Math.floor(Math.random()*nr);
}

function checkPS(user,pass) {
  if (pass.length<6 || user.length<6) {
    return -1;
  } else {
    var len,allu,myadd,eb,cd,hj,hk,hl,hh,ch,hm,hn;

    len  = pass.length;
    len4 = len/4;

    allu = 0.2;
    for (hj=0; hj<len; hj++) {
      eb = 2.5 - Math.abs(2-(hj+1)/len4);

      if (hj<user.length) {
        cd = user.charCodeAt(hj);
        ch = user.charAt(hj);
      } else {
        cd = 0;
        ch = '';
      }

      if (hj<pass.length) {
        hk = pass.charCodeAt(hj);
        hh = pass.charAt(hj);
        hn = user.indexOf(hh);
        hl = pass.indexOf(hh);
        hm = pass.lastIndexOf(hh);
      } else {
        hk = 0;
        hl = 0;
      }

      if (hk!=cd) {
        myadd = 0;
        if (hl==hm) { myadd += 0.1; }
        if (Math.abs(hk-cd) == 32 && hh.toUpperCase() == ch.toUpperCase() ) { hk = 0; }

        if (hk>=97 && hk<=122)             { myadd += 0.16; } else
        if ((hk>=65 && hk<=90) || hk==49)  { myadd += 0.2;  } else
        if (hk>=48 && hk<=57)              { myadd += 0.4*eb; } else
        if (hk>0)                          { myadd += 0.9*eb; }
        
        if (hn>=0) { myadd = myadd/2; }
        allu += myadd;
      }
    }
  }

  hk = Math.floor(allu);
    // + str/2 + dig/3 + letU/4 + letL/4 ) );
  if (hk>4) hk = 4;
  if (hk>len-5) hk = len-5;
  return hk;
}


var oldps = 0;
    colArr = new Array ('#606060','#FF4040','#CC8A00','#328C26','#9330DF');
function passStr(user,pass) {
  if (oldps>=0) {
    getObj('ps'+oldps).style.background = '#E8E8E8';
  }
  oldps = checkPS(getObj(user).value,getObj(pass).value);

  if (oldps>=0) {
    getObj('ps'+oldps).style.background = colArr[oldps];
  }
}

var sj = rand(1000000);
function genNewPic(rid,pid) {
  npid = pid + sj;
  sj ++;
  getObj('rPic').src = 'genPic.pl?rid=' + rid + '&pid=' + npid;
}


