function openwin(popurl) {
    winpops = window.open(popurl, "mapWin", "width=460,height=328,top=1,left=100,scrollbars=no");
    winpops.focus();
}

function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i = 0; i < changeImages.arguments.length; i += 2) {
            document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
        }
    }
}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {
        Home_over = newImage("/images/Home-over.gif");
        ContactUs_Home_over = newImage("/images/ContactUs-Home_over.gif");
        About_Home_over = newImage("/images/About-Home_over.gif");
        News_Events_Home_over = newImage("/images/News%26Events-Home_over.gif");
        HomeInsurance_over = newImage("/images/HomeInsurance-over.gif");
        AutoInsurance_HomeInsurance_over = newImage("/images/AutoInsurance-HomeInsurance.gif");
        LifeInsurance_HomeInsurance_over = newImage("/images/LifeInsurance-HomeInsurance.gif");
        InsuranceTerms_HomeInsurance_over = newImage("/images/InsuranceTerms-HomeInsuranc.gif");
        MJ_21_HomeInsurance_over = newImage("/images/MJ_21-HomeInsurance_over.gif");
        ClaimsAss_HomeInsurance_over = newImage("/images/ClaimsAss-HomeInsurance_over.gif");
        Insurance_Forms_over = newImage("/images/InsuranceForms-over.gif");
        Personal_Insurance_over = newImage("/images/PersonalInsurance_over.gif");
        preloadFlag = true;
    }
}

preloadImages();

function properName(fieldVal) {
    var strInvalidChars = "0123456789+*!@#$%^&()={}<>?|";
    var i = 0;
    var strError = "";
    while (i < fieldVal.length) {
        if (strInvalidChars.indexOf(fieldVal.charAt(i)) != -1) {
            strError += fieldVal.charAt(i);
        }
        i++;
    }
    return strError;
}

function fieldLength(fieldvalue) {
    if (fieldvalue.valueOf() == 0)
        return false;
    else
        return true;
} // end of function check

function validate() {
    var personName = document.requestquotation.name;
    var emailField = document.requestquotation.email;
    var telNo = document.requestquotation.phone;
    var address = document.requestquotation.address;
    var city = document.requestquotation.city;
    var province = document.requestquotation.province;
    var postalCode = document.requestquotation.postalcode;
    var employerAssoc = document.requestquotation.employer;

    var month = document.requestquotation.expmonth;
    var day = document.requestquotation.expday;
    var year = document.requestquotation.expyear;


    var errorChecking = "";

    var name = true;
    var email = true;

    strErrors = ""; tempStr = "";

    if (fieldLength(personName.value) == 0) {
        strErrors += "Name\n";
        name = false;
    }
    if (name == true) {
        if ((errorChecking = properName(personName.value)) != "") {
            strErrors += "\nName can not contain " + errorChecking + "\n";
        }
    }
    if (fieldLength(emailField.value) == 0) {
        strErrors += "Email\n";
        email = false;
    }
    if (fieldLength(emailField.value) != 0) {
        var reg1 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
        if (!reg1.test(emailField.value)) {
            strErrors += "Please enter a valid email address\n";
        }
    }

    if (fieldLength(address.value) == 0) {
        strErrors += "Address\n";
    }

    if (fieldLength(city.value) == 0) {
        strErrors += "City\n";
    }
    if (fieldLength(province.value) == 0) {
        strErrors += "Province\n";
    }
    if (fieldLength(postalCode.value) == 0) {
        strErrors += "Postal Code\n";
    }
    if (fieldLength(telNo.value) == 0) {
        strErrors += "Telephone\n";
    }
    if (fieldLength(employerAssoc.value) == 0) {
        strErrors += "Employer Association\n";
    }
    
    if (strErrors != "") {
        tempStr = "Please fill out the following before proceeding\n\n";
        strErrors = tempStr + strErrors;
    }

    //Checking Policy Expiry date
    if (month.selectedIndex == 0 || day.selectedIndex == 0 || year.selectedIndex == 0) {
        strErrors += "\n\n ***** Policy Expiration ***** \n\n";

        if (month.selectedIndex == 0) {
            strErrors += "Please select a month\n";
        }
        if (day.selectedIndex == 0) {
            strErrors += "Please select a day\n";
        }
        if (year.selectedIndex == 0) {
            strErrors += "Please select a year\n";
        }
    }

    if (strErrors != "") {
        alert(strErrors);
        return false;
    }
    else
    { return true; }

}