  var image = null;
  var smaller = true;
  var intWidth = 0;
  var imgSrc = new String("");
  var intChangePictureInterval = 5000;
  var intTurnPictureInterval = 100;
  var strSendToEmail = new String("jensib@jensib.dk");
  //var strSendToEmail = new String("tma@awud.dk");

  var imgRidder = new Image(10,10);
  var imgStripper = new Image(10,10);
  var imgIndianer = new Image(10,10);
  var imgStruds = new Image(10,10);

  function preloadimages()
  {
    imgRidder.src = "billeder/flip_ridder.jpg";
    imgStripper.src = "billeder/flip_stripper.jpg";
    imgIndianer.src = "billeder/flip_indianer.jpg";
    imgStruds.src = "billeder/flip_struds.jpg";
  }

  var timer = null;
  function turnPicture(img)
  {
    smaller = true;
    image = img;
    intWidth = image.width;
    imgSrc = image.src;

    setTimeout("_turnPicture()", intTurnPictureInterval);
  }

  function _turnPicture()
  {
    var turnSize = 35;
    
    if (smaller == true)
    {
      if (image.width > 0)
      { image.width -= turnSize; }
      else
      { 
        smaller = false; 

        if (imgSrc.indexOf("flip_") > -1)
        { imgSrc = imgSrc.replace("flip_" + image.id, image.id); }
        else
        { imgSrc = imgSrc.replace(image.id, "flip_" + image.id); }
        
        image.src = imgSrc;
      }

      setTimeout("_turnPicture()", intTurnPictureInterval);
    } else {
      if (image.width < intWidth)
      { 
        if ((image.width + turnSize) <= intWidth)
        { image.width += turnSize; }
        else
        { image.width = intWidth; }

        setTimeout("_turnPicture()", intTurnPictureInterval);
      }
      else
      { 
        gotopage(image);        
      }
    }
  }
  
  function flipimage(image, mousein)
  {
    var strSrc = new String(image.src);
    var strFileNameAdd = new String("flip_");
    
    if (mousein==true)
    { 
      strSrc = strSrc.replace(image.name, strFileNameAdd + image.name);
    } 
    else 
    {
      strSrc = strSrc.replace(strFileNameAdd + image.name, image.name);
     }

    image.src = strSrc;
  }

  function changepictures()
  {
    setInterval("_changepictures()", intChangePictureInterval);
  }

  function _changepictures()
  {
    var i1_src = new String(ridder.src);
    if (i1_src.indexOf("flip_") > -1)
    { i1_src = i1_src.replace("flip_", ""); }

    var i2_src = new String(stripper.src);
    if (i2_src.indexOf("flip_") > -1)
    { i2_src = i2_src.replace("flip_", ""); }

    var i3_src = new String(indianer.src);
    if (i3_src.indexOf("flip_") > -1)
    { i3_src = i3_src.replace("flip_", ""); }

    var i4_src = new String(struds.src);
    if (i4_src.indexOf("flip_") > -1)
    { i4_src = i4_src.replace("flip_", ""); }

    ridder.src = i4_src;
    i4_src = i4_src.substr(i4_src.lastIndexOf("/")+1, i4_src.length);
    i4_src = i4_src.substr(0, i4_src.lastIndexOf("."));
    ridder.name = i4_src;
    ridder.alt = i4_src;
    
    stripper.src = i1_src;
    i1_src = i1_src.substr(i1_src.lastIndexOf("/")+1, i1_src.length);
    i1_src = i1_src.substr(0, i1_src.lastIndexOf("."));
    stripper.name = i1_src;
    stripper.alt = i1_src;
    
    indianer.src = i2_src;
    i2_src = i2_src.substr(i2_src.lastIndexOf("/")+1, i2_src.length);
    i2_src = i2_src.substr(0, i2_src.lastIndexOf("."));
    indianer.name = i2_src;
    indianer.alt = i2_src;
    
    struds.src = i3_src;   
    i3_src = i3_src.substr(i3_src.lastIndexOf("/")+1, i3_src.length);
    i3_src = i3_src.substr(0, i3_src.lastIndexOf("."));
    struds.name = i3_src;
    struds.alt = i3_src;
  }
  
  function gotopage(image)
  {
    var strDocumentName = new String(document.location.href);
    var strLocation = new String(document.location.href);
    
    if (strDocumentName.lastIndexOf("/")+1 < strDocumentName.length)
    {
        strDocumentName = strDocumentName.substring(strDocumentName.lastIndexOf("/")+1);
        strLocation = strLocation.replace(strDocumentName, image.name + ".html");
    } else {
        strLocation += image.name + ".html";
    }

//    alert(strLocation);
    document.location.href = strLocation;
  }
  
  function sendemailviaoutlook(fromaddress, subject, text)
  {
    strMailToString = "mailto:" + strSendToEmail;
    strMailToString += "?subject='" + subject + "'";
    strMailToString += "&body='" + text + "'";
    
    document.location.href = strMailToString;

    alert("Din Email er sendt - Mange tak for din email!");
  }
  
  function sendforesporgsel(fromname, fromaddress, arrangementtype, other, figur, performdate, text)
  {
    if (validateemail(fromaddress) && validatedate(performdate) && validatestring(fromname) && validatestring(arrangementtype) && validatestring(figur) && validatestring(text))
    {
      var strText = new String();
      strText += "Afsenders navn: " + fromname + "\r";
      strText += "Afsenders email: " + fromaddress + "\r";
      strText += "Arrangementstype: " + arrangementtype + "\r";

      if (other != "" && other != null)
      { 
        strText += "Anden arrangementstype: " + other + "\r"; 
      }

      strText += "Ønsket figur: " + figur + "\r";
      strText += "Dato for optræden: " + performdate + "\r";
      strText += "Yderligere tekst: " + text;
    
      sendemailviaasp(fromaddress, "Forspørgsel", strText);
    }
  }
  
  function sendemailviaasp(fromaddress, subject, text)
  {
    if (validateemail(fromaddress) && validatestring(subject) && validatestring(text))
    {
      strMailToString = "scripts/sendmail.asp";
      strMailToString += "?toemail=" + strSendToEmail;
      strMailToString += "&fromemail=" + fromaddress;
      strMailToString += "&subject=" + formathtmlstring(subject);
      strMailToString += "&text=" + formathtmlstring(text);
      strMailToString += "&test=false";
    
      var wnd = window.open(strMailToString, 'Mail_Afsender', "width=8,height=6", null);

      alert("Din Email er nu blevet sendt - Mange tak for din Email!");
      
      emailform.reset();
    }
  }
  
  function validateemail(address)
  {
    var strErrors = new String();
    var strAddress = new String(address);
    
    if (strAddress.length == 0)
    {
      strErrors += " Emailadressen må ikke være tom \r";
    }
    if (strAddress.indexOf("@") == -1)
    {
      strErrors += " Emailadressen SKAL indeholde @ \r";
    }
    if (strAddress.indexOf(".") == -1)
    {
      strErrors += " Emailadressen SKAL indeholde . \r";
    }
    if ((strAddress.length - strAddress.lastIndexOf(".")) <= 2)
    {
      strErrors += " Emailadressen SKAL have mindst 2 tegn efter . \r";
    }
    if ((strAddress.lastIndexOf(".") - strAddress.lastIndexOf("@")) <= 3)
    {
      strErrors += " Emailadressen SKAL have et domæne bestående af mindst 3 tegn \r";
    }
    if (strAddress.indexOf("@") <= 1)
    {
      strErrors += " Emailadressen SKAL have mindst et tegn foran @'et \r";
    }
    
    if (strErrors.length > 0)
    {
      alert(strErrors);
      
      return false;
    } else {
      return true;
    }
  }
  
  function validatedate(datetovalidate)
  {
    var arrDate = new Array();
    var dtCurrentDate = new Date();
    var strErrors = new String();

    if (datetovalidate.indexOf("-") == -1)
    {
      strErrors += "Datoen er ikke i korrekt format \r";
      strErrors += " Brug venligst følgende format \r";
      strErrors += "  dd-mm-åååå \r";

      alert(strErrors);
      return false;
    }

    arrDate = datetovalidate.split("-");
    if (arrDate.length != 3)
    {
      strErrors += "Datoen er ikke i korrekt format \r";
      strErrors += " Brug venligst følgende format \r";
      strErrors += "  dd-mm-åååå \r";

      alert(strErrors);
      return false;
    }
    if (arrDate[1] > 12)
    {
      strErrors += " Der er kun 12 måneder i et år. \r";
    }
    if (arrDate[1] == 1 || arrDate[1] == 3 || arrDate[1] == 5 || arrDate[1] == 7 || arrDate[1] == 8 || arrDate[1] == 10 || arrDate[1] == 12)
    {
      if (arrDate[0] > 31)
      {
        strErrors += " der er kun 31 dage i den indtastede måned \r";
      }
    }
    if (arrDate[1] == 4 || arrDate[1] == 6 || arrDate[1] == 9 || arrDate[1] == 11)
    {
      if (arrDate[0] > 30)
      {
        strErrors += " der er kun 30 dage i den indtastede måned \r";
      }
    }
    if (arrDate[1] == 2)
    {
      if(checkleapyear(arrDate[2]))
      {
        if (arrDate[0] > 29)
        {
          strErrors += " der er kun 29 dage i den indtastede måned \r";
        }
      } else {
        if (arrDate[0] > 28)
        {
          strErrors += " der er kun 28 dage i den indtastede måned \r";
        }
      }
    }
    if (arrDate[2] > (dtCurrentDate.getFullYear() + 10))
    {
      strErrors += " datoen er mere end 10 år frem i tiden \r";
    }

    if (strErrors.length > 0)
    {
      strErrors = "Datoen er ikke i korrekt format \r" + strErrors;
      strErrors += " Brug venligst følgende format \r";
      strErrors += "  dd-mm-åååå \r";

      alert(strErrors);
      
      return false;
    } else {
      return true;
    }
  }
  
  function checkleapyear(datea)
  {
    if(datea%4 == 0)
    {
      if(datea%100 != 0)
      {
        return true;
      } else {
        if(datea%400 == 0)
		{
		  return true;
		} else {
          return false;
        }
      }
    }

    return false;
  }

  function validatestring(str)
  {
    var strString = new String(str);
    var strErrors = new String();

    if (strString.length == 0)
    {
      strErrors += " der skal indtastes noget i alle felter \r";
    }

    if (strErrors.length > 0)
    {
      alert(strErrors);
      
      return false;
    } else {
      return true;
    }
  }
  
  function formathtmlstring(str)
  {
    var strString = new String(str);
    var strErrors = new String();
    
    if (strString.length > 0)
    {
      return escape(strString);
    }
  }
