//own.js - Copyright 2008 Bluemind Software

    function Clear(div) { 
          if (document.getElementById) { // DOM3 = IE5, NS6 
            document.getElementById(div).innerHTML = ''; 
          } 
        } 
    function Show(div) { 
          if (document.getElementById) { // DOM3 = IE5, NS6 
            document.getElementById(div).style.display = 'block'; 
          } 
        } 
    function Hide(div) { 
          if (document.getElementById) { // DOM3 = IE5, NS6 
            document.getElementById(div).style.display = 'none'; 
          } 
        } 
        function CalculeazaVarsta() {
          Clear('div_taxa');
          Hide('varsta2');
          var data = new Date();
          data.setFullYear(document.getElementById('an').value,document.getElementById('luna').value-1,document.getElementById('zi').value);
          var idata = new Date();
          idata.setFullYear(document.getElementById('ian').value,document.getElementById('iluna').value-1,document.getElementById('izi').value);
      months = Math.ceil(data.getMonthsBetween2(idata));
          years = Math.ceil(months/12);
          selected = 0;
          if (years == 1){
            if (months == 1){selected = 1;} 
            else if (months <= 3){selected = 2;} 
            else if (months <= 6){selected = 3;} 
            else if (months <= 9){selected = 4;} 
            else if (months <= 12){selected = 5;} 
          }
          else{
            if (years > 1){selected = 6;} 
            if (years > 2){selected = 7;} 
                if (years > 3){selected = 8;} 
                if (years > 4){selected = 9;} 
                if (years > 5){selected = 10;} 
                if (years > 6){selected = 11;} 
                if (years > 7){selected = 12;} 
                if (years > 8){selected = 13;} 
                if (years > 9){selected = 14;} 
                if (years > 10){selected = 15;}
                if (years > 11){selected = 16;} 
                if (years > 12){selected = 17;} 
                if (years > 13){selected = 18;} 
                if (years > 14){selected = 19;} 
          }
          document.getElementById('s_varsta').selectedIndex  = selected;
          getReducere();
        }
        function CheckEuro34() {
          Clear('div_taxa');
          var motorizare = document.getElementById('s_motorizare').value;
          if (motorizare <=1 && motorizare>=0) {Show('euro34');}
          else{Hide('euro34')}
          getTaxaSpecifica();
          if (motorizare <=1) {getFormula1();} 
          else {getFormula2();} 
        }
        
var xmlHttp, xmlHttp2, xmlHttp3;
var processing_subscription = new Boolean(false);


function getSubscription(){
  if (!processing_subscription){
  processing_subscription=true;
  xmlHttp3=GetXmlHttpObject();
  if (xmlHttp3==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="addmember.php";
  url=url+"?fname="+document.getElementById("fname").value;
  url=url+"?lname="+document.getElementById("lname").value;
  url=url+"?email="+document.getElementById("email").value;
  url=url+"?sid="+Math.random();
  xmlHttp3.onreadystatechange=getSubscriptionStateChanged;
  xmlHttp3.open("GET",url,true);
  xmlHttp3.send(null);
  }
  else{
    alert('O apasare este suficienta. Multumim');
  }
} 

function getFormula1(){
  xmlHttp2=GetXmlHttpObject();
  if (xmlHttp2==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="formula1.html";
  url=url+"?sid="+Math.random();
  xmlHttp2.onreadystatechange=getFormulaStateChanged;
  xmlHttp2.open("GET",url,true);
  xmlHttp2.send(null);
} 

function getFormula2(){
  xmlHttp2=GetXmlHttpObject();
  if (xmlHttp2==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="formula2.html";
  url=url+"?sid="+Math.random();
  xmlHttp2.onreadystatechange=getFormulaStateChanged;
  xmlHttp2.open("GET",url,true);
  xmlHttp2.send(null);
} 

function getReducere(){
  Clear('div_taxa');
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="reducere.php";
  url=url+"?s_varsta="+document.getElementById("s_varsta").value;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=getReducereStateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function getTaxaSpecifica(){
  Clear('div_taxa');
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="taxa_specifica.php";
  url=url+"?s_motorizare="+document.getElementById("s_motorizare").value;
  url=url+"&cc="+document.getElementById("cc").value;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=getTaxaSpecificaStateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function getTaxaSpecifica_co2(){
  Clear('div_taxa');
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="taxa_specifica_co2.php";
  url=url+"?co2="+document.getElementById("co2").value;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=getTaxaSpecifica_co2StateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function getReducereFiltru(){
  Clear('div_taxa');
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="reducere_filtru.php";
  url=url+"?cb_filter="+document.getElementById("cb_filter").checked;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=getReducereFiltruStateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function getTaxa(){
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="taxa.php";
  url=url+"?s_varsta="+document.getElementById("s_varsta").value;
  url=url+"&s_motorizare="+document.getElementById("s_motorizare").value;
  url=url+"&cc="+document.getElementById("cc").value;
  url=url+"&co2="+document.getElementById("co2").value;
  url=url+"&cb_filter="+document.getElementById("cb_filter").checked;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=getTaxaStateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function getSubscriptionStateChanged() { 
  if (xmlHttp3.readyState==4){ 
    document.getElementById('div_subscription').innerHTML=xmlHttp3.responseText;
  }
}

function getFormulaStateChanged() { 
  if (xmlHttp2.readyState==4){ 
    document.getElementById('formula').innerHTML=xmlHttp2.responseText;
  }
}

function getReducereStateChanged() { 
  if (xmlHttp.readyState==4){ 
    document.getElementById("div_reducere").innerHTML=xmlHttp.responseText;
    Show('div_reducere');
  }
}

function getTaxaSpecificaStateChanged() { 
  if (xmlHttp.readyState==4){ 
    document.getElementById("div_taxa_specifica").innerHTML=xmlHttp.responseText;
    Show('div_taxa_specifica');
  }
}

function getTaxaSpecifica_co2StateChanged() { 
  if (xmlHttp.readyState==4){ 
    document.getElementById("div_taxa_specifica_co2").innerHTML=xmlHttp.responseText;
    Show('div_taxa_specifica_co2');
  }
}

function getReducereFiltruStateChanged() { 
  if (xmlHttp.readyState==4){ 
    document.getElementById("div_reducere_filtru").innerHTML=xmlHttp.responseText;
    Show('div_reducere_filtru');
  }
}

function getTaxaStateChanged() { 
  if (xmlHttp.readyState==4){ 
    document.getElementById("div_taxa").innerHTML=xmlHttp.responseText;
    Show('div_taxa');
  }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
