
//---------------------
//Navigation Menu
//---------------------

function mousePassOver(id)
{
   //alert("boo");
   objRef(id).style.background="#39f";
   objRef(id).style.border.color="#ccc #000 #000 #ccc";
   objRef(id).style.color="#fff";
}

function mousePassOut(id)
{
   objRef(id).style.background="#06C";
   objRef(id).style.border.color="#aaa #000 #000 #aaa";
   objRef(id).style.color="#fff";
}

function mousePressDown(id)
{
   objRef(id).style.background="#06C";
   objRef(id).style.border.color="#000 #ccc #ccc #000";
   objRef(id).style.color="#f93";
}

//---------------------
//Header Expand/Contract and Fade/Brighten
//---------------------

function beginNow()
{

   hide("navigation");
   document.body.style.backgroundImage="url('images/mwcbgC.jpg')";
   preload();
   origHeight = parseInt(objRef("header").offsetHeight - 2 + evilChk());
   setTimeout("moveFade(" + true + ")", 1000);
   setTimeout("animate();", 1000);
   setTimeout("moveFade(" + false + ")", 6000);
}

function moveFade(init)
{
   obj = objRef("header").style;
   if (init)
   {
      intervalDID = setInterval("moveDown()", 20);
      intervalCID = setInterval("colorFade(" + true + ")", 50)
      obj.backgroundColor = "rgb(0,102,204)";
      obj.borderBottom = "2px solid #ffd";
      obj.backgroundImage = "url(images/ctop.gif)";
      obj.color = "#ffd";
   }
   else
   {
      intervalUID = setInterval("moveUp()", 20);
      setTimeout("secondTrig()", 500);
   }
}

function secondTrig()
{
      obj = objRef("header").style;
      intervalCID = setInterval("colorFade(" + false + ")", 50);
      obj.borderBottom = "2px solid #000";
      obj.backgroundImage = 'url(images/top.jpg)';
      obj.color = "#fff";
}








function colorFade(x)
{
   var color = objRef("header").style.backgroundColor;
   var rgb = (color.charAt(0) != '#') ? rgbClean(color): rgbConvert(color).split(',');

   if (x)
   {
      compre(1,rgb);
      if (rgb[1] >= 246 )
         clearTimeout ( intervalCID );
   }
   else
   {
      compre(-1,rgb);
      if (rgb[1] <= 111 )
         clearTimeout ( intervalCID );
   }
}

function rgbConvert(color)
{
   return parseInt(color.substring(1,3),16) + "," +
      parseInt(color.substring(3,5),16) + "," +
      parseInt(color.substring(5,7),16);

}

function rgbClean(color)
{
   var rgb = color.split(',');
   rgb[0] = rgb[0].substring(4,rgb[0].length);
   return rgb;
}

function compre(x,rgb)
{
   objRef("header").style.backgroundColor = "rgb(" +
      (parseInt(rgb[0]) + (15 * x)) + "," +
      (parseInt(rgb[1]) + (9 * x)) + "," +
      (parseInt(rgb[2]) + (1 * x)) + ")";
}

function moveDown()
{
   move(2);
   if (parseInt(objRef("header").style.height) > 250)
       clearTimeout ( intervalDID );
}

function moveUp()
{
   move(-2);
   if (parseInt(objRef("header").style.height) <= origHeight)
   {
      clearTimeout ( intervalUID );
      show("navigation");
      document.body.style.backgroundImage = "url('images/mwcbg.gif')";
      show("newLogo");
   }
}

function move(x)
{
   objRef("header").style.height = objRef("header").offsetHeight + (x - evilChk()) + "px";
}

function evilChk()
{
   return (/MSIE\s[6]/.test(navigator.userAgent)) ? 0 : 2 ;
}








//---------------------
//Header Animate
//---------------------

function animate()
{
   objRef("anim_married").style.top = "-64px";
   show("anim_married");
   objRef("anim_married").style.zIndex = "4";
   dropLogo(wChk());
   setTimeout("stamp()", 3000);
   setTimeout("exitStageRight(wChk())", 5000);
}

function hide(id)
{
   objRef(id).style.visibility = "hidden";
}

function show(id)
{
   objRef(id).style.visibility = "visible";
}

function dropLogo(width)
{
   objm = objRef("anim_married").style;
   objm.left = ((width / 2) - 136) + "px";
   if ((parseInt(objm.top)) <= 30)
   {
      objm.top =(parseInt(objm.top) + 2) + "px";
      setTimeout( "dropLogo(wChk())", 20);
   }
}

function stamp()
{
   objwc = objRef("anim_withChildren").style;
   objwc.zIndex = 5;
   objwc.left = parseInt(objRef("anim_married").style.left) + 30 + "px";
   objwc.top = "40px";
   objwc.visibility = "visible"
}

function exitStageRight(width)
{
   objm = objRef("anim_married").style;
   objwc = objRef("anim_withChildren").style;

   objm.left = (parseInt(objm.left)) - 10 + "px";
   objwc.left = (parseInt(objwc.left)) + 10 + "px";

   if ((parseInt(objm.left)) >= -274 && (parseInt(objwc.left) <= (width + 207)))
      setTimeout( "exitStageRight(wChk())", 20);
   else
   {
      hide("anim_married");
      hide("anim_withChildren");
   }
}

function wChk()
{
   return objRef("header").offsetWidth;
}

function objRef(id)
{
   return document.getElementById(id);
}









function preload()
{
  var str = "http://redgum.bendigo.latrobe.edu.au/~ma2perry/int23wd/images"
  if(document.images){
   img_preload = new Image();
   img_urls = new Array(
    'bottom.jpg',
    'cTop.gif',
    'logoMarried.gif',
    'logoStamp.gif',
    'mwcbg.gif',
    'newLogo.jpg',
    'top.jpg'
   );
   for(var url = 0; url < img_urls.length; url++)
    img_preload.src = str + img_urls[url];
  }
}

//---------------------
//Questionnaire Validation
//---------------------


function validate()
{
   var validation = true;
   if (objRef("username").value.length < 3 )
   {
      validation = false;
      alert("Must enter a username with atleast 3 Characters");
   }

   if (objRef("password").value.length < 3)
   {
      validation = false;
      alert("Must enter a Password with atleast 3 Characters");
   }

   if (validation)
   {
      objRef("password").value = reverse(objRef("password").value);
      if (objRef("q7Name").value.length > 0)
         objRef("q7Name").value = objRef("q7Name").value.toLowerCase();
   }
   return validation;
}

function reverse(str)
{
   var revPwd = "";
   for (var i = str.length ; i >= 0 ; i--)
      revPwd += str.charAt(i);
   return revPwd;
}
