/*
 * @author Mark Rowntree
 *
 * Common Javascript methods
 *
 * Date: 03/06/2010
 *
 */
//<![CDATA[

function validateForm(){
    selValue = document.getElementById('location2')[document.getElementById('location2').selectedIndex].value;
    document.getElementById('searchForm').action = "/search/" + selValue;
    return true;
}
if(document.body){
    document.body.onload = init();
    document.body.onunload = uninit();
}

function init(){
//    if(/^\/properties/.test(window.location.pathname)){
//        addEventListener(document.getElementById);
//    }
}

function uninit(){
    if(/^\/properties/.test(window.location.pathname)){
        GUnload();
    }
}

function showImages(){
    if(document.getElementById('houseImages') && document.getElementById('map')){
        document.getElementById('houseImages').style.display = "block";
        document.getElementById('map').style.display = "none";
    }
}

function showGM(){
    if(document.getElementById('houseImages') && document.getElementById('map')){
        document.getElementById('houseImages').style.display = "none";
        document.getElementById('map').style.display = "block";
        load(s_postcode,s_propertyname,s_country);
    }
}

function isValidEmail(subject){
    var emailPattern = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
    return emailPattern.test(subject);
}

function isValidPhoneNumber(subject){
    var phoneNumberPattern = new RegExp(/^0[0-9\ ]+$/);
    return phoneNumberPattern.test(subject);
}

function validate_interest_from(){
    if(document.getElementById('interested_form')){
        if((/.+[^\W]+/.test(document.getElementById('i_name').value)) && (/.+[^\W]+/.test(document.getElementById('i_tel').value)) && (/.+[^\W]+/.test(document.getElementById('i_email').value))){
            var bAllOk = true;
            var a_message = [];
            if(!isValidEmail(document.getElementById('i_email').value)){
                bAllOk = false;
                a_message.push("The email address is not valid");
            }
            if(!isValidPhoneNumber(document.getElementById('i_tel').value)){
                bAllOk = false;
                a_message.push("The phone number is not valid");
            }
            if(bAllOk){
                return true;
            }else{
                alert("There were errors:\r\n" + a_message.join("\r\n"));
                return false;
            }
        }else{
            alert('Please fill in all fields');
            return false;
        }
    }
}

//]]>

