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{
					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 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('isYear')!=-1) 
				{ 
					if (val.length<4)
					{
						errors+='- '+nm+' must contain Valid Year YYYY.\n';
		
					}
					else if(isNaN(val))
					{
						errors+='- '+nm+' must contain Valid Year YYYY.\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 doc
} // Ends the "trim" function

//CODE FOR RECURRENCE STUFF

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)
{		
	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 checkchecked(objForm)
{
	if(is_any_check_box_checked(objForm.elements)){
	return true;
	}
	else{
		alert("Select at least one check box.");		
		return false;
	}
}

function checkall1(objForm){
	len = objForm.elements.length;
	//objForm = document.frm1;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (objForm.elements[i].type=='checkbox') {
			objForm.elements[i].checked=true;
		}
	}
}
function uncheckall1(objForm){
	len = objForm.elements.length;
	//objForm = document.frm1;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (objForm.elements[i].type=='checkbox') {
			objForm.elements[i].checked=false;
		}
	}
}

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;
	}
}


function validform_register(formname)
{
	//alert("sss"); 
	//exit;
	if(MM_validateForm(formname,'login_name','Login Name', 'R', 'password', 'Password', 'R', 'conf_password', 'Confirm Password', 'R','email','Email','RisEmail', 'name', 'Name', 'R','phone','Phone','R','captcha','Image Code','R')) 
	{
		if(window.document.frm1.password.value!=window.document.frm1.conf_password.value)
		{	alert("Password and Confirm Password Not Matched !"); 
			window.document.frm1.password.value='';
			window.document.frm1.conf_password.value=''
			window.document.frm1.password.focus();
			return false;
		}
		if(!window.document.frm1.terms.checked)
		{	
			alert("You have to accept the User Agreement and Privacy Policy !"); 
			return false;
		}
		if(!window.document.frm1.agecheck.checked)
		{	
			alert("You Have to atleast 18 years old. !"); 
			return false;
		}
		return true;
	} 
	else
	{
		return false;
	}
}

function validform_review(formname)
{
	if(MM_validateForm(formname,'review','Review','R','rate','Rate','R')) 
	{
		return true;
	} else{
		return false;
	}
}
function validform_invite(formname)
{
	if(MM_validateForm(formname,'email1','Email1','RisEmail','email2','Email2','isEmail','email3','Email3','isEmail','email4','Email4','isEmail','email5','Email5','isEmail')) 
	{
		return true;
	} else{
		return false;
	}
}

function validform_save_business(formname)
{
	if(MM_validateForm(formname,'bus_name','Business Name','R','rating','Rate','R')) 
	{
		return true;
	} else{
		return false;
	}
}

function validform_contact_grabber(formname)
{
	if(MM_validateForm(formname,'email','Email','RisEmail')) 
	{
		return true;
	} else{
		return false;
	}
}

function validform_save_question(formname)
{
	if(MM_validateForm(formname,'category','Category','R','subject','Subject','R','content','Content','R')) 
	{
		return true;
	} else{
		return false;
	}
}

function validform_save_answer(formname)
{
	if(MM_validateForm(formname,'content','Content','R')) 
	{
		return true;
	} else{
		return false;
	}
}

function validform_save_deal(formname)
{
	if(MM_validateForm(formname,'item_name','Title','R', 'item_price_pay', 'Price you pay', 'R', 'website', 'Website url', 'R', 'link', 'Item Link', 'R', 'item_detail', 'Item detail', 'R')) 
	{
		return true;
	} else{
		return false;
	}
}

function valid_send_deal_mail(formname)
{
	if(MM_validateForm(formname,'from','From email','RisEmail', 'to', 'To email', 'RisEmail')) 
	{
		return true;
	} else{
		return false;
	}
}