/*
  This file contains all the javascript functions
   used for the current pages in the website.
*/

/*
  This function removes the blank spaces from the begining and end
  of the string str.
*/
function trim(str)
{
	var i;
	var start, end;
	var strTemp;
	strTemp = "";

	for(i=0;i<str.length;i++)
	{
		if( (str.charAt(i) == "" || str.charAt(i) == " ") )
		{}
		else
		{
			start = i;
			break;
		}
	}

	for(i=str.length-1;i >= 0;i--)
	{
		if( str.charAt(i) == "" || str.charAt(i) == " " )
		{}
		else
		{
			end = i;
			break;
		}
	}
	var spaceCount = 0;
	for(i=start;i<=end; i++)
	{
		if(i+1 < end)
		{
			if(str.charAt(i) == " " && str.charAt(i+1) == " ")
			{ }
			else
			{
				strTemp = strTemp + str.charAt(i);
			}
		}
		else
		{
			strTemp = strTemp + str.charAt(i);
		}
	}
	return strTemp;
 }

/*
  This function checks for the user level validations of the
  contact us form. This function returns true for valid input
  else returns false with a valid pop up message box.

*/
function chkContactus(form, cmsg)
{
	var name = trim(form.realname.value);
	var email = trim(form.email.value);
	var subject = trim(form.subject.value);
	var comment = trim(form.comments.value);

	var msg = '';

	if(name == '')
		msg = 'Please enter ' + form.realname.title;
	else if(email == '')
		msg = 'Please enter ' + form.email.title;
	else if(subject == '')
		msg = 'Please enter ' + form.subject.title;
	else if(comment == '' || comment == cmsg)
		msg = 'Please enter ' + form.comments.title;

	if(msg == '')
		return true;
	else{
		alert(msg);
		return false;
	}
}

