/* Stops sites from framing the page */
if (top != self) {
top.location = self.location;
}

// Image Slider

function $(a){return document.getElementById(a)}
var spacing = -430;
var pos = 1;
// Total number of items
var maxPos = 5;
function slide(num){
	var con = $('carrierImagesHold');
	if(con.timer==undefined)con.timer = setInterval("slideTick("+num+")", 1);
}
function slideTick(num){
	var con = $('carrierImagesHold');
	var cur = Number(con.style.left.replace("px","")) + num;
	if (cur == ((pos-num)*spacing)){
		clearInterval(con.timer);
		con.timer = undefined;
		pos = pos - num;
		if (pos % (maxPos+1) == 0){
			if (pos == 0) pos = maxPos;
			else pos = 1;
			con.style.left=(pos*spacing)+"px";
			return;
		}
	}
	con.style.left=cur+"px";
}

function ShowHide(toShow, toHide)
{
	/*
		used with a button 'onclick' event.
		toShow - array with the IDs of the elements to be shown
		toHide - array with the IDs of the elements to be hidden
		
	*/
	if (document.getElementById(toShow) != null)
	{
		Display(document.getElementById(toShow));
	}
	
	if (document.getElementById(toHide) != null)
	{
		UnDisplay(document.getElementById(toHide));
	}
			
}

function Display(displayControl)
{
	if(displayControl != null)
	{
		displayControl.style.display='';			
	}
}
function UnDisplay(displayControl)
{
	if (displayControl != null)
	{
		displayControl.style.display='none';
	}
}


function FormatPhone(ctrl)
//Adds dashes to a Phone field if the field is in correct format
{
	var val = ctrl.value;
	
	var replaceExpr = /\W/g	
	val = val.replace(replaceExpr,'');
	replaceExpr = /_/g
	val = val.replace(replaceExpr,'');	
	
	var phone = '';
	if(val.length > 3)
	{
		phone = val.substr(0,3) + '-';
	}
	if(val.length > 6)
	{
		phone += val.substr(3,3)+ '-'+val.substr(6);
	}
	else
	{
		phone += val.substr(3);
	}
	if(phone.length > 1)
	{
		ctrl.value = phone;
	}
	

}

// popup box for quote results page

function questionPop() {
	document.getElementById('questionPopupHold').style.display='block';
}

function questionPopClose() {
	document.getElementById('questionPopupHold').style.display='none';
}

function SetFocus( ctrlId)
{
	var ctrl = document.getElementById(ctrlId);
	if(ctrl != null)
	{
		ctrl.focus();
	}
}

// popup box for term-life-insurance-quoteEF page

function secIcon() {
	document.getElementById('securityIcons').style.display='block';
}

function secIconClose() {
	document.getElementById('securityIcons').style.display='none';
}

function SetFocus( ctrlId)
{
	var ctrl = document.getElementById(ctrlId);
	if(ctrl != null)
	{
		ctrl.focus();
	}
}


/***********************************************************************
Get the URL parameter. Use to detect the current page variation for the
insurance quote pages.

Returns: url param 
************************************************************************/

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
{
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
}
    return vars;
}

/***********************************************************************
Get the current filename of the page you're on.
Returns: string 
************************************************************************/
function getFileName()
{    
    var pg = window.location.href;
    var regex = new RegExp("[^/]*$");
    var fileName = regex.exec(pg); // Default.aspx for example..

    return fileName;
}
