// JavaScript Document
function kontakt() {
	w=window.open("kontakt.htm","Kontakt","width=405,height=340",1);
}

function korzysci() {
	w=window.open("korzysci.htm","Korzyści","width=455,height=310",1);
}

function elektroniczne_formaty() {
	w=window.open("elektroniczne_formaty.htm","Elektroniczne_formaty_tłumaczeń","width=565,height=345",1);
}

function cennik_szczegolowy() {
	w=window.open("cennik_szczegolowy.htm","Cennik_szczegółowy","width=820,height=520",1);
}

function pomoc_wycena() {
	w=window.open("pomoc_wycena.htm","Pomoc","width=480,height=385",1);
}

function wycena_indywidualna() {
	window.opener.location="wycena_indywidualna.htm";
    window.close();
}

function mapka() {
	window.opener.location="mapka.htm";
    window.close();
}

function zamowienie() {
	window.opener.location="zamowienie.htm";
    window.close();
}

/******************************** traduction polonaise **********************************/

function contact() {
	w=window.open("contact.htm","Contact","width=405,height=340",1);
}

function aide_devis() {
	w=window.open("aide_devis.htm","Aide","width=480,height=365",1);
}

function devis_detaille() {
	window.opener.location="devis_detaille.htm";
    window.close();
}

function formats_electroniques() {
	w=window.open("formats_electroniques.htm","Formats_électroniques_pris_en_charge","width=660,height=345",1);
}

function avantages() {
	w=window.open("avantages.htm","Vos_avantages_fidélité","width=455,height=310",1);
}

function commande() {
	window.opener.location="commande.htm";
    window.close();
}


/******************************** EN **********************************/

function contact_en() {
	w=window.open("contact_en.htm","Contact","width=405,height=340",1);
}

function quotation_guide() {
	w=window.open("quotation_guide.htm","Guide","width=480,height=365",1);
}

function detailed_quotation() {
	window.opener.location="detailed_quotation.htm";
    window.close();
}

function electronic_formats() {
	w=window.open("electronic_formats.htm","Formats","width=660,height=345",1);
}

function incentives() {
	w=window.open("incentives.htm","Incentives","width=455,height=310",1);
}

function order() {
	window.opener.location="order.htm";
    window.close();
}


/*************************************** wycena *****************************************/

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/*************************************** wycena pl ***************************************/

function validateForm() { //v4.0+
  var errors='';
  
  var oF,oT,vF,vT;
  // languages
  oF=MM_findObj('fromLang');
  oT=MM_findObj('toLang');
  vF=oF.value;
  vT=oT.value;
  if(vF=='' || vT=='')
    errors+='- nie wybrano języka tłumaczenia.\n';
  else
  if(vF==vT)
    errors+='- wybrano tłumaczenie na ten sam język.\n';
  else
  if((vF>1 && vT>1) || (vF==0 || vT==0)) {
    var browserName = navigator.appName;
	  var topPx = (browserName=="Netscape")?"screenX":"top";
	  var leftPx = (browserName=="Netscape")?"screenY":"left";

    window.open('info.htm','info',"toolbar=no,height=210,width=440,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,"+leftPx+"=100,"+topPx+"=100");
    return;
  }  
  
  var o,d,vP,vD,vD2,num; 
  o=MM_findObj('pages');
  d='\'Ilość stron do tłumaczenia\''; 
  if ((vP=o.value)!="") {
	  // liczba stron , -> .
	  vP = vP.replace(",", ".");
    num = parseFloat(vP);
    if (isNaN(vP)) 
      errors+='- pole '+d+' musi zawierać wartość liczbową.\n';
    if (num<1 && num >0) 
      num = 1;
    if (num<=0) 
      errors+='- pole '+d+' musi zawierać wartość liczbową większą od 0.\n';
  } else 
    errors += '- wypełnij pole '+d+'\n'; 
   
  o=MM_findObj('date');
  o2=MM_findObj('workDays');
  d='\'Termin oddania tłumaczenia\'';
  d2='\'Ilość dni roboczych na tłumaczenie\'';
  vD = o.value;
  if(vD=="DD.MM.RRRR") vD = "";
  vD2=o2.value;
  if((vD!="") || (vD2!="")) {
    if((vD!="") && (vD2=="") ) {
      vD_array = vD.split(".");
      var day = vD_array[0];
      var month = vD_array[1];
     	var year = vD_array[2];
     	if(year < 2000) {
     	  switch(year.length) {
     	    case 2 :
     	      year = "20"+year;
     	      break;
     	    case 1 :
     	      year = "200"+year;
     	      break;
     	  }
     	}
      vD = day+'-'+month+'-'+year;
      var date = new Date(year, month-1, day);
      var today = new Date();
      today = new Date(today.getFullYear(), today.getMonth(), today.getDate()-1);
      if (isNaN(date) || (date.getDate() != ((day-1)+1)) || (date.getMonth() != (month-1)) || (date.getFullYear() != year) || (today>=date))
        errors+='- pole '+d+' musi zawierać poprawną, przyszłą date w formacie DD.MM.RR lub DD.MM.RRRR.\n';
      else 
      if ((date.getDay() == 6) || (date.getDay() == 0))
        errors+='- popraw pole '+d+': powinno zawierać dzień roboczy ('+o.value+' to '+((date.getDay() == 6)?'sobota':'niedziela')+').\n';
      vD2='';
    } else {
      numD = parseFloat(vD2);
      if (isNaN(vD2)) 
        errors+='- pole '+d2+' musi zawierać wartość liczbową.\n';
      if (numD<1) 
        errors+='- pole '+d2+' musi zawierać wartość liczbową większą od 0.\n';
      vD='';
    }
  } else 
    errors += '- wypełnij pole '+d+' lub '+d2+'\n';
  
  if (errors) 
    alert('Uwaga:\n'+errors);
  else {
    var browserName = navigator.appName;
	  var topPx = (browserName=="Netscape")?"screenX":"top";
	  var leftPx = (browserName=="Netscape")?"screenY":"left";
  
    window.open('wycena.php?from='+vF+'&to='+vT+'&pages='+num+'&date='+vD+'&days='+vD2,'untitled',"toolbar=no,height=480,width=580,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,"+leftPx+"=100,"+topPx+"=100");
  }
		
  document.returnValue = (errors == '');

}

/*************************************** wycena fr*****************************************/

function validateForm_fr() { //v4.0+
  var errors='';
  
  var oF,oT,vF,vT;
  // languages
  oF=MM_findObj('fromLang');
  oT=MM_findObj('toLang');
  vF=oF.value;
  vT=oT.value;
  if(isNaN(parseInt(vF)) || isNaN(parseInt(vT)))
    errors+='- choisir la langue source ou cible.\n';
  else
  if((vF==1 && vT==2) || (vF==2 && vT==1) || (vF==3 && vT==7) || (vF==4 && vT==8))
    errors+='- modifier la langue source ou cible.\n';
  else
  if((vT == 2 || vT == 7 || vT == 8 ) && vF != 2 )
  	errors+='- cette langue n\'est traduite que depuis le polonais\n';
  
  var oW,vW,num; 
  // pages
  oW=MM_findObj('words');
  if ((vW=oW.value)!="") {
    num = parseInt(vW);
    if (isNaN(vW)) 
      errors+='- le nombre de mots doit contenir un chiffre.\n';
    if (num<1) 
      errors+='- le nombre de mots doit etre supérieur a 0.\n';
  } else 
    errors += '- veuillez saisir le nombre de mots\n'; 
  
  if (errors) 
    alert('! :\n'+errors);
  else {
    var browserName = navigator.appName;
	  var topPx = (browserName=="Netscape")?"screenX":"top";
	  var leftPx = (browserName=="Netscape")?"screenY":"left";
	  
    window.open('devis.php?from='+vF+'&to='+vT+'&words='+vW,'untitled',"toolbar=no,height=440,width=500,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,"+leftPx+"=100,"+topPx+"=100");
  }
		
  document.returnValue = (errors == '');

}  
  /*************************************** wycena en*****************************************/

function validateForm_en() { //v4.0+
  var errors='';
  
  var oF,oT,vF,vT;
  // languages
  oF=MM_findObj('fromLang');
  oT=MM_findObj('toLang');
  vF=oF.value;
  vT=oT.value;
  if(isNaN(parseInt(vF)) || isNaN(parseInt(vT)))
    errors+='- choose source or target language.\n';
  else
  if((vF==1 && vT==2) || (vF==2 && vT==1) || (vF==3 && vT==7) || (vF==4 && vT==8))
    errors+='- change source or target language.\n';
  else
  if((vT == 2 || vT == 7 || vT == 8 ) && vF != 2 )
  	errors+='- this language can be translated only from Polish\n';
  
  var oW,vW,num; 
  // pages
  oW=MM_findObj('words');
  if ((vW=oW.value)!="") {
    num = parseInt(vW);
    if (isNaN(vW)) 
      errors+='- word count must contain a number.\n';
    if (num<1) 
      errors+='- word count must be higher than 0.\n';
  } else 
    errors += '- please enter the word count\n'; 
  
  if (errors) 
    alert('! :\n'+errors);
  else {
    var browserName = navigator.appName;
	  var topPx = (browserName=="Netscape")?"screenX":"top";
	  var leftPx = (browserName=="Netscape")?"screenY":"left";
	  
    window.open('quotation.php?from='+vF+'&to='+vT+'&words='+vW,'untitled',"toolbar=no,height=440,width=500,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,"+leftPx+"=100,"+topPx+"=100");
  }
		
  document.returnValue = (errors == '');


}
