function LTrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;
      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}
function checkInvalidChars(curObjVal)
{
	//var checkStr = curObj.value;
	var checkStr = curObjVal;
	var checkInvalid = new Array();
	
	checkInvalid[0] = "'";
	checkInvalid[1] = "\"";
	
	var isInvalid = false;

	for (i = 0;  i < checkStr.length;  i++)
  	{
		ch = checkStr.charAt(i);

    		for (j = 0;  j < checkInvalid.length;  j++)
      		{
      			if (ch == checkInvalid[j])
      			{
      				isInvalid = true;
        			break;
        		}
      		}
  	}
	/*
	if (isInvalid)
  	{
		errorMessage = objName + " cannot contain special characters like (', \"\")";
		alert(errorMessage);
    		curObj.focus();
    		curObj.select();
		//errorStr = errorStr + "<BR>"+ objName + " cannot contain special characters like (', \"\")";
		//document.all.ERRORLIST.innerHTML = errorStr;
  	}
  	*/
  	
  	return isInvalid;
}

function validRequired(formFieldvalue)
{
	var result = true;
	
	if ( (RTrim(LTrim(formFieldvalue)) == "")  || checkInvalidChars(formFieldvalue))
	{
		result = false;
	}
	return result;
}

function clearFormErrorMessages()
{
	document.all.ERRORLIST.innerHTML = ""; 
} 

function inquiry_Action_Func()
{
	CONTACTNAME = document.all.CONTACTNAME.value;
	EMAIL = document.all.EMAIL.value;
	CONTACTPHONE  = document.all.CONTACTPHONE.value;
	TECHSKILLS = document.all.TECHSKILLS.value;
	WORKEXPERIENCE = document.all.WORKEXPERIENCE.value;
	PROJECTDETAILS = document.all.PROJECTDETAILS.value;
	if(!validateInquiryForm(CONTACTNAME,EMAIL,TECHSKILLS,WORKEXPERIENCE,PROJECTDETAILS))
	{
		return false;
	}
	else
	{
		clearFormErrorMessages();
	}

	document.all.JOBFORM.submit();		
	return true;
}
function validateInquiryForm(CONTACTNAME,EMAIL,TECHSKILLS,WORKEXPERIENCE,PROJECTDETAILS)
{
	var errorStr ="";
	var CONTACTNAME = CONTACTNAME;
	var EMAIL = EMAIL;
	var TECHSKILLS = TECHSKILLS;
	var WORKEXPERIENCE = WORKEXPERIENCE;
	var PROJECTDETAILS = PROJECTDETAILS;

	
	if (!validRequired(CONTACTNAME))
	{
		errorStr = 	errorStr + "contact name, ";
	}
	if (!validRequired(EMAIL))
	{
		errorStr = 	errorStr + "E-mail, ";
	}
	
	if (!validRequired(TECHSKILLS))
	{
		errorStr = 	errorStr + "Technical Skills, ";
	}
	
	if (!validRequired(WORKEXPERIENCE))
	{
		errorStr = 	errorStr + "Work Experience, ";
	}

	if (!validRequired(PROJECTDETAILS))
	{
		errorStr = 	errorStr + "Project Details, ";
	}


	if(errorStr!="")
	{
		errorStr ="Error : Please enter valid entries in " + errorStr;
		errorStr = errorStr.substring(0,(errorStr.length-2));
		errorStr = errorStr + ". Note : Special characters are not accepted !"
		document.all.ERRORLIST.innerHTML = errorStr;
		return false;
	}

	return true;
}


