function SetSearchLocation(location) {

	if (location) {

		var searchDropDown = document.getElementById("select2");
		if (searchDropDown) {
			searchDropDown.value = location;

		}
	}
}


function OpenWindow(urlToOpen, width, height) {
    window.open(urlToOpen, 'Map', 'width='+ width +',height='+ height +',menubar=no,status=no,location=no,toolbar=no,resizable=yes,scrollbars=no');
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        } 
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}

/*
    Function used for onkeypress form submission
*/
function forceClick(e, elemId) {
    var elem = document.getElementById(elemId);
    var evt = (e) ? e : window.event;
    var intKey = (evt.which) ? evt.which : evt.keyCode;

    if (intKey == 13) {
        elem.click();
        return false;
    }

    return true;
}


function handleEnter(targetBtn, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    alert(keyCode);
    if (keyCode == 13) {
        document.getElementById(targetBtn).click();
        return false;
    }

    return true;
}

// Business Contact form validation
function validateBusinessForm(senderValue, emailControlID, telephoneControlID, mobileControlID) {

    var emailControl = $("#" + emailControlID);
    var telephoneControl = $("#" + telephoneControlID);
    var mobileControl = $("#" + mobileControlID);
    
    
    if (senderValue == 1) {
        // Email contact only
        emailControl.css("backgroundColor", "#FFFFFF");
        emailControl.attr("disabled", false);
        telephoneControl.css("backgroundColor", "#CCCCCC");
        telephoneControl.attr("disabled", true);
        mobileControl.css("backgroundColor", "#CCCCCC");
        mobileControl.attr("disabled", true);
    }
    else if (senderValue == 2) {
        // Telephone contact only
        emailControl.css("backgroundColor", "#CCCCCC");
        emailControl.attr("disabled", true);
        telephoneControl.css("backgroundColor", "#FFFFFF");
        telephoneControl.attr("disabled", false);
        mobileControl.css("backgroundColor", "#FFFFFF");
        mobileControl.attr("disabled", false);
    }
    else if (senderValue == 3) {
        // Either contact methods
        emailControl.css("backgroundColor", "#FFFFFF");
        emailControl.attr("disabled", false);
        telephoneControl.css("backgroundColor", "#FFFFFF");
        telephoneControl.attr("disabled", false);
        mobileControl.css("backgroundColor", "#FFFFFF");
        mobileControl.attr("disabled", false);
    }
    
    return true;
}


/* Change Location */
$(document).ready(function() {

    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        //var maskHeight = $(document).height();
        //var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        //$('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        //$('#mask').fadeIn(1000);
        //$('#mask').fadeTo("slow", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(20);

    });

    //if close button is clicked
    $('.modal .close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        //$('#mask').hide();
        $('.modal').fadeOut(20);
    });

    //if mask is clicked
    //$('#mask').click(function() {
    //    $(this).hide();
    //    $('.window').hide();
    //});

});

	
