﻿function homeInsuranceForm(){
    for(var i=0; i<dropArray.length; i++)
    {
        if(document.getElementById(dropArray[i].dropID))
        {
            document.getElementById(dropArray[i].dropID).onchange = dropChange;
            document.getElementById(dropArray[i].dropID).onchange();
        }
    }
	var anchors = document.getElementsByTagName('a');
	for(var i=0; i<anchors.length; i++)
	{
		if(anchors[i].getAttribute('rel')=="pop")
		{
			anchors[i].onclick = function(){
				window.open(this.getAttribute('href'),"popWindow","width=500,height=500,location=0");
				return false;
			}
		}
		if(anchors[i].getAttribute('rel')=="external")
		{
			anchors[i].onclick = function(){
				window.open(this.getAttribute('href'));
				return false;
			}
		}
	}
}

function dropChange()
{
    var thisDrop = arr(this.id);
    var hiddenSection = document.getElementById(thisDrop.hiddenID);
    var field = document.getElementById(thisDrop.field);
    
    if(this.options[this.selectedIndex].value=="")
    {
        if(thisDrop.defaultVal==thisDrop.showVal)
        {
            hiddenSection.style.display = "block";
        }
        else
        {
            hiddenSection.style.display = "none";
        }
    }
    if(this.options[this.selectedIndex].value==thisDrop.showVal)
    {
        hiddenSection.style.display = "block";
    } 
    else if(this.options[this.selectedIndex].value==thisDrop.hideVal)
    {
        hiddenSection.style.display = "none";
    }
    if((this.options[this.selectedIndex].value==thisDrop.showVal) && this.options[this.selectedIndex].value==0)
    {
        field.value = thisDrop.fieldVal;
    }
	else if((this.options[this.selectedIndex].value==thisDrop.hideVal) && this.options[this.selectedIndex].value!=0)
    {
        field.value = thisDrop.fieldVal;
    }
	else if(this.options[this.selectedIndex].value=="" && field.value!=thisDrop.fieldVal)
	{
		field.value = 0;
	}
}

function drops(dropID,hiddenID,field,fieldVal,showVal,hideVal,defaultVal)
{
    //dropdown ID
    this.dropID = dropID;
    //ID of hidden section
    this.hiddenID = hiddenID;
    //Associated field
    this.field = field;
    //Value to set the field to
    this.fieldVal = fieldVal;
    //The values that should result in showing the hidden section
    this.showVal = showVal;
    //The values that should result in hiding the hidden section
    this.hideVal = hideVal;
    //The value that should be used if nothing is selected
    this.defaultVal = defaultVal;
}

var dropArray = new Array();
dropArray.push(new drops('homequote_crBuildings', 'buildingsOptional', 'homequote_crBuildingsSum', '500000', 'Yes', 'No', 'No'));
dropArray.push(new drops('homequote_crContents', 'contentsOptional', 'homequote_crContentsSum', '75000', 'Yes', 'No', 'No'));
dropArray.push(new drops('homequote_crBuildings500k', 'buildingsSumReq', 'homequote_crBuildingsSum', '500000', 'No', 'Yes', 'Yes'));
dropArray.push(new drops('homequote_crContents50k', 'contentsSumReq', 'homequote_crContentsSum', '75000', 'No', 'Yes', 'Yes'));

function arr(id)
{
    var result = null;
    for(var i=0; i<dropArray.length; i++)
    {
        if(dropArray[i].dropID==id){
            result = dropArray[i];
        }
    }
    return result;
}

		function bcCheck(source, args)
		{
			var crBuildings = document.getElementById("homequote_crBuildings");
			var crContents = document.getElementById("homequote_crContents");
			if(crBuildings.value!="Yes"&&crContents.value!="Yes")
			{
				args.IsValid = false;
			}
			else
			{
				args.IsValid = true;
			}
		}

addLoadEvent(homeInsuranceForm);

function checkPrivacy(source, args) { 
var cb = document.getElementById('ctl00_cntMainBody_ChkPrivacy');

if ( cb.checked == true ) { 
args.IsValid = true; 

} else {args.IsValid = false; 
}

}
