function findObj(theObj, theDoc)
{
  var p, i, foundObj;

  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  return foundObj;
}


function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' powinno zawierać adres e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' powinno zawierać liczbę.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' powinno zawierać liczbę z przedziału ( '+min+' ; '+max+' ).\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' jest wymagane.\n'; }
  } if (errors) alert('Wystąpiły następujące błędy:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}


function MM_validateFormen() { //v4.0
 
 var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormen.arguments;
  for (i=0; i<(args.length-2); i+=3) {
    test=args[i+2]; val=MM_findObj(args[i],document);
    if (val){        
        nm=val.name;
        if ((val=val.value)!="") {
             if (test.indexOf('isEmail')!=-1) {
                   p=val.indexOf('@');
                   if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
             }
             else if (nm=='emailform')  {
              if (  String.fromCharCode(65)!=val.toUpperCase() )
                 {
                   nm='the first letter of the alphabet ("A")';
                   errors += '- '+nm+' is required.\n';
                   }
                }
             /*else if (test!='R') {
                num = parseFloat(val);
                if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
                if (test.indexOf('inRange') != -1) {
                   p=test.indexOf(':');
                   min=test.substring(8,p); max=test.substring(p+1);
                   if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
                }
             }*/
         }
         else if (test.charAt(0) == 'R') {
             if (nm=='emailform' )  nm='the first letter of the alphabet';
             errors += '- '+nm+' is required.\n';
         }
    }
  }
  if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}





function validateZapOfertowe(){
	MM_validateForm('imie','','R','nazwisko','','R','stanowisko','','R','nazwa_firmy','','R','ulica','','R','kod','','R','miejscowosc','','R','telefon','','R','email','','RisEmail');
	return document.MM_returnValue;

}

function validateDealer(){
	if (document.dealer.zgoda.checked) return true;
	else 
		{
		alert('Należy wyrazić zgodę na przetwarzanie danych osobowych.');
		return false;
		}
}



function validateZapOfertoween(){
	MM_validateFormen('first_name','','R','last_name','','R','title','','R','company','','R','street','','R','postcode','','R','town','','R','country','','R','telephone','','R','email','','RisEmail','emailform','','R');
	return document.MM_returnValue
}



function validateDealeren(){
	
	if (document.dealer.zgoda.checked) return true;
	else 
		{
		alert('You have to agree to the processing your personal data.');
		return false;
		}
}

