var errorColor = "transparent";
var okColor = "transparent";

//Initialise validation for page
function autoValidationInit()
{
    var age=document.getElementById("age");
	
	var ageErr=document.getElementById("error1");

	var ddlNoClaims = (document.all!=null?document.all["noClaims"]:document.getElementById("noClaims"));
	var ddlLicenseType = (document.all!=null?document.all["licence"]:document.getElementById("licence"));
	var ddlLocation = (document.all!=null?document.all["motorQuoteCountyId"]:document.getElementById("motorQuoteCountyId"));
	var ddlEngineSize = (document.all!=null?document.all["engineSize"]:document.getElementById("engineSize"));	
	var errorNoClaims = (document.all!=null?document.all["errorNoClaims"]:document.getElementById("errorNoClaims"));
	var errorNoClaimsAge = (document.all!=null?document.all["errorNoClaimsAge"]:document.getElementById("errorNoClaimsAge"));
	var errorLicenseType = (document.all!=null?document.all["errorLicenseType"]:document.getElementById("errorLicenseType"));
	var errorLocation = (document.all!=null?document.all["errorLocation"]:document.getElementById("errorLocation"));
	var errorEngineSize = (document.all!=null?document.all["errorEngineSize"]:document.getElementById("errorEngineSize"));	
	var carvalue=document.getElementById("carValue");
	var carvalueErr=document.getElementById("error2");
	var acceptMotor=document.getElementById("accept");
	var accept=document.getElementById("acceptedAssumptions");
	var acceptMotorErr=document.getElementById("error3");
	var acceptErr=document.getElementById("assumptionsAcceptedError");
	
	age.errorMessage = ageErr;
	age.isNumericValidation = true;

	ddlNoClaims.errorMessage = errorNoClaims;
	ddlEngineSize.errorMessage = errorEngineSize;
	ddlLicenseType.errorMessage = errorLicenseType;
	ddlLocation.errorMessage = errorLocation;
	carvalue.errorMessage = carvalueErr;
	carvalue.isNumericValidation = true;
	accept.errorMessage = acceptErr;
	acceptMotor.errorMessage = acceptMotorErr;
	ddlNoClaims.errorMessageAge = errorNoClaimsAge;
	
	age.onblur = autoValidateAge;	
	carvalue.onblur = autoValidateCarValue;	
	ddlNoClaims.onblur = autoValidateNoClaims;
	ddlEngineSize.onblur = autoValidateDDL;
	ddlLicenseType.onblur = autoValidateDDL;
	ddlLocation.onblur = autoValidateDDL;
	accept.onclick = autoValidateCBX;
	acceptMotor.onclick = autoValidateCBX;
	
	
	document.getElementById('contentsPercentageId').onchange = contentPercentage;

    document.getElementById('coverTypeId').onchange = coverType;

    document.getElementById('rebuildCost').onchange = function(){contentPercentage();rebuild();handleContentsPercentageList();autoValidateRebuidCost()} ;

    document.getElementById('contentsValue').onblur = contents;
    document.getElementById('contentsValue').onchange = onContentsValueChange;
}

function autoValidateRebuidCost()
{
	var rebuildCostElem  = document.getElementById("rebuildCost");	
	var coverTypeIdElem  = document.getElementById("coverTypeId");	

	rebuildCostErrorElem = document.getElementById("rebuildCostError");	
	rebuildCostAmountErrorElem = document.getElementById("rebuildCostAmountError");

	if(coverTypeIdElem.value == 1 || coverTypeIdElem.value == 2 || coverTypeIdElem.value == 3)
	{
			if(rebuildCostElem.value == '')
			{
				//rebuildCostAmountErrorElem.style.display = "none";
				//rebuildCostErrorElem.style.display = "block";
			}
			else if(parseInt(stripCommas(rebuildCostElem.value)) < 125000)
			{
				rebuildCostErrorElem.style.display = "none";
				rebuildCostAmountErrorElem.style.display = "block";
			}
			else
			{
				rebuildCostErrorElem.style.display = "none";
				rebuildCostAmountErrorElem.style.display = "none";
			}
	}

}

function autoValidateJointAge(ev)
{
    var jointage=document.getElementById("jointPartyAge");
	var jointageRadioObj=document.getElementById("isJointParty");

    var ageErr=document.getElementById("jointAgeManError");

    if (validateNumeric(jointage.value)) {
		if (jointage.value<18) {
			error=1;
			//ageErr.style.display="block";
			document.getElementById("jointAgeManError").innerHTML = "You must be at least 18 years to purchase car insurance here";
			
		} else {
			ageErr.style.display="none";
		}
	} else {
		error=1;
		ageErr.style.display="block";
		if(jointage.value=="")
		{ document.getElementById("jointAgeManError").innerHTML = " Please enter your age"; }
		else
		{ document.getElementById("jointAgeManError").innerHTML = " Your age must be a number"; }
	}
}

function showAge(){
	$('#jointParty').slideDown();
}

function hideAge(){
	
	$('#jointParty').slideUp();
	document.getElementById('jointPartyAge').value='';
}

function onContentsValueChange(event) {
    var element = document.getElementById('contentsValue');

	handleContentsValueChange(element);
}

function handleContentsValueChange(element) {	
	$('#contentsPercentageId').val('-1');		
}

function autoValidateAge(ev)
{
    var age=document.getElementById("age");
    var ageErr=document.getElementById("error1");
    var errorNoClaimsAge = (document.all!=null?document.all["errorNoClaimsAge"]:document.getElementById("errorNoClaimsAge"));

    if (validateNumeric(age.value)) {
		if (age.value<18) {
			error=1;
			ageErr.style.display="block";
			document.getElementById("error1").innerHTML = "You must be at least 18 years to purchase car insurance here";
			
		} else {
			ageErr.style.display="none";
			
			if(validateNoClaimAndAge()==false){
				    error = 1;
				    errorNoClaimsAge.style.display = "block";
				}
			else{
				    errorNoClaimsAge.style.display = "none";
			    }
		}
	} else {
		error=1;
		ageErr.style.display="block";
		if(age.value=="")
		{ document.getElementById("error1").innerHTML = " Please enter your age"; }
		else
		{ document.getElementById("error1").innerHTML = " Your age must be a number"; }
	}
}



function autoValidateCarValue(ev)
{
    var carvalue=document.getElementById("carValue");
	var carvalueErr=document.getElementById("error2");

	// Change #6439
	// Ciaran Moran 08/01/2010
	// Facilitate commas in the car value field - added stripCommas
	// 
	if (validatePositiveNumeric(stripCommas(carvalue.value))) {
		carvalueErr.style.display="none";
	} else {
		error=1;
		carvalueErr.style.display="block";
	}
}

function autoValidateNoClaims(ev)
{
    var select;
	var errorAge = false;
    if(document.all)
        select = event.srcElement;
    else
        select = ev.target;
    
    var error = !validateDDL(select);
	 if(!error)
	 {
		errorAge = !validateNoClaimAndAge();
     }
	 
    select.errorMessage.style.display = (error?"block":"none");
	select.errorMessageAge.style.display = (errorAge?"block":"none");
    select.parentNode.style.backgroundColor = (error?errorColor:okColor);
	select.parentNode.style.backgroundColor = (errorAge?errorColor:okColor);
}

function autoValidateDDL(ev)
{
    var select;
    if(document.all)
        select = event.srcElement;
    else
        select = ev.target;
    
    var error = !validateDDL(select);
    
    select.errorMessage.style.display = (error?"block":"none");
    select.parentNode.style.backgroundColor = (error?errorColor:okColor);
}

function autoValidateCBX(ev)
{
    var input;
    if(document.all)
        input = event.srcElement;
    else
        input = ev.target;
    
    var error = !input.checked;
    
    input.errorMessage.style.display = (error?"block":"none");
    input.parentNode.style.backgroundColor = (error?errorColor:okColor);
}

//function getCookie(c_name)
//{
//    if (document.cookie.length>0)
//    {
//        c_start=document.cookie.indexOf(c_name + "=");
//       if (c_start!=-1)
//        { 
//            c_start=c_start + c_name.length+1; 
//            c_end=document.cookie.indexOf(";",c_start);
//            if (c_end==-1) c_end=document.cookie.length;
//            return unescape(document.cookie.substring(c_start,c_end));
//        } 
//    }
//    return "";
//}

//function createCookie(firstname,days)
//    {
        /*if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = "FBD_USER_FIRSTNAME="+firstname+expires+"; path=/";
		*/
//    }
    
//function eraseCookie()
//{
    //createCookie("",-1);
//}

//function checkForCookie()
//{
    //createCookie("Peadar",1);

	/*
    var firstName = "";
    
    var nameEQ = "FBD_USER_FIRSTNAME=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(length,c.length);
        if (c.indexOf(nameEQ) == 0) firstName = c.substring(nameEQ.length,c.length);
    }
    
    if(firstName != "")
    {
        document.getElementById("savedQuotesLink").style.display = "block";
        document.getElementById("userGreeting").innerHTML = "Hello " + firstName;
        document.getElementById("userGreeting").style.display = "block";
        document.getElementById("talkToUsLink").className = "";
    }
    */
    //eraseCookie();
//}

//function setCookie(c_name,value,expiredays)
//{
//    var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
//    document.cookie=c_name+ "=" +escape(value)+
//    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
//}

//function checkCookie()
//{
//    var cookieVal = getTheMReference('mName');     
//    if(cookieVal==""){      
//        cookieVal=getCookie('mData');             
//        document.getElementById('mRef').value=cookieVal;
//        return;                                                     
//    }
//    setCookie('mData',cookieVal,365);     
//    document.getElementById('mRef').value=cookieVal;
//}

//function getTheMReference( name ){  
//    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
//    var regexS = "[\\?&]"+name+"=([^&#]*)";  var regex = new RegExp( regexS );  
//    var results = regex.exec( window.location.href );  
//    if( results == null )    
//    return "";  
//    else    
//    return results[1];
//}
    
// JavaScript Document
/* 
  ------------------------------------
  PVII Menu CSS Express Drop-Down Menu
  by Project Seven Development
  www.projectseven.com
  ------------------------------------
*/
function P7_ExpMenu(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='p7menubar';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}


function checkCharacterEnteredIsNumber(elementId)
{
    var element = document.getElementById(elementId);
    
    if(isNaN(new Number(stripCommas(element.value))))
    {
        element.value = element.value.substring(0, element.value.length - 1);
    } 
}
function stripCommas(num)
{	
	var re = /,/g;
    return num.replace(re,"");
}
function removeErrorStyle() {
    var genderErr=document.getElementById("errorGender");
    genderErr.style.display="none";
}
function validateDDL(ddl)
{
    return (ddl != null && ddl.selectedIndex > 0);
}
/*
* Author: Noel O Connor
*Description: validates the number of no claims years with the age of the driver to see if the NCD is possible.
*noClaims is the NCD and -1 is being taken from it because the value and plus 1 from what the actually options are.
* i.e. value = 1, options =1year NCD
*/
function validateNoClaimAndAge(){
	
	var noClaims=document.getElementById("noClaims");
	var age=document.getElementById("age");

	if( age.value !='' && (age.value - (noClaims.value - 1)) < 17)
		return false;
	else
		return true;
}
function clipDDLs()
{
    if(document.all==null || typeof document.body.style.maxHeight != "undefined") // If IE7/firefox/opera/safari... not need to clip
        return;
    else
    {
        var selects = document.getElementsByTagName("select");
        for(var i=0;i<selects.length;i++)
            selects[i].style.visibility = "hidden";                
    }
}
function unclipDDLs()
{
    if(document.all==null || typeof document.body.style.maxHeight != "undefined")
        return;
    else
    {
        var selects = document.getElementsByTagName("select");
        for(var i=0;i<selects.length;i++)
            selects[i].style.visibility = "visible";
    }
}


/*Tooltips text*/

var homepageTooltips = new Array();
homepageTooltips['IINCCD'] = "Please enter the number of years No Claims Bonus discount you have earned on an insurance policy IN YOUR OWN NAME. This bonus must have been earned either in Ireland or the UK. Your insurance company sends you a No Claims Bonus statement at renewal time and we will require a copy of this from you.";

/*..................................................*/
/*.................... FBD Car Insurance Benefits ......................*/
/*..................................................*/

homepageTooltips['BEN101'] = "";
homepageTooltips['BEN102'] = "Only provide 31 days cover as standard";
homepageTooltips['BEN103'] = "Only provide 93 days as standard";
homepageTooltips['BEN104'] = "Only provide 31 days cover as standard";

homepageTooltips['BEN201'] = "";
homepageTooltips['BEN202'] = "";
homepageTooltips['BEN203'] = "";
homepageTooltips['BEN204'] = "";

homepageTooltips['BEN301'] = "";
homepageTooltips['BEN302'] = "But only available as standard on certain packages.";
homepageTooltips['BEN303'] = "";
homepageTooltips['BEN304'] = "";

homepageTooltips['BEN401'] = "";
homepageTooltips['BEN402'] = "Sold within optional extra benefits package limit &euro;750 (Except 'Executivefirst' where €1,500 provided as Standard).";
homepageTooltips['BEN403'] = "Covered provided you prove person who stole keys is likely to know where your car is.";
homepageTooltips['BEN404'] = "";

homepageTooltips['BEN501'] = "";
homepageTooltips['BEN502'] = "";
homepageTooltips['BEN503'] = "";
homepageTooltips['BEN504'] = "";

homepageTooltips['BEN601'] = " ";
homepageTooltips['BEN602'] = "";
homepageTooltips['BEN603'] = "";
homepageTooltips['BEN604'] = "";

homepageTooltips['BEN701'] = "";
homepageTooltips['BEN702'] = "";
homepageTooltips['BEN703'] = "";
homepageTooltips['BEN704'] = "";

homepageTooltips['BEN801'] = "";
homepageTooltips['BEN802'] = "";
homepageTooltips['BEN803'] = "";
homepageTooltips['BEN804'] = "";


/*..................................................*/
/*.................... FBD Quick Quote ......................*/
/*..................................................*/


homepageTooltips['NCD'] = "How many years No Claims discount or bonus have you earned  in your own name in either Ireland or the UK? <br><br>Please note that YOUR INSURANCE CERTIFICATE AND SCHEDULE WILL NOT BE ISSUED until we receive a copy of your No Claims Bonus statement from your existing insurance company.<br><br>You can only use a No Claims Bonus on one insurance policy and the bonus must have been earned within the last four weeks.";
homepageTooltips['ENG'] = "Your car engine size will be detailed on your vehicle registration document. It can be detailed in cc or L - eg if you have a 1598cc car choose the 1.6L answer.";

/*..................................................*/
/*.................... Home Estimator ......................*/
/*..................................................*/


homepageTooltips['HE01'] = "Please select the type of house your property is.";
homepageTooltips['HE02'] = "Please select the number of bedrooms in your house.";
homepageTooltips['HE03'] = "Calculate the total floor area (in square feet) of your home by measuring the internal length and breadth of the house and multiplying these measurements together. <br/><br/>Normally the upper floor is the same size as the ground floor. If it is different you should calculate each area separately. <br/><br/> Typical house size based on number of bedroom: <br/><br/> 2 bedrooms: 750 sq ft<br/>3 bedrooms: 1,023 sq ft<br/>4 bedrooms: 1,270 sq ft";
homepageTooltips['HE04'] = "Add in a &euro; amount for higher than average kitchen fittings, built-in wardrobes, finishes (e.g. hardwood timber floors), etc. You should also add for fire/burglar alarms.";
homepageTooltips['HE05'] = "Add in a &euro; amount for any external constructions. Total rebuild costs for garages range from &euro;16,200 for a single attached garage to &euro;29,160 for a double attached garage.";


/*..................................................*/
/*.................... Home Quick Quote ......................*/
/*..................................................*/


homepageTooltips['Home_Rebuild'] = "This is the estimated cost to completely rebuild your property and all out-buildings. If you are unsure of this value click on the Estimate link. The minimum value must be &#128;125,000.";
homepageTooltips['Home_Contents'] = "Select either a % of the rebuild cost or enter a monetary amount. Contents includes all household goods and personal effects of every description and fixtures and fittings. These items should belong to you or to members of your family permanently residing with you.";
homepageTooltips['Home_Claim'] = "Tell us when your last home insurance claim was made, if any.";
homepageTooltips['Home_Burglar'] = "Tell us what type of burglar alarm, if any, is fitted to the property.";




/*..................................................*/
/*.................... FBD Full Quote Results......................*/
/*..................................................*/


homepageTooltips['FQ001'] = "Full round-the-clock driveway and roadside assistance in the event of a mechanical breakdown or accident, in both Ireland and UK.";
homepageTooltips['FQ002'] = "Provides for the repair or replacement of damaged or broken glass in the windscreen or windows of your car, with NO impact on your No Claims Discount.";
homepageTooltips['FQ003'] = "Provides cover for anyone with a full driving license aged between 25 and 71 to drive your car.";
homepageTooltips['FQ004'] = "In the event of a single claim you will not lose your No Claims Discount entirely, it will merely be reduced by 20%. Plus, after 36 months claims free driving with FBD you can make a single claim without any impact on your No Claims Discount.";

/*..................................................*/
/*.................... FBD Quick Quote Results......................*/
/*..................................................*/


homepageTooltips['QQ001'] = "Provides cover for injury to other people and damage to others' property. Includes full EU cover for leisure travel, third party driving of other cars, and 24/7 accident support.";
homepageTooltips['QQ002'] = "Provides fire and theft cover without effect on No Claims Discount. Includes cover for loss of personal property in the car up to &#8364;400, fire brigade attendance charges up to &#8364;2,000, replacement locks up to &#8364;750, PLUS all covers provided under Third Party.";
homepageTooltips['QQ003'] = "Provides cover for accidental damage to your car. Includes windscreen cover, 24/7 breakdown assistance, personal accident cover upto &#8364;5,000,  passenger medical expenses up to &#8364;1,000,  courtesy car, replacement as new for car less than 1 year old, PLUS all covers provided under Third Party, Fire & Theft.";

/*..................................................*/
/*.................... FBD Quick Quote Results......................*/
/*..................................................*/


homepageTooltips['IIOC3'] = "We will pay you for personal belongings damaged or stolen due to accident, fire, or attempted theft, while they are in your car up to a value of EUR200.";
homepageTooltips['IIOC4'] = "Full 24/7 roadside and driveway assistance in the event of mechanical breakdown or accident.";
homepageTooltips['IIOC5'] = "Gives you (the policyholder) Third Party cover when you drive a car owned by someone else.";
homepageTooltips['IIOC6'] = "We will provide you with a replacement hire car if are off the road following an accident.";
homepageTooltips['IIOC7'] = "Personal accident benefit for you or your spouse, and medical expenses up to EUR1,000 for each person injured if your car is involved in an accident.";
homepageTooltips['IIOC8'] = "If your car is less than 12 months old with less than 25,000kms on the clock and owned by the policyholder we will provide you with a brand new car if the old one is written off in an accident.";
homepageTooltips['IIREG'] = "This is the registration number (which appears on the number plate) of the vehicle you want to insure. If you purchase an insurance policy and have the incorrect registration details then you will not be insured for that vehicle.";
homepageTooltips['IICACD'] = "No Nonsense has access to a wide range of insurance and personal finance products that could save you money. You will not be under any obligation and you can withdraw your permission at any time.";
homepageTooltips['IIPAYM'] = "If you wish to pay by direct debit directly from your bank account you can pay an initial deposit and we will spread the remaining instalments over a 7 month period. An interest fee does apply to the direct debit amount. Please note that any changes in the insurance premiums/terms charged to you will result in an alteration to the APR.";
homepageTooltips['IIDDAC'] = "The bank account must be able to process direct debit payments. Check with your bank if you are unsure.";
homepageTooltips['IIDDAT'] = "Are you the authorised signatory on this account. Do you require a second signatory on this account? Select NO if you have a joint account that requires both signatures, and we will send you a Direct Debit Instruction which you will both need to sign.";
homepageTooltips['IIDDBC'] = "Please choose one the following dates upon which the payment will be deducted from your bank account each month: 1st, 8th, 15th or 22nd";
homepageTooltips['IICCVN'] = "This is the last three digits of the security number which appears beside your signature on the BACK of your credit card.";
homepageTooltips['IICCAT'] = "Please indicate if you wish us to automatically renew your policy next year. We will send you notifiaction of your renewal at least 30 days in advance. Your credit card information will not be stored by us.";
homepageTooltips['IIYMCD'] = "Select the year your car was manufactured. Please note that we can currently only insure cars that are less than ten years old.";
homepageTooltips['IIDCOR'] = "Please note that in the event that any information provided by you is incorrect or that you do not provide us with information that could reasonably be deemed to affect your policy, your insurance will be invalid and you could face prosecution.";
homepageTooltips['II'] = "";
homepageTooltips['II'] = "";
homepageTooltips['II'] = "";
homepageTooltips['II'] = "";


/* Fadding Functions */
function fadeIn(idObjToFadeIn)
{
    var objToFadeIn = null;
        
    if(document.all)
        objToFadeIn = document.all[idObjToFadeIn];
    else
        objToFadeIn = document.getElementById(idObjToFadeIn);
    
    if(objToFadeIn==null)
        return;
    
    objToFadeIn.style.opacity = 0;  
    objToFadeIn.style.visibility = "visible";   
              
    setTimeout("animateFadeIn(document.getElementById('"+objToFadeIn.id+"'));",40);
}
function animateFadeIn(objToFadeIn)
{
    if(objToFadeIn==null)
        return;
        
    if(document.all)
    {
        setOpacity(objToFadeIn,1);        
        return;
    }       
              
    var opacity = getOpacity(objToFadeIn);
         
    if(opacity>=1)
        return;
   
    if(opacity==0)
        setOpacity(objToFadeIn,0.25);
    else if(opacity==0.25)  
        setOpacity(objToFadeIn,0.5);
    else if(opacity==0.5)  
        setOpacity(objToFadeIn,0.75);
    else 
    {
        setOpacity(objToFadeIn,1);
        return;
    }  
    
    opacity = getOpacity(objToFadeIn);
           
    if(opacity<1)    
        setTimeout("animateFadeIn(document.getElementById('"+objToFadeIn.id+"'));",40);
}
function setOpacity(obj,val)
{
    if(document.all)
        obj.style.filter = "alpha(opacity="+parseInt(val*100)+")";
    else
        obj.style.opacity = val;
}
function getOpacity(obj)
{
    if(document.all)
    {
       return parseFloat(obj.style.filter.substring(obj.style.filter.indexOf("=")+1,obj.style.filter.indexOf(")")))/100;
    }
    else
       return parseFloat(obj.style.opacity);
}
function fadeOut(idObjToFadeOut)
{
    var objToFadeOut = null;
        
    if(document.all)
        objToFadeOut = document.all[idObjToFadeOut];
    else
        objToFadeOut = document.getElementById(idObjToFadeOut);
    
    if(objToFadeOut==null)
        return;
    
    setOpacity(objToFadeOut,1);
    objToFadeOut.style.visibility = "visible";    
              
    setTimeout("animateFadeOut(document.getElementById('"+objToFadeOut.id+"'));",30);
}
function animateFadeOut(objToFadeOut)
{
    if(objToFadeOut==null)
        return;
             
    var opacity = getOpacity(objToFadeOut);
    
    if(opacity<=0)
        return;
       
    if(opacity==1)
        setOpacity(objToFadeOut,0.6);   
    else if(opacity==0.6)  
       setOpacity(objToFadeOut,0.3);   
    else 
    {
        objToFadeOut.style.visibility = "hidden";
        setOpacity(objToFadeOut,0);
        return;  
    }
   opacity = getOpacity(objToFadeOut);
    if(opacity>0)    
        setTimeout("animateFadeOut(document.getElementById('"+objToFadeOut.id+"'));",30);
    
}

function onInstantSubmit() {
    if(validateInstant()) {
        document.qqForm.submit();
    } else {
        return false;
    }
}

function validateInstant() { /* Homepage instant quote */ 
	var error=0;

	var age=document.getElementById("age");
	var ageErr=document.getElementById("error1");
	
	/* Arekibo */
	var ddlNoClaims = (document.all!=null?document.all["noClaims"]:document.getElementById("noClaims"));
	var ddlLicenseType = (document.all!=null?document.all["licence"]:document.getElementById("licence"));
	var ddlLocation = (document.all!=null?document.all["motorQuoteCountyId"]:document.getElementById("motorQuoteCountyId"));
	var ddlEngineSize = (document.all!=null?document.all["engineSize"]:document.getElementById("engineSize"));	
	var errorNoClaims = (document.all!=null?document.all["errorNoClaims"]:document.getElementById("errorNoClaims"));
	var errorNoClaimsAge = (document.all!=null?document.all["errorNoClaimsAge"]:document.getElementById("errorNoClaimsAge"));
	var errorLicenseType = (document.all!=null?document.all["errorLicenseType"]:document.getElementById("errorLicenseType"));
	var errorLocation = (document.all!=null?document.all["errorLocation"]:document.getElementById("errorLocation"));
	var errorEngineSize = (document.all!=null?document.all["errorEngineSize"]:document.getElementById("errorEngineSize"));	
	
	if(validateDDL(ddlNoClaims)==false)
	{
	    error = 1;
	    errorNoClaims.style.display = "block";
	}
	else
	{
	    errorNoClaims.style.display = "none";
    }
		
	if(validateDDL(ddlLicenseType)==false)
	{
	    error = 1;
	    errorLicenseType.style.display = "block";
	}
	else
	{
	    errorLicenseType.style.display = "none"; 
	}
	
	if(validateDDL(ddlLocation)==false)
	{
	    error = 1;
	    errorLocation.style.display = "block";
	}
	else
	{
	    errorLocation.style.display = "none";
	}    
	    
	if(validateDDL(ddlEngineSize)==false)
	{
	    error = 1;
	    errorEngineSize.style.display = "block";
	}
	else
	{
	    errorEngineSize.style.display = "none";
    }
	/***********/
	
	if (validateNumeric(age.value)) {
		if (age.value<17) {
			error=1;
			ageErr.style.display="block";
			document.getElementById("error1").innerHTML = "You must be at least 17 years to purchase car insurance here";
			
		} else {
			ageErr.style.display="none";
			
			if(validateNoClaimAndAge()==false){
				    error = 1;
				    errorNoClaimsAge.style.display = "block";
				}
			else{
				    errorNoClaimsAge.style.display = "none";
			    }
		}
	} else {
		error=1;
		ageErr.style.display="block";
		if(age.value=="")
		{ document.getElementById("error1").innerHTML = " Please enter your age"; }
		else
		{ document.getElementById("error1").innerHTML = " Your age must be a number"; }
	}
	

	var carvalue=document.getElementById("carValue");
	var carvalueErr=document.getElementById("error2");

	// Change #6439
	// Ciaran Moran 08/01/2010
	// Facilitate commas in the car value field - added stripCommas
	// 
	if (validatePositiveNumeric(stripCommas(carvalue.value))) {
		carvalueErr.style.display="none";
	} else {
		error=1;
		carvalueErr.style.display="block";
	}

	var accept=document.getElementById("accept");
	var acceptErr=document.getElementById("error3");

	if (!accept.checked) {
		error=1;
		acceptErr.style.display="block";
		
	} else {
		acceptErr.style.display="none";
	}
	
	var genderMale=document.getElementById("genderId1");
	var genderFemale=document.getElementById("genderId2");
	var genderErr=document.getElementById("errorGender");
	
	if(!genderMale.checked && !genderFemale.checked) {
	    error=1;
	    genderErr.style.display="block";
	} else {
	    genderErr.style.display="none";
	}

	if (error==1) {
		return false;
	} else {
		return true;
	}
}

function validateNumeric(val) { /* Numeric */
	if (val=="") {
		return false;
	}

	var validChars="0123456789";
	var Char;

	for (i = 0; i<val.length; i++) {
		Char=val.charAt(i);
		if (validChars.indexOf(Char)==-1) {
			return false;
		}
	}

	return true;
}
function validatePositiveNumeric(val) { /* Numeric */
	if (val=="") {
		return false;
	}

	var validChars="0123456789";
	var Char;
	var nonZero = false;

	for (i = 0; i<val.length; i++) {
		Char=val.charAt(i);
		if (validChars.indexOf(Char)==-1) {
			return false;
		}
		if(Char!="0"){
			nonZero = true;
		}
	}
	if(!nonZero)
		return false;
	return true;
}

function kainos_ensureSelected_Message(elementId)
{
	var element = document.getElementById(elementId);
	var labelError = document.getElementById(elementId + "Error");
	if (element.value == -1 ) {
		labelError.style.display = "block";
	}
	else {
		labelError.style.display = "none";
	}	
}

function submit_Validation() 
{
	if(static_Submit_Validation())
	{
		var homeQuoteDetails = document.getElementById('homeQuoteDetails');
		homeQuoteDetails.submit();
	}
} 
function static_Submit_Validation()
{
	//variable that will stop the form submitting if it
	 
	//gets set to false
	var submit = true;
	//Now get all the relevant Status elements
	var coverTypeIdErrorElem = document.getElementById('coverTypeIdError');
	var lastClaimIdErrorElem = document.getElementById('lastClaimIdError');
	var countyIdErrorElem = document.getElementById('countyIdError');
	var rebuildCostErrorElem = document.getElementById('rebuildCostError');
	var rebuildCostAmountErrorElem = document.getElementById('rebuildCostAmountError');
	var contentsValueErrorElem = document.getElementById('contentsValueError');
	var contentsMin1ErrorElem = document.getElementById('contentsMin1Error');
	var contentsMin2ErrorElem = document.getElementById('contentsMin2Error');
	var burgularAlarmIdErrorElem = document.getElementById('burgularAlarmIdError');
	var ageErrorElem = document.getElementById('ageError');
	var jointageErrorElem = document.getElementById('jointAgeError');
	var ageManError = document.getElementById('ageManError');
	var assumptionsAcceptedError = document.getElementById('assumptionsAcceptedError');
	
	coverTypeIdErrorElem.style.display = "none";
	lastClaimIdErrorElem.style.display = "none";
	countyIdErrorElem.style.display = "none";
	rebuildCostErrorElem.style.display = "none";
	rebuildCostAmountErrorElem.style.display = "none";
	contentsValueErrorElem.style.display = "none";
	burgularAlarmIdErrorElem.style.display = "none";
	ageErrorElem.style.display = "none";
	jointageErrorElem.style.display = "none";
	ageManError.style.display="none";
	contentsMin1ErrorElem.style.display= "none";
	contentsMin2ErrorElem.style.display= "none";
	
	var coverTypeIdElem = document.getElementById('coverTypeId');
	var lastClaimIdElem = document.getElementById('lastClaimId');
	var countyIdElem = document.getElementById('countyId');
	var rebuildCostElem = document.getElementById('rebuildCost');
	var contentsValueElem = document.getElementById('contentsValue');
	var burgularAlarmIdElem = document.getElementById('burgularAlarmId');
	var ageElem = document.getElementById('ageHome').value;
	var assumptionsAccepted = document.getElementById('acceptedAssumptions');

	var jointAgeErrorElem = document.getElementById('jointAgeError').value;
	var isJointPartyElem = document.getElementsByName('isJointParty');

	var radioVal = "";

	for(var i = 0; i < isJointPartyElem.length; i++) {
		if(isJointPartyElem[i].checked) {
			radioVal = isJointPartyElem[i].value;
		}
	}

	if(radioVal=="Yes"){

		var ageElem = document.getElementById('jointPartyAge').value;
		var ageJointErrorElem = document.getElementById('jointAgeError');
		var ageJointManError = document.getElementById('jointAgeManError');

		if(ageElem == "")
		{
			submit = false;
			ageJointManError.style.display = "block";
			ageJointErrorElem.style.display = "none";
		}
		else if(!(IsNumeric(ageElem))) 
		{
			submit = false;
			ageJointErrorElem.style.display = "block";
			ageJointManError.style.display = "none";
		}
		else if(ageElem < 18)
		{
			submit = false;
			ageJointErrorElem.style.display = "block";
			ageJointManError.style.display = "none";
		}
			
	}

	var ageElem = document.getElementById('ageHome').value;

	if(ageElem == "")
	{
		submit = false;
		ageManError.style.display = "block";
	}
	else if(!(IsNumeric(ageElem))) 
	{
		submit = false;
		ageErrorElem.style.display = "block";
	}
	else if(ageElem < 18)
	{
		submit = false;
		ageErrorElem.style.display = "block";
	}
	else
	{
		ageErrorElem.style.display = "none";
	}
	
	//HANDLE COVER TYPE VALIDATION
	//Only invalid if "please select" is selected
	if(coverTypeIdElem.value == -1)
	{
		submit = false;
		coverTypeIdErrorElem.style.display = "block";
	}
	else
	{
		coverTypeIdErrorElem.style.display = "none";
	}
	
	//HANDLE COUNTY VALIDATION
	//Only invalid if "please select" is selected
	if(countyIdElem.value == -1)
	{
		submit = false;
		countyIdErrorElem.style.display = "block";
	}
	else
	{
		countyIdErrorElem.style.display = "none";
	}

	//HOME INSURANCE CLAIM VALIDATION
	//Only invalid if "please select" is selected
	if(lastClaimIdElem.value == -1)
	{
		submit = false;
		lastClaimIdErrorElem.style.display = "block";
	}
	else
	{
		lastClaimIdErrorElem.style.display = "none";
	}

	//HOME BURGLAR ALARM VALIDATION
	//Only invalid if "please select" is selected
	if(burgularAlarmIdElem.value == -1)
	{
		submit = false;
		burgularAlarmIdErrorElem.style.display = "block";
	}
	else
	{
		burgularAlarmIdErrorElem.style.display = "none";
	}


	//HANDLE CONTENTS VALUE VALIDATION
	if(contentsValueElem.value == '')
	{
		submit = false;
		contentsValueErrorElem.style.display = "block";
	}
	else if(coverTypeIdElem.value == 1)
	{
		if(parseInt(stripCommas(contentsValueElem.value)) < 25000)
		{
			submit = false;
			contentsMin1ErrorElem.style.display = "block";
		}
	}
	else if(coverTypeIdElem.value != 6)
	{
		if(parseInt(stripCommas(contentsValueElem.value)) < 10000)
		{
			submit = false;
			contentsMin2ErrorElem.style.display = "block";
		}
	}
	else
	{
		contentsValueErrorElem.style.display = "none";
		contentsMin1ErrorElem.style.display = "none";
		contentsMin2ErrorElem.style.display = "none";
	}
	
	//HANDLE REBUILD COST VALIDATION IF THE CORRECT HOUSE IS SELECTED FOR INSURANCE COVER
	if(coverTypeIdElem.value == 1 || coverTypeIdElem.value == 2 || coverTypeIdElem.value == 3)
	   {
			if(rebuildCostElem.value == '')
			{
				submit = false;
				rebuildCostErrorElem.style.display = "block";
			}
			else if(parseInt(stripCommas(rebuildCostElem.value)) < 125000)
			{
				submit = false;
				rebuildCostAmountErrorElem.style.display = "block";
			}
			else
			{
				rebuildCostErrorElem.style.display = "none";
			}
		}
		
		
	if(validateCoverStartDate()){
		submit = false;
	}
	
	//HANDLE ASSUMPTIONS VALIDATION	
	//if the element is null
	if(assumptionsAccepted.checked == false)
	{	
		submit = false;
		assumptionsAcceptedError.style.display = "block";
	}
	else{
		assumptionsAcceptedError.style.display = "none";
	}
	
	return submit;
}

function validateCoverStartDate()
{
    var error = false;

	var coverStartDate=document.getElementById("coverStartDate");
	var coverStartDateRangeError=document.getElementById("coverStartDateRangeError");
	var coverStartDateError=document.getElementById("coverStartDateError");
	var coverStartDateManError=document.getElementById("coverStartDateManError");

	if (coverStartDate.value!='') {
		coverStartDateManError.style.display="none";
	} else if (error==false)
	{
		coverStartDateManError.style.display="block";
		error = true;
	}

	if (isValidDate(coverStartDate.value)) {
		coverStartDateError.style.display="none";
	} else if (error==false)
	{
		coverStartDateError.style.display="block";
		error = true;
	}

	//more than 30 days
	if (isWithInValidDateRange(coverStartDate.value)) {
		coverStartDateRangeError.style.display="none";
	} else if (error==false) 
	{
		coverStartDateRangeError.style.display="block";
		error = true;
	}

	return error;
}

function isValidDate(s) {
    // format D(D)/M(M)/(YY)YY
    var dateFormat = /^\d{1,4}[\.|\/|-]\d{1,2}[\.|\/|-]\d{1,4}$/;

    if (dateFormat.test(s)) {
        // remove any leading zeros from date values
        s = s.replace(/0*(\d*)/gi,"$1");
        var dateArray = s.split(/[\.|\/|-]/);
      
        // correct month value
        dateArray[1] = dateArray[1]-1;

        // correct year value
        if (dateArray[2].length<4) {
            // correct year value
            dateArray[2] = (parseInt(dateArray[2]) < 50) ? 2000 + parseInt(dateArray[2]) : 1900 + parseInt(dateArray[2]);
        }

        var testDate = new Date(dateArray[2], dateArray[1], dateArray[0]);
        if (testDate.getDate()!=dateArray[0] || testDate.getMonth()!=dateArray[1] || testDate.getFullYear()!=dateArray[2]) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}

function isWithInValidDateRange(coverStartDate){

	var validCSD=true;
	
	var dt1  = coverStartDate.substring(0,3); 
	var mon1 = coverStartDate.substring(3,6); 
	var yr1  = coverStartDate.substring(6,10);  
	var temp1 = mon1 + dt1 + yr1;

	var cfd = Date.parse(temp1);
	var today =new Date();
	today.setDate(today.getDate()-1);

	var maxRange=new Date().setDate(today.getDate()+30);
	var coverStart=new Date(cfd);


	if(coverStart > maxRange){
		validCSD=false;
	}

	if(coverStart <= today){
		validCSD=false;
	}

	return validCSD;

}
		

function handleAgeBlur()
{
    var ageElem = document.getElementById('ageHome').value;
    var ageErrorElem = document.getElementById('ageError');
	var ageManError = document.getElementById('ageManError');

    if(ageElem == "")
	{
		ageManError.style.display = "block";
		ageErrorElem.style.display = "none";
	}
	else if(!(IsNumeric(ageElem))) 
	{
		ageErrorElem.style.display = "block";
		ageManError.style.display = "none";
	}
	else if(ageElem < 18)
	{
		ageErrorElem.style.display = "block";
		ageManError.style.display = "none";
	}
	else
	{
		ageErrorElem.style.display = "none";
		ageManError.style.display = "none";
	}
}

function handleJointAgeBlur()
{
    var ageElem = document.getElementById('jointPartyAge').value;
    var ageErrorElem = document.getElementById('jointAgeError');
	var ageManError = document.getElementById('jointAgeManError');

    if(ageElem == "")
	{
		ageManError.style.display = "block";
	}
	else if(!(IsNumeric(ageElem))) 
	{
		ageErrorElem.style.display = "block";
	}
	else if(ageElem < 18)
	{
		ageErrorElem.style.display = "block";
	}
	else
	{
		ageErrorElem.style.display = "none";
		ageManError.style.display = "none";
	}
}

function handleHomeCheckboxChange()
{
    var assumptionsAccepted = document.getElementById('acceptedAssumptions');
    var assumptionsAcceptedError = document.getElementById('assumptionsAcceptedError');

    //HANDLE ASSUMPTIONS VALIDATION	
	//if the element is null
	if(assumptionsAccepted.checked == false)
	{	
		submit = false;
		assumptionsAcceptedError.style.display = "block";
	}
	else{
		assumptionsAcceptedError.style.display = "none";
	}
}

function contentPercentage()
{
	var element = document.getElementById('contentsPercentageId');

	if ($(element).val() > 0 && isFormatedFloat($('#rebuildCost').val())) 
	{
		var rebuild = $('#rebuildCost').val().replace(/,/g, '');
		var value = Math.round(( rebuild * ($(element).val()*10) )/100);
		var val = convertToIntegerAmount(value.toString());
		var val2 = "" + val;
		val2 = val2.replace(/,/g, '');
		$('#contentsValue').val(val2);
		$('#contentsValue').focus();
	}
}

function handleContentsPercentageList()
{

    var element = $('#rebuildCost');
    var value = element.val();
    element.val(value);
    value = value.replace(/,/g, '');
    if (value >= 250000) {
	    // if there is no 10% already added
	    if ($('#contentsPercentageId').children()[1].value != 1)
	    {
		    $('#contentsPercentageIdPS').after('<option value="1">10%</option>');
	    }
    } else {
	    // if and only if 10% is already displayed
	    if ($('#contentsPercentageId').children()[1].value == 1) {
		    $($('#contentsPercentageId').children()[1]).remove();
	    }
    }

    // update value of contentsValue when percentage is set!
    if ($('#contentsPercentageId') != -1) {
	    // simulate that percentage has changed :)
	    //handleContentsPercentageChange($('#contentsPercentageId'));
    }
}
	
	
function coverType (event)
{
    var element;
	if (!event) var event = window.event;
	if (event.target) element = event.target;
	else if (event.srcElement) element = event.srcElement;

	if (element.value >= 1 && element.value <= 3) {
		if (document.getElementById('rebuildCostOption').style.display == 'none') {
			$('#rebuildCostOption').slideDown();
			$('#contentsPercentageIdOption').slideDown();
		}
	} else {
		$('#rebuildCostOption').slideUp();
		$('#contentsPercentageIdOption').slideUp();
		var contentsPercentageId = document.getElementById("contentsPercentageId");
		contentsPercentageId.value = -1;
	}
}

function rebuild()
{
    
    var element = document.getElementById('rebuildCost');
	var value = $(element).val().replace(/,/g, '');
	$(element).val(convertToIntegerAmount(value));
}

function contents(event) 
{
    var element = document.getElementById('contentsValue');

	var value = $(element).val().replace(/,/g, '');
	$(element).val(convertToIntegerAmount(value));
	
	var contentsValueElem = document.getElementById('contentsValue');
	var coverTypeIdElem = document.getElementById('coverTypeId');
    var contentsValueErrorElem = document.getElementById('contentsValueError');
	var contentsMin1ErrorElem = document.getElementById('contentsMin1Error');
	var contentsMin2ErrorElem = document.getElementById('contentsMin2Error');

    //HANDLE CONTENTS VALUE VALIDATION
	if(contentsValueElem.value == '')
	{
		contentsValueErrorElem.style.display = "block";
	}
	else if(coverTypeIdElem.value == 1)
	{
		if(parseInt(stripCommas(contentsValueElem.value)) < 25000)
		{
			contentsMin1ErrorElem.style.display = "block";
		}
		else
	    {
		    contentsValueErrorElem.style.display = "none";
		    contentsMin1ErrorElem.style.display = "none";
		    contentsMin2ErrorElem.style.display = "none";
	    }
	}
	else if(coverTypeIdElem.value != 6)
	{
		if(parseInt(stripCommas(contentsValueElem.value)) < 10000)
		{
			contentsMin2ErrorElem.style.display = "block";
		}
		else
	    {
		    contentsValueErrorElem.style.display = "none";
		    contentsMin1ErrorElem.style.display = "none";
		    contentsMin2ErrorElem.style.display = "none";
	    }
	}
	else
	{
		contentsValueErrorElem.style.display = "none";
		contentsMin1ErrorElem.style.display = "none";
		contentsMin2ErrorElem.style.display = "none";
	}
}

//function gup( name )
//{
//  var regexS = "[\\?&]"+name+"=([^&#]*)";
//  var regex = new RegExp( regexS );
//  var tmpURL = window.location.href;
//  var results = regex.exec( tmpURL );
//  if( results == null )
//    return null;
//  else
//    return results[1];
//}

//function pareseURLParameters() {
//    var parameters = ['ageHome', 'countyId', 'quote', 'contentsValue', 'rebuildCost', 'contentsPercentageId', 'coverTypeId'];
//    for (var i = 0; i < parameters.length; i++) {
//          var value = gup(parameters[i]);
//          if (value == null || document.getElementById(parameters[i]) == null) {
//                continue;
//          }
//          document.getElementById(parameters[i]).value = value;
//    }
//}

function ShowCarQuote()
{
    document.getElementById('carQuote').style.display = 'block';
	document.getElementById('homeQuote').style.display = 'none';
	document.getElementById('carQuoteCompBox').style.display = 'block';
	document.getElementById('homeQuoteCompBox').style.display = 'none';
	document.getElementById('rightCar').style.display = 'block'; 
	document.getElementById('rightHome').style.display = 'none'; 
    document.getElementById('carSelectTab').className = 'carQuoteSelectionTabOn';
  	document.getElementById('homeSelectTab').className = 'homeQuoteSelectionTabOff';
}

function ShowHomeQuote()
{
    document.getElementById('carQuote').style.display='none';
	document.getElementById('homeQuote').style.display='block';
	document.getElementById('carQuoteCompBox').style.display='none';
	document.getElementById('homeQuoteCompBox').style.display='block';
	document.getElementById('rightCar').style.display = 'none'; 
	document.getElementById('rightHome').style.display = 'block'; 
    document.getElementById('carSelectTab').className = 'carQuoteSelectionTabOff';
    document.getElementById('homeSelectTab').className = 'homeQuoteSelectionTabOn';
}

function ShowRetrievePopUp()
{
	document.getElementById('RetrievePopUp').style.display='block';
}
function HideRetrievePopUp()
{
	document.getElementById('RetrievePopUp').style.display='none';
}


function isFormatedFloat(value)
{
	return (value.length > 0 && value != null) && /^\d{0,3}(,\d{3}){0,2}(\.\d{1,2})?$/.test(value);
}

function IsNumeric(numWithoutComma)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < numWithoutComma.length && IsNumber == true; i++) 
      { 
      Char = numWithoutComma.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;  
}

function convertToInteger(value)
{
    return value.replace(/,/g, '');
}

//Converting number to comma value
function convertToIntegerAmount(valueToConvert)
{
	var aDotParts = valueToConvert.split('.');
	var intPart = aDotParts[0];
	
	// count dots
	if (aDotParts.length > 2) {
		throw new Error('Badly formed number: ' + this.inspect())
	}
	var x = new String();
	// maybe there are already comas in a number string - check it
	if (intPart.indexOf(',',0) != -1)
	{
		var aComaParts = intPart.split(',');
		//if (aComaParts[0].length > 3) {
		//	throw new Error('Badly formed number: ' + this.inspect())
		//}
		//aComaParts.slice(1).each(function(part) {
		//	if (part.length != 3) {
				throw new Error('Badly formed number: ' + this.inspect())
		//	}
		//}.bind(this));
	}
	else
	{
		// no comas so create your own
		intPart = convertIntPart(intPart)

	}
	
	return intPart
}

function convertIntPart(intPart) {
	var result = '';
	var sInt = intPart;
	var len = sInt.length; 

	if (len <= 3) {
		return intPart;
	}
	
	var comaIdx = len % 3;
	
	if (comaIdx) {
		result = sInt.substr(0, comaIdx) + ',';
	}
	for (; comaIdx < len; comaIdx += 3 ) {
		result += sInt.substr(comaIdx, 3) + ',';
	}
	
	// cut last coma off
	return result.substr(0, result.length-1); 
}

//methods for popups

function quoteDetailsFadeIn(value)
{
	var elem = document.getElementById(value);
	var elem2 = document.getElementById("coverTypeId");

	elem2.style.visibility="hidden";
	elem2 = document.getElementById("countyId");
	setEstimatorCountyStatic();
	elem2.style.visibility="hidden";
	elem2 = document.getElementById("contentsPercentageId");
	elem2.style.visibility="hidden";

	elem2 = document.getElementById("lastClaimId");
    if (elem2) {
	    elem2.style.visibility="hidden";
    }
    elem2 = document.getElementById("burgularAlarmId");
    if (elem2) {
	    elem2.style.visibility="hidden";
    }
	if (elem) {
		elem.style.display="block";
		elem.style.visibility="visible";
	}
	fadeIn(value);
}

function setEstimatorCountyStatic() {
 var countyId = document.getElementById("countyId").value;
 var estimatorDoc = window.frames["estimatorIFrame"].document;
 var iframeCounty = estimatorDoc.getElementById("countyLabel");
 var countyName = getCountyName(countyId);
 iframeCounty.innerHTML = countyName;
}

function getCountyName(countyId) {
	var countyNames = {28:"Carlow ", 29:"Cavan ", 30:"Clare ", 31:"Co. Dublin ", 32:"Cork City ", 33:"Co. Cork ", 34:"Donegal ", 36:"Dublin 1 ", 37:"Dublin 2 ", 38:"Dublin 3 ", 39:"Dublin 4 ", 40:"Dublin 5 ", 41:"Dublin 6 ", 42:"Dublin 6W ", 43:"Dublin 7 ", 44:"Dublin 8 ", 45:"Dublin 9 ", 46:"Dublin 10 ", 47:"Dublin 11 ", 48:"Dublin 12 ", 49:"Dublin 13 ", 50:"Dublin 14 ", 51:"Dublin 15 ", 52:"Dublin 16 ", 53:"Dublin 17 ", 54:"Dublin 18 ", 55:"Dublin 19 ", 56:"Dublin 20 ", 57:"Dublin 21 ", 58:"Dublin 22 ", 59:"Dublin 23 ", 60:"Dublin 24 ", 61:"Galway ", 62:"Kerry ", 63:"Kildare ", 64:"Kilkenny ", 65:"Laois ", 66:"Leitrim ", 67:"Co. Limerick ", 68:"Limerick City ", 69:"Longford ", 70:"Louth ", 71:"Mayo ", 72:"Meath ", 73:"Monaghan ", 74:"Offaly ", 75:"Roscommon ", 76:"Sligo ", 83:"Co. Tipperary ", 79:"Waterford ", 80:"Westmeath ", 81:"Wexford ", 82:"Wicklow "};

	return countyNames[countyId];
}

function quoteDetailsFadeOut(value) {
	var elem = document.getElementById(value);
	var elem2 = document.getElementById("coverTypeId");
	elem2.style.visibility="visible";
	elem2 = document.getElementById("countyId");
	elem2.style.visibility="visible";
	elem2 = document.getElementById("contentsPercentageId");
	elem2.style.visibility="visible";
	elem2 = document.getElementById("lastClaimId");
if(elem2) {
	elem2.style.visibility="visible";
}
elem2 = document.getElementById("burgularAlarmId");
if(elem2) {
	elem2.style.visibility="visible";
}
	fadeOut(value);
}

function kainos_estimatorText()
{	
	var houseTypeHouseOwnedEstimatorText = document.getElementById('houseTypeHouseOwnedEstimatorText');
	var houseTypeHouseOwnedLetOutEstimatorText = document.getElementById('houseTypeHouseOwnedLetOutEstimatorText');
	var houseTypeHolidayHouseOwnedEstimatorText = document.getElementById('houseTypeHolidayHouseOwnedEstimatorText');
	var houseTypeHouseRentedEstimatorText = document.getElementById('houseTypeHouseRentedEstimatorText');
	var houseTypeAppartmentEstimatorText = document.getElementById('houseTypeAppartmentEstimatorText');
	
	var estimatorText = document.getElementById('estimatorText');
	var coverTypeId = document.getElementById('coverTypeId').value;
	
	if((coverTypeId == 1) || (coverTypeId == 6))
	{
		estimatorText.innerHTML = houseTypeHouseOwnedEstimatorText.innerHTML;
	}
	else if(coverTypeId == 2)
	{
		estimatorText.innerHTML = houseTypeHouseOwnedLetOutEstimatorText.innerHTML;
	}
	else if(coverTypeId == 3)
	{
		estimatorText.innerHTML = houseTypeHolidayHouseOwnedEstimatorText.innerHTML;
	}
	else if(coverTypeId == 4)
	{
		estimatorText.innerHTML = houseTypeHouseRentedEstimatorText.innerHTML;
	}
	else if(coverTypeId == 5)
	{
		estimatorText.innerHTML = houseTypeAppartmentEstimatorText.innerHTML;
	}
	//if no cover type is selected then just default to the text for type 1
	else
	{
		estimatorText.innerHTML = houseTypeHouseOwnedEstimatorText.innerHTML;
	}
}


function alphanumeric(alphane)
			{
			var numaric = alphane;
			for(var j=0; j<numaric.length; j++)
			{
			var alphaa = numaric.charAt(j);
			var hh = alphaa.charCodeAt(0);
			
			if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
			{				
			}
			else {
				if(j == 3 && hh == 32){
				}
				else{
					return false;
				}
			}
			}
			return true;
			}
			
function trim(stringToTrim) 

{
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
			
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
 

function retrieveQuote(formName){
		var retrievalForm = document.forms[formName]; 
		var quoteref = retrievalForm.elements["quotationReference"].value;

		quoteref = quoteref.toUpperCase();
		quoteref = trim(quoteref);
		retrievalForm.elements["quotationReference"].value = quoteref;											
		if (quoteref.length == 6) {
			quoteref = quoteref.substring(0,3) + " " + quoteref.substring(3,6);
			retrievalForm.elements["quotationReference"].value = quoteref;
		}
		if (quoteref.length > 7 || quoteref.length < 6 || alphanumeric(quoteref) == false) {
			document.getElementById('mandatory').style.display = 'block';
			return false;
		}
						
		retrievalForm.elements["retrievalSubmit"].click();
	}
