function MM_validateForm() 
{ 	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	j=0;
	//	/^([-a-zA-Z0-9._]+@[-a-zA-Z0-9.]+(\.[-a-zA-Z0-9]+)+)$/;
	var regEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	var regBlank = /[^\s]/;
	var regAlphaNum = /^([a-zA-Z0-9_]+)$/;
	var regDate = /^([0-9_]+-[0-9][0-9]+-[0-9][0-9]+)$/;
	
	//alert (MM_validateForm.arguments[1].name);
	//alert("sss--->"+document.forms[""+args[0]].elements[""+args[0]].value);
	for (i=1; i<(args.length-2); i+=3) 
	{	
		mesg=args[i+1];
		test=args[i+2]; 
		val=document.forms[""+args[0]].elements[""+args[i]];
		    if (val) 
		{	nm=mesg; 
			
			val = val.value;
			//if ((val=val.value)!="") 
			if(regBlank.test(val))
			{
				if(test.indexOf('isEqual')!=-1)
				{
					result = trim(val);
				if(result.length==0){
				errors +='- Please enter your '+nm+ '.\n'; 
				}else{
					equal_obj_val = test.substring(8,test.indexOf(":"));
					mesg_string =test.substring((test.indexOf(":")+1));
					if(val != document.forms[""+args[0]].elements[""+equal_obj_val].value)
					{
						errors+='- '+nm+' and '+mesg_string+' are not same.\n';
					}
				}
				}
				else if(test.indexOf('isAlphaNum')!=-1)
				{
				result = trim(val);
				if(result.length==0){
				errors += '- '+nm+' is required.\n'; 
				}else{
					if(!regAlphaNum.test(val))
					{
						errors+='- '+nm+': Only Alpha Numeric and "_" Chars Allowed.\n';
					}
				}
				}
				else if (test.indexOf('isDate')!=-1) 
				{ 
					p=val.indexOf('-');
			        
					if (p != 4 )
					{
						errors+='- '+nm+' must contain Valid Date YYYY-MM-DD.\n';
		
					}
					else if(!regDate.test(val))
					{
						errors+='- '+nm+' must contain Valid Date YYYY-MM-DD.\n';
					}
			     }
				else if (test.indexOf('isEmail')!=-1) 
				{ 
					p=val.indexOf('@');
					s=val.indexOf('.');
			        if (p<1 || p==(val.length-1))
					{
						errors+='- Please enter a valid '+nm+' address.\n';
		
					}
					//else if(s<p || s==(val.length-1))
					else if(!regEmail.test(val))
					{
						errors+='-Please enter a valid '+nm+' address.\n';
					}
			     }
				else if (test.indexOf('isUrl')!=-1) 
				{ 
					p=val.indexOf('http://');
					s=val.indexOf('.');
			        if (p<0 || p==(val.length-1))
					{
						errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
		
					}
					else if(s<p || s==(val.length-1))
					{
						errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
					}
			     }else if (test.indexOf('isChar')!=-1) 
				 { 
					var first_char;
					first_char= val.charAt(0);
					if(first_char==0||first_char==1||first_char==2||first_char==3||first_char==4||first_char==5||first_char==6||first_char==7||first_char==8||first_char==9){
					 errors+='- '+nm+' must starts with  a char.\n';
					}
			     }
	   			 else if (test!='R') 
				 {
				 result = trim(val);
					if(result.length==0){
					errors +='- '+nm+' is required.\n'; 
					}
				    if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) 
					{ num = parseFloat(val);
						p=test.indexOf(':');
						min=test.substring(4,p); 
						max=test.substring(p+1);
						if (num<min || max<num) 
						errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					} 
					if (val.indexOf('-') != -1) 
					{ 
						errors+='- '+nm+' must contain a number without dashes sign.\n';
					} 
					if (val.indexOf('+') != -1) 
					{ 
						errors+='- '+nm+' must contain a number without plus sign.\n';
					}
					
				}else if (test.charAt(0)=='R')
				{
				result = trim(val);
				if(result.length==0){
				errors += '- Please enter your '+nm+' .\n'; 
				}
				} 
			}
			else if (test.charAt(0) == 'R'){
				errors += '- Please enter your '+nm+'.\n'; 
			}
		}
		if(errors !="")
		{	if(j<=0)
			{
				
				focusitem = document.forms[""+args[0]].elements[""+args[i]];
				j++;
			}	
			
		}
	} 
	
//return errors;
  
  if (errors)
  {
	alert('Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n'+errors);
	
	focusitem.focus();
	return false;
   }
   else
	return true;

//  document.MM_returnValue = (errors == '');
	
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

//CODE FOR RECURRENCE STUFF



function valid_orderform(formname)
{	if(MM_validateForm(formname,'lender_company','Lender Company','R','lender_contact_name','Lender Contact Name','R','lender_phone','Lender Phone','R','leander_email','Leander Email','R','property_number','Property Number','R','property_street_name','Property Street Name','R','property_city','Property City','R','property_state','Property State','R','property_zip_code','Property Zip Code','R','prime_seller_fname','Seller First Name','R','prime_seller_address','Seller Address','R','prime_buyer_fname','Buyer First Name','R','prime_buyer_address','Buyer Buyer Address','R','ordering_party','Ordering Party','R','applicant_company','Applicant Company or Name','R','applicant_attn','Applicant Attn','R','applicant_address','Applicant address','R','applicant_phone','Applicant Phone','R','applicant_fax','Applicant Fax','R','applicant_email','Applicant Email','RisEmail'))
	{return true;}
	else
	{return false;}
}

function valid_neuuser(formname)
{
	if(MM_validateForm(formname,'user_login','Login Name','R','user_password','user_password','R','user_email','Email ID','RisEmail'))
	{return true;}
	else
	{return false;}
}

function valid_orderform1(formname)
{
	if(MM_validateForm(formname,'name','Name','R','applicant_email','E-mail','RisEmail','comment','Comments/Questions','R'))
	{return true;}
	else
	{return false;}
}

function valid_orderform2(formname)
{
	if(MM_validateForm(formname,'fld_email','Email','RisEmail'))
	{return true;}
	else
	{return false;}
}
function valid_orderform3(formname)
{
	if(MM_validateForm(formname,'password_change','Password','RisEqualrpassword:Confirm Password'))
	{return true;}
	else
	{return false;}
}
function valid_orderform4(formname)
{
	if(MM_validateForm(formname,'remail','Email','RisEmail'))
	{return true;}
	else
	{return false;}
}
function valid_orderform5(formname)
{
	if(MM_validateForm(formname,'pin','Pin','RisNaN','second_password','Second Password','R'))
	{
		return true;
		}
	else
	{
		return false;
	}
}
function contact(formname)
{
		if(MM_validateForm(formname,'name','Name','R','email','Email','RisEqualconfirm_email:Confirm Email','email','email','RisEmail','username','Username','R','query_title','Query Title','R','query','Query','R'))
		{
			return true;
		}
	else
	{
		return false;
	}
}

  
 
function logon(formname)
{
		if(MM_validateForm(formname,'username','Username','R','password','Password','R'))
		{
			return true;
		}
	else
	{
		return false;
	}
}
function forget_pws(formname)
{
		if(MM_validateForm(formname,'email','Email','RisEmail'))
		{
			return true;
		}
	else
	{
		return false;
	}
}
function forget_pws1(formname)
{
		if(MM_validateForm(formname,'username','Username','R'))
		{
			return true;
		}
	else
	{
		return false;
	}
}
function lostpassword(formname)
{
		if(MM_validateForm(formname,'username','Username','R','pincode','4 Digit pin code','RisNaN','mother_name','Mother Name','R'))
		{
			return true;
		}
	else
	{
		return false;
	}
}
function check(formname)
{
		if(MM_validateForm(formname,'userid','Username','R','password','Password','RisEqualrpassword:Confirm Password','f_name','first name','R','l_name','last name','R'))
		{
			return true;
		}
	else
	{
		return false;
	}
}
function valid_login1(formname)
{
		if(MM_validateForm(formname,'username','Username','R','password','Password','R'))
		{
			return true;
		}
	else
	{
		return false;
	}
}
function signup(formname)
{
		if(MM_validateForm(formname,'password','Password','RisEqualrpassword:Confirm Password','email','Email','RisEqualremail:Confirm Email','email','Email','RisEmail'))
		{
			return true;
		}
	else
	{
		return false;
	}
}
function valid_login(formname)
{
if(MM_validateForm(formname,'username','User Name','RisCharinRange'))
{return true;}
else
{return false;}

}
function checkform(formname)
{
if(MM_validateForm(formname,'userid','username','R','password','password','RisEqualrpassword:rtype password','email','email address','RisEmail','f_name','first name','R','l_name','last name','R','address','street address','R','city','city','R','state','state','R','zip','zip code','R'))
{return true;}
else
{return false;}

}
function check_login(formname)
{
if(MM_validateForm(formname,'userid','username','R','password','password','R'))
{return true;}
else
{return false;}

}
function post_commercial(formname)
{
if(MM_validateForm(formname,'p_headline','property headline','R','p_description','property description','R','p_type','property type','R','p_location','town/city','R','p_price_range','price range','R','p_visibility','visibility','R','p_area','square.ft','R','p_terms','terms','R','p_lotsize','property size','R','p_broker_fees','broker fees','R','p_office_type','office type','R','p_available_month','property available month','R','p_available_year','property available year','R','p_floor_level','property floor level','R','p_year_built','property year built','R','p_deposit','property deposit','R'))
{return true;}
else
{return false;}

}
function forgetpassword(formname)
{
if(MM_validateForm(formname,'email','email','RisEmail'))
{return true;}
else
{return false;}

}

function post_residential(formname)
{
if(MM_validateForm(formname,'p_headline','property headline','R','p_description','property description','R','p_type','property type','R','p_location','town/city','R','p_price_range','price range','R','p_duration','duration','R','p_bedroom','bedroom','R','p_bathroom','bathroom','R','p_furnished','furnished','R','p_area','square.ft','R','p_terms','terms','R','p_lotsize','property size','R','p_broker_fees','broker fees','R','p_pet_policy','pet policy','R','p_available_month','property available month','R','p_available_year','property available year','R','p_floor_level','property floor level','R','p_deposit','property deposit','R'))
{return true;}
else
{return false;}

}
function roommate(formname)
{
if(MM_validateForm(formname,'state','state','R','town_id','town/city','R','heading','heading','R','aboutme','aboutme','R','i_am_looking_for','i am looking_for','R','movemonth','movemonth','R','moveday','moveday','R','moveyear','moveyear','R','gender_id','gender','R','max_rent','max rent','R','sexual_orientation_id','sexual orientation','R','pet_id','pet','R'))
{return true;}
else
{return false;}

}
function search(formname)
{
if(MM_validateForm(formname,'state','state','R'))
{return true;}
else
{return false;}
}
function c_password(formname)
{
	if(MM_validateForm(formname,'old_password','old password','R','new_password','new Password','RisEqualcnew_password:confirm password'))
	{return true;}
	else
	{return false;}
}
 function signup(formname)
{
	if(MM_validateForm(formname,'friend_email','friend email','RisEmail','heading','heading','R','fname','first name','R','lname','last name','R','email','email','RisEmail','country','country','R','username','username','R','password','Password','RisEqualcpassword:confirm password','s_question','security question','R','answer','answer','R'))
	{return true;}
	else
	{return false;}
}
  function QA(formname)
{
	if(MM_validateForm(formname,'title','username','R','description','description','R'))
	{return true;}
	else
	{return false;}
}
  function links_exc(formname)
{
	if(MM_validateForm(formname,'your_name','Your Name','R','email','Email Address','RisEmail','title_website','Title','R','des','Text','R','url','Url','RisUrl','link_location','Location of our link on your site','R','category','Category','R'))
	{return true;}
	else
	{return false;}
}
 function feedback_validate(formname)
{
	if(MM_validateForm(formname,'your_name','your name','R','email','email','RisEmail','message','message','R'))
	{return true;}
	else
	{return false;}
}
 function newscheck(formname)
{
	if(MM_validateForm(formname,'name','name','R','email','email','RisEmail'))
	{return true;}
	else
	{return false;}
}
 function payment(formname)
{
	if(MM_validateForm(formname,'name','name','R','card','card name','R'))
	{return true;}
	else
	{return false;}
}
 function change_password(formname)
{
	if(MM_validateForm(formname,'s_question','security question','R','answer','answer','R','old_password','old password','R','new_password','new Password','RisEqualc_password:confirm password'))
	{return true;}
	else
	{return false;}
}
 function check_out(formname)
{
	if(MM_validateForm(formname,'contact_person','contact person','R','email','email','RisEmail','phone','phone','R','country','country','R'))
	{return true;}
	else
	{return false;}
}
 function paypal(formname)
{
	if(MM_validateForm(formname,'contact_person','contact person','R','email','email','RisEmail','phone','phone','R','first_name','first name','R','last_name','last name','R','country','country','R'))
	{return true;}
	else
	{return false;}
}
 function forget(formname)
{
	if(MM_validateForm(formname,'username','user name','R','email','email','RisEmail'))
	{return true;}
	else
	{return false;}
}

 
