// Cookies Start
// Cookie reader START
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
	  //alert(getCookieVal);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
// Cookie reader END

// Get Query Variable START

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
}

// Get Query Variable END

// Affiliate Cookie Checker START
function LoadPreQuoteCookies()
{
	//debugger;
	var Aff_Cookie = GetCookie('affiliateId');
	var Promocode_Cookie = GetCookie('promocode');
	var Aff_QueryVariable = getQueryVariable('affiliateId');
	var Promocode_QueryVariable = getQueryVariable('promocode');
	
	var addressURL = window.location.href;
	//alert("addressURL: "+addressURL);
	var queryString = addressURL.substring(addressURL.lastIndexOf( "?" ));
	if (queryString == addressURL)
	{
	queryString = "";
	//alert("queryString: ");
	}
	var fileNamePath = addressURL.replace(queryString,'');
	//alert("fileNamePath: "+fileNamePath);
	var Aff_URL = "";
	var Promo_URL = "";
	var yesString = "";
	var yesplusAmp = "";
	var plusAmp = "";
	// Check to see if affiliate query values exist and if not, check for cookie values
	if (Aff_QueryVariable > "")
	{
		Aff_URL = "affiliateId="+Aff_QueryVariable;
		yesplusAmp = 1 ;
		yesString = "?" ;
	}
	else if (Aff_Cookie > "")
	{
		Aff_URL = "affiliateId="+Aff_Cookie;
		yesplusAmp = 1 ;
		yesString = "?" ;
	}
	// Check to see if promocode query values exist and if not, check for cookie values
	if (Promocode_QueryVariable  > "")
	{
		Promo_URL = "promocode="+Promocode_QueryVariable;
		yesString = "?" ;
		if (yesplusAmp == 1) {plusAmp = "&" ;}
	}
	else if (Promocode_Cookie  > "")
	{
		Promo_URL = "promocode="+Promocode_Cookie;
		yesString = "?" ;
		if (yesplusAmp == 1) {plusAmp = "&" ;}
	}
	

	// Build URL
	var NewURL = fileNamePath+yesString+Aff_URL+plusAmp+Promo_URL;
	var CurrentURL = window.location.href;
	var CurrentURL = CurrentURL.substring(CurrentURL.lastIndexOf('/') + 1);
	
	if (NewURL !== addressURL)
	{
		//alert("it ran");
		document.location.href=NewURL;
	}
}


var tickImageString = "<img src=\"/shared/images/tick.gif\" border=\"0\" alt=\"Included in policy price\" title=\"Included in policy price\" />";
var crossImageString = "<img src=\"/quotetemplates/images/ico/cross_ico.png\" border=\"0\" alt=\"Not Avaliable\" title=\"Not Avaliable\" />";
var circleImageString = "<img src=\"/quotetemplates/images/ico/optional_ico.png\" border=\"0\" alt=\"Optional, can be added to policy on next page\" title=\"Optional, can be added to policy on next page\" />";

//compare page options section
function DisplayOptionsRollOver(cell,text)
{
    cell.innerHTML = text;
}


function AffTestCookie(aff_status)
{
if (aff_status == "set")
{
	document.cookie = "affiliateId=1600";
} 
else 
{
	document.cookie = "affiliateId=";
}
}

function PromoTestCookie(promo_status)
{
if (promo_status == "set")
{
	document.cookie = "promocode=testPromo";
}
else
{
	document.cookie = "promocode=";
}
}
// Affiliate Cookie Checker END

function LoginMenuShowHide(WhatToDo)
{
    //SideBar.ascx
    try
    {
	    if (WhatToDo == 'expand')
	    {
		    document.getElementById('btn_login_up').style.display = 'none';
		    document.getElementById('btn_login_down').style.display = 'block';
		    document.getElementById('login_down_pane').style.display = 'block';
		    document.cookie = "SideBar=expand";
	    }
	    else if (WhatToDo == 'collapse')
	    {
		    document.getElementById('btn_login_up').style.display = 'block';
		    document.getElementById('btn_login_down').style.display = 'none';
		    document.getElementById('login_down_pane').style.display = 'none';
		    document.cookie = "SideBar=collapse";
	    }
    }
    catch (error)
    {
	    //alert('No need to run LoginMenuShowHide() as we're logged-in');	
    }
}

function SideBar() {
// SideBar.ascx
// Check to see if cookies are enabled
// set login box to default expand 
LoginMenuShowHide('expand');

document.cookie = "Test=1";
var TestCookie = GetCookie('Test');
var SideBar = GetCookie('SideBar');

	if (TestCookie == 1)
	{   
	    // Check to see if cookies are enabled
		LoginMenuShowHide('collapse'); 
	}
	else
	{   
	    // if not then show login pane
	    LoginMenuShowHide('expand');
	    if (document.getElementById('btn_login_down') != null)
	    { document.getElementById('btn_login_down').style.display = 'none'; }

	    if (document.getElementById('btn_login_down_no_cookies') != null)
	    { document.getElementById('btn_login_down_no_cookies').style.display = 'block'; }
	}
	
	if (SideBar == 'expand')
	{
		LoginMenuShowHide('expand');
	}
	else if (SideBar == 'collapse')
	{
		LoginMenuShowHide('collapse');
	}
}

function LoginNewOldCustomerShowHide_OnClick(WhatToDo)
{   
//Do nothing
}

function LoginNewOldCustomerShowHide(WhatToDo)
{   
//Do nothing    
}

function LoginNewOldCustomer_OnLoad()
{
//Do nothing
}

function LoginNewOldCustomer()
{
//Do nothing
}
// Cookies End

// Yes/No Age endorsements_valuables.aspx START
function endorsements_valuables_Age_Start()
{
	document.getElementById('ageDiv').style.display = 'none';
	//document.getElementById('CheckBoxNew').checked = false;
	setTimeout("document.getElementById('CheckBoxNew').checked = false;",0);

}
function endorsements_valuables_Age_YesNo(WhichBox)
{	
var CheckBoxNew = document.getElementById('CheckBoxNew');
var CheckBoxOld = document.getElementById('CheckBoxOld');
var ageDiv = document.getElementById('ageDiv');
var ageDivOld = document.getElementById('ageDivOld');
var ageCheckBtnSubmit = document.getElementById('getQuoteHazardousActivityLinkButtonShow');
var ageCheckBtnSubmitOff = document.getElementById('getQuoteHazardousActivityLinkButtonHide');
ageCheckBtnSubmit.style.display = 'block';
ageCheckBtnSubmitOff.style.display = 'none';
if (WhichBox == 'CheckBoxNew')
{
	if (CheckBoxNew.checked)
		{	
			//alert('CheckBoxOld.checked = true');
			CheckBoxNew.checked = true;
			CheckBoxOld.checked = false;
			ageDivOld.style.background = '#FFFFFF';
		}
	else
		{
			//alert('CheckBoxNew.checked = true');
			CheckBoxNew.checked = false;
			CheckBoxOld.checked = true;
			ageDivOld.style.background = '#FAF8C7';
		}
}
else if (WhichBox == 'CheckBoxOld')
{
	if (CheckBoxOld.checked)
		{	
			//alert('CheckBoxOld.checked = true');
			CheckBoxNew.checked = false;
			CheckBoxOld.checked = true;
			ageDiv.style.display = 'block';
			ageDivOld.style.background = '#FAF8C7';
		}
	else
		{
			//alert('CheckBoxNew.checked = true');
			CheckBoxNew.checked = true;
			CheckBoxOld.checked = false;
			ageDiv.style.display = 'none';
			ageDivOld.style.background = '#FFFFFF';
		}	
}
}
// Yes/No Age END

// Compare Dropdown START
function GetEventTarget(evt) {
	if (evt.srcElement) return evt.srcElement;
	if (evt.target) return evt.target;
	return null;
}

var g_LastDivPopUp;
function CloseLastPopUp()
{
    if(g_LastDivPopUp)
	{
	    g_LastDivPopUp.style.display="none";
	}
}

function GoPop(evt, ele, message, origStyle) 
{
    CloseLastPopUp();
	var popup = document.createElement("div");
	g_LastDivPopUp = popup;
	
	popup.id = "divHelp" + message;
	popup.style.position = "absolute";
	popup.style.marginLeft = "136px";
	//popup.setAttribute("class", "divHelp");
	popup.innerHTML = "<div class='popup'><div class='popupviewer'><div class='popupinfo'>" + description[message] + "</div></div></div>";
	popup.onmouseout = function() { KillPopupEvent(evt, origStyle); }
	if (ele.parentNode) {
	    //ele.parentNode.parentNode.className = ele.parentNode.parentNode.className = ' RowHighlighted';
	    ele.parentNode.insertBefore(popup, ele);
	}
}

function GoPopAdditional(evt, ele, message, origStyle) 
{
	CloseLastPopUp();
	
	var popup = document.createElement("div");
	g_LastDivPopUp = popup;
	
	num = message+20;
	popup.id = "divHelp" + num;
	popup.style.position = "absolute";
	popup.innerHTML = "<div class='popup'><div class='popupviewer'><div class='popupinfo'>" + adddescription[message] + "</div></div></div>";
	popup.onmouseout = function() { KillPopupEvent(evt, origStyle); }
	if (ele.parentNode) {
	    //ele.parentNode.parentNode.className = ele.parentNode.parentNode.className = ' RowHighlighted';
	    ele.parentNode.insertBefore(popup, ele);
	}
}

function KillPopup(ele, origStyle) {
	if (ele.parentNode) {
        //if (window.getComputedStyle) // firefox or opera
        //    ele.parentNode.parentNode.className = ele.parentNode.parentNode.className.replace(/RowHighlighted/gi, origStyle);
        //else // ie
    	//    ele.parentNode.parentNode.parentNode.className = ele.parentNode.parentNode.parentNode.className.replace(/RowHighlighted/gi, origStyle);
        CloseLastPopUp();
	}
}

function KillPopupEvent(evt, origStyle) 
{
	if (!evt) evt = window.event;
	var ele = GetEventTarget(evt);
	if (ele.parentNode) {
	    if (window.getComputedStyle) // firefox or opera
	        ele.parentNode.parentNode.className = ele.parentNode.parentNode.className.replace(/RowHighlighted/gi, origStyle);
	    else // ie
	    	ele.parentNode.parentNode.parentNode.className = ele.parentNode.parentNode.parentNode.className.replace(/RowHighlighted/gi, origStyle);
	    CloseLastPopUp();
	}
}

// Compare Dropdown END

// Help info balloon START
function GoPopHelp(ele, message) {
	var popuphelp = document.createElement("div");
	popuphelp.style.position = "absolute";
	popuphelp.id = "popuphelp_"+message;

	var browserName=navigator.appName;
	
	if (browserName == "Microsoft Internet Explorer")
	{
	    popuphelp.innerHTML = "<table cellpadding='0' cellspacing='0' class='popuphelp'><tr><td class='GoPopHelpTitle' width='200'><b>"+ helpterm[message] +"</b></td><td align='right' width='80'><img src='/shared/images/Template_Images/btn_popup_largeText.gif' onClick=\"textSizeChange('large','" + popuphelp.id + "');\" id='largeText" + popuphelp.id + "' style='cursor:pointer;float:left;' alt='View large text.'/><img src='/shared/images/Template_Images/btn_popup_smallText.gif' onClick=\"textSizeChange('small','" + popuphelp.id + "');\" id='smallText" + popuphelp.id + "' style='display:none;cursor:pointer;float:left;' alt='View small text.'/><img src='/shared/images/Template_Images/close_popup.gif' OnClick='KillPopupHelp(" + popuphelp.id + ");' style='cursor:pointer;float:right;' alt='Close this popup'/></td></tr><tr><td colspan='2' valign='top'><div class='popuphelptextarea' style='overflow:auto;' id='popuphelptextarea" + popuphelp.id + "'>  " + helpdescription[message]; +"  <div/></td></tr></table>";
	}
	else
	{
			var infoWindow = window.open("","infoWindow", "tollbars = no,width=350, height=400, satus=yes, scrollbars=yes, resize=no, menubar=no");
			infoWindow.document.body.innerHTML ='<style>body{font-family:arial; font-size:9pt;}</style><div style=" margin-bottom:15px;"><strong>'+helpterm[message]+'</strong></div><div>'+helpdescription[message]+'</div>';
	}

	ele.parentNode.insertBefore(popuphelp, ele);
	
	if (GetCookie('popupFontSize') == 'large' )
	{
		textSizeChange('large',popuphelp.id);
	}
}


function KillPopupHelp(messageID) {
	var browserName=navigator.appName;
	if (browserName == "Microsoft Internet Explorer")
	{
	    messageID.parentNode.removeChild(messageID);
	}
	else
	{
	    messageID.parentNode.removeChild(messageID);
	}
}

//Help descriptions
var helpterm = new Array(14);
var helpdescription = new Array(14);

helpterm[0] = 'Serial Number';
helpdescription[0] = '<img src="/Templates/images/serial.gif" width="164" height="39" /><br /><br />Your computer serial number is typically located on the back of your computer casing or on the underside of your laptop.<br /><br />Look for a white sticker together with a barcode similar to example shown and provide the unique number shown below the barcode.';

helpterm[1] = 'Dates';
helpdescription[1] = 'Please enter the year format in YYYY.';

helpterm[2] = 'UK / Eire residents';
helpdescription[2] = 'You must have been resident in the United Kingdom, Northern Ireland, Channel Islands, Isle of Man or Eire for 6 months out of the last 12 months (or more) at the time you bought or renewed your policy.';

helpterm[3] = 'Promotional Code';
helpdescription[3] = 'If you have a promotional code then please enter it here';

helpterm[4] = 'Citymain Administrators Ltd';
helpdescription[4] = "InsureandGo are delighted to have Citymain as their underwriter for computer insurance.<br/><br/>Citymain has been protecting customer's valuable electronics for 23 years. Our expertise covers an extensive range of electronic devices such as computers, laptops, notebooks, mobile phones and other portable gadgetry. We are a dedicated and professional company who use integrity, skill and diligence to provide a first class service";

helpterm[5] = 'Forgotten your password?';
helpdescription[5] = 'To retrieve your password please enter your email address and press the \'email-it\' button. Shortly after you\'ll receive an email containing you password.';

helpterm[6] = 'Hazardous Sports';
helpdescription[6] = 'Blurb';

helpterm[7] = 'Home Visits';
helpdescription[7] = 'Blurb';

helpterm[8] = 'Valuables';
helpdescription[8] = 'Blurb';

helpterm[9] = 'Extreme Ski';
helpdescription[9] = 'Blurb';

helpterm[10] = 'Baggage and Money';
helpdescription[10] = 'We will pay you if your baggage or personal effects are lost, stolen, damaged or delayed. There is a single item and valuables limit, which is dependent on the policy you have chosen, as is the total amount of money we will pay out.';

helpterm[11] = 'Double Excess & Excess Waiver';
helpdescription[11] = 'By selecting Double Excess the price of your policy will reduce but the excess you will have to pay should you make a claim will be double the standard amount. By selecting Excess Waiver the price of your policy will go up, however you won’t have to pay any excess at all should you make a claim.';

helpterm[12] = 'Excess Waiver';
helpdescription[12] = 'Claims under most sections of the policy will be subject to an excess by paying an additional premium you can have no excess to pay.';

helpterm[13] = 'Winter Sports';
helpdescription[13] = 'We will pay for your hospital bills and repatriation to the UK should you be injured or fall ill during your trip. In addition the policy covers you if your ski or snowboard equipment is lost, stolen or damaged. There is a single item and valuables limit, which is dependent on the policy you have chosen, as is the total amount of money we will pay out.';

helpterm[14] = 'Business';
helpdescription[14] = 'We will pay you if your business equipment (such as computer equipment, communication devices and other business related equipment) is lost, stolen or damaged. The total amount we will pay is dependent on the policy you choose.';

helpterm[15] = 'Golf';
helpdescription[15] = 'We will pay you for loss, damage or theft of your golf equipment. We will also pay towards the cost of hiring alternative golf equipment if yours is delayed or lost on your outward-bound journey for more than 12 hours. The total amount we will pay you is dependent on the policy you choose.';

helpterm[16] = 'Family Definition';
helpdescription[16] = 'To qualify for a family policy, the following definition of \'family\' applies:<br/><br/> An individual and his or her husband or wife or partner (as long as they have lived together for six months or more) and their dependent children or legally adopted children who are aged under 18 and are either in full-time education or living with them.';

helpterm[17] = 'Privacy Statement';
helpdescription[17] = 'Your email address will be used to send you quote and purchase information, and will NOT be passed on or sold to any other 3rd parties.';

helpterm[18] = 'Compare Policies';
helpdescription[18] = 'Annual policies can save you money if you are planning to go away more than once in the next twelve months, particularly if one of those holidays is for winter sports.  Click here to compare the benefits of annual policies over a single policy.';

function textSizeChange(size,id)
{
	var largeFontSize = '12px';
	var smallFontSize = '11px';
	
	//alert(obj.parentNode);
	if (size == 'large'){
	document.getElementById('popuphelptextarea'+id).style.fontSize = largeFontSize;
	document.getElementById('largeText'+id).style.display = 'none';
	document.getElementById('smallText'+id).style.display = 'block';
	document.cookie = "popupFontSize=large";
	
	//GetCookie('promocode');
	}
	if (size == 'small'){
	document.getElementById('popuphelptextarea'+id).style.fontSize = smallFontSize;
	document.getElementById('smallText'+id).style.display = 'none';
	document.getElementById('largeText'+id).style.display = 'block';
	document.cookie = "popupFontSize=small";
	}
}

//HELP info Balloon END


function formatDateOnTextChange(inputBox)
{
    
    if(inputBox.value.length==0)
    {
        inputBox.value = '-- / -- / ----';
    }
}


function removeLeadingZeros(str)
{
    while (str.charAt(0)=="0")
    {
        str = str.substring(1,str.length);
    }
    
    return str;
}

function checkDateForAmtPanelDisplay() {
    var lblAnnualDateAfterTodayWarning = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_lblAnnualDateAfterTodayWarning");
    if (lblAnnualDateAfterTodayWarning != null) {
        var today = new Date();
        var coverStartDateEle = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_txtCoverStartDate");
        var coverStartDate = new Date();
        var dateParts = coverStartDateEle.value.split(/[^0-9]/gi);
        var dateDay = 0;
        var dateMonth = 0;
        var dateYear = 0;

        //start date
        try {
            if (dateParts.length == 3) {
                dateDay = parseInt(removeLeadingZeros(dateParts[0]), 10);
                dateMonth = parseInt(removeLeadingZeros(dateParts[1]), 10);
                dateYear = parseInt(removeLeadingZeros(dateParts[2]), 10);

                if (dateYear.toString().length <= 2) {
                    dateYear = dateYear + 2000;
                }

                coverStartDate = new Date(dateYear, dateMonth - 1, dateDay);

                var lblAnnualDateAfterTodayWarning = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_lblAnnualDateAfterTodayWarning");
                if (lblAnnualDateAfterTodayWarning != null) {
                    var today = new Date();

                    if (coverStartDate > today)
                        lblAnnualDateAfterTodayWarning.style.display = "block";
                    else
                        lblAnnualDateAfterTodayWarning.style.display = "none";
                }
            }
        }
        catch (e) { }

        if (coverStartDate > today)
            lblAnnualDateAfterTodayWarning.style.display = "block";
        else
            lblAnnualDateAfterTodayWarning.style.display = "none";
    }
}

/* Start: Calendar JS */
function setDaysDropDown() {
    //debugger;
    var coverStartDateEle = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_txtCoverStartDate");
    var coverEndDateEle = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_txtCoverEndDate");
    var daysMonthsSelectorEle = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_ddCoverDateDaysMonths");
    
    var coverStartDate = new Date();
    var coverEndDate = new Date();
	
	var dateParts = coverStartDateEle.value.split(/[^0-9]/gi);
	var dateDay = 0;
    var dateMonth = 0;
    var dateYear = 0;
                
    //start date
    try
    {
        if(dateParts.length == 3)
        {
            dateDay = parseInt(removeLeadingZeros(dateParts[0]),10);
            dateMonth = parseInt(removeLeadingZeros(dateParts[1]),10);
            dateYear = parseInt(removeLeadingZeros(dateParts[2]),10);
            
            if(dateYear.toString().length <= 2)
            {
                dateYear = dateYear + 2000;
            }

            coverStartDate = new Date(dateYear, dateMonth - 1, dateDay);

            var lblAnnualDateAfterTodayWarning = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_lblAnnualDateAfterTodayWarning");
            if (lblAnnualDateAfterTodayWarning != null) {
                var today = new Date();

                if (coverStartDate > today)
                    lblAnnualDateAfterTodayWarning.style.display = "block";
                else
                    lblAnnualDateAfterTodayWarning.style.display = "none";
            }
        }
    }
    catch(e)
    {}
    
    //end date
    try
    {
        dateParts = coverEndDateEle.value.split(/[^0-9]/gi);   
    }
    catch(e)
    {}
    
    try
    {
        if(dateParts.length == 3)
        {
            dateDay = parseInt(removeLeadingZeros(dateParts[0]),10);
            dateMonth = parseInt(removeLeadingZeros(dateParts[1]),10);
            dateYear = parseInt(removeLeadingZeros(dateParts[2]),10);
            
            if(dateYear.toString().length <= 2)
            {
                dateYear = dateYear + 2000;
            }
	        
            coverEndDate = new Date(dateYear,dateMonth-1,dateDay);
        }
    }
    catch(e)
    {}
    
    var timeSpanMili = coverEndDate.getTime() - coverStartDate.getTime();
    var timeSpanDays = ((((timeSpanMili / 1000) / 60) / 60) / 24) //days
    
    var numItems = daysMonthsSelectorEle.options.length;
    
    for(i=0;i<numItems;i++)
    {
        if(timeSpanDays < daysMonthsSelectorEle.options[i].value)
        {
            daysMonthsSelectorEle.options[i].selected = true;
            break;
        }
        
    }
}


function setDateOnDaysChange(inputType)
{
	    //debugger;
    var coverStartDateEle = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_txtCoverStartDate");
    var coverEndDateEle = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_txtCoverEndDate");
	     
	    var daysValue = 1;
	    if(inputType == 'dd')
	    {
	        var daysMonthsSelectorEle = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_ddCoverDateDaysMonths");
	        daysValue = parseInt(removeLeadingZeros(daysMonthsSelectorEle.options[daysMonthsSelectorEle.selectedIndex].value));
	    }
	    else if(inputType == 'tb')
	    {
	        var daysMonthsSelectorEle = document.getElementById("_ctl0__ctl0_cphBody_cphContentBodyLeft_iagCoverDetailsControl_ddCoverDateDaysMonths");
	        daysValue = parseInt(removeLeadingZeros(daysMonthsSelectorEle.value));
	        
	        if(isNaN(daysValue) || (daysValue==0))
	        {
	            daysValue = 1;
	        }
	    }
	    else
	    {
	        return;
	    }
	    
	    var coverStartDate = new Date();
	    var dateParts = coverStartDateEle.value.split(/[^0-9]/gi);
	    
	    try
	    {
	        if(dateParts.length == 3)
	        {
	            var dateDay = parseInt(removeLeadingZeros(dateParts[0]));
	            var dateMonth = parseInt(removeLeadingZeros(dateParts[1]));
	            var dateYear = parseInt(removeLeadingZeros(dateParts[2]));
	            
	            if(dateYear.toString().length <= 2)
	            {
	                dateYear = dateYear + 2000;
	            }
    	        
	            coverStartDate = new Date(dateYear,dateMonth-1,dateDay);
	        }
	    }
	    catch(e)
	    {}

	    var coverEndDate = new Date(coverStartDate);
	    var currentDay = parseInt(coverStartDate.getDate());
	    var newDay = (currentDay + daysValue) -1;
	    
	    coverEndDate.setDate(newDay);

	    coverStartDateEle.value = FormatDateToString(coverStartDate);
	    coverEndDateEle.value = FormatDateToString(coverEndDate);
    
}
/*End: Calendar JS*/

function FormatDateToString(dateToFormat)
{
    var day  = dateToFormat.getDate();
	var month  = (dateToFormat.getMonth() + 1);
	var year  = dateToFormat.getFullYear();
	    
    var dateStr = '';
	    
    if(day < 10)
    {
        dateStr +=  '0' + day;
    }
    else
    {
        dateStr += day;
    }
	    
    if(month < 10)
    {
        dateStr +=  '/0' + month;
    }
    else
    {
        dateStr += '/' +month;
    }
	    
	dateStr += '/' +year;
	
	return dateStr;
}

/*
function setDateDropDowns_Init()
{
    var coverStartDayEle = document.getElementById("CoverStartDateControl_DateDayDropDownList");
    var coverStartMonthEle = document.getElementById("CoverStartDateControl_DateMonthDropDownList");
    var coverStartYearEle = document.getElementById("CoverStartDateControl_DateYearTextBox");

    var coverEndDayEle = document.getElementById("CoverEndDateControl_DateDayDropDownList");
    var coverEndMonthEle = document.getElementById("CoverEndDateControl_DateMonthDropDownList");
    var coverEndYearEle = document.getElementById("CoverEndDateControl_DateYearTextBox");

     coverStartDayEle.innerHtml += " onclick='setDateDropDowns()' "; 
     
}

function setDateDropDowns()
{
    var coverStartDayEle = document.getElementById("CoverStartDateControl_DateDayDropDownList");
    var coverStartMonthEle = document.getElementById("CoverStartDateControl_DateMonthDropDownList");
    var coverStartYearEle = document.getElementById("CoverStartDateControl_DateYearTextBox");

    var coverEndDayEle = document.getElementById("CoverEndDateControl_DateDayDropDownList");
    var coverEndMonthEle = document.getElementById("CoverEndDateControl_DateMonthDropDownList");
    var coverEndYearEle = document.getElementById("CoverEndDateControl_DateYearTextBox");
}
*/

function setAddressRecordLookup()
{
	clearAddress();
	
	var formEle = document.getElementById("foundAddressListBox").value;

	document.getElementById("selectedaddressprompt").innerHTML = formEle;
	
    selectedItem = formEle.split(",");
	
	var address1Value = selectedItem[0];
	var address2Value = selectedItem[1];
	
	
	if ( address1Value == "" )
	{
		address1Value = selectedItem[1];
		address2Value = "";
	}
	
	document.Form1.tb_AddressLine1.value = address1Value;
	document.Form1.tb_AddressLine2.value = address2Value;
	document.Form1.tb_TownOrCity.value = selectedItem[2];
	document.Form1.tb_County.value = selectedItem[3];
	
	if ( selectedItem[4] ) {
		document.Form1.tb_County.value = selectedItem[3];
	} else {
		document.Form1.tb_County.value = "";
	}
		
}

function clearAddress()
{
	document.Form1.tb_AddressLine1.value = "";
	document.Form1.tb_AddressLine2.value = "";
	document.Form1.tb_TownOrCity.value = "";
	document.Form1.tb_County.value = "";
}

function DisplayDOBMask(dob, func)
{
    if (func == "display" && dob.value == "")
    {
        dob.value = "dd/mm/yyyy";
    }
    else if (func == "set" && dob.value == "dd/mm/yyyy")
    {
        dob.value = "";
    }
}