
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;
        }
        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 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 + 1700;
    	else if(payment==2) val = val + 1200;
    	else if(payment==3) val = val + 1200;
		else if(payment==4) val = val + 1500;
    	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 getElementsByClass(node,searchClass,tag) {
  var classElements = new Array();
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("\b"+searchClass+"\b");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
return classElements;
}
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 showOneDiv(id,n,prefix){
	for(var i=1;i<=n;++i)
		if(i!=id)
			hidediv(prefix+i);
	showdiv(prefix+id);
	for(i=1; i <= n; i++){
		var link = document.getElementById('newnesslink'+i);
		if(i==id)
			link.style.backgroundImage = "url(/_img/pag_bg_a.gif)";
		else
			link.style.backgroundImage = "url(/_img/pag_bg.gif)";
	}
}
