
function mm_swapimgrestore() { //v3.0
	var i,x,a=document.mm_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.osrc;i++) x.src=x.osrc;
}

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;
}

function mm_swapimage() { //v3.0
  var i,j=0,x,a=mm_swapimage.arguments; document.mm_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=mm_findobj(a[i]))!=null){document.mm_sr[j++]=x; if(!x.osrc) x.osrc=x.src; x.src=a[i+2];}
}

function openURL(url,title,options){
	okno = window.open(url,title,options);
	okno.focus();
	return false;
}

    function isValidEmail(str) {
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    }


    
	
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 "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

    
 /*     
	function changePayForm(){
    	var bv = mm_findobj("basketvalue");
    	var tv = mm_findobj("totalvalue");
    	var paymentObj = mm_findobj("payment");
    	var payment = paymentObj.value;    	
    	
    	var val = eval(bv.value);
    	
    	if(payment==1) val = val + 1200;
    	else if(payment==2) val = val + 800;
    	else if(payment==3) val = val + 1800;
		else if(payment==4) val = val + 1200;
    	tv.value = "" + (val/100) + " zł";
    }
	*/
    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';
			}
		}
    }
    
    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 checkOrderForm()
	{
        form = document.forms["order"];
		
		var nabywca = form.nabywca.value;
		var odbiorca = form.odbiorca.value;
		
		//if (nabywca!=1 && nabywca!=2)
        //    return false;
		
		//if (odbiorca!=1 && odbiorca!=2)
        //    return false;
		
		if(nabywca==1){
			if(form.f_name.value==''){
			    form.f_name.focus();
			    alert("Podaj imię i nazwisko");
			    return false;
			}
		}
		
		if(nabywca==2){
			if(form.f_company.value==''){
			    form.f_company.focus();
			    alert("Podaj nazwę firmy");
			    return false;
			}
			if(form.f_nip.value==''){
			    form.f_nip.focus();
			    alert("Podaj NIP");
			    return false;
			}
		}
		
        if(form.f_street.value==''){
            form.f_street.focus();
            alert("Podaj nazwę ulicy i numer domu / mieszkania");
            return false;
        }
		
        if(form.f_zip.value==''){
            form.f_zip.focus();
            alert("Podaj kod pocztowy");
            return false;
        }
		
        if(form.f_city.value==''){
            form.f_city.focus();
            alert("Podaj miejscowość");
            return false;
        }
		
        if(form.f_tel.value==''){
            form.f_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;
		}
		
		if(odbiorca==1){
			if(nabywca==2){
				if(form.d_name.value==''){
					form.d_name.focus();
					alert("Podaj imię i nazwisko");
					return false;
				}
			}
		}
		
		if(odbiorca==2){
			
			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;
			}
			
		}
		        
        return true;
    }
	
	function changeVisibility(co,force)
    {
	//console.log("Co zawiera %s", co);
        if (force=='') {
            co.style.display=='' ? co.style.display='' : co.style.display='none'
        } else if (force=='show') {
            co.style.display=''
        } else if (force=='hide') {
            co.style.display='none'
        }
    }

    function changeVisibilityById(co,force)
    {
        changeVisibility(document.getElementById(co),force)
    }
    
	function chnab(nab)
    {
		if (nab!=1 && nab!=2)
            return
			
        var elem = new Array(4)
        elem[0]='f_name'
        elem[1]='f_company'
        elem[2]='f_nip'
		elem[3]='d_name'
		elem[4]='f_country'
        
		var elem2 = new Array(4)
        elem2[0]='_f_name'
        elem2[1]='_f_company'
        elem2[2]='_f_nip'
		elem2[3]='_d_name'
		elem2[4]='_f_country'
        
		form = document.forms["order"];     		
		var odbiorca = form.odbiorca.value;
		
        if (nab==1) {
            changeVisibilityById(elem[0],'show')
			changeVisibilityById(elem[1],'hide')
			changeVisibilityById(elem[2],'hide')			
			//document.getElementById(elem2[0]).value=''
			if(odbiorca=='1'){
				changeVisibilityById(elem[3],'hide')
			}
        }else{
			changeVisibilityById(elem[0],'hide')
			changeVisibilityById(elem[1],'show')
			changeVisibilityById(elem[2],'show')			
			//document.getElementById(elem2[1]).value=''
			//document.getElementById(elem2[2]).value=''
			if(odbiorca=='1'){
				changeVisibilityById(elem[3],'show')
				//document.getElementById(elem2[3]).value=''
			}
		}    
    }
	
	function chnab2(nab,forma)
    {
		if (nab!=1 && nab!=2)
            return;
        
		form = document.forms[forma];     		
		var odbiorca = form.odbiorca.value;
		
        if (nab==1) {
            changeVisibilityById('_f_name','show');
			changeVisibilityById('_f_company','hide');
			changeVisibilityById('_f_nip','hide');			
			document.getElementById('f_company').value='';
			document.getElementById('f_nip').value='';
			if(odbiorca=='1'){
				changeVisibilityById('_d_name','hide');
				document.getElementById('d_name').value='';
			}
        }else{
			changeVisibilityById('_f_name','hide');
			changeVisibilityById('_f_company','show');
			changeVisibilityById('_f_nip','show');
			document.getElementById('f_name').value='';
			if(odbiorca=='1'){
				changeVisibilityById('_d_name','show');
			}
		}    
    }
	
	function chodb(odb)
    {
		if (odb!=1 && odb!=2)
            return
			
        var elem = new Array(6)
        elem[0]='d_name'
        elem[1]='d_company'
        elem[2]='d_street'
        elem[3]='d_zip'
        elem[4]='d_city'
		elem[5]='d_tel'        
		elem[6]='d_country'        
        
		var elem2 = new Array(6)
        elem2[0]='_d_name'
        elem2[1]='_d_company'
        elem2[2]='_d_street'
        elem2[3]='_d_zip'
        elem2[4]='_d_city'
		elem2[5]='_d_tel' 
		elem2[6]='_d_country' 
		
		form = document.forms["order"];     		
		var nabywca = form.nabywca.value;
		
        if (odb==1) {
            for (i=0;i<elem.length;i++)
                changeVisibilityById(elem[i],'hide')
			if(nabywca=='2'){
				changeVisibilityById(elem[0],'show')
				//document.getElementById(elem2[0]).value=''	
			}
        }else{
			for (i=0;i<elem.length;i++)
				changeVisibilityById(elem[i],'show')
			//for (i=0;i<elem2.length-1;i++)
				//document.getElementById(elem2[i]).value=''	
		}    
    }	
	
	function chodb2(odb,forma)
    {
		if (odb!=1 && odb!=2)
            return;
			
        var elem = new Array(6)
        elem[0]='_d_name';
        elem[1]='_d_company';
        elem[2]='_d_street';
        elem[3]='_d_zip';
        elem[4]='_d_city';
		elem[5]='_d_tel';      
		elem[6]='_d_country';        
        
		var elem2 = new Array(6)
        elem2[0]='d_name';
        elem2[1]='d_company';
        elem2[2]='d_street';
        elem2[3]='d_zip';
        elem2[4]='d_city';
		elem2[5]='d_tel';
		elem2[6]='d_country'; 
		
		form = document.forms[forma];     		
		var nabywca = form.nabywca.value;
		
        if (odb==1) {
            for (i=0;i<elem.length;i++)
                changeVisibilityById(elem[i],'hide');
			for (i=0;i<elem2.length-1;i++)
				if(nabywca=='1')document.getElementById(elem2[i]).value='';	
				else if(elem2[i]!='d_name')document.getElementById(elem2[i]).value='';
			if(nabywca=='2'){
				changeVisibilityById(elem[0],'show');
			}
        }else{
			for (i=0;i<elem.length;i++)
				changeVisibilityById(elem[i],'show');
		}    
    }	
	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);
}
