//----------------------------- navigation hover fix for ie6 -----------------------------//
sfHover = function() {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//----------------------------- slideshow -----------------------------//
$(document).ready(function(){
    // Set up our options for the slideshow...
    var myOptions = {
        noImages: 3,
        path: "images/slideshow_images/",  // Relative path with trailing slash.
        captions: {
            1:'<h3>Interior Renovation</h3> <p>Work With Top Architects and Designers</p> <a href="interior_contactus.html" class="contactUs"></a> <a href="interior_home.html" class="learnMore"></a>',
            2:'<h3>Commercial Renovation</h3> <p>We Have Done Extensive Renovations</p> <a href="commercial_contactus.html" class="contactUs"></a> <a href="commercial_home.html" class="learnMore"></a>',
			 3:'<h3>ATEC Environmental</h3> <p>Complete Solutions, Turn-key Easy</p> <a href="environmental_contactus.html" class="contactUs"></a> <a href="environmental_home.html" class="learnMore"></a>'
        },
        links: { // Each image number must be listed here, unless no links are required at all, then links option can be ommitted.
            1:"",
            2:"",
			3:""
        },
        linksOpen:'newWindow',
        timerInterval: 6500, // 6500 = 6.5 seconds
	randomise: false // Start with random image?
    };
    $('#example_1_container').easySlides(myOptions);
})

//----------------------------- form validation -----------------------------//
function validateFormOnSubmit(theForm) {
    var reason = "";

    reason += validateEmpty(theForm.name, 'Name');
    reason += validateEmpty(theForm.phone, 'Phone');
    reason += validateEmail(theForm.email);

    if (reason != "") {
        alert(reason);
        return false;
    }
    return true;
}
function validateEmpty(fld, fldName) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.background = '#FF7F7F';
        error = fldName + " is required.\n";
    } else {
        fld.style.background = '#fff';
    }
    return error;
}
function trim(s) {
    return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    if (fld.value == "") {
        fld.style.background = '#FF7F7F';
        error = "Email is required.\n";
    } else if (!emailFilter.test(tfld)) {
        fld.style.background = '#FF7F7F';
        error = "Please enter a valid email address.\n";
    } else {
        fld.style.background = '#fff';
    }
    return error;
}
