function check_for_spaces(str)
/*-----------------------------------------------------------------------------
    check_for_spaces    : To check whether the string contains a space.

                          Returns:
                              true    No space in input string.
                              false   If there is space in input string.

    str                 : Input string which is to be checked.

    Written by          : C.V. Patil
                          (email:channa.patil@opticalfusion.net)
    Address             : C-511, Rajmahal Vilas Ext.,
                          10th Cross, Sadashiva Nagar,
                          Bangalore-560080,
                          India.
    Telephone           : (080)-23611974
    Date                : 18-Aug-2006.

    Copyright (c) 2006, Optical Fusion, Inc., USA.
    All Rights Reserved.
------------------------------------------------------------------------------*/
{
    // Holds length of the input string.
    str_len = str.length

    // Inititalize return value as true.
    return_value = true;

    // Check for space.
    for (i = 0; i <= str_len -1; i++) {

        char_val = str.substring(i, i+1);
        if (char_val == ' ') {

            // Return false if a space found.
            return_value = false;

            // Exit loop.
            break;
        }
    }

    // Return true if no space found.
    return return_value;
}    
	
	
	
	
	
function check_for_subject(str)
/*-----------------------------------------------------------------------------
    check_for_subject    : To check whether the string contains a space.

                          Returns:
                              true    No space in input string.
                              false   If there is space in input string.

    str                 : Input string which is to be checked.

    Written by          : C.V. Patil
                          (email:channa.patil@opticalfusion.net)
    Address             : C-511, Rajmahal Vilas Ext.,
                          10th Cross, Sadashiva Nagar,
                          Bangalore-560080,
                          India.
    Telephone           : (080)-23611974
    Date                : 18-Aug-2006.

    Copyright (c) 2006, Optical Fusion, Inc., USA.
    All Rights Reserved.
------------------------------------------------------------------------------*/
{
    // Holds length of the input string.
    str_len = str.length

    // Inititalize return value as true.
    return_value = true;

    // Check for space.
    for (i = 0; i <= str_len -1; i++) {

        char_val = str.substring(i, i+1);
        if (char_val.match(/^[a-zA-Z0-9.,]+$/)) {

            // Return false if a space found.
            return_value = true;

            // Exit loop.
            break;
        } else {
		
		    return_value = false;
			break;
		}
    }

    // Return true if no space found.
    return return_value;
}    
	
	
		



	
function contactvalidations()
/*-----------------------------------------------------------------------------
    contactvalidations  : To validate the input fields of HTML Form

                          Returns:
                             true    If valid input.
                             false   If not valid.

    Written by          : C.V. Patil
                          (email:channa.patil@opticalfusion.net)
    Address             : C-511, Rajmahal Vilas Ext.,
                          10th Cross, Sadashiva Nagar,
                          Bangalore-560080,
                          India.
    Telephone           : (080)-23611974
    Date                : 18-Aug-2006.

    Copyright (c) 2006, Optical Fusion, Inc., USA.
    All Rights Reserved.
------------------------------------------------------------------------------*/
{
    
	 // Get the value from the email id field.
     emailid = document.frmcontact.txtemailid.value;
	 
    // Initialize return value as true.
    return_value = true;         

	// Check whether the email id field is empty or not.
	if (emailid == "") {

		// Display the error message if empty.
		alert("Please enter the emailid");

		// Set the focus to  emailid field and exit from function.
		document.frmcontact.txtemailid.focus();
		return_value = false;
	} else {

		// Check whether the emailid contains any space.
		if (check_for_spaces(emailid) != true) {

			// Display the error message.
			alert ("Please remove the space from emailid.");

			// Set focus to the emailid field and exit from function.
			document.frmcontact.txtemailid.focus();
			return_value = false;
		} else {

			/* there must be >= 1 character before @, so we  */
			/* start looking at character position 1         */
			/* (i.e. second character)                       */
			str_emailid            = document.frmcontact.txtemailid.value;
			var i                  = 1;
			var str_emailid_length = str_emailid.length;

			/* look for @ */
			while ((i < str_emailid_length) && (str_emailid.charAt(i) != "@")) {
				i++
			}

			/* Check whetehr the @ character pressent or not. */
			if ((i >= str_emailid_length) || (str_emailid.charAt(i) != "@")) {

				/* Display the error message if @ not present. */
				alert("Please Enter correct Email ID");

				/* Set the focus to the mailid field and exit from the */
				/* function.                                           */
				document.frmcontact.txtemailid.focus();
				return_value = false;
			} else {

				/* If @ present move to check the next character. */
				i += 2;
			}

			if (return_value == true) {

				/* look for dot. */
				while ((i < str_emailid_length) && (str_emailid.charAt(i) != ".")) {
					i++
				}

				/* there must be at least one character after the dot. */
				if ((i >= str_emailid_length - 1) || (str_emailid.charAt(i) != ".")) {

					/* Display the error message if there is no         */
					/* character after the dot. Set the failure status. */
					alert("Please Enter correct Email ID");
					document.frmcontact.txtemailid.focus();
					return_value = false;
				}
			}
		}
	}
	
	if (return_value == true) {
	
	    // Get the value from the subject field.
        subject = document.frmcontact.txtsubject.value;

        // Check whether the subject field is empty or not.
        if (subject == "") {

            // Display the error message if empty.
            alert("Please enter the Subject");

            // Set the focus to  subject field and exit from function.
            document.frmcontact.txtsubject.focus();
            return_value = false;
        } else {
            
            // Check whether the subject contains any space.
            if (check_for_subject(subject) != true) {

                // Display the error message.
                alert ("Please remove the space from Subject.");

                // Set focus to the subject field and exit from function.
                document.frmcontact.txtsubject.focus();
                return_value = false;
	        }
		}
	}
	
	
	if (return_value == true) {
	
	    // Get the value from the message field.
        message = document.frmcontact.txtmessage.value;

        // Check whether the message field is empty or not.
        if (message == "") {

            // Display the error message if empty.
            alert("Please enter the Message");

            // Set the focus to  message field and exit from function.
            document.frmcontact.txtmessage.focus();
            return_value = false;
        } else {

            // Check whether the message contains any space.
            if (check_for_subject(message) != true) {

                // Display the error message.
                alert ("Please remove the space from Message.");

                // Set focus to the emailid field and exit from function.
                document.frmcontact.txtmessage.focus();
                return_value = false;
	        }
		}
	}
	
	// Return true if everything is correct.
    return return_value;
}
