﻿var menu = function() {
	var t = 15, z = 50, s = 6, a;
	function dd(n) { this.n = n; this.h = []; this.c = [] }
	dd.prototype.init = function(p, c) {
		a = c; var w = document.getElementById(p), s = w.getElementsByTagName('ul'), l = s.length, i = 0;
		for (i; i < l; i++) {
			var h = s[i].parentNode; this.h[i] = h; this.c[i] = s[i];
			h.onmouseover = new Function(this.n + '.st(' + i + ',true)');
			h.onmouseout = new Function(this.n + '.st(' + i + ')');
		}
	}
	dd.prototype.st = function(x, f) {
		var c = this.c[x], h = this.h[x], p = h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow = 'hidden';
		if (f) {
			p.className += ' ' + a;
			if (!c.mh) { c.style.display = 'block'; c.style.height = ''; c.mh = c.offsetHeight; c.style.height = 0 }
			if (c.mh == c.offsetHeight) { c.style.overflow = 'visible' }
			else { c.style.zIndex = z; z++; c.t = setInterval(function() { sl(c, 1) }, t) }
		} else { p.className = p.className.replace(a, ''); c.t = setInterval(function() { sl(c, -1) }, t) }
	}
	function sl(c, f) {
		var h = c.offsetHeight;
		if ((h <= 0 && f != 1) || (h >= c.mh && f == 1)) {
			if (f == 1) { c.style.filter = ''; c.style.opacity = 1; c.style.overflow = 'visible' }
			clearInterval(c.t); return
		}
		var d = (f == 1) ? Math.ceil((c.mh - h) / s) : Math.ceil(h / s), o = h / c.mh;
		c.style.opacity = o; c.style.filter = 'alpha(opacity=' + (o * 100) + ')';
		c.style.height = h + (d * f) + 'px'
	}
	return { dd: dd }
} ();

var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = ((u - h) + 70) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

function validateDropDown(source, clientside_arguments)
{
	clientside_arguments.IsValid = $(source.controltovalidate).selectedIndex > 0;
}

function validateCheckBox(source, clientside_arguments)
{
	clientside_arguments.IsValid = $(source.controltovalidate).checked;
}

// Rollover Version 3.0+
// Written by Macromedia.
// Last Edited: 13/06/2003
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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 Popup(thisURL, winName, wd, ht, scrlbars, resizing)
{
	var newWindow = window.open(thisURL + '?mode=popup', winName, "toolbar=no,width=" + wd + ",height=" + ht + ",location=no,directories=no,status=yes,menubar=no,scrollbars=" + scrlbars + ",resizable=" + resizing);
	if (newWindow != null)
  {
		newWindow.focus();
  }
}

 function PopupWithoutMode(thisURL, winName, wd, ht, scrlbars, resizing)
 {
 	var newWindow = window.open(thisURL, winName, "toolbar=no,width=" + wd + ",height=" + ht + ",location=no,directories=no,status=yes,menubar=no,scrollbars=" + scrlbars + ",resizable=" + resizing);
 	if (newWindow != null)
 	{
 		newWindow.focus();
 	}
}

 

//close up all the rows with these style classes
//imageStyle - style on image + or -
//answerStyle - style on row answer
function hideAllAnswers(imageStyle, answerStyle)
{	
  var arrImage = $$('.' + imageStyle);
  arrImage.each(function(item) {
			item.src = '/images/plus.gif';
  });
  $$('.' + answerStyle).invoke('hide');
}

//open up all the rows with these style classes
function showAllAnswers(imageStyle, answerStyle)
{
  var arrImage = $$('.' + imageStyle);
  arrImage.each(function(item) {
			item.src = '/images/minus.gif';
  });
	$$('.' + answerStyle).invoke('show');
}

//when the user clicks the plus or minus button, open or close the information row
function toggleAnswer(imgID, rowName)
{
	$(rowName).toggle();
	$(imgID).src = $(rowName).visible() ? '/images/minus.gif' : '/images/plus.gif';
}

//When the user enters a name in either of the enterdetails pages, dynamically update the policy summary
function NameSummary(title, firstName, lastName) 
{
    var ddTitle = $(title);
    var tbFirstName = $(firstName);
    var tbLastName = $(lastName);

    var fullName = ddTitle[ddTitle.selectedIndex].text;
    if (tbFirstName.value != '') 
    {
        fullName = fullName + ' ' + tbFirstName.value
    }
    if (tbLastName.value != '') 
    {
        fullName = fullName + ' ' + tbLastName.value
    }
    return fullName;
}

//When the user enters a dob in either of the enterdetails pages, dynamically update the policy summary
function DateSummary(day, month, year) 
{
    var ddDay = $(day);
    var ddMonth = $(month);
    var ddYear = $(year);

    var dte = 'DD MMM YYYY';
    if (ddDay.selectedIndex != 0 && ddMonth.selectedIndex != 0 && ddYear.selectedIndex != 0) 
    {
        dte = ddDay[ddDay.selectedIndex].text + '-' + ddMonth[ddMonth.selectedIndex].text + '-' + ddYear[ddYear.selectedIndex].text;
    }
    return dte;
}

