﻿function positionControlCenter(controlToAlign)
{
    var parentContainer = document.getElementById('pgC');
    var coord = findPos(parentContainer);
    var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
    var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
    var dsoctop=document.all? iebody.scrollTop : pageYOffset;

    controlToAlign.style.left = coord[0] + (parentContainer.offsetWidth / 2) - (controlToAlign.offsetWidth / 2) + "px"; 
    controlToAlign.style.top = coord[1] + (dsoctop) - (controlToAlign.offsetHeight / 2) + "px";
}
function showControl(ctrl)
{
    if(ctrl == null)
    {   
        return;
    }
    
    ctrl.style.display = 'block';
}
function hideControl(ctrl)
{
    if(ctrl == null)
    {   
        return;
    }
    
    ctrl.style.display = 'none';
}
function findPos(obj) 
{
	var curleft = curtop = 0;
    if (obj.offsetParent) 
    {
        do 
        {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
	}    
	return [curleft,curtop];
}

var curPop = null;
var curPopSubj = null;
function regPop(ctrl, subj)
{
    curPop = ctrl;
    curPopSubj = subj;
}

function manValid(c,c2)
{
    var ctrl = document.getElementById(c);
    if( ctrl != null )
    {
        ValidatorEnable(ctrl, true);
    }
    ctrl = document.getElementById(c2);
    if( ctrl != null )
    {
        ValidatorEnable(ctrl, true);
    }
}

var dataSent = false;
function checkData()
{   
    if(dataSent == true)
    {
        return;
    }

    ValidatorEnable(document.getElementById(curPop + '_rN'), true);
    ValidatorEnable(document.getElementById(curPop + '_rP'), true);
    ValidatorEnable(document.getElementById(curPop + '_reqPhone'), true);

    var ctrlN = document.getElementById(curPop + '_tN');
    var ctrlP = document.getElementById(curPop + '_tP');

    if(ctrlP.value.length == 13)
    {
        var pathArr = window.location.pathname.split( '/' );

        var data = "lead~" + pathArr[pathArr.length - 1] + "~" + curPopSubj + "~";
        data += ctrlN.value + "~" + ctrlP.value;
        dataSent = true;
        Insurance.lead.GetData(data); 
        hideControl(conPop);
    }
}

var popupOn = false;
var conPop = null;
function popup()
{ 
    if(dataSent == true)
    {
        return;
    }

    conPop = document.getElementById('conPop');
    if(conPop != null)
    {
        positionControlCenter(conPop);
        showControl(conPop);
        popupOn = true;
    }
}

function showFinalPopup()
{
    var conPopF = document.getElementById('conPopFinal');
    if(conPopF != null)
    {
        positionControlCenter(conPopF);
        showControl(conPopF);
        document.getElementById('ctl00_prg01').style.display = 'block';
    }
}
function hideFinalPopup()
{
    var conPopF = document.getElementById('conPopFinal');
    if(conPopF != null)
    {
        positionControlCenter(conPopF);
        hideControl(conPopF);
        document.getElementById('ctl00_prg01').style.display = 'none';
    }
}

function clsPop()
{
    if(conPop != null)
    {
        hideControl(conPop);
    }
}

function finalPrompt()
{
    if(popupOn)
    {
        showFinalPopup();
        if (confirm('Refer family, friends, and coworkers - Win $200, Call us today at\n\n                               (586) 731-9300\n\nAre you sure you want to leave?'))
        { 
        return true; 
        }else{ 
        hideFinalPopup();
        return false; 
        } 
    }
}

var timer;
var timing=45000;
timer=setTimeout("popup()", timing);

