//----------------------------------
function window_open(url,name,width,height,scroll)
{
  var NewWin = window.open(url,name,'align=center,toolbar=no,status=no,location=no,directories=no,resizable=no,width='+width+',height='+height+',scrollbars='+scroll+', left=0px, top=0px, menubar=no')
  NewWin.focus();
}

//----------------------------------
function window_print(url,name,width,height,scroll)
{
  var NewWin = window.open(url,name,'align=center,toolbar=no,status=no,location=no,directories=no,resizable=no,width='+width+',height='+height+',scrollbars='+scroll+', left=0px, top=0px, menubar=no')
  NewWin.focus();
  NewWin.print();
}

//----------------------------------
function popupWindow(pict) {
  pop2window = window.open('p_popup_image.php?pict='+ pict,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=50,left=50')
  pop2window.focus();
}


//---------------------------------- newsletterForm
function checkMail()   {
  //var mailsent = document.newsletterForm.mailsent.value;
  var name = document.newsletterForm.name.value;;
  var email;
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i


  if (filter.test(document.newsletterForm.email.value)) {
    email = document.newsletterForm.email.value;
    var a = true;
  } else {
    alert("Proszę wprowadzić prawidłowy adres e-mail.");
    var a = true;
    return false;
  }

  if(document.newsletterForm.checkAction[0].checked == true) {
    var checkAction = document.newsletterForm.checkAction[0].value;
  } 

  if (document.newsletterForm.checkAction[1].checked == true) {
    var checkAction = document.newsletterForm.checkAction[1].value;
  }

  /*
  var data = 'index.php?option=com_yanc&listid='+ listid + '&action=' + yancAction;


  if( a ) {
    document.newsletterForm.action = data;
  }
  */

  if( a ) {
    document.newsletterForm.action = "";
  }
  
  return true;
}


//---------------------------------- 
function _mpFormCheck(formobj, formName){

  if (formName == 'RegisterForm') { 
    // Enter name of mandatory fields
    var fieldRequired = Array("userlogin", "userpass1", "userpass2", "name", "email");
    // Enter field description to appear in the dialog box
    var fieldDescription = Array("Login", "Hasło", "Powtórzenie hasła", "Nazwa firmy", "Email");  
  }

  // dialog message
  var alertMsg = "Proszę uzupełnić następujące pola:\n";
  
  var l_Msg = alertMsg.length;
  
  for (var i = 0; i < fieldRequired.length; i++){
    var obj = formobj.elements[fieldRequired[i]];
    if (obj){
      switch(obj.type){
      case "select-one":
        //if (((obj.selectedIndex == -1 || obj.options[obj.selectedIndex].value == "")) && (formobj.elements['signature'].value == "")) {
        //  alertMsg += " - " + fieldDescription[i] + "\n";
        //}
        break;
      case "select-multiple":
        if (obj.selectedIndex == -1){
          alertMsg += " - " + fieldDescription[i] + "\n";
        }
        break;
      case "text":
        if (obj.value == "" || obj.value == null){
          alertMsg += " - " + fieldDescription[i] + "\n";
        } 
        break;      
      case "password":
        if (obj.value == "" || obj.value == null){
          alertMsg += " - " + fieldDescription[i] + "\n";
        } 
        break;
      case "textarea":
        if (obj.value == "" || obj.value == null){
          alertMsg += " - " + fieldDescription[i] + "\n";
        } 
        break;
      default:
      }
      if (obj.type == undefined){
        var blnchecked = false;
        for (var j = 0; j < obj.length; j++){
          if (obj[j].checked){
            blnchecked = true;
          }
        }
        if (!blnchecked){
          alertMsg += " - " + fieldDescription[i] + "\n";
        }
      }
    }
  }

  if (formobj.elements['userpass1'].value != formobj.elements['userpass2'].value) {
    alertMsg += "\nWprowadzone hasła nie są identyczne! Proszę wpisać ponownie. \n";
  }
  
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  if (!filter.test(formobj.elements['email'].value)) {
    alertMsg += "\nWprowadzone nieprawidłowy format adresu email! Proszę wpisać ponownie. \n";
  }


  //**************************
  if (alertMsg.length == l_Msg){
    return true;
  }else{
    alert(alertMsg);
    return false;
  }
}

//---------------------------------- 
function confirmLinkUseradmin(theLink, theAdditionalText)
{
    var confirmMsg  = ' ';
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(confirmMsg + '\n' + theAdditionalText);
    if (is_confirmed) {
        theLink.href;
    }

    return is_confirmed;
} // end of the 'confirmLinkUseradmin()' function

//---------------------------------- 
function _mpMailFormCheck(formobj, formName){

  if (formName == 'mailForm') { 
    // Enter name of mandatory fields
    var fieldRequired = Array("firstname", "surname", "email", "phone", "cres", "text");
    // Enter field description to appear in the dialog box
    var fieldDescription = Array("Imię", "Nazwisko", "E-mail lub Numer telefonu", "Numer telefonu", "Wynika działania matematycznego", "Treść wiadomości");  
  }

  // dialog message
  var alertMsg = "Proszę uzupełnić następujące pola:\n";
  
  var l_Msg = alertMsg.length;
  
   if ( (formobj.elements['firstname'].value == "") || (formobj.elements['firstname'].value == null) ) {
     alertMsg += " - " + fieldDescription[0] + "\n";
   } 
   
   if (formobj.elements['surname'].value == "" || formobj.elements['surname'].value == null){
     alertMsg += " - " + fieldDescription[1] + "\n";
   } 
   if ( (formobj.elements['email'].value == "" || formobj.elements['email'].value == null) && (formobj.elements['phone'].value == "" || formobj.elements['phone'].value == null) ) {
     alertMsg += " - " + fieldDescription[2] + "\n";
   } 
   if (formobj.elements['cres'].value == "" || formobj.elements['cres'].value == null){
     alertMsg += " - " + fieldDescription[4] + "\n";
   } 
   if (formobj.elements['text'].value == "" || formobj.elements['text'].value == null){
     alertMsg += " - " + fieldDescription[5] + "\n";
   } 



  //**************************
  if (alertMsg.length == l_Msg){
    return true;
  }else{
    alert(alertMsg);
    return false;
  }
}
