function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		m_ozter_over = newImage("images/menu/m_ozter-over.gif");
		kosmetika_over = newImage("images/menu/kosmetika-over.gif");
		m_ozvody_over = newImage("images/menu/m_ozvody-over.gif");
		m_indozon_over = newImage("images/menu/m_indozon-over.gif");
		m_spol_over = newImage("images/menu/m_spol-over.gif");
		preloadFlag = true;
	}
}
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 P7_autoLayers() { //v1.4 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;a=parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc){p7c=new Array();document.p7setc=true;for(var u=0;u<10;u++){
 p7c[u]=new Array();}}for(k=0;k<p7c[a].length;k++){if((g=MM_findObj(p7c[a][k]))!=null){
 b=(document.layers)?g:g.style;b.visibility="hidden";}}for(k=1;k<args.length;k++){
 if((g=MM_findObj(args[k]))!=null){b=(document.layers)?g:g.style;b.visibility="visible";f=false;
 for(var j=0;j<p7c[a].length;j++){if(args[k]==p7c[a][j]) {f=true;}}
 if(!f){p7c[a][p7c[a].length++]=args[k];}}}
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//funkce pro validaci formularoveho pole.. zadne mezery a zalomeni radku
function containsspaces(s) {
	for(var i = 0; i < s.value.length; i++) {
	var c = s.value.charAt(i);
	if ((c == ' ') || (c == '\n') || (c == '\t')) {
		alert('Pole nesmí obsahovat mezerové znaky');
		return false;
		}
	}
	return true;
}

function isblank(s) {
	for(var i = 0; i < s.length; i++) {
	var c = s.charAt(i);
	if ((c != ' ') && (c != '\n') && (c != '\t')) {
		return false;
		}
	}
	return true;
}

//funkce pro souhrnou validaci formulare
function verify(f) 
{
  var msg;
  var empty_fields = "";
  var errors = "";

  // Loop through the elements of the form, looking for all
  // text and textarea elements that don't have an
  //  "optional" property defined.  Then, check for fields
  // that are empty and make a list of them.
  // Also, if any of these elements have a "min" or a "max"
  // property defined, then verify that they are numbers 
  // and that they are in the right range.
  // Put together error messages for fields that are wrong.
  for(var i = 0; i < f.length; i++)
  {
     var e = f.elements[i];

     if (((e.type == "text") || (e.type == "password") || (e.type == "textarea")) && e.required == true)
     {
        // first check if the field is empty
        if ((e.value == null) ||
            (e.value == "") ||
            isblank(e.value))
        {
           empty_fields += "\n        " +
                           e.description;
           continue;
        }

        // Now check for fields that are supposed 
        // to be numeric.
        if (e.numeric ||
           (e.min != null) ||
           (e.max != null))
        {
           var v = parseFloat(e.value);
           if (isNaN(v) ||
              ((e.min != null) && (v < e.min)) ||
              ((e.max != null) && (v > e.max)))
           {
              errors += "\n- The field " +
                        e.description +
                        " must be a number";
              if (e.min != null)
                 errors += " that is greater than " +
                           e.min;

              if (e.max != null &&
                  e.min != null)
                 errors += " and less than " +
                           e.max;

              else if (e.max != null)
                 errors += " that is less than " +
                           e.max;

              errors += ".\n";
           }
        }

        // Now check for fields that are supposed 
        // to be emails.
        // Not exactly as described in RFC 2822, but 
        // a rough attempt
        // of the form "local-bit@domain-bit"
        if (e.email && !isblank(e.value))
        {
           var seenAt = false;
           var append = "";
           for(var j = 0; j < e.value.length; j++)
           {
              var c = e.value.charAt(j);
              if ((c == ' ') ||
                  (c == '\n') ||
                  (c == '\t'))
                 append += 
     "\n           - neobsahovat mezeru";
              if ((c == '@') && (seenAt == true))
                 append += 
     "\n           - obsahovat pouze jeden znak @";
              if (c == '@')
                 seenAt = true;		
           }

           if (seenAt == false)
              append += 
     "\n           - obsahovat znak @";
           if (append)
              errors += "- Pole " +
                        e.description +
                        " musí: " + append;
        }

        // Now check for fields that are supposed 
        // to be DOBs.
        if (e.dob && !isblank(e.value))
        {
           var slashCount = 0;
           var append = "";
           var addedError1 = false;
           var addedError2 = false;

           for(var j = 0; j < e.value.length; j++)
           {
              var c = e.value.charAt(j);

              if ((c == '/'))
                 slashCount++;

              if (c != '/' &&
                 (c < '0' || c > '9') &&
                 addedError1 == false)
              {
                 addedError1 = true;
                 append += 
     "\n           - musí obsahovat pouze čísla " +
     "a lomítka";
              }
           }

           if (j != 10 || slashCount != 2)
              append += 
     "\n           - musí mít formát DD/MM/YYYY";
           if (slashCount != 2)
              append += 
     "\n           - musí obsahovat dvě lomítka";
           if (append)
              errors +=  "- Pole " + 
                         e.description + 
                         " musí: " + append;
        }

        // Now check for fields that are supposed 
        // not to have spaces
        if (e.nospaces)
        {
           var seenAt = false;
           var append = "";

           for(var j = 0; j < e.value.length; j++)
           {
              var c = e.value.charAt(j);
			  var x = false;
              if ((c == ' ') ||
                  (c == '\n') ||
                  (c == '\t'))
              var x = true;   
           }
				 if (x==true) {
				 errors += "- Pole " + e.description +
                           " nesmí obsahovat mezerové znaky \n";
				 }
        }

     } // if (type is text or textarea) and !optional
  } // for each character in field

  // Now, if there were any errors, then display the
  // messages, and return true to prevent the form from
  // being submitted.  Otherwise return false
  if (!empty_fields && !errors) 
     return true;

  msg  = "______________________________________________________\n\n"
  msg += "Formulář nebyl odeslán z důvodů těchto chyb:\n";
  msg += "Opravte prosím uvedené nedostatky a odešlete formulář znovu.\n";
  msg += "______________________________________________________\n\n"

  if (empty_fields)
  {
     msg += "- Tato vyžadovaná pole jsou prázdná:"
           + empty_fields + "\n";
     if (errors)
        msg += "\n";
  }
  msg += errors;
  alert(msg);
  return false;
}

//funkce na kontrolu rovnosti potvrzeni hesla nebo dvou poli
function thesame(value1, value2, description)
{
  if (((value1 != null) || 
       (value1 != "")) && 
       value2 != "" && 
       value1 != value2)
  {
       alert("The " + description + " musí být totožná.");
       return (false);
  }
  return (true);
}