// JavaScript Document
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_email(s1){
	if(trim(s1.name1.value)==""){
		alert("Please specify name")
		s1.name1.focus()
		return false
	}
	if(trim(s1.phone.value)==""){
		alert("Please specify phone number")
		s1.phone.focus()
		return false
	}
	if(trim(s1.email.value)==""){
		alert("Please specify your emailid")
		s1.email.focus()
		return false
	}else{
			st=s1.email.value;
			if(checkEmail(st)==false)
			{
					alert("Invalid Email Id \n"+st);
					s1.email.focus();
					return false;
			}
	}
	if(trim(s1.message.value)==""){
		alert("Please specify your message")
		s1.message.focus()
		return false
	}
}
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
	}

}
function validate_orderforms(s1){
	if(trim(s1.CLIENT.value)==""){
		alert("Please specify your name")
		s1.CLIENT.focus()
		return false
	}
	if(trim(s1.LOAN.value)==""){
		alert("Please specify loan details")
		s1.LOAN.focus()
		return false
	}
	if(trim(s1.STREET.value)==""){
		alert("Please specify street details")
		s1.STREET.focus()
		return false
	}
	
	if(trim(s1.ZIP.value)==""){
		alert("Please specify zip code")
		s1.ZIP.focus()
		return false
	}
	if(trim(s1.COUNTY.value)==""){
		alert("Please specify county details")
		s1.COUNTY.focus()
		return false
	}
	if(trim(s1.ATTORNEY.value)==""){
		alert("Please specify attorney details")
		s1.ATTORNEY.focus()
		return false
	}
	if(trim(s1.MORTGAGOR.value)==""){
		alert("Please specify mortgagor details")
		s1.MORTGAGOR.focus()
		return false
	}
	if(trim(s1.BNAME.value)==""){
		alert("Please specify listing borker details")
		s1.BNAME.focus()
		return false
	}
	
	if(trim(s1.BPHONE.value)==""){
		alert("Please specify listing borker phone")
		s1.BPHONE.focus()
		return false
	}
	
}
function validate_login(s1){

	if(trim(s1.COMPANY.value)==""){
		alert("Please specify your company name")
		s1.COMPANY.focus()
		return false
	}
	if(trim(s1.pwd.value)==""){
		alert("Please specify password")
		s1.pwd.focus()
		return false
	}
}