function openWin(https,wid,hei,name){
shopWin = open(https, name, "scrollbars=no,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 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 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.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.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.persona.value=='') {

           alert(_res[10]);
           document.FormReg.persona.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 checkFormPukes() {


       if (document.SendForms.pasutitajs_name.value=='') {

           alert(_res[22]);
           document.SendForms.pasutitajs_name.focus();
           return false;

       }

       if (document.SendForms.pasutitajs_phone.value=='') {

           alert(_res[23]);
           document.SendForms.pasutitajs_phone.focus();
           return false;

       }

       if (document.SendForms.pasutitajs_email.value=='') {

           alert(_res[24]);
           document.SendForms.pasutitajs_email.focus();
           return false;

       }

       if (document.SendForms.pasutitajs_email.value != '') {
           _ret = checkMail(document.SendForms.pasutitajs_email.value);
           if (!_ret) {
              alert(_res[20]);
              document.SendForms.pasutitajs_email.focus();
              return false;
           }

       }


       if (document.SendForms.adresats_name.value=='') {

           alert(_res[22]);
           document.SendForms.adresats_name.focus();
           return false;

       }

       if (document.SendForms.adresats_phone.value=='') {

           alert(_res[23]);
           document.SendForms.adresats_phone.focus();
           return false;

       }

       if (document.SendForms.adresats_other.value=='') {

           alert(_res[25]);
           document.SendForms.adresats_other.focus();
           return false;

       }

       if (document.SendForms.pieg_date.value=='') {

           alert(_res[26]);
           document.SendForms.pieg_date.focus();
           return false;

       }

       if (document.SendForms.pieg_time.value=='') {

           alert(_res[26]);
           document.SendForms.pieg_time.focus();
           return false;

       }

       if (!document.SendForms.agree.checked) {

           alert(_res[27]);
           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;
}