
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 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;
        }
        mail = form.email.value;
        
        if(mail=='' || mail.length<6 || mail.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 changePayForm(){
		form = document.forms["order"];
		
		bv = form.basketvalue;
		tv = form.totalvalue;
		
    	var paymentObj = form.payment;
		
		
		var payment = paymentObj.value;
		
    	var val = eval(bv.value);
    	
    	if(payment==1) val = val + 1200;
    	else if(payment==2) val = val + 700;
    	else if(payment==3) val = val + 1200;
		else if(payment==4) val = val + 1800;
		
    	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 getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else{
			radioObj.checked='checked';
			return radioObj.value;
			}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	radioObj[1].checked='checked';
	return radioObj[1].value;
}
