function openBookURL(id,title,options){
	var url = 'http://www.bookmaster.pl/ksiazka/'+id+'.xhtml';
	okno = window.open(url,'_self');
	okno.focus();
	return false;
}
function bookAddURL(id,title,options){
	var url = '/koszyk/'+id+'/';
	okno = window.open(url,'_self');
	okno.focus();
	return false;
}
function updatePayForm(){
		var form=document.forms['order'];
		var checkedValue=getCheckedValue(form.payment);
		if(checkedValue==''){
			var checks=form['payment'];
			checks.checked='checked';
			checks[0].checked='checked';
			checkedValue=getCheckedValue(form.payment);
		}
		var totalBox=form.totalvalue;
		var totalVal=parseInt(form.basketvalue.value);
		var name='cost'+checkedValue;
		//alert(name);
		var shipCost=document.getElementById(name).value;
		
		shipCost=parseInt(shipCost);
		//alert(shipCost);
		totalVal+=shipCost;
		totalVal/=100;
		//totalBox.value=''+totalVal+' z-';
		totalBox.value=''+number_format(totalVal,2,".",",")+' zł';
}
function done(){
	var form=document.forms['order'];
	form.sub.disabled=true;
	return true;
}
function checkOrderForm(){
	form = document.forms["order"];
	
	var msg = '';

	if(form.d_name.value==''){
		form.d_name.focus();
		alert("Podaj imię i nazwisko");
		return false;
	}
	if(form.d_street.value==''){
		form.d_street.focus();
		alert("Podaj nazwę ulicy i numer domu / mieszkania");
		return false;
	}
	if(form.d_zip.value==''){
		form.d_zip.focus();
		alert("Podaj kod pocztowy");
		return false;
	}
	if(form.d_city.value==''){
		form.d_city.focus();
		alert("Podaj miejscowość");
		return false;
	}
	if(form.d_tel.value==''){
		form.d_tel.focus();
		alert("Podaj numer telefonu");
		return false;
	}
	var email = form.email.value;
	
	if(email=='' || email.length<6 || email.indexOf('@')==-1){
		form.email.focus();
		alert("Podaj prawidłowy adres email");
		return false;
	}

	var cf = form.checkf.checked;

	if(cf && form.f_name.value==''){
		form.f_name.focus();
		alert("Podaj imię i nazwisko osoby zamawiającej\nJeżeli wpiszesz nazwę firmy imię i nazwisko nie pojawi się na fakturze.");
		return false;
	}
	if(cf && form.f_company.value!='' && form.f_nip.value==''){
		form.f_nip.focus();
		alert("Podaj NIP");
		return false;
	}
	if(cf && form.f_street.value==''){
		form.f_street.focus();
		alert("Podaj nazwę ulicy");
		return false;
	}
	if(cf && form.f_zip.value==''){
		form.f_zip.focus();
		alert("Podaj kod pocztowy");
		return false;
	}
	if(cf && form.f_city.value==''){
		form.f_city.focus();
		alert("Podaj nazwę miejscowości");
		return false;
	}
	return true;
} 
function copyinvoice(){
	var form = document.forms["order"];
	form.f_name.value = form.d_name.value;
	form.f_street.value = form.d_street.value;
	form.f_zip.value = form.d_zip.value;
	form.f_city.value = form.d_city.value;
	form.f_company.value = form.d_company.value;
}   
function showInvoiceForm(){
	var form = document.forms["order"];
	var cf = form.checkf.checked;
	if(cf){
		showdiv('a2');
	}
	else{
		hidediv('a2');
	}
//    alert('cf' + cf);
}
function number_format(number, decimals, dec_point, t_sep){
   var intstr;
   var output = '';
   
   if(typeof(decimals) == 'undefined')
      decimals = 2;
      
   if(typeof(dec_point) == 'undefined'||number<1000)
      dec_point = '';
      
   if(typeof(t_sep) == 'undefined')
      t_sep = '';
   
   // czesc calkowita   
   int = parseInt(number);
   
   // czesc ulamkowa
   float = parseInt(Math.round((number-parseInt(number))*100));
   
   intstr = int+'';
   
   j = intstr.length;
   
   if((i = j%3) != 0)
      output += intstr.substring(0, i);
   
   while(i < j)
   {
      output += dec_point+''+intstr.substring(i, i+3);
      i += 3;
   }
   
   if(float > 0)
      output += t_sep+''+float;
   
   return(output);
}
function getCheckedValue(radioObj){
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function showdiv(id) {
    //safe function to show an element with a specified id
    
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'block';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'block';
        }
        else { // IE 4
            document.all.id.style.display = 'block';
        }
    }
}   
function hidediv(id) {
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'none';
        }
        else { // IE 4
            document.all.id.style.display = 'none';
        }
    }
}
  
