// JavaScript Document

imgs=[['/images/2010/rotator/apply_online.jpg','/images/2010/rotator/no_premium_d.jpg','/images/2010/rotator/15_percent_discount.jpg','/images/2010/rotator/dental.jpg','/images/2010/rotator/group.jpg']];

function jumpPage(newLoc)
    {
 newPage = newLoc.options[newLoc.selectedIndex].value
 if(newPage != "")
 parent.window.location = newPage   
    }

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];}}
}

// -----------------------------------------------
//   --->   Ultimate Javascript Slideshow   <---
//   --->   Author: Znupi                   <---
//   --->   Contact: znupi69@gmail.com      <---
// -----------------------------------------------
//imgs = [
//	[ "pics1/pic1.jpg", "pics1/pic2.jpg", "pics1/pic3.jpg", "pics1/pic4.jpg", "pics1/pic5.jpg" ],
//	[ "pics2/pic1.jpg", "pics2/pic2.jpg", "pics2/pic3.jpg", "pics2/pic4.jpg", "pics2/pic5.jpg", "pics2/pic6.jpg" ]
//];
//var ss1 = new SlideShow(imgs, 'slideDIV1', 2, 50, 0.05);
//imgs = [
//	[ "pics3/pic1.jpg", "pics3/pic2.jpg", "pics3/pic3.jpg", "pics3/pic4.jpg" ],
//	[ "pics4/pic01.gif", "pics4/pic02.gif", "pics4/pic03.gif", "pics4/pic04.gif" ]
//];
//var ss2 = new SlideShow(imgs, 'slideDIV2', 2, 20, 0.05);
//
//>>>>>>>>Parameters explanation>>>>>>>>
//
//1. The first parameter is a multidimensional array,
//   each child-array being an 'image set'. The slideshow
//   will start with the first set. Note: if you only want
//   one image set, you will still have to declare a
//   multi-dimensional array, like [ [ 'image1.gif', 'image2.gif'] ].
//2. The second argument is the div's id in which you must have an
//   image. Example markup:
//   <div id="slideDIV"><img src="" alt="Slideshow"></div>
//   In this case, your second argument will be 'slideDIV'. Also, you
//   will need some CSS to it, so here's the minimum CSS to use:
//   div#slideDIV {
//			background: url('load.gif') 50% 50% no-repeat #000; /* for the loading image */
//			width: 320px; /* same as images */
//			height: 240px; /* same as images */
//			line-height: 0; /* fix IE space below image */
//		}
//		div#slideDIV img {
//			opacity: 0; /* So it doesn't show while loading */
//			filter: alpha(opacity=0); /* the same, for IE */
//		}
//3. The third argument is the pause between two images. Literally the time
//   from when an image stops fading in, to when it starts fading out. (seconds)
//4. The fourth argument is the delay between two frames. The lower value this has,
//   the faster the fading between images is. (miliseconds)
//5. The last argument is the 'step'. The amount of opacity that changes between
//   two frames, basically the higher value, the faster but the rougher the animation.
//   This has to be between 0 and 1. If set to 1, there will be no animation at all.
//(*) I recommend you use 2, 20-50, 0.05 as the last three arguments.
//
//<<<<<<<<Parameters explanation<<<<<<<<
//
//>>>>>>>>Changing the image set>>>>>>>>
//
//To change the 'image set', you have to just call a simple function. For example,
//if you defined your slideshow like "var mySlideShow = new SlideShow(imgs, 'somediv', 2, 20, 0.05),
//you will have to call "mySlideShow.chgImgSet(1)" to change to the second image set.
//Example HTML: <a href="javascript:void(0)" onclick="mySlideShow.chgImgSet(1)">View the second set of images</a>
//
//<<<<<<<<Changing the image set<<<<<<<<

function SlideShow(aImg, sID, iPause, iDelay, iStep)
{
	var imgs = aImg;
	var preLoadObjs = Array();
	var loadedImgs = 0;
	var totalImgs= 0;
	var pause = iPause;
	var delay = iDelay;
	var step = iStep;
	var curIndex = 0;
	var curImgSet = 0;
	var curOpc = 1;
	var curDir = 0;
	var tOut = null;
	var sID = sID;
	var oDIV = null;
	var oIMG = null;
	var i;
	this.init = function()
	{
		oDIV = document.getElementById(sID);
		oIMG = oDIV.getElementsByTagName("img")[0];
		for (i=0; i < imgs.length; i++) totalImgs += imgs[i].length;
		for (i=0; i < imgs.length; i++)
		{
			for (j=0; j < imgs[i].length; j++)
			{
				preLoadObjs[preLoadObjs.length] = new Image();
				preLoadObjs[preLoadObjs.length-1].src = imgs[i][j];
				if (!window.opera)
				{
					if (preLoadObjs[preLoadObjs.length-1])
						countLoadedImgs();
					else
						preLoadObjs[preLoadObjs.length-1].onload = countLoadedImgs;
				}
				if (i == imgs.length-1 && j == imgs[i].length-1 && window.opera)
				{
					start();
				}
			}
		}
	}
	var countLoadedImgs = function()
	{
		loadedImgs++;
		if (loadedImgs == totalImgs) start();
	}
	var start = function()
	{
		oIMG.src = imgs[curImgSet][0];
		oIMG.style.opacity = "1";
		if (window.ActiveXObject) oIMG.style.filter = "alpha (opacity=100)";
		curOpc = 1;
		oDIV.style.backgroundImage = "url('" + imgs[curImgSet][1] + "')";
		curIndex++;
		tOut = setTimeout(doSlide, pause*1000);
	}
	var doSlide = function()
	{
		if (!curDir)
		{
			curOpc-=step;
			oIMG.style.opacity = curOpc;
			if (window.ActiveXObject) oIMG.style.filter = "alpha (opacity=" + (curOpc*100) + ")";
			if (curOpc > 0) tOut = setTimeout(doSlide, delay);
			else {
				changeImgs();
				curDir = 1;
				tOut = setTimeout(doSlide, pause*1000);
			}
		}
		else
		{
			curOpc+=step;
			oIMG.style.opacity = curOpc;
			if (window.ActiveXObject) oIMG.style.filter = "alpha (opacity=" + (curOpc*100) + ")";
			if (curOpc < 1) tOut = setTimeout(doSlide, delay);
			else
			{
				changeImgs();
				curDir = 0;
				tOut = setTimeout(doSlide, pause*1000);
			}
		}
	}
	var changeImgs = function()
	{
		if (curIndex < imgs[curImgSet].length-1) curIndex++;
		else curIndex = 0;
		if (!curDir)
		{
			oIMG.src = imgs[curImgSet][curIndex];
			curOpc = 0;
			oIMG.style.opacity = 0;
		}
		else oDIV.style.backgroundImage = "url('" + imgs[curImgSet][curIndex] + "')";
	}
	this.chgImgSet = function(newImgSet)
	{
		if (newImgSet != curImgSet)
		{
			clearTimeout(tOut);
			curImgSet = newImgSet;
			curIndex = 0;
			start();
		}
	}
}
var cSlideShow;
function initSlideShow()
{
	cSlideShow=new SlideShow(imgs,'slider',3,30,0.05);
	//window.setTimeout("startSlideShow()",2000);
	cSlideShow.init();
}

function startSlideShow()
{
	cSlideShow.init();
}


var popUpWidth = screen.availWidth;
var popUpHeight = screenAvailableHeight;
var popUpLeft = 0;
var popUpTop = 0;
var popUpLeftEasement = 10;
var popUpBottomEasement = 35;
var screenAvailableHeight = screen.availHeight - popUpBottomEasement;
var popUpWindowsParameters;

function setPopUpWidth(widthInPixels) {
	popUpWidth = widthInPixels;
	if (screen.availWidth < popUpWidth || popUpWidth < 1) {
		popUpWidth = screen.availWidth - popUpLeftEasement;
	}
}

function setPopUpHeight(heightInPixels) {
	popUpHeight = heightInPixels;
	if (screenAvailableHeight < popUpHeight || popUpHeight < 1) {
		popUpHeight = screenAvailableHeight;
	}	
}

function setPopUpLeft(leftPositionInPixels) {
	popUpLeft = leftPositionInPixels;
	if (screen.availWidth < popUpLeft + popUpWidth) {
		popUpLeft = screen.availWidth - popUpWidth;
	}
	if (popUpLeft < 0) popUpLeft = 0;
}

function setPopUpTop(topPositionInPixels) {
	popUpTop = topPositionInPixels;
	if (screenAvailableHeight < popUpTop + popUpHeight) {
		popUpTop = screenAvailableHeight - popUpHeight;
	}
	if (popUpTop < 0) popUpTop = 0;
}

function setPopUpLeftEasement(easementInPixels) {
	popUpLeftEasement = easementInPixels;
	if (popUpLeftEasement > screen.availWidth / 2) {
		popUpLeftEasement = 10;
	}
	if (popUpLeftEasement < 1) popUpLeftEasement = 0;
}

function setPopUpBottomEasement(easementInPixels) {
	popUpBottomEasement = easementInPixels;
	if (popUpBottomEasement > screenAvailableHeight / 2) {
		popUpBottomEasement = 35;
	}
	if (popUpBottomEasement < 1) popUpBottomEasement = 0;
}

function setPopUpDimensions(widthInPixels, heightInPixels, leftInPixels, topInPixels) {
	if(widthInPixels) setPopUpWidth(widthInPixels);
	if(heightInPixels) setPopUpHeight(heightInPixels);
	if(leftInPixels) setPopUpLeft(leftInPixels);
	if(topInPixels) setPopUpTop(topInPixels);
}

function setPopUpParameters(newParameters) {
	popUpWindowsParameters = newParameters;
}

function setPopUpCenter() {
	setPopUpLeft((screen.availWidth - popUpWidth - popUpLeftEasement) / 2);
	setPopUpTop((screenAvailableHeight - popUpHeight - popUpBottomEasement) / 2);
}

function submitFormToWindow(theForm, windowName, theWaitPage){
	window.open(theWaitPage, windowName, popUpWindowsParameters + ',width=' + popUpWidth + ',height=' + popUpHeight + ',left=' + popUpLeft + ',top=' + popUpTop);
	theForm.target = windowName;	
}

function submitFormToBPWindow(theForm, windowName, theWaitPage){
	window.open(theWaitPage, windowName, popUpWindowsParameters + ',width=1050' + ',height=600'  + ',left=' + popUpLeft + ',top=' + popUpTop);
	theForm.target = windowName;	
}

function openPopUpWindow(thePage, windowName) {
	newWin = window.open(thePage, windowName, popUpWindowsParameters + ',width=' + popUpWidth + ',height=' + popUpHeight + ',left=' + popUpLeft + ',top=' + popUpTop);
	if(newWin) newWin.focus();
	return false;
}

function openPopUnderWindow(thePage, windowName) {
	newWin = window.open(thePage, windowName, popUpWindowsParameters + ',width=' + popUpWidth + ',height=' + popUpHeight + ',left=' + popUpLeft + ',top=' + popUpTop);
	if(newWin) newWin.blur();
	window.focus();
	return false;
}

function openPopUpLink(theLink, windowName, windowWidth, windowHeight){
	if(!windowHeight){ windowHeight = 720;}
	if(!windowWidth){ windowWidth = 1020;}
	setPopUpDimensions(windowWidth,windowHeight);
	return openPopUpWindow(theLink.href, windowName);
}

function openPopUpHref(theLink, windowName, windowWidth, windowHeight){
	if(!windowHeight){ windowHeight = 720;}
	if(!windowWidth){ windowWidth = 1020;}
	setPopUpDimensions(windowWidth,windowHeight);
	return openPopUpWindow(theLink, windowName);
}

function setPopUpNormal(){
	setPopUpParameters('scrollbars,resizable,toolbar,location,directories');
}

// set defaults
setPopUpParameters('scrollbars,resizable,dependent');


// Contributors 
// Ilkka Huotari at http://www.editsite.net
// Mathieu 'p01' HENRI at http://www.p01.org/
// http://seky.nahory.net/2005/04/rounded-corners/
// Steven Wittens at http://www.acko.net/anti-aliased-nifty-corners
// Original Nifty Corners by Alessandro Fulciniti at http://pro.html.it/esempio/nifty/
function NiftyCheck() {
  if(!document.getElementById || !document.createElement) {
    return false;
  }
  var b = navigator.userAgent.toLowerCase();
  if (b.indexOf("msie 5") > 0 && b.indexOf("opera") == -1) {
    return false;
  }
  return true;
}

function Rounded(className, sizex, sizey, sizex_b, sizey_b) {
	var bk;
	if (!NiftyCheck()) return;
	if (typeof(sizex_b) == 'undefined')
		sizex_b = sizex;
	if (typeof(sizey_b) == 'undefined')
		sizey_b = sizey;
	var v = getElements(className);
	var l = v.length;
	for (var i = 0; i < l; i++) {
		color = get_current_style(v[i],"background-color","transparent");
		bk = get_current_style(v[i].parentNode,"background-color","transparent");
		AddRounded(v[i], bk, color, sizex, sizey, true);
		AddRounded(v[i], bk, color, sizex_b, sizey_b, false);
	}
}

Math.sqr = function (x) {
  return x*x;
};

function Blend(a, b, alpha) {

  var ca = Array(
    parseInt('0x' + a.substring(1, 3)), 
    parseInt('0x' + a.substring(3, 5)), 
    parseInt('0x' + a.substring(5, 7))
  );
  var cb = Array(
    parseInt('0x' + b.substring(1, 3)), 
    parseInt('0x' + b.substring(3, 5)), 
    parseInt('0x' + b.substring(5, 7))
  );
  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);

  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);
}

function AddRounded(el, bk, color, sizex, sizey, top) {
  if (!sizex && !sizey)
	return;
  var i, j;
  var d = document.createElement("div");
  d.style.backgroundColor = bk;
  var lastarc = 0;
  for (i = 1; i <= sizey; i++) {
    var coverage, arc2, arc3;
    // Find intersection of arc with bottom of pixel row
    arc = Math.sqrt(1.0 - Math.sqr(1.0 - i / sizey)) * sizex;
    // Calculate how many pixels are bg, fg and blended.
    var n_bg = sizex - Math.ceil(arc);
    var n_fg = Math.floor(lastarc);
    var n_aa = sizex - n_bg - n_fg;
    // Create pixel row wrapper
    var x = document.createElement("div");
    var y = d;
    x.style.margin = "0px " + n_bg + "px";
	x.style.height='1px';
	x.style.overflow='hidden';
    // Make a wrapper per anti-aliased pixel (at least one)
    for (j = 1; j <= n_aa; j++) {
      // Calculate coverage per pixel
      // (approximates circle by a line within the pixel)
      if (j == 1) {
        if (j == n_aa) {
          // Single pixel
          coverage = ((arc + lastarc) * .5) - n_fg;
        }
        else {
          // First in a run
          arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
          coverage = (arc2 - (sizey - i)) * (arc - n_fg - n_aa + 1) * .5;
          // Coverage is incorrect. Why?
          coverage = 0;
        }
      }
      else if (j == n_aa) {
        // Last in a run
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = 1.0 - (1.0 - (arc2 - (sizey - i))) * (1.0 - (lastarc - n_fg)) * .5;
      }
      else {
        // Middle of a run
        arc3 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j) / sizex)) * sizey;
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = ((arc2 + arc3) * .5) - (sizey - i);
      }
      
      x.style.backgroundColor = Blend(bk, color, coverage);
	  if (top)
	      y.appendChild(x);
      else
	      y.insertBefore(x, y.firstChild);
      y = x;
      var x = document.createElement("div");
		x.style.height='1px';
		x.style.overflow='hidden';
      x.style.margin = "0px 1px";
    }
    x.style.backgroundColor = color;
    if (top)
	    y.appendChild(x);
    else
		y.insertBefore(x, y.firstChild);
    lastarc = arc;
  }
  if (top)
	  el.insertBefore(d, el.firstChild);
  else
	  el.appendChild(d);
}

function getElements(className) {
	var elements = [];
	var el = document.getElementsByTagName('DIV');  
	var regexp=new RegExp("\\b"+className+"\\b");
	for (var i = 0; i < el.length; i++) 
	{
		if (regexp.test(el[i].className)) 
			elements.push(el[i]);
	}
	return elements;
}

function get_current_style(element,property,not_accepted)
{
  var ee,i,val,apr;
  try
  {
    var cs=document.defaultView.getComputedStyle(element,'');
    val=cs.getPropertyValue(property);
  }
  catch(ee)
  {
    if(element.currentStyle)
  	{
	    apr=property.split("-");
	    for(i=1;i<apr.length;i++) apr[i]=apr[i].toUpperCase();
	    apr=apr.join("");
	    val=element.currentStyle.getAttribute(apr);
   }
  }
  if((val.indexOf("rgba") > -1 || val==not_accepted) && element.parentNode)
  {
	 if(element.parentNode != document) 
		 val=get_current_style(element.parentNode,property,not_accepted);
	 else
		 val = '#FFFFFF';
  }
  if (val.indexOf("rgb") > -1 && val.indexOf("rgba") == -1)
	  val = rgb2hex(val);
  if (val.length == 4)
	  val = '#'+val.substring(1,1)+val.substring(1,1)+val.substring(2,1)+val.substring(2,1)+val.substring(3,1)+val.substring(3,1);
  return val;
}

function rgb2hex(value)
{
	var x = 255;
	var hex = '';
	var i;
	var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
	var array=regexp.exec(value);
	for(i=1;i<4;i++) hex += ('0'+parseInt(array[i]).toString(16)).slice(-2);
	return '#'+hex;
}


// Automatically sets focus to the next form element when the current form element's maxlength has been reached.
0
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Cyanide_7 |  */
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}


