/*
Script Name: formGenMsg

Author: Marcus Kielly
Date: 23 March 2009
Company: Deckchair

Description:
This function takes an array and parses it into a sequence of
error messages which it returns to the callee

RELATIONSHIPS:
submitForm (in formHandle.js)
*/



function capitalise(str)
    {
	//extract the first letter of str
	var letter = str.substr(0,1);
	//return letter capitalised concatonated with
	//str minus it's first letter
	return letter.toUpperCase() + str.substr(1);
    }


function errMsgGen(msgArray){
    // initialise variables
    var msgParsedArray = new Array();
    var msg = "";

    for(var i=0;i<msgArray.length;i++){

        //extract input name
        //NOTE - test for presence of "_" character
        var errorInput = msgArray[i][0];
        var inputTitle=msgArray[i][0];
        var errorCase=msgArray[i][1];


        switch(errorCase){
            case "required":
            capTitle = capitalise(inputTitle);
            msg =  capTitle + " is required";
            break;

            case "alphabet":
            msg = inputTitle + " must use alphabetic characters only";
            break;

            case "numeric":
            msg = inputTitle + " must use numeric characters only";
            break;

            case "alphanum":
            msg = inputTitle + " can only use a combination of letters and numbers";
            break;

            case "email":
            msg = "You have entered an invalid email address.";
            break;

            case "phone":
            msg = "You have entered an invalid phone number. Only use numbers or spaces";
            break;

            case "checkreq":
            msg = "You need to tick the " + inputTitle + " box";
            break;

            }
        var inputMsgPair=[errorInput,msg];
        msgParsedArray.push(inputMsgPair);
        }
    return msgParsedArray;
    }









