
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 trim(str)
{
   return RTrim(LTrim(str));
}

function checkEmail(str)
	{
		if((str.indexOf("@")==-1) || (str.indexOf(".")==-1))
		{
			fstr="Please Enter @ or .";
			return false;
		}
		else
		{
		if((str.indexOf("@") == 0) || (str.indexOf(".") == 0))
		{
			fstr="@ or . Cannot Be first";
			return false;
		}
		if((str.indexOf("@") == (str.length-1)) || (str.indexOf(".") == (str.length-1)))
		{
			fstr="@ or . Cannot Be Last";
			return false;
		}

		if(str.indexOf("@") > str.indexOf("."))
		{
			fstr="@ Should be After .";
			return false;
		}
		if((str.indexOf("@")+1) == str.indexOf("."))
		{
			fstr="@. IS Invalid Email";
			return false;
		}
		}
		var cp=0;					
		for(i=0;i<str.length;i++)
		{
			c=str.charAt(i);
			b=(((c >= "0") && (c <= "9")) || ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == ".") || (c == "@") || (c == "_")|| (c == "-"))
			if(c=="@") cp++;
			if(b==true)
			   continue;
			else
			{
				fstr="Cannot include "+c;
				return false;
			}
		}
		if(cp==2)
		{
			fstr="@ cannnot be repetaed";
			return false;

		}
		return true;
	}

function validate(s1){
	if(trim(s1.yname.value)==""){
		alert("Please enter your name")
		s1.yname.focus()
		return false
	}
	if(trim(s1.cname.value)==""){
		alert("Please enter your company name")
		s1.cname.focus()
		return false
	}
	if(trim(s1.emailid.value)==""){
		alert("Please enter your emailid")
		s1.emailid.focus()
		return false
	}else{
			st=s1.emailid.value;
			if(checkEmail(st)==false)
			{
					alert("Invalid Email Id \n"+st);
					s1.emailid.focus();
					return false;
			}
	}
	if(trim(s1.message.value)==""){
		alert("Please enter your message")
		s1.message.focus()
		return false
	}
	if(trim(s1.select.value)==""){
		alert("Please enter your message")
		s1.select.focus()
		return false
	}
	if(trim(s1.userdigit.value)==""){
		alert("Please enter your security digit")
		s1.userdigit.focus()
		return false
	}
	stext=s1.userdigit.value
	if(stext.length<5){
		alert("Please enter your security digit")
		s1.userdigit.focus()
		return false
	}
	if (IsNumeric(stext) == false) 
      {
      alert("Please check - non numeric value!");
	  return false
      }

}
function validate_this_contact(s){

	
	if(trim(s.yname.value)==""){
		alert("Please enter your name")
		s.yname.focus()
		return false
	}
	if(trim(s.emailid.value)==""){
		alert("Please enter your email ")
		s.emailid.focus()
		return false
	}else{
			st=s.emailid.value;
			if(checkEmail(st)==false)
			{
					alert("Invalid Email Id \n"+st);
					s.emailid.focus();
					return false;
			}
	}
	if(trim(s.country.value)==""){
		alert("Please enter country where you are located")
		s.country.focus()
		return false
	}
	flag=false
	str="";
	for(i=0;i<s.service.length;i++){
		if(s.service[i].checked){
			flag=true
			str=str + s.service[i].value + " , "
		}
	}	
	if(flag==false){
		alert("Please select service you are looking for ")
		return false
	}else{
		s.s_cat.value=str
	}
	if(trim(s.message.value)==""){
		alert("Please specify about requirement")
		s.message.focus()
		return false
	}
	if(trim(s.select.value)==""){
		alert("Please select how did you know about us")
		s.select.focus()
		return false
	}
	if(trim(s.userdigit.value)==""){
		alert("Please enter your security digit")
		s.userdigit.focus()
		return false
	}
	stext=s.userdigit.value
	if(stext.length<5){
		alert("Please enter your security digit")
		s.userdigit.focus()
		return false
	}
	if (IsNumeric(stext) == false) 
      {
      alert("Please check - non numeric value!");
	  return false
      }
	
}
function validate_this_feed(s){

	if(trim(s.yname.value)==""){
		alert("Please enter your name")
		s.yname.focus()
		return false
	}
		if(trim(s.emailid.value)==""){
		alert("Please enter your email ")
		s.emailid.focus()
		return false
	}else{
			st=s.emailid.value;
			if(checkEmail(st)==false)
			{
					alert("Invalid Email Id \n"+st);
					s.emailid.focus();
					return false;
			}
	}
	if(trim(s.country.value)==""){
		alert("Please enter country where you are located")
		s.country.focus()
		return false
	}
	if(trim(s.p_name.value)==""){
		alert("Please enter project name")
		s.p_name.focus()
		return false
	}
	if((trim(s.projtype.value)=="")&&(trim(s.project_other.value)=="")){
		alert("Please specify the project category")
		s.project_other.focus()
		return false
	}
	if(trim(s.p_name.value)==""){
		alert("Please enter project name")
		s.p_name.focus()
		return false
	}
	flag=false
	str="";
	for(i=0;i<s.rating.length;i++){
		if(s.rating[i].checked){
			flag=true
			str=str + s.rating[i].value 
		}
	}	
	if(flag==false){
		alert("Please give a rating ")
		return false
	}else{
		s.s_cat.value=str
	}
	if(trim(s.message.value)==""){
		alert("Please describe your feedback")
		s.message.focus()
		return false
	}
	if((s.again[0].checked==false)&&(s.again[1].checked==false)){
		alert("Please specify whether you will choose vision studio for your future work")
		//s.project_other.focus()
		return false
	}
	if(trim(s.userdigit.value)==""){
		alert("Please enter your security digit")
		s.userdigit.focus()
		return false
	}
	stext=s.userdigit.value
	if(stext.length<5){
		alert("Please enter your security digit")
		s.userdigit.focus()
		return false
	}
	if (IsNumeric(stext) == false) 
      {
      alert("Please check - non numeric value!");
	  return false
      }
	
}
function validate_this_bug(s){
	if(trim(s.emailid.value)==""){
		alert("Please enter your email ")
		s.emailid.focus()
		return false
	}else{
			st=s.emailid.value;
			if(checkEmail(st)==false)
			{
					alert("Invalid Email Id \n"+st);
					s.emailid.focus();
					return false;
			}
	}
	if(trim(s.url.value)==""){
		alert("Please enter error page URL page url")
		s.country.focus()
		return false
	}
	if(trim(s.message.value)==""){
		alert("Please explian when the bug occur")
		s.message.focus()
		return false
	}
	
	if(trim(s.userdigit.value)==""){
		alert("Please enter your security digit")
		s.userdigit.focus()
		return false
	}
	stext=s.userdigit.value
	if(stext.length<5){
		alert("Please enter your security digit")
		s.userdigit.focus()
		return false
	}
	if (IsNumeric(stext) == false) 
      {
      alert("Please check - non numeric value!");
	  return false
      }
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

