var _Last = '';


function selall(r) {    for (i = 0; i < allf; i++) {        if (document.getElementById(r+i).checked) {            document.getElementById(r+i).checked = false;
        } else {
            document.getElementById(r+i).checked = true;
        }
    }
}

function webstatistika_help(_fl) {
	document.write(_fl);
}

function textCounter(field, countfield, maxlimit) {	if (field.value.length > maxlimit) {
	    field.value = field.value.substring(0, maxlimit);
	} else {
        countfield.value = maxlimit - field.value.length;
	}
}

function setactiveJs(b) {
    document.getElementById('f'+_curractiveJs).className = 'inactivejs';
    document.getElementById('f'+_curractiveJs+'x').className = 'inactivejs2';
    document.getElementById('f'+b).className = 'activejs';
    document.getElementById('f'+b+'x').className = 'activejs2';
    _curractiveJs = b;
    document.getElementById('innhtml').innerHTML = _arrayjs[b];
}


function setColor(nums, _element){
    if (nums == 1) {
       document.getElementById(_element).style.color = '#CC0C0D';
       var cmdString = 'setTimeout("setColor(2, \''+_element+'\')", 500);';
       eval(cmdString);

    } else {
       document.getElementById(_element).style.color = '#FFDE00';
       var cmdString = 'setTimeout("setColor(1, \''+_element+'\')", 500);';
       eval(cmdString);
    }

}

function checkProdName() {

    if (document.addFormCheck.T1lv.value=='') {

        document.addFormCheck.T1lv.focus();
        return false;

    }

    return true;

}

function setOpenC(name, value) {
      document.cookie = name + "=" + escape(value);
}


function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
document.getElementById('xd'+value).innerHTML = '&nbsp;<img src="/mora/images/pay.gif" alt="" border=0 align="absmiddle">';
if (_Last != '' && _Last != value) {
document.getElementById('xd'+_Last).innerHTML = '';
}
_Last = value;
}


function setLST( value ) {
    if (document.getElementById('xd'+value)) {
        document.getElementById('xd'+value).innerHTML = '&nbsp;<img src="/mora/images/pay.gif" alt="" border=0 align="absmiddle">';
        _Last = value;
    }
}

function Get_Cookie( name ) {

var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

function setColor(nums, _element){
    if (nums == 1) {
       document.getElementById(_element).style.color = '#CC0C0D';
       var cmdString = 'setTimeout("setColor(2, \''+_element+'\')", 500);';
       eval(cmdString);

    } else {
       document.getElementById(_element).style.color = '#FFDE00';
       var cmdString = 'setTimeout("setColor(1, \''+_element+'\')", 500);';
       eval(cmdString);
    }

}

function openWin(https,wid,hei,name){
shopWin = open(https, name, "scrollbars=no,status=1,resizable=no,width="+wid+",height="+hei+"");
        shopWin.focus();
}

function openWinScroll(https,wid,hei,name){
shopWin = open(https, name, "scrollbars=yes,resizable=no,width="+wid+",height="+hei+"");
        shopWin.focus();
}

function openWinScrollPrint(https,wid,hei,name){
shopWin = open(https, name, "scrollbars=yes,toolbar=1,resizable=no,width="+wid+",height="+hei+"");
        shopWin.focus();
}

function submitform() {
  document.foratrmekl.submit();
}


function _checkSearch() {

     if (document.formPostSearch.T1.value.length < 3) {

           alert(_res[21]);
           document.formPostSearch.T1.focus();
           return false;

     }
     return true;

}

function setfade(a, b) {
   i = 0;
   while(document.getElementById('fid'+i)) {
       var x = document.getElementById('fid'+i);
       x.filters.alpha.opacity=100;
       //alert(x);
       i++;
   }

   if (document.getElementById(a)) {

       var x = document.getElementById(a);
       x.filters.alpha.opacity=b;

   }

}


function setfade2(a, b) {
   i = 0;
   while(document.getElementById('fid'+i)) {
       var x = document.getElementById('fid'+i);
       x.filters.alpha.opacity=100;
       //alert(x);
       i++;
   }

   if (document.getElementById(a)) {

       var x = document.getElementById(a);
       x.filters.alpha.opacity=b;

   }

}

function setOpener(_id, fileUrl) {
    document.getElementById(_id).value = rootfileurl + fileUrl;
}


function cForm(form, fname){
       form.target = fname;
       form.action='editlast.php';
       openWinScroll('loading.php', 450, 220, fname);
       //win=window.open(,fname,'scrollbars=no,resizable=no,width=310,height=249');

}

function cForm_D(form, fname){
       form.target = fname;
       form.action='addfirm/update_kods.php';
       openWinScroll('pas/loading.php', 770, 600, fname);
       //win=window.open(,fname,'scrollbars=no,resizable=no,width=310,height=249');

}

function OnLoadFunctions() {
    timeDiff();
    populate();

}

function movein4(which,html){
which.style.background='#FF6600'
}
function moveout4(which, html){
which.style.background='#c9141d'
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
}

function confirmLink()
{
    confirmMsg  = 'Uzmanību! ';
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm('Uzmanību \ntiešām dzēst?');
    if (is_confirmed) {
       // theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
}

function chstyle(a, b) {

    var x = document.getElementById(b);
   // alert(x);
    x.className  = a;

}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }

    return str;
}

function vis(a) {


    if (a == 0) {
        _sel = 'hidden';
        _sel2 = 'none';
    } else {
        _sel = 'visible';
        _sel2 = 'inline';
    }

    document.getElementById('search').style.visibility = _sel;
    document.getElementById('selvis').style.display = _sel2;
    document.getElementById('selvis').style.visibility = _sel;

}

function checkMail(x)
{
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (filter.test(x)) return 1;
        else return 0;
}


function checkFormSend() {

       if (document.form1.lig_no_1.value=='' || document.form1.lig_no_2.value=='') {

           alert('Ievadiet Līguma numurs');
           document.form1.lig_no_2.focus();
           return false;
       }


       if (document.form1.firm_name.value=='') {

           alert('Ievadiet Firmas nosaukums');
           document.form1.firm_name.focus();
           return false;

       }

       if (document.form1.jur_addr.value=='') {

           alert('Ievadiet Juridiskā adrese');
           document.form1.jur_addr.focus();
           return false;

       }

       if (document.form1.reg_no.value=='') {

           alert('Ievadiet Reģistrācijas numurs');
           document.form1.reg_no.focus();
           return false;

       }
       if (document.form1.reg_gads.value=='') {

           alert('Ievadiet Reģistrācijas gads');
           document.form1.reg_gads.focus();
           return false;

       }
       if (document.form1.reg_men.value=='') {

           alert('Ievadiet Reģistrācijas mēnesis');
           document.form1.reg_men.focus();
           return false;

       }
       if (document.form1.reg_day.value=='') {

           alert('Ievadiet Reģistrācijas datums');
           document.form1.reg_day.focus();
           return false;

       }
       if (document.form1.banka.value=='') {

           alert('Ievadiet Banka');
           document.form1.banka.focus();
           return false;

       }
       if (document.form1.konts.value=='') {

           alert('Ievadiet Konts');
           document.form1.konts.focus();
           return false;

       }
       if (document.form1.persona.value=='') {

           alert('Ievadiet Kontaktpersona');
           document.form1.persona.focus();
           return false;

       }

       if (document.form1.phone.value=='') {

           alert('Ievadiet Tālrunis');
           document.form1.phone.focus();
           return false;

       }
       if (document.form1.login.value=='') {

           alert('Ievadiet Lietotājs login');
           document.form1.login.focus();
           return false;

       }
       if (document.form1.pass.value=='') {

           alert('Ievadiet Parole');
           document.form1.pass.focus();
           return false;

       }

       if (document.form1.email.value != '') {
           _ret = checkMail(document.form1.email.value);
           if (!_ret) {
              alert('Nepareiza e-pasta adrese');
              document.form1.email.focus();
              return false;
           }

       }


       return true;
}



function checkFormSendClient() {



       if (document.FormReg.firm_name.value=='') {

           alert(_res[0]);
           document.FormReg.firm_name.focus();
           return false;

       }

       if (document.FormReg.jur_addr.value=='') {

           alert(_res[1]);
           document.FormReg.jur_addr.focus();
           return false;

       }

       if (document.FormReg.reg_no.value=='') {

           alert(_res[2]); ;
           document.FormReg.reg_no.focus();
           return false;

       }

       if (document.FormReg.banka.value=='') {

           alert(_res[6]);
           document.FormReg.banka.focus();
           return false;

       }
       if (document.FormReg.konts.value=='') {

           alert(_res[7]);
           document.FormReg.konts.focus();
           return false;

       }

       if (document.FormReg.phone.value=='') {

           alert(_res[11]);
           document.FormReg.phone.focus();
           return false;

       }

       if (document.FormReg.email.value != '') {
           _ret = checkMail(document.FormReg.email.value);
           if (!_ret) {
              alert(_res[20]);
              document.FormReg.email.focus();
              return false;
           }

       }


       return true;
}

function setactive2(a, b) {

   i = 0;
   while(document.getElementById('bid'+i)) {
       var x = document.getElementById('bid'+i);
       x.style.fontWeight="normal";
       i++;
   }

   if (document.getElementById(a)) {

       var x = document.getElementById(a);
       x.style.fontWeight="bold";

   }
   current = b;
}
function change_im(id, image){
   document.getElementById(id).src=image;
}