﻿function loadInSIFR(){

var Lucida = {src: '/ewcommon/fonts/Lucida_Sans.swf',ratios: [6,1.32,7,1.28,8,1.31,9,1.27,10,1.25,11,1.24,12,1.23,13,1.22,14,1.21,15,1.2,16,1.22,17,1.2,18,1.2,19,1.19,20,1.19,21,1.18,22,1.18,23,1.19,24,1.19,25,1.18,26,1.18,27,1.18,28,1.17,29,1.17,30,1.16,31,1.18,32,1.17,33,1.17,34,1.16,35,1.17,36,1.16,37,1.16,38,1.16,39,1.17,40,1.16,41,1.16,42,1.16,43,1.16,44,1.16,45,1.15,46,1.16,47,1.16,48,1.16,49,1.16,50,1.16,51,1.15,52,1.15,53,1.15,54,1.16,55,1.15,56,1.15,57,1.15,58,1.15,59,1.15,60,1.15,61,1.15,62,1.15,63,1.15,64,1.15,65,1.15,66,1.15,67,1.15,68,1.15,69,1.15,70,1.15,71,1.15,72,1.15,73,1.15,74,1.15,76,1.14,77,1.15,78,1.15,80,1.15,81,1.15,82,1.14,83,1.14,84,1.14,85,1.15,86,1.15,87,1.14,88,1.15,89,1.14,90,1.14,91,1.14,92,1.15,93,1.14,94,1.14,95,1.14,96,1.14,97,1.14,98,1.14,99,1.14,100,1.14,101,1.14,102,1.14,103,1.14,104,1.14,105,1.14,106,1.14,107,1.14,108,1.14,109,1.14,110,1.14,111,1.14,112,1.14,113,1.14,114,1.14,115,1.14,116,1.14,117,1.14,118,1.14,119,1.14,120,1.14,121,1.14,122,1.14,123,1.14,124,1.14,1.14]};
var Lucida_Demibold = {src: '/ewcommon/fonts/Lucida_Sans_Demibold_Roman.swf',ratios: [6,1.32,7,1.28,8,1.31,9,1.27,10,1.25,11,1.24,12,1.23,13,1.22,14,1.21,15,1.2,16,1.22,17,1.2,18,1.2,19,1.19,20,1.19,21,1.18,22,1.18,23,1.19,24,1.19,25,1.18,26,1.18,27,1.18,28,1.17,29,1.17,30,1.16,31,1.18,32,1.17,33,1.17,34,1.16,35,1.17,36,1.16,37,1.16,38,1.16,39,1.17,40,1.16,41,1.16,42,1.16,43,1.16,44,1.16,45,1.15,46,1.16,47,1.16,48,1.16,49,1.16,50,1.16,51,1.15,52,1.15,53,1.15,54,1.16,55,1.15,56,1.15,57,1.15,58,1.15,59,1.15,60,1.15,61,1.15,62,1.15,63,1.15,64,1.15,65,1.15,66,1.15,67,1.15,68,1.15,69,1.15,70,1.15,71,1.15,72,1.15,73,1.15,74,1.15,76,1.14,77,1.15,78,1.15,80,1.15,81,1.15,82,1.14,83,1.14,84,1.14,85,1.15,86,1.15,87,1.14,88,1.15,89,1.14,90,1.14,91,1.14,92,1.15,93,1.14,94,1.14,95,1.14,96,1.14,97,1.14,98,1.14,99,1.14,100,1.14,101,1.14,102,1.14,103,1.14,104,1.14,105,1.14,106,1.14,107,1.14,108,1.14,109,1.14,110,1.14,111,1.14,112,1.14,113,1.14,114,1.14,115,1.14,116,1.14,117,1.14,118,1.14,119,1.14,120,1.14,121,1.14,122,1.14,123,1.14,124,1.14,1.14]};
  sIFR.debugMode = true;
  sIFR.delayCSS  = true;
  sIFR.activate(Lucida);
  sIFR.activate(Lucida_Demibold);
  
  sIFR.replace(Lucida, {selector: '#mainLayout H2.title',wmode: 'transparent',css: ['.sIFR-root {color:#ffffff;text-align: left;font-size: 14px;padding: 0;}','a { text-decoration: none; }','a:link { color: #414141; }','a:hover { color: #555555; }'],offsetTop:8,tuneHeight:14});
}

var renewalSubmitButtonClicked = false;
$(document).ready(function() {
    $(".renewalSubmit").click(function() {
        renewalSubmitButtonClicked = true;
    });
});

function form_check_renewalForm(oForm) {

        var oElem, i, bValid, cCheckRadio, cTestName, oOptions, bSelected, nElemTypeGroup, cId, cName;
        var aRadioCheck = new Array();
        var bHasDisabledButton = false
        bValid = true;

        if (renewalSubmitButtonClicked) {


            for (i = 0; i < oForm.length; i++) {
                oElem = oForm.elements[i]

                switch (oElem.type) {
                    case "text": nElemTypeGroup = 1; break;
                    case "textarea": nElemTypeGroup = 1; break;
                    case "checkbox": nElemTypeGroup = 3; break;
                    case "radio": nElemTypeGroup = 3; break;
                    case "select-one": nElemTypeGroup = 2; break;
                    case "select-multiple": nElemTypeGroup = 2; break;
                    default: nElemTypeGroup = 0; break;
                }

                // Check if the element is required
                if (oElem.className.toLowerCase().indexOf("required") >= 0) {
                    switch (nElemTypeGroup) {

                        case 1:
                            if (form_check_value(oElem.value)) {
                                form_alert("required", oElem)
                                bValid = false
                            }
                            break;
                        case 2:
                            if (oElem.selectedIndex < 0) {
                                form_alert("required", oElem)
                                bValid = false
                            }
                            else if (form_check_value(oElem.options[oElem.selectedIndex].text)) {
                                form_alert("required", oElem)
                                bValid = false
                            }
                            break;
                        case 3:
                            // Check if the checkbox group has already been checked through
                            cCheckRadio = "," + aRadioCheck.join(",") + ","
                            cTestName = "," + oElem.name + ","
                            if (cCheckRadio.indexOf(cTestName) < 0) {

                                // Not found - let's do the checks
                                aRadioCheck.push(oElem.name)
                                oOptions = document.getElementsByName(oElem.name)
                                bSelected = false;
                                if (oOptions.length > 1) {
                                    for (i = 0; i < oOptions.length; i++) { if (oOptions[i].checked) { bSelected = true; break } }
                                }
                                if (!bSelected && oOptions.length > 1) {
                                    form_alert("required", oElem)
                                    bValid = false
                                }
                            }
                            break;
                    }
                    if (!bValid) { break }
                }
            }

            if (bValid) {
                for (i = 0; i < oForm.length; i++) {
                    oElem = oForm.elements[i]
                    if (oElem.type == 'text' || oElem.type == 'textarea') {
                        if (form_check_value(oElem.value)) { oElem.value = ''; }
                    }
                }
            }

            if (bValid) {
                // Check for Disabled Buttons
                for (i = 0; i < oForm.length; i++) {
                    oElem = oForm.elements[i];
                    if (oElem.type == "hidden" && oElem.id.indexOf("ewSubmitClone_") == 0) {
                        cId = oElem.id.replace(/ewSubmitClone_/, "")
                        cName = oElem.name.replace(/ewSubmitClone_/, "")
                        form_disable_button(oForm, cId, cName)
                        oElem.id = cId
                        oElem.name = cName
                        bHasDisabledButton = true;
                    }
                }

                if (bHasDisabledButton) {
                    for (i = 0; i < oForm.length; i++) {
                        oElem = oForm.elements[i];
                        if (oElem.type == "submit" || oElem.type == "button") { oElem.disabled = true; }
                    }
                }
            }
        }
        renewalSubmitButtonClicked = false;
        return bValid;
   
}

function form_check_quoteForm(oForm) {
	var oElem, i,bValid,cCheckRadio,cTestName,oOptions,bSelected, nElemTypeGroup, cId, cName;
	var aRadioCheck = new Array();
	var bHasDisabledButton = false
	bValid = true;
	
	
	for (i=0; i<oForm.length;i++ ) {
		oElem = oForm.elements[i]
		
		switch (oElem.type) {
			case "text": nElemTypeGroup = 1; break;
			case "textarea": nElemTypeGroup = 1; break;
			case "checkbox": nElemTypeGroup = 3; break;
			case "radio": nElemTypeGroup = 3; break;
			case "select-one": nElemTypeGroup = 2; break;
			case "select-multiple": nElemTypeGroup =2; break;
			default: nElemTypeGroup = 0; break;
		}
		
		// Check if the element is required
		if (oElem.className.toLowerCase().indexOf("required")>=0) {
			switch (nElemTypeGroup) {

				case 1:
				    if (form_check_value(oElem.value)) {
						form_alert("required",oElem)
						bValid = false
					}
					break;
				case 2: 
					if (oElem.selectedIndex < 0) {
						form_alert("required",oElem)
						bValid = false						
					}
					else if (form_check_value(oElem.options[oElem.selectedIndex].text)) {
						form_alert("required",oElem)
						bValid = false					
					}
					break;					
				case 3:
					// Check if the checkbox group has already been checked through
					cCheckRadio = "," + aRadioCheck.join(",") + ","
					cTestName = "," + oElem.name + ","
					if (cCheckRadio.indexOf(cTestName)<0) {
						
						// Not found - let's do the checks
						aRadioCheck.push(oElem.name)
						oOptions = document.getElementsByName(oElem.name)
						bSelected = false;
						if (oOptions.length>1) {
							for (i=0; i<oOptions.length;i++) { if(oOptions[i].checked) { bSelected = true; break } }
						}
						if (!bSelected && oOptions.length>1) {
							form_alert("required",oElem)
							bValid = false	
						}
					}
					break;		
			}
			if (!bValid) { break }
		}
	}
	
	if (bValid) {
	    bValid = compareEmailAddresses(oForm);
	}
	
	if (bValid) {
		for (i=0; i<oForm.length;i++ ) {
			oElem = oForm.elements[i]		
			if (oElem.type == 'text' ||  oElem.type == 'textarea') {
				if (form_check_value(oElem.value)) {oElem.value = '';}
			}
		}
	}
	
	
	if (bValid) {
		// Check for Disabled Buttons
		for (i=0; i<oForm.length;i++ ) {
			oElem = oForm.elements[i];
			if (oElem.type=="hidden" && oElem.id.indexOf("ewSubmitClone_")==0) {
				cId = oElem.id.replace(/ewSubmitClone_/,"")
				cName = oElem.name.replace(/ewSubmitClone_/,"")
				form_disable_button(oForm,cId,cName)
				oElem.id=cId
				oElem.name=cName
				bHasDisabledButton = true;
			}
		}
		
		if (bHasDisabledButton) {
			for (i=0; i<oForm.length;i++ ) {
				oElem = oForm.elements[i];
				if (oElem.type=="submit" || oElem.type=="button") {oElem.disabled=true;}
			}
		}	
	}
	
	return bValid;
}

function compareEmailAddresses(oForm){
	
	var cEmail, cEmail2; //, oElemEmail2;
	
	cEmail == "";
	cEmail2 == "";
	
	for (i=0; i<oForm.length;i++ ) {
        oElem = oForm.elements[i];
        if(oElem.id=="cContactEmail"){
            cEmail = oElem.value;
        }
        else if(oElem.id=="cContactEmail2") {
            cEmail2 = oElem.value;
            oFocusElem = oElem;
        }
	}
	
	if (cEmail == cEmail2){
	    bValid = true;
	}
	else{
        alert("Email addresses entered do not match.  Please confirm they are correct.");
	    bValid = false;
	    oFocusElem.focus();
	}
	return bValid
}