///////////////////////////
// /includes/checkform.js
// functions used to check form
// David PEREZ
// Jan 2002
// Oracy Interactive
///////////////////////////

// whitespace characters

  	var whitespace = " \t\n\r";
	var check_count = 0;
	var check_count2 = 0;

// Check whether string s is empty.

function isEmpty(s)

{ return ((s == null) || (s.length == 0)) }

function isWhitespace (s)

{

     var i;

     // Is s empty?

     if (isEmpty(s)) return true;


     // Search through string's characters one by one

     // until we find a non-whitespace character.

     // When we do, return false; if we don't, return true.



     for (i = 0; i < s.length; i++)

     {

          // Check that current character isn't whitespace.

          var c = s.charAt(i);


          if (whitespace.indexOf(c) == -1) return false;

     }



     // All characters are whitespace.

     return true;

	}



// isEmail (STRING s [, BOOLEAN emptyOK]) // check if the email address is valid

function isEmail (s)

{   


	
	if (isEmpty(s)) 

       if (isEmail.arguments.length == 1) return false;

       else return (isEmail.arguments[1] == true);


   
    // is s whitespace?

    if (isWhitespace(s)) return false;


    
    // there must be >= 1 character before @, so we

    // start looking at character position 1 

    // (i.e. second character)

    var i = 1;

    var sLength = s.length;


    // look for @

    while ((i < sLength) && (s.charAt(i) != "@"))

    { i++

    }


    if ((i >= sLength) || (s.charAt(i) != "@"))

		{

			errorValid="Please enter a valid email address ie yourname@yourcompany.com";

			 
			 return false;

}

    else

		 i += 2;



    // look for .

    while ((i < sLength) && (s.charAt(i) != "."))

    { i++

    }



    // there must be at least one character after the .

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) 

{

			errorValid="Please enter a valid email address ie yourname@yourcompany.com";


			
			return false;



}

    else return true;

}  

// validate inputs in forms
function validateData(val)
{
	strerror = "";
	demo = "";
	tail = "";
	if(val==1)
	{	
			
			if(document.forms[0].v_bsf.value == "" || !parseFloat(document.forms[0].v_bsf.value))
			{
				strerror += "BSF\r"
				demo += " v_bsf"
				tail += " .focus();"
			}
			if(document.forms[0].v_tvr.value == "" || !parseFloat(document.forms[0].v_tvr.value))
			{
				strerror += "TVR\r"
				demo += " v_tvr"
				tail += " .focus();"
			}			
	}
	if(val==2)
	{	
			
			if(document.forms[0].v_previous_tvr.value == "" || !parseFloat(document.forms[0].v_previous_tvr.value))
			{
				strerror += "previous TVR\r"
				demo += " v_previous_tvr"
				tail += " .focus();"
			}		
			
	}
	if(val==3)
	{				
			
			if((document.forms[0].v_bsf.value == "" || !parseFloat(document.forms[0].v_bsf.value)))
			{				
				strerror += "BSF\r"
				demo += " v_bsf"
				tail += " .focus();"
			}							
	}	
	if(strerror != "")	 
	{
		alert("Please enter the following information:\r"+ strerror)
		var demo_array = demo.split(" ");
		var tail_array = tail.split(" ");		
		eval('document.forms[0].' + demo_array[1] + tail_array[1]);
		return false;
	}	
	else
	{
		return true;
	}
}

function isPressed(val)
{
	button = val;
}
