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-/_ :?;\n\r.,\']+)$/;
	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{
					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';
					}
				}
				}
				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 characters, underscore "_" , commas and fullstops 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('isExt')!=-1) 
				{	
					p=val.indexOf('.jpg');
					s=val.indexOf('.gif');
					q=val.indexOf('.jpeg');
			        if ((p<1 || p==(val.length-1)) && (s<1 || s==(val.length-1)) && (q<1 || q==(val.length-1)))
					{
						errors+='- '+nm+' File should be in .jpg, .jpeg, .gif format!.\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('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(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);
				if(result.length==0){
				errors += '- '+nm+' is required.\n'; 
				}
				} 
			}
			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


function delete_confirm(form)
{
	if(form.delete1.value == "Delete")
	{	
		if(confirm("are you sure?"))
		{
			form.submit;
		}
		else
		{
			return false;
		}
	}
}



function Decline_confirm(form)
{
	if(form.delete1.value == "Decline")
	{	
		if(confirm("are you sure?"))
		{
			form.submit;
		}
		else
		{
			return false;
		}
	}
}




function checkall(objForm){

	len = objForm.elements.length;

	var i=0;
	for( i=0 ; i<len ; i++) {
		if (objForm.elements[i].type=='checkbox') {
			objForm.elements[i].checked=objForm.check_all.checked;
		}
	}
}

function is_any_check_box_checked(fObj)
{
	found=false;
	for(i=0;i<fObj.length;i++)
	{
		if(fObj[i].type=="checkbox" && fObj[i].checked) 
		{
			found=true;
			break	
		}		
	}
	return found;
}
function checkCheckboxes(fObj)
{		
	////////alert("aaaaaa");
	if(is_any_check_box_checked(fObj)==true)
	{
		if(confirm("Are you sure?"))
		{
			return true;  
		}
		else 
		{
			return false;  
		}
	}
	else if(is_any_check_box_checked(fObj)==false)
	{
		alert("Select at least one check box.");		
		return false;
	}
}
function checkCheckboxes_album_delete(delete_id,user_add_auto_id,SET_ID)
{
	//alert("user_add_auto_id"+user_add_auto_id);
	//alert("SET_ID"+SET_ID);
	location.href='album-photos.php?SET_ID='+SET_ID+'&image_name[]='+user_add_auto_id+'&act=deletephoto';
}
function ValidateInfo()
{	with(window.document.ChangePasswordForm)
	{	
		
		if(oldpassword_skip.value=="")
		{	alert("Enter Old Password !"); 
			oldpassword_skip.focus();return false;
		}

		if(password.value=="")
		{	alert("Enter Password !"); 
			password.focus();return false;
		}
		if(confirmpassword_skip.value=="")
		{	alert("Enter Confirm Password !"); 
			confirmpassword_skip.focus();return false;
		}
		if(password.value!=confirmpassword_skip.value)
		{	alert("New Password doesn't match confirm password !"); 
			confirmpassword_skip.focus();return false;
		}
		
		return true;
	}
}

//CODE FOR RECURRENCE STUFF



function valid_join_user(formname)
{
	if(!MM_validateForm(formname,'user_email_id', 'Email ID', 'RisEqualuser_re_email_id:Confirm Retype E-mail', 'user_email_id', 'Email ID', 'isEmail', 'user_login_name','Username','R', 'user_password', 'Password', 'RisEqualuser_re_password:Confirm Retype Password', 'dlr_comp_name', 'Company Name', 'isAlphaNum', 'dlr_comp_abn', 'Company ABN', 'isAlphaNum', 'dlr_comp_licence', 'Licence Number', 'isAlphaNum', 'dlr_comp_website', 'Company Web Site', 'isUrl', 'dlr_description', 'Company Description', 'isAlphaNum', 'dlr_first_name', 'First Name', 'RisAlphaNum', 'dlr_last_name', 'Last Name', 'isAlphaNum', 'dlr_address', 'Address', 'RisAlphaNum', 'dlr_city', 'City', 'RisAlphaNum', 'dlr_state', 'State', 'RisAlphaNum', 'dlr_postcode', 'Postcode', 'RisAlphaNum', 'dlr_country', 'Country', 'R', 'dlr_phone', 'Phone', 'isAlphaNum', 'dlr_mobile', 'Mobile Number', 'isAlphaNum', 'dlr_fax', 'Fax Number', 'isAlphaNum'))	{
	return false;
	}
	if(document.forms[formname].Agreement.checked == false) {
		alert("You must accept the terms of Use and  Privacy Policy of Findapart.com")
		return false;
	}
	return true;
}


function valid_classifieds(formname)
{
	if(!MM_validateForm(formname,'login_name', 'Email Address', 'RisEqualuser_re_email_id:Confirm Retype E-mail', 'login_name', 'Email ID', 'isEmail', 'user_login_name','Username','R', 'user_password', 'Password', 'RisEqualuser_re_password:Confirm Retype Password', 'cl_comp_name', 'Company Name', 'isAlphaNum', 'cl_comp_licence', 'Licence Number', 'isAlphaNum', 'cl_comp_website', 'Company Web Site', 'isUrl', 'cl_first_name', 'First Name', 'RisAlphaNum', 'cl_last_name', 'Last Name', 'isAlphaNum', 'user_email_id', 'Email Id', 'RisEmail', 'cl_address', 'Address', 'RisAlphaNum', 'cl_city', 'City', 'RisAlphaNum', 'cl_state', 'State', 'RisAlphaNum', 'cl_postcode', 'Postcode', 'RisAlphaNum', 'cl_country', 'Country', 'R', 'cl_phone', 'Phone Number', 'isAlphaNum', 'cl_mobile', 'Mobile Number', 'isAlphaNum', 'cl_fax', 'Fax Number', 'isAlphaNum', 'cl_title', 'Title', 'RisAlphaNum', 'cl_description', 'Description', 'isAlphaNum', 'ccat_id', 'Category', 'R', 'csub_cat_id', 'SubCategory', 'R', 'txtFile', 'Photo', 'isExt'))	{
	return false;
	}
	if(document.forms[formname].Agreement.checked == false) {
		alert("You must accept the terms of Use and  Privacy Policy of Findapart.com")
		return false;
	}
	return true;
}


function valid_update_classifieds(formname)
{
	if(!MM_validateForm(formname,'user_email_id', 'Email ID', 'RisEmail', 'user_login_name','Username','R', 'user_password', 'Password', 'RisEqualuser_re_password:Confirm Retype Password', 'cl_comp_website', 'Company Web Site', 'isUrl', 'cl_first_name', 'First Name', 'R', 'cl_address', 'Address', 'R', 'cl_city', 'City', 'R', 'cl_state', 'State', 'R', 'cl_postcode', 'Postcode', 'R', 'cl_country', 'Country', 'R', 'cl_title', 'Title', 'R', 'ccat_id', 'Category', 'R', 'csub_cat_id', 'SubCategory', 'R', 'txtFile', 'Photo', 'isExt'))	{
	return false;
	}
	if(document.forms[formname].Agreement.checked == false) {
		alert("You must accept the terms of Use and  Privacy Policy of Findapart.com")
		return false;
	}
	return true;
}


function valid_add_contact(formname)
{
	if(MM_validateForm(formname,'your_name','Your Name','RisAlphaNum', 'email_address', 'Email Address', 'RisEmail', 'phone_no', 'Phone', 'isAlphaNum', 'contact_title', 'Subject', 'RisAlphaNum', 'contact_text', 'Leave your comments and/or feedback for Cad.com', 'isAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_tel_a_friend(formname)
{
	if(MM_validateForm(formname,'user_name','Your Name','RisAlphaNum', 'user_email_id', 'Your Email ID', 'RisEmail', 'taf_friends_name', 'Friend Name', 'isAlphaNum', 'taf_friends_email', 'Friend Email ID', 'RisEmail', 'taf_message', 'Message', 'RisAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_add_cat(formname)
{
	if(MM_validateForm(formname,'cat_name','Category Name','R'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_admin_add_page_con(formname)
{
	if(MM_validateForm(formname,'page_name','Page Name','R', 'page_description', 'Page Text', 'R'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_admin_add_faq_q_s(formname)
{
	if(MM_validateForm(formname,'faq_question','Question','R', 'faq_answer', 'Answer', 'R'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_send_newsletter(formname)
{
	if(MM_validateForm(formname,'email_from','From','RisEmail', 'subject', 'Subject', 'R', 'type', 'Select Type of News Letter', 'R'))
	{
		return true;
	} else{
		return false;
	}
}


function valid_send_email(formname)
{
	if(MM_validateForm(formname,'email_from','From','RisEmail', 'subject', 'Subject', 'R', 'html_text', 'HTML Email Text', 'R'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_admin_user_add(formname)
{
	if(MM_validateForm(formname,'admin_ful_name','Admin Name','R','admin_username','Admin Login Name','R', 'admin_password','Admin Password','R','admin_type_id','Admin Type','R','manage_site_id','Manage Site Name','R'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_class_user_add(formname)
{
	if(MM_validateForm(formname,'cl_login_name','Login Email Id','RisEmail','cl_password','Password','R'))
	{
		return true;
	} else{
		return false;
	}
}




function valid_find_part(formname)
{
	if(MM_validateForm(formname,'make', 'Manufacturer', 'R', 'model', 'Model', 'isAlphaNum', 'engines', 'Engines', 'R', 'transmissions', 'Transmissions', 'R', 'description','Description of Part','RisAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_find_part2(formname)
{
	if(MM_validateForm(formname,'sub2_id', 'Sub Category', 'R', 'transmissions', 'Transmissions', 'R', 'description','Description of Part','RisAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}



function valid_start_find_part(formname)
{
	if(MM_validateForm(formname,'categories_id', 'Categories', 'R', 'make', 'Manufacturer', 'R', 'model', 'Model', 'isAlphaNum', 'engines', 'Engines', 'R', 'transmissions', 'Transmissions', 'R', 'description','Description of Part','RisAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}


function valid_find_part_next(formname)
{
	if(MM_validateForm(formname,'user_f_l_name','First and Last Name','RisAlphaNum', 'user_email', 'User Email', 'RisEmail', 'user_city', 'City or Town', 'RisAlphaNum', 'user_state', 'State of Province', 'RisAlphaNum', 'user_zip_cobe', 'Zip Code', 'RisAlphaNum', 'user_country', 'Country', 'R', 'user_phone_no', 'Phone Number', 'isAlphaNum', 'user_b_h_phone_no', 'B/H Phone Number', 'isAlphaNum', 'user_a_h_phone_no', 'A/H Phone Number', 'isAlphaNum', 'user_mobile_no', 'Mobile', 'isAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}



function valid_manufactur(formname)
{
  if(MM_validateForm(formname,'categories_id','manufactures','subcat_name', 'Category Name', 'R', 'man_name', 'Manufactur Name', 'R'))
	{
		return true;
	} else{
		return false;
	}
}


function valid_models(formname)
{
	if(MM_validateForm(formname,'categories_id', 'Category Name', 'R', 'make_id', 'Manufactur Name', 'R', 'mod_name', 'Models Name', 'R'))
	{
		return true;
	} else{
		return false;
	}
}



function valid_search_part(formname)
{
	if(MM_validateForm(formname,'man_name', 'Manufacturer', 'R'))
	{
		return true;
	} else{
		return false;
	}
}



function valid_search_date_by(formname)
{
	if(MM_validateForm(formname,'report_start_date_day', 'From Date', 'R', 'report_start_date_month', 'From Month', 'R', 'report_start_date_year', 'From Year', 'R', 'end_start_date_day', 'To Day', 'R', 'end_start_date_month', 'To Month', 'R', 'end_start_date_year', 'To year', 'R'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_send_enq(formname)
{
	if(MM_validateForm(formname,'name', 'Name', 'RisAlphaNum', 'email', 'Email', 'RisEmail', 'web', 'Web', 'isUrl', 'bph', 'B/Ph', 'isAlphaNum', 'hph', 'Ah/Ph', 'isAlphaNum', 'mobile', 'Mobile', 'RisAlphaNum', 'fax', 'Fax', 'isAlphaNum', 'comments', 'Comments', 'isAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}




function valid_update_classf(formname)
{
	if(MM_validateForm(formname, 'cl_comp_name', 'Company Name', 'isAlphaNum', 'cl_comp_website', 'Company Web Site', 'isUrl', 'user_email_id', 'Email Address', 'RisEmail', 'cl_first_name', 'First Name', 'RisAlphaNum', 'cl_last_name', 'Last Name', 'isAlphaNum', 'cl_city', 'City', 'RisAlphaNum', 'cl_state', 'State/Province', 'RisAlphaNum', 'cl_postcode', 'Postcode/Zip code', 'RisAlphaNum', 'cl_country', 'Country', 'R', 'cl_phone', 'Phone Number', 'isAlphaNum', 'cl_mobile', 'Mobile  Number', 'isAlphaNum', 'cl_fax', 'Fax Number', 'isAlphaNum', 'cl_title', 'Title', 'RisAlphaNum', 'cl_description', 'Description', 'isAlphaNum', 'ccat_id', 'Category', 'R', 'csub_cat_id', 'SubCategory', 'R', 'cl_price', 'Price', 'isNaN', 'txtFile', 'Photo', 'isExt'))
	{
		return true;
	} else{
		return false;
	}
}
