function get_radio_value(obiekt)
{
for (var i=0; i < obiekt.length; i++)
   {
   if (obiekt[i].checked)
      {
      var rad_val = obiekt[i].value;
      }
   }
   return rad_val;
}

function przelicz_badania()
{
var link='?set=0';
for (var i = 0; i<300 ; i++) {
	pole = 'document.badania_form.pytanie_'+i;
  obiekt = eval(pole);    
if(typeof obiekt != "undefined"){
	 
if (get_radio_value(obiekt)>0) link=link+'&'+'pyt'+i+'='+get_radio_value(obiekt);

}
}

http = getHTTPObject();
var myurl = 'http://www.pakiety.diag.pl/lista_badan.php'+link;
  http.open("GET", myurl, true);
  http.onreadystatechange = function() {
    if (http.readyState == 4) {
      var textout = http.responseText;
      document.getElementById('lista_badan').innerHTML=textout;
    }
  };
  http.send(null);


}




function getHTTPObject() {
  if (typeof XMLHttpRequest != 'undefined') {
    return new XMLHttpRequest();
  } try {
    return new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      return new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
  } return false;
}

// nakladka flash 
function html2Swf(id) {
  $a = id.split("_");
  var headlineWd = $a[0];
  var headlineHg = $a[1];
  var headlineName = $a[2];

  var headlineId = headlineName + "_swf";
  var headlineObjId = headlineName + "_obj";
  var headlineFile = "flash/" + id + ".swf";

  var inputTag = document.getElementById(headlineId);
  var temp = inputTag.innerHTML;
  var temp = removeNL(temp);

  var flashvars = {temp: temp};
  var params = {menu: "false", scale: "noscale", wmode: "transparent"};
  var attributes = {id: headlineObjId, name: headlineObjId};
  swfobject.embedSWF(headlineFile, headlineId, headlineWd, headlineHg, "9.0.0", "flash/expressInstall.swf", flashvars, params, attributes);
}
// przetwarzanie htmla dla flasha
function removeNL(s) {
  r = "";
  for (i=0; i < s.length; i++) {
    if (s.charAt(i) != '\n' &&
        s.charAt(i) != '\r' &&
        s.charAt(i) != '\t') {
      r += s.charAt(i);
      }
    }
  return r;
}

function checkNum(val) {
	if (!is_numeric(val)) {
		alert('Proszę podać poprawny wiek');
		document.registerForm.sendFormButton.disabled=true;
	} else {
		document.registerForm.sendFormButton.disabled=false;
	}
}

function chechPostal(val) {
	if (!postal_code_validate(val)&&val!=='') {
		alert ('Niepoprawny kod pocztowy. Proszę wpisać w postaci 00-000');
		document.registerForm.sendFormButton.disabled=true;
	} else {
		document.registerForm.sendFormButton.disabled=false;
	}
}

function mailChecker(val) {
	if (!email_validate(val)) {
		alert ('Niepoprawny adres email.')
		document.registerForm.sendFormButton.disabled=true;
	} else {
		document.registerForm.sendFormButton.disabled=false;
	}
}


function email_validate(src) 
{
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(src);
}

function postal_code_validate(src) {
  var regex = /^[0-9]{2}\-[0-9]{3}$/;
  return regex.test(src);
}

function is_numeric (mixed_var) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: David
    // +   improved by: taith
    // +   bugfixed by: Tim de Koning
    // +   bugfixed by: WebDevHobo (http://webdevhobo.blogspot.com/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: is_numeric(186.31);
    // *     returns 1: true
    // *     example 2: is_numeric('Kevin van Zonneveld');
    // *     returns 2: false
    // *     example 3: is_numeric('+186.31e2');
    // *     returns 3: true
    // *     example 4: is_numeric('');
    // *     returns 4: false
    // *     example 4: is_numeric([]);
    // *     returns 4: false

    return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
}

function checkUpdateProfil() {
	if (document.getElementById('password_old').value==''){
		alert('nie podano starego hasła');
		return false;
	} else {
		if (document.getElementById('password').value!==document.getElementById('password2').value) {
			alert('powtórzono rózniące się od siebie nowe hasło');
			return false;			
		} else {
			return true;
		}
	}
	
}

