function initAll(){
load_footer_counters();
//flash_header_insert();
}

function initAllIndex(){
initAll();
get_cennik('stabilna');
get_cennik('beta');
get_cennik_info('stabilna','wersja','stabilna_wersja');
get_cennik_info('beta','wersja','beta_wersja');
}

function initAllCennik(){
initAll();
get_cennik('stabilna');
get_cennik('beta');
/*get_cennik_info('stabilna','opis','stabilna_opis');
get_cennik_info('beta','opis','beta_opis');*/
get_cennik_info('stabilna','wersja','stabilna_wersja');
get_cennik_info('beta','wersja','beta_wersja');
}

function initAllHosting(){
initAll();
pokazCene();
}

function flash_header_insert(){
	if(FlashDetect.installed){
	 document.getElementById('head_btn1').innerHTML='<embed src="menu.swf" width="666" height="183"></embed>';
	}
}



// GLOBAL

function showHideDiv(Name){
  if(document.getElementById(Name).style.display=='block'){
    document.getElementById(Name).style.display='none';
  }else{
    document.getElementById(Name).style.display='block';
  }
}

function processing_field(Name){
document.getElementById(Name).innerHTML='<div align="center"><img src="img_template/wait.gif" border="0"></div>';
}

function get_page_news(Amount){
processing_field('left_menu_news');
new Ajax.Request('request.php?q=get_page_news&amount='+Amount,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      document.getElementById('left_menu_news').innerHTML=response;
    },
    onFailure: function(){document.getElementById('left_menu_news').innerHTML='pusto'; }
  });
}

function processing_field(Name){
  document.getElementById(Name).innerHTML='<div align="center"><img src="img_template/wait.gif" border="0"></div>';
}


function get_cennik(Version){
var FieldName='cennik_'+Version;
processing_field(FieldName);
new Ajax.Request('request.php?q=get_cennik&version='+Version,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      document.getElementById(FieldName).innerHTML=response;
    },
    onFailure: function(){document.getElementById(FieldName).innerHTML='pusto'; }
  });
}

function get_cennik_info(Version, Type, FieldName){
processing_field(FieldName);
new Ajax.Request('request.php?q=get_cennik_info&version='+Version+'&type='+Type,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      document.getElementById(FieldName).innerHTML=response;
    },
    onFailure: function(){document.getElementById(FieldName).innerHTML='pusto'; }
  });
}

function load_footer_counters(){
  processing_field('footer_counters');
  var Text=' ';
  document.getElementById('footer_counters').innerHTML=Text;
}

function rodzaj(){
  if(document.getElementById('rodzajSelect').value=='firma'){
    document.getElementById('firmaOsobaHide').style.display='block';
  }else{
    document.getElementById('firmaOsobaHide').style.display='none';
  }
}

//validacja formularza kontaktowego
function validate(InputName){
  var Input=document.getElementById(InputName);
  var go=true;
  //wyłączenie walidacji dla pól o nazwach
  if(InputName=='xml_activation' || InputName=='licence_activation' || InputName=='nip' || InputName=='subdomena'|| InputName=='subdomenaLogin'|| InputName=='licence_test' || InputName=='user_file'){
    go=false;
  }
  if(InputName=='nazwa_firmy' && document.getElementById('firmaOsobaHide').style.display=='none'){
    go=false;
  }
  if(InputName=='nip' && document.getElementById('firmaOsobaHide').style.display=='none'){
    go=false;
  }

if(go==true){
  var ValidatorArea=document.getElementById(InputName+'Validator');
  var Valid=true;

  	//validacja dlugosci
  	if(InputName=='nazwa_firmy' || InputName=='nr_klienta'  || InputName=='fv_ulica' || InputName=='fv_nr_domu' || InputName=='fv_miejscowosc' || InputName=='koresp_ulica'|| InputName=='koresp_nr_domu' || InputName=='koresp_miejscowosc'){
		if(InputName=='fv_nr_domu' || InputName=='koresp_nr_domu'){
	  		if(Input.value.length<1){
	  			Valid=false;
	  		}
  		}else{
	  		if(Input.value.length<3){
	  			Valid=false;
	  		}
	  	}
  	}else{
	    if(Input.value.length<5){
	      Valid=false;
	    }
	}

    //imie_nazwisko
    if(InputName=='imie_nazwisko'){
      if(!Input.value.match(' ')){
        Valid=false;
      }
    }

    //email
    if(InputName=='email'){
      if(!Input.value.match('@')){
        Valid=false;
      }
      if(Input.value.match(' ')){
        Valid=false;
      }
    }


    //nr klienta
    if(InputName=='nr_klienta'){
      if(Input.value.length!=5){
        Valid=false;
      }
    }

    //nip
 /*   if(InputName=='nip'){
      var Val=Input.value.replace(/-/g, '');
      if(Val.length<10){
        var Suma;
        var Nip=Val;
        Suma=parseInt(parseInt(Nip[0])*6);
        Suma=parseInt(parseInt(Nip[1])*5)+Suma;
        Suma=parseInt(parseInt(Nip[2])*7)+Suma;
        Suma=parseInt(parseInt(Nip[3])*2)+Suma;
        Suma=parseInt(parseInt(Nip[4])*3)+Suma;
        Suma=parseInt(parseInt(Nip[5])*4)+Suma;
        Suma=parseInt(parseInt(Nip[6])*5)+Suma;
        Suma=parseInt(parseInt(Nip[7])*6)+Suma;
        Suma=parseInt(parseInt(Nip[8])*7)+Suma;
        if(Suma%11!=Nip[9]){
          Valid=false;
        }
        Valid=false;
      }
    }*/

    //domena
    if(InputName=='subdomenaCheck'){
      if(Input.value=='true'){
        Valid=true;
      }else{
      	Valid=false;
      }
    }

    switch(Valid){
      case true:
        ValidatorArea.innerHTML='&nbsp;<img src="images/kontakt_ico_ok.gif" border="0" />';
      break;
      case false:
        ValidatorArea.innerHTML='&nbsp;<img src="images/kontakt_ico_error.gif" border="0" />';
      break;
    }
    return Valid;
  }else{
    return true;
  }
}

function validateAllForm(){
  var formArea=document.getElementById('formContactInside');
  var formAreaInput=formArea.getElementsByTagName('input');
  var Ret='';
  var Input='';
  var GlobalValid=true;
  for(I=0; I<formAreaInput.length; I++){
    var Input=formAreaInput[I];
    var Valid=validate(Input.name);
    var Input='';
    if(!Valid){
      GlobalValid=false;
    }
  }
  switch(GlobalValid){
    case true:
      document.getElementById('contactProcess').style.display='block';
      document.getElementById('contactProcessOff').style.display='none';
    break;
    case false:
      document.getElementById('contactProcess').style.display='none';
      document.getElementById('contactProcessOff').style.display='block';
    break;
  }
}


/*Wybór formularza*/
function formContactChoose(){
  var ChosenFormNumber=document.getElementById('chooseSelect').selectedIndex;
  var ChosenFormId=document.getElementById('chooseSelect').options[ChosenFormNumber].value;
  var FormInsertArea=document.getElementById('formContactInside');
  if(ChosenFormId==''){
    var FormInsert='<div class="formEmpty"></div>';
  }else{
    var FormInsert=document.getElementById(ChosenFormId).innerHTML;
  }
  FormInsertArea.innerHTML=FormInsert;
  if(ChosenFormId!=''){
    validateAllForm();
  }
  document.getElementById('formContactInside').style.display='block';
  //Effect.SlideDown('formContactInside');
}

//wysłanie formularza kontaktu
function contactProcess(){
        document.getElementById('contactFormular').action = 'kontakt';
        document.getElementById('sendProcess').value='yes';
        document.getElementById('contactFormular').submit();
}
// kopiowanie danych z danych do faktury na dane korespondencyjne
function formContactDataCopy(){
	document.getElementById('koresp_imie_nazwisko').value=document.getElementById('fv_imie_nazwisko').value;
	document.getElementById('koresp_ulica').value=document.getElementById('fv_ulica').value;
	document.getElementById('koresp_nr_domu').value=document.getElementById('fv_nr_domu').value;
	document.getElementById('koresp_kod').value=document.getElementById('fv_kod').value;
	document.getElementById('koresp_miejscowosc').value=document.getElementById('fv_miejscowosc').value;
	validateAllForm();
}

//sprawdzenie dostepnosci domeny
function checkDomain(){
	Name=document.getElementById('subdomena').value;
	Login=document.getElementById('subdomenaLogin').value;
	document.getElementById('subdomenaCheckInfo').innerHTML='<img src="images/loader.gif" border="0" />';
new Ajax.Request('request.php?q=check_domain&name='+Name+'&login='+Login,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      if(response=='1'){
      	domainCheckSet('true');
      }else{
      	domainCheckSet('false');
      }
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
}

function domainCheckSet(Value){
	document.getElementById('subdomenaCheck').value=Value;
	domainCheckShowInfo(Value);
	validateAllForm();
}

function domainCheckSetFalse(){
	document.getElementById('subdomenaCheck').value='false';
	domainCheckShowInfo('false');
	document.getElementById('subdomenaCheckInfo').innerHTML='';
	validateAllForm();
}

function domainCheckShowInfo(Value){
	switch(Value){
		case 'true':
			document.getElementById('subdomenaCheck').value='true';
			document.getElementById('subdomenaCheckInfo').innerHTML='Domena jest wolna.';
		break;
		case 'false':
			document.getElementById('subdomenaCheck').value='false';
			document.getElementById('subdomenaCheckInfo').innerHTML='Domena/login jest zajęty lub nieprawidłowy.';
		break;
	}
}

//przyciski licencji i xmla
function xmlActivate(){
  if(document.getElementById('xml_activation').value==''){
    document.getElementById('xmlPlease').style.color='red';
    document.getElementById('xmlPlease').style.fontWeight='bold';
    document.getElementById('xml_activation').value='yes';
  }else{
    document.getElementById('xmlPlease').style.color='#505050';
    document.getElementById('xmlPlease').style.fontWeight='normal';
    document.getElementById('xml_activation').value='';
  }
}
function licenceActivate(){
  if(document.getElementById('licence_activation').value==''){
    document.getElementById('licencePlease').style.color='red';
    document.getElementById('licencePlease').style.fontWeight='bold';
    document.getElementById('licence_activation').value='yes';
  }else{
    document.getElementById('licencePlease').style.color='#505050';
    document.getElementById('licencePlease').style.fontWeight='normal';
    document.getElementById('licence_activation').value='';
  }
}
function licenceTest(){
  if(document.getElementById('licence_test').value==''){
    document.getElementById('licenceTest').style.color='red';
    document.getElementById('licenceTest').style.fontWeight='bold';
    document.getElementById('licence_test').value='yes';
  }else{
    document.getElementById('licenceTest').style.color='#505050';
    document.getElementById('licenceTest').style.fontWeight='normal';
    document.getElementById('licence_test').value='';
  }
}