/* 
 "Error links should move focus to the field in error"
 dependencies jquery 1.2.6
 */

/* function to move focus to the field next to the anchor */

function MoveFocus(){
	configErrors = {
    alternateMapping: [{
        errorFieldName: "departureCity",
        replacedFieldName: "depcity"
    }, {
        errorFieldName: "arrivalCity",
        replacedFieldName: "arrcity"
    }]
}
    this.destination = $(this).attr("href").split("#anchor_");
    $(this).bind("click", function(){
        if ($("[name=" + this.destination[1]+"]").length == 0) {
            for (i = 0; i < configErrors.alternateMapping.length; i++) {
                if (this.destination[1] == configErrors.alternateMapping[i].errorFieldName) {
					this.destination[1]=configErrors.alternateMapping[i].replacedFieldName
                }
            }
        }
       location.href =  $(this).attr("href");;
        $("[name=" + this.destination[1]+"]").focus();
        return false;
    })
}

$(function(){
	/* get the collection of links in the error message */
    $(".error a").each(MoveFocus)
})

