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 += '- '+nm+' is required.\n'; 
				}
				else if(result.length>=8){
				errors += '- '+nm+' must be less than or equal to 8 characters.\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+' must be same to '+mesg_string+'.\n';
					}
				}
				}
				if(test.indexOf('isLimit')!=-1)
				{
					result = trim(val);
				if(result.length==0){
				errors += '- '+nm+' is required.\n'; 
				}else if(result.length>=200)
					{
						errors+='- '+nm+' must be less than or equal to 200 characters.\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+='- '+nm+' must contain an e-mail Address.\n';
		
					}
					//else if(s<p || s==(val.length-1))
					else if(!regEmail.test(val))
					{
						errors+='- '+nm+' must contain a valid e-mail 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('isUr')!=-1) 
				{ 
					p=val.indexOf('http://www');
					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(val.charAt(10)!='.')
					{
						errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
					}
					for(t=0;t<=(val.length-1);t++)
					{
						if(val.charAt(t)==' ')
						{
							errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
							break;
						}
					}
			     }
				 else if (test.indexOf('isU')!=-1) 
				{ 
					for(t=8;t<=(val.length-1);t++)
					{
						if(val.charAt(t)=='/')
						{
							errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
							break;
						}
					}
			     }
				 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 (test.indexOf('inRange') != -1) 
					{ num = parseFloat(val);
						p=test.indexOf(':');
						min=test.substring(8,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);
				
				} 
			}
			else if (test.charAt(0) == 'R'){
				errors += '- '+nm+' is required.\n'; 
			}
		}
		if(errors !="")
		{	if(j<=0)
			{
				
				focusitem = document.forms[""+args[0]].elements[""+args[i]];
				j++;
			}	
			
		}
	} 
	
//return errors;
  
  if (errors)
  {
	alert('The following error(s) occurred:\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','lender_email','Leander Email','RisEmail','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'))
	{
	document.orderform.lender_company.disabled=false;
	document.orderform.lender_contact_name.disabled=false;
	document.orderform.lender_address.disabled=false;
	document.orderform.lender_city.disabled=false;
	document.orderform.lender_state.disabled=false;
	document.orderform.lender_zip_code.disabled=false;
	document.orderform.lender_phone.disabled=false;
	document.orderform.lender_fax.disabled=false;
	document.orderform.lender_email.disabled=false; 
	return true;
	} else
	{return false;}
}

function valid_contactform(formname)
{	if(MM_validateForm(formname,'fld_company','Company Name','R','fld_fname','Frist Name','R','fld_phone','Phone No.','R','fld_email','Email','RisEmail'))
	{
	document.orderform.fld_company.disabled=false;
	document.orderform.fld_fname.disabled=false;
	document.orderform.fld_lname.disabled=false;
	document.orderform.fld_address.disabled=false;
	document.orderform.fld_addresscity.disabled=false;
	document.orderform.fld_addressstate.disabled=false;
	document.orderform.fld_addresszip.disabled=false;
	document.orderform.fld_phone.disabled=false;
	document.orderform.fld_fax.disabled=false;
	document.orderform.fld_email.disabled=false; 

	return true;
	}else
	{return false;}
}

function valid_linkquesry(formname)
{	if(MM_validateForm(formname,'email','Email','RisEmail','name','Name','R','url','URL','R','question','Question','R'))
	{
	document.orderform.email.disabled=false;
	document.orderform.name.disabled=false;
	document.orderform.url.disabled=false;
	document.orderform.question.disabled=false;

	return true;
	}else
	{return false;}
}

function valid_registration(formname)
{	 
	if(MM_validateForm(formname,'email','Official Email','RisEmail','password','Password','RisEqualpassword1:Retype Password','link_title','Website Name','R','link_url','URL','RisUrl','link_url','URL','isU','link_desc','Description','RisLimit','category_id','Category','R'))
	{return true;}
	
	else
	{return false;}
}
function valid_reg(formname)
{	if(MM_validateForm(formname,'first','First Name','R','second','Second Name','R','Page_Rank','Page Rank','R','link_url','URL','RisUrl','link_desc','Description','R','category_id','Category','R','email','Email','RisEmail','number','Number of Pages','R','payment','Payment Mode','R','price','Price','R','Age','Website Age','R','keywords','Keyword','R','language','Language','R','external','Number of External Links','R','title','Advertisement Title','R'))
	{
	document.orderform.first.disabled=false;
	document.orderform.second.disabled=false;
	document.orderform.fld_lname.disabled=false;
	document.orderform.link_url.disabled=false;
	document.orderform.link_desc.disabled=false;
	document.orderform.category_id.disabled=false;
	document.orderform.title.disabled=false;
	document.orderform.payment.disabled=false;
	document.orderform.Page_Rank.disabled=false;
	document.orderform.number.disabled=false;
	document.orderform.email.disabled=false; 
	document.orderform.price.disabled=false; 
	document.orderform.age.disabled=false; 
	document.orderform.keywords.disabled=false; 
	document.orderform.language.disabled=false; 

	return true;
	}else
	{return false;}
}



 
function valid_new_url(formname)
{	 
	if(MM_validateForm(formname,'link_title','Website Name','R','link_url','URL','RisUrl','link_url','URL','isU','link_desc','Description','RisLimit','category_id','Category','R','host_name','Host Name','R','user_name','User Name','R','pass','Password','R'))
	{return true;}
	else
	{return false;}
}
function valid_url(formname)
{	 
	if(MM_validateForm(formname,'link_title','Website Name','R','link_url','URL','RisUrl','link_desc','Description','RisLimit','category_id','Category','R'))
	{return true;}
	
	else
	{return false;}
}
function forget_password(formname)
{
	if(MM_validateForm(formname,'email','Official Email id','RisEmail'))
	{return true;}
	else
	{return false;}
}
function valid_ftp(formname)
{
	if(MM_validateForm(formname,'host_name','Host Name','R','user_name','User Name','R','password','Password','R'))
	{return true;}
	else
	{return false;}
}
function valid_user(formname)
{
	if(MM_validateForm(formname,'email','Username','RisEmail','password','Password','R'))
	{return true;}
	else
	{return false;}
}
function valid_form2(formname)
{	 
	if(MM_validateForm(formname,'name','Name','R','email','Official Email','RisEmail','rec_link','Reciprocate Link','R','category_id','Category','R','link_title','Link Title','R','link_url','Link URL','RisUrl','link_desc','Link Description','R','password','Password','RisEqualpassword1:Confirm Password'))
	{return true;}
	
	else
	{return false;}
}
function valid_form3(formname)
{	 
	if(MM_validateForm(formname,'full_name','Full Name','R','phone','Phone','R','url','URL','R','email','Email','RisEmail','host_name','Host Name','R','user_name','User Name','R','password','Password','R'))
	{return true;}
	
	else
	{return false;}
}
function valid_admin(formname)
{
	if(MM_validateForm(formname,'txtUsername','Username','R','txtPassword','Password','R'))
	{return true;}
	else
	{return false;}
}
function valid_contact(formname)
{
	if(MM_validateForm(formname,'Description','Description','RisLimit','Companyname','Company Name','R','Fullname','Full Name','R','email','E-Mail','RisEmail','domain','Domain','R','telephoneNum','telephone Number','R','country','Country','R'))
	{return true;}
	else
	{return false;}
}
function valid_mochaqry(formname)
{
	if(MM_validateForm(formname,'web_url','Website URL','RisUrl','full_name','Full Name','R','email','Email Address','RisEmail','query','Query','R'))
	{return true;}
	else
	{return false;}
}
function valid_seoservice(formname)
{
	if(MM_validateForm(formname,'url','Website URL','RisUrl','email','Email Address','RisEmail'))
	{return true;}
	else
	{return false;}
}
function valid_seoservice1(formname)
{
	if(MM_validateForm(formname,'web_url','Website URL','RisUrl','keywords','Keywords','R','email_add','Email Address','RisEmail'))
	{return true;}
	else
	{return false;}
}
function valid_seocombo(formname)
{
	if(MM_validateForm(formname,'pagerank','desired Page Rank','R','keywords','Number of Keywords','R','designs','No. of Search Engine Designs','R','emails','Contact Number with Country Code','R','email','Email Address','RisEmail','name','Name','R'))
	{return true;}
	else
	{return false;}
}
function valid_commocha(formname)
{
	if(MM_validateForm(formname,'url','Website URL','RisUr'))
	{return true;}
	else
	{return false;}
}
function valid_seoquery(formname)
{
	if(MM_validateForm(formname,'name','Name','R','email','Email','RisEmail','budget','Budget','R','comment','Comment','R'))
	{return true;}
	else
	{return false;}
}