/*
    filename : regular_exp.js
	created on : Monday, January 05, 2004
	created by : rohinee
	type : java script file 
	description : 

	it contains the regular expression to be used in data validation in java script function to check the values

	modified on : Thursday, January 15, 2004
	modified by : rohinee
	modified for : function to validate email is added

	modified on  :Monday, February 02, 2004
	modified by : rohinee
	modified for : added validtion for ratio to be entered in a:b format

	last modified : Tuesday, June 01, 2004
	modified by : rohinee
	modified for : regular expression for checking - alphabets, comma, dot, bracket, hyphen, space

	last modified	: Monday, November 21, 2005
	modified for		: to put in expression for test marks per question ( answered correctly or wrongly), it can contain numbers, OR and % and sign and space
*/

    var prdstr=/^[a-zA-Z]+((\s)|[0-9]|[a-zA-Z]|['[']|[']']|[-])*$/;
    var AlphaNumstr=/^([a-zA-Z]|[0-9])+([0-9]|[a-zA-Z])*$/;
    var AlphaNumSpacestr=/^([a-zA-Z]|[0-9])+((\s)|[0-9]|[a-zA-Z])*$/;
    var AlphaNumSpaceCommastr=/^([a-zA-Z]|[0-9])+((\s)|[0-9]|[a-zA-Z]|[','])*$/;

    var AlphaSpacestr=/^[a-zA-Z]+((\s)|[a-zA-Z])*$/;
    var AlphaSpaceBracketDotstr=/^([a-zA-Z]|['(']|[')'])+((\s)|[a-zA-Z]|['(']|[')']|['.'])*$/;
    var AlphaSpaceBracketDotSlashstr=/^([a-zA-Z]|['(']|[')'])+((\s)|[a-zA-Z]|['(']|[')']|['.']|['/'])*$/;
//var AlphaSpaceBracketDotSlashPercentstr=/^([a-zA-Z]|[0-9]|['(']|[')'])+((\s)|[0-9]|[a-zA-Z]|['(']|[')']|['.']|['/']|['%'])*$/;

	var AlphaSpaceBracketDotSlashPercentstr=/^([a-zA-Z]|[0-9]|['(']|[')'])+((\s)|[0-9]|[a-zA-Z]|['(']|[')']|['%'])*$/;

	var AlphaSpaceBracketstr=/^([a-zA-Z]|['(']|[')'])+((\s)|[a-zA-Z]|['(']|[')'])*$/;

//Monday, May 31, 2004
// added for intitute name validation changed as per NW's request

	var AlphaSpaceCommaBracketHyphen = /^([a-zA-Z]|['(']|[')'])+((\s)|[a-zA-Z]|['(']|[')']|['.']|[-]|[',']|['&'])*$/;

    var Numstr =/^[0-9]+[0-9]*$/;
    var NaturalNumstr =/^[1-9]+[0-9]*$/;
//    var NumDecimalstr =/^[0-9]+([0-9]|['.'])*$/;
	var NumDecimalstr = /^[0-9]+[\.]{0,1}([0-9])*$/;

	var Numberstr =/^[0-9]+([0-9])*$/;
//2/12/04    var Floatstr =/^([0-9])+([0-9]*|[\.]{0,1})$/;
    var Floatstr =/^([0-9])+([0-9]|['.'])*$/;
    var NumstrForRatio =/^[0-9]+[':']{1}([0-9])+$/;

// regular expression for file name - alphabets, numbers, dot (once), underscore
    var FileNameStr = /^([a-zA-Z]|[0-9])+([0-9]|[a-zA-Z_])*[\.]{1}([a-zA-Z])*$/;

// regular expression for test marking information

    var TestMarkingStr = /^([0-9])+([0-9]|[a-zA-Z_]|(\s)|['.'])*(['%']|[a-zA-Z]|[0-9]|['*'])*$/;


    function validateFileName(pstrFileNm)
	{
// parametet - file name as object
        if( !FileNameStr.test(pstrFileNm.value))
		{
		    return false;
		}
		else
		{
		    return true;
		}     

	}    // function validateFileName()

	function validateNumber(s1,strNm)
    {
		var character = String.fromCharCode(s1.keyCode);
		if(!((character>= "0" && character <= "9")))
		{
			alert("Only numerals are accepted for this field.");
			return false;
			//document.forms[0].strNm.focus();
			strNm.focus();
		}

    }    //function validateNumber(s1,strNm)

function validateNumberWithDecimal(txtNum)
{

    if(!NumDecimalstr.test(txtNum.value))
	{
//        alert("Only numbers with decimal points are accepted.");
		//txtNum.focus();
		return false;	    
	}
	else
	{
	    return true;
	}
}    // function validateNumberWithDecimal(txtNum)

// check for numbers as input
function validateNumberOnly(txtNum)
{

    if(!Numberstr.test(txtNum.value))
	{
//        alert("Only numbers with decimal points are accepted.");
		//txtNum.focus();
		return false;	    
	}
	else
	{
	    return true;
	}
}    // function validateNumberOnly(txtNum)

function validateNaturalNumber(txtNum)
{

    if(!NaturalNumstr.test(txtNum.value))
	{
       // alert("Only numbers are accepted.");
		//txtNum.focus();
		return false;	    
	}
	else
	{
	    return true;
	}


}    // function validateNumberWithDecimal(txtNum)


function validateRatio(txtNumRatio)
{
    if(!NumstrForRatio.test(txtNumRatio.value))
	{
	    alert("The ratio should be entered as a:b with a and b as numbers");
		return false;

	}
	else
	{
	    return true;
	}
}    // function validateRatio(txtNum)

function validateTextWithSpace(strTextVal)
{
    if(!AlphaSpacestr.test(strTextVal.value))
	{
	    alert("Only alphabets with space are allowed for this field.");
		//strTextVal.focus();
		//strTextVal.select();
		return false;
	}    
    else
	{
	    return true;
	}
}    //function validateTextWithSpace()


function validateTextWithSpaceBracket(strTextVal)
{
    if(!AlphaSpaceBracketstr.test(strTextVal.value))
	{
	    //alert("Only alphabets with space and/or bracker are allowed for this field.");
		//strTextVal.focus();
		//strTextVal.select();
		return false;
	}    
    else
	{
	    return true;
	}
}    //function validateTextWithSpace()


function validateTextWithSpaceBracketCommaHyphen(strTextVal)
{
	//<viren>s
	//alert(strTextVal.value);
    if(!AlphaSpaceCommaBracketHyphen.test(strTextVal.value))
	{
	    //alert("Only alphabets with space and/or bracker are allowed for this field.");
		//strTextVal.focus();
		//strTextVal.select();
		return false;
	}    
    else
	{
	    return true;
	}
}    //function validateTextWithSpace()


function validateTextWithAlphaSpaceBracketDotSlashstr(strTextVal)
{
    if(!AlphaSpaceBracketDotSlashstr.test(strTextVal.value))
	{
	    //alert("Only alphabets with space and/or bracker are allowed for this field.");
		//strTextVal.focus();
		//strTextVal.select();
		return false;
	}    
    else
	{
	    return true;
	}
}

function validateTextWithAlphaSpaceBracketDotSlashPercentstr(strTextVal)
{
	//alert(strTextVal.value);
    if(!AlphaSpaceBracketDotSlashPercentstr.test(strTextVal.value))
	{
	    alert("Only alphabets with space and/or bracker are allowed for this field.");
		//strTextVal.focus();
		//strTextVal.select();
		return false;
	}    
    else
	{
		//alert("proper value");
	    return true;
	}
}

function validateTextWithSpaceBracketDot(strTextVal)
{
    if(!AlphaSpaceBracketDotstr.test(strTextVal.value))
	{
	    //alert("Only alphabets with space and/or bracker are allowed for this field.");
		//strTextVal.focus();
		//strTextVal.select();
		return false;
	}    
    else
	{
	    return true;
	}
}    //function validateTextWithSpace()

//check for alphnumeric - not on keypress
function validateAlphaNumStr(strTextVal)
{
    if(!AlphaNumstr.test(strTextVal.value))
	{
	    //alert("Only alphabets and numbers are allowed.");
		//strTextVal.focus();
		//strTextVal.select();
		return false;
	}    
    else
	{
	    return true;
	}
}    //function validateTextWithSpace()


function validateText(s1,strText)
{
	var character = String.fromCharCode(s1.keyCode);
	if(!((character>= "A" && character <= "Z") ||(character>="a" && character <= "z")))
	{
   	    alert("Only alphabets are accepted for this field.");
		return false;
		//document.forms[0].strText.focus();
		strText.focus();
	}
    else
	{
	    return true;
	}
}    //function validateText(s1,strText)

function validateAlphanum(s1,strAlphaNum)
{
	var character = String.fromCharCode(s1.keyCode);
	if(!((character>= "A" && character <= "Z") ||(character>="a" && character <= "z") || (character>=0 && character<=9)))
	{
   	    alert("Only alphabets and numerals are accepted for this field.");
		return false;
		//document.forms[0].strAlphaNum.focus();
		//strAlphaNum.focus();
	}
    else
	{
	    return true;
	}
}    // function validateAlphanum(s1,strAlphaNum)

// function to check that @ not present in email

function validateEmail(pstrText)
{		
	var find = pstrText.value.indexOf('@',0);
	if(find >= 0)
	{
		//alert("You cannot enter character @ in the text box");
		//y.focus();
        return false;
	}
	else
	{
	    return true;

	}
}    // function valemail(x,y)

function validateAlphaNumCommaStr(strTextVal)
{
	if(!AlphaNumSpaceCommastr.test(strTextVal.value))
	{
	    //alert("Only alphabets and numbers are allowed.");
		//strTextVal.focus();
		//strTextVal.select();
		return false;
	}    
    else
	{
	    return true;
	}

}

// to validate test marks - per question for answering correct or incorrect answer
    function validateMarks(pstrMark)
	{
        if( !TestMarkingStr.test(pstrMark.value))
		{
		    return false;
		}
		else
		{
		    return true;
		}     

	}    //  function validateMarks(pstrMark)

