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 regNumeric = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	var regDate = /^([0-9_]+-[0-9][0-9]+-[0-9][0-9]+)$/;
	var regPhone=/[0-9]{3}-[0-9]{3}-[0-9]{4}$/;
	var minLength = 5;
	
	//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 "_" coma,  single cots and Chars Allowed.\n';
					}
				}
				}
				else if(test.indexOf('isNumeric')!=-1)
				{
				result = trim(val);
				if(result.length==0){
				errors += '- '+nm+' is required.\n'; 
				}else{
					if(!regNumeric.test(val))
					{
						errors+='- '+nm+': Only Numeric Value is 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');

					r=val.indexOf('.JPG');
					t=val.indexOf('.GIF');
					u=val.indexOf('.JPEG');
			        if ((p<1 || p==(val.length-1)) && (s<1 || s==(val.length-1)) && (q<1 || q==(val.length-1)) && (r<1 || r==(val.length-1)) && (t<1 || t==(val.length-1)) && (u<1 || u==(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

//isAlphaNum , isUrl, isEmail, isNaN , isChar, R, isExt


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.QueryID.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;
	}
}
function valid_loginform(formname)
{
	if (MM_validateForm(formname,'admin_name','Admin Name','R','admin_pass','Password','R'))
	{
		return true;
	} else{
		return false;
	}
}
function valid_emploginform(formname)
{
	if (MM_validateForm(formname,'emp_login_id','User Name','R','emp_password','Password','R'))
	{
		return true;
	} else{
		return false;
	}
}
function valid_frmforgotpassword(formname)
{
	if (MM_validateForm(formname,'txtEmail','Email id','RisEmail'))
	{
		return true;
	}else{
		return false;
	}
}
function valid_frmeditproadmin(formname)
{
	
	if(MM_validateForm(formname,'txtpass','Password','R','txtname','Name','R','txtemail','Email Address','RisEmail','txtcontact','Contact No.','RisNumeric'))
	{
		
		return true;
	} else{
		return false;
	}
}
function valid_frmChangeSector(formname)
{
	
	if(MM_validateForm(formname,'txttitle','Title','R'))
	{
		return true;

	} else{
		return false;
	}
}
function valid_frmChangelocation(formname)
{
	
	if(MM_validateForm(formname,'loca_name','loca_name','R'))
	{
				return true;

	} else{
		return false;
	}
}
function valid_frmeditsub(formname)
{
	
	if(MM_validateForm(formname,'desc','Description','R','duration','Duration (in days)','RisNaN','price','Price','RisNaN'))
	{
		
		return true;
	} else{
		return false;
	}
}
function valid_frmaddemployer(formname)
{
	
	if(MM_validateForm(formname,'cname','Company Name','R','cperson','Contact Person','R','loginid','Login ID','R','password','Password','R','sector','sector','R','location','Location','R','email','Email Address','RisEmail','cnumber','Contact Number','R','address','Address','R','website','Website','R'))
	{
		
		return true;
	} else{
		return false;
	}
}
function valid_frmnewsletter(formname)
{
	
	if(MM_validateForm(formname,'title','Title','R','enddate','Date and Time','R','sendto','Send to','R','subject','Subject','R'))
	{
		
		return true;
	} else{
		return false;
	}
}
function valid_frmsendreply(formname)
{
	updateRTE('rte1');
	if(MM_validateForm(formname,'sline','Subject Line','R'))
	{
		
		return true;
	} else{
		return false;
	}
}
function valid_sendnewsletter(formname)
{

//	alert(document.frmAddTemplates.rte1.value);	
	//make sure hidden and iframe values are in sync before submitting form
	updateRTE('rte1'); //use this when syncing only 1 rich text editor ("rtel" is name of editor)
	//updateRTEs(); //uncomment and call this line instead if there are multiple rich text editors inside the form
	//alert("Submitted value: "+document.frmsendnews.rte1.value) ;//alert submitted value
	if(MM_validateForm(formname,'title','Newsletter Title','R','rte1','Create Newsletter','R'))
	{

		return true; //Set to false to disable form submission, for easy debugging.
		
		
	} else{
		return false;
	}
}
function valid_cms(formname)
{

//	alert(document.frmAddTemplates.rte1.value);	
	//make sure hidden and iframe values are in sync before submitting form
	updateRTE('rte1'); //use this when syncing only 1 rich text editor ("rtel" is name of editor)
	//updateRTEs(); //uncomment and call this line instead if there are multiple rich text editors inside the form
	//alert("Submitted value: "+document.frmsendnews.rte1.value) ;//alert submitted value
	if(MM_validateForm(formname,'rte1','Create Newsletter','R'))
	{

		return true; //Set to false to disable form submission, for easy debugging.
		
		
	} else{
		return false;
	}
}
function valid_postAds(formname)
{
	updateRTE('rte1'); //use this when syncing only 1 rich text editor ("rtel" is name of editor)
	if(MM_validateForm(formname,'txtcname','Company Name','R','website','Website','R','location','Location','R','sector','Sector','R'))
	{
		return true; //Set to false to disable form submission, for easy debugging.
	} else{
		return false;
	}
}
function valid_postAdddd(formname)
{
	if(MM_validateForm(formname,'txtjobtitle','Job Title','R','txtJobDesc','Job Description','R','experience_level','Experience Level','R','relevant_qualifications','Relevant Qualifications','R','year_of_exp','Year of Exp','R','sector','Sector','R','location','Location','R','salary','Salary','R','txtEdu','Education','R','txtConPerson','Contact Person','R','txtemail','Email','RisEmail','txtContNo','Contact Number','R','txtMobile','Mobile Number','R','txtadd1','Building','R','txtadd2','Road','R','txtadd3','District','R','txttown','Town','R','txtState','County','R','txtcountry','Country','R','txtPostCode','Post Code','R'))
	{
		return true; //Set to false to disable form submission, for easy debugging.
	} else{
		return false;
	}
}

function valid_addnewsletter(formname)
{
	
	//make sure hidden and iframe values are in sync before submitting form
	updateRTE('rte1'); //use this when syncing only 1 rich text editor ("rtel" is name of editor)
	//updateRTEs(); //uncomment and call this line instead if there are multiple rich text editors inside the form
	//alert("Submitted value: "+document.frmsendnews.rte1.value) ;//alert submitted value
	if(MM_validateForm(formname))
	{

		return true; //Set to false to disable form submission, for easy debugging.		
	} else{
		return false;
	}
}
function valid_contact_us(formname)
{
	
	if(MM_validateForm(formname,'First_Name','First Name','R','Last_Name','Last Name','R' ,'Phone','Phone No','RisNumeric','Email','Email','RisEmail','Message','Questions and/or Comments','R'))
	{
		return true;
	} else{
		return false;
	}
}
function valid_frmseekers_registration(formname)
{
	if(MM_validateForm(formname,'txt_username','UserName','R','txt_password','Password','R','txt_name','Name','R','txt_email','Email Address','RisEmail','txt_contact_no','Contact No','R','txt_mobile','Mobile No','R','txt_add1','Building No','R','txt_add2','Road No','R','txt_add3','District','R','txt_town','Town','R','txt_state','County','R','txt_country','Country','R','txt_post_code','Post Code','R','sector','sector','R','location','Location','R'))
	{
		return true;
	} else{
		return false;
	}
}
function valid_editseekers_registration(formname)
{
	if(MM_validateForm(formname,'txt_password','Password','R','txt_name','Name','R','txt_email','Email Address','RisEmail','txt_contact_no','Contact No','R','txt_mobile','Mobile No','R','txt_add1','Building No','R','txt_add2','Road No','R','txt_add3','District','R','txt_town','Town','R','txt_state','County','R','txt_country','Country','R','txt_post_code','Post Code','R','sector','sector','R','location','Location','R'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_registration(formname)
{
	
	if(MM_validateForm(formname,'emp_name','UserName','R','emp_pass','Password','R','epm_con_person','Company Name','R','emp_email','Email Address','RisEmail','txt_emp_con_no','Contact No','R','txt_emp_mobile','Mobile No','R','txt_emp_add1','Building No','R','txt_emp_add2','Road No','R','txt_emp_add3','District','R','txt_emp_town','Town','R','txt_emp_state','County','R','txt_emp_country','Country','R','txt_emp_postcode','Post Code','R','compname','Company Name','R','comp_website','Web site','R','sector','sector','R','location','Location','R'))
	{
		return true;
	} else{
		return false;
	}
}
function valid_edit_registration(formname)
{
	updateRTE('rte1');
	if(MM_validateForm(formname,'txt_pass','Password','R','cont_person','Contact Person','R','usemail','Email Address','RisEmail','usnumber','Contact No','R','mob_no','Mobile No','R','add1','Building No','R','add2','Road No','R','add3','District','R','town','Town','R','state','County','R','country','Country','R','post_code','Post Code','R','compname','Company Name','R','comp_website','Web site','R','sector','sector','R','location','Location','R'))
	{
		return true;
	} else{
		return false;
	}
}

function valid_need_support(formname)
{
	
	if(MM_validateForm(formname,'txt_subject','Subject','R','txt_message','Message','R'))
	{
		return true;
	} else{
		return false;
	}
}
function valid_index(formname)
{
	if(MM_validateForm(formname,'txt_keyword','Key Word','R'))
	{
	return true;

	} else{
		return false;
	}
}
function valid_job(formname)
{
	if(MM_validateForm(formname,'chk','Select Job','R'))
	{
	return true;

	} else{
		return false;
	}
}
function valid_sendmail(formname)
{
	updateRTE('rte1');
	if(MM_validateForm(formname,'txt_from','From','R'))
	{		
		return true;
	} else{
		return false;
	}
}
function valid_addtemplate(formname)
{
	updateRTE('rte1');
	if(MM_validateForm(formname,'txt_temp_name','Template Name','R','rte1','Template Message','R'))
	{		
		return true;
	} else{
		return false;
	}
}

