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 regString = /^([a-zA-Z][^\b]+)$/;
	var regPhone = /^([0-9][0-9][0-9]+-[0-9][0-9][0-9]+-[0-9][0-9][0-9][0-9])$/;
	var regAlphaNum = /^([a-zA-Z0-9-+/_& :;\n\r.,\']+)$/;
	//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('isString')!=-1)
				{
				result = trim(val);
				if(result.length==0){
				errors += '- '+nm+' is required.\n'; 
				}else{
					if(!regString.test(val))
					{
						errors+='- '+nm+': Only Chars Allowed.\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('isPhone')!=-1) 
				{ 
					p=val.indexOf('-');
					 if(!regPhone.test(val))
					{
						errors+='- '+nm+' must contain Valid Phone Number xxx-xxx-xxxx\n';
					}
			     }
				  else if (test.indexOf('isPassword')!=-1) 
				{ 
					p=val.indexOf('-');
					result = trim(val);
  					 if(result.length<5)
					{
						errors+='- '+nm+' must contain must contain at least 5 characters\n';
					}
			     }


				else if (test.indexOf('isExtNew')!=-1) 
				{	
					pp=val.indexOf('.pdf');
					ss=val.indexOf('.doc');

					aa=val.indexOf('.PDF');
					bb=val.indexOf('.DOC');

			        if ((pp<1 || pp==(val.length-1)) && (ss<1 || ss==(val.length-1))
					&& (aa<1 || aa==(val.length-1)) && (bb<1 || bb==(val.length-1))	
					)
					{
						errors+='- '+nm+' File should be in .doc, .pdf format!.\n';
		
					}
				}

 				else if (test.indexOf('isExt')!=-1) 
				{	
					p=val.indexOf('.jpg');
					s=val.indexOf('.gif');
					q=val.indexOf('.jpeg');
					z=val.indexOf('.png');

					a=val.indexOf('.JPG');
					b=val.indexOf('.GIF');
					c=val.indexOf('.JPEG');
					d=val.indexOf('.PNG');

			        if ((p<1 || p==(val.length-1)) && (s<1 || s==(val.length-1)) && (q<1 || q==(val.length-1)) && (z<1 || z==(val.length-1))
					&& (a<1 || a==(val.length-1)) && (b<1 || b==(val.length-1)) && (c<1 || c==(val.length-1)) && (d<1 || d==(val.length-1))
					)
					{
						errors+='- '+nm+' File should be in .jpg, .jpeg, .gif, .png 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

//CODE FOR RECURRENCE STUFF


//


function delete_confirm(form)
{
	if(form.delete1.value == "Delete")
	{	
		if(confirm("Are you sure you want to Delete? "))
		{
			form.submit;
		}
		else
		{
			return false;
		}
	}
}


function delete_confirm1(form)
{
	if(form.delete1.value == "Delete")
	{	
		if(confirm("Are you sure you want to Create Zip File? "))
		{
			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 check_box_checked(fObj){
	if(is_any_check_box_checked(fObj)==false)
	{
		alert("Select at least one check box.");		
		return false;
	}
	return true;
	}
function Delconfirm(a)
 {
  if(confirm("Are you sure you want to delete this Record?"))
   {
    window.location.href=a;
    return true;
   }
 }

function valid_user_type(usertype)
{
if(MM_validateForm(usertype, 'usertype_name','User Type','R'))
	{
		return true;
	} else{
		return false;
	}
}


function check_gallery(gallery)
{
	if(MM_validateForm(gallery, 'gallery_img_name','Gallery Name','R', 'gallery_image1','Upload Gallery Image','R'))
	{
		return true;
	} else{
		return false;
	}
}



function check_edit_gallery(gallery)
{
	if(MM_validateForm(gallery, 'gallery_img_name','Image Name','R'))
	{
		return true;
	} else{
		return false;
	}
}

function check_news(news)
{
	if(MM_validateForm(news, 'news_title','New Title','R', 'news_desc','New Description','R'))
	{
		return true;
	} else{
		return false;
	}
}

function check_logo(logo)
{
	if(MM_validateForm(logo, 'logo_name','Logo Name','R', 'logo_url', 'Url','isUrl','logo_img1','Logo Image','R'))
	{
		return true;
	} else{
		return false;
	}
}
function check_logo1(logo)
{
	if(MM_validateForm(logo, 'logo_name','Logo Name','R', 'logo_url', 'Url','isUrl'))
	{
		return true;
	} else{
		return false;
	}
}

function validation_Paswd(newuser)
{
	var pwd=document.newuser.user_pwd.value;
	var re_pwd=document.newuser.re_user_pwd.value;
if(pwd!=re_pwd)
{
	alert("Error:Varify Password does not match!");
	document.newuser.re_user_pwd.value='';
	document.newuser.user_pwd.focus();
	}
}



var http_request = false;
var tempTxt;
function makeRequest(url,txt,strVariables) 
	{
	
	http_request = false;
	tempTxt=txt;
	if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType)
			{
			http_request.overrideMimeType('text/xml');
			// See note below about this line
			}
		}
	else if (window.ActiveXObject)
		{ // IE
		try
			{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch (e)
			{
			try
				{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch (e)
				{
				}
			}
		}
	if (!http_request)
		{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
		}
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	http_request.send(strVariables);
	http_request.onreadystatechange = alertContents;
	}

function alertContents()
	{
	
	if (http_request.readyState == 4)
		{
		if (http_request.status == 200)
			{		
				var resul= http_request.responseText;
				document.getElementById(tempTxt).innerHTML=http_request.responseText;
				if(tempTxt=="img")
				{
					var resul= http_request.responseText;
					
					document.getElementById('img').innerHTML=resul;
					
					//document.getElementById('shippingArea').innerHTML=b;
					
					if(resul=='$0.00')
					{
						document.getElementById('img').innerHTML='121';
						//document.getElementById('display').style.display = 'none';
					}
				}
			}
			else
				{
				alert('There was a problem with the request.');
				}
		   }
		else if (http_request.readyState == 1 )
			{
			
			document.getElementById(tempTxt).innerHTML = "sorry";
			
			}
		}


	function showimage(path)
   {
	 window.open("image.show.php?path="+path,"","status=1,width=500,height=500,scrollbars=1,resizable=1,menubar=1"); 
	 }
	
	function check_contactus(contactus)
{
	if(MM_validateForm(contactus, 'name','Name','R', 'contact_phone','Phone Number','RisNan', 'contact_email_id','Email ID','RisEmail', 'query', 'Query', 'R'))
	{
		return true;
	} else{
		return false;
	}
}
	


	

	
var http_request = false;
var tempTxt;
function makeRequest(url,txt,strVariables) 
	{
	
	http_request = false;
	tempTxt=txt;
	if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType)
			{
			http_request.overrideMimeType('text/xml');
			// See note below about this line
			}
		}
	else if (window.ActiveXObject)
		{ // IE
		try
			{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch (e)
			{
			try
				{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch (e)
				{
				}
			}
		}
	if (!http_request)
		{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
		}
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	http_request.send(strVariables);
	http_request.onreadystatechange = alertContents;
	}

function alertContents()
	{
	
	if (http_request.readyState == 4)
		{
		if (http_request.status == 200)
			{		
				var resul= http_request.responseText;
				document.getElementById(tempTxt).innerHTML=http_request.responseText;
				if(tempTxt=="img")
				{
					var resul= http_request.responseText;
					
					document.getElementById('img').innerHTML=resul;
					
					//document.getElementById('shippingArea').innerHTML=b;
					
					if(resul=='$0.00')
					{
						document.getElementById('img').innerHTML='121';
						//document.getElementById('display').style.display = 'none';
					}
				}
			}
			else
				{
				alert('There was a problem with the request.');
				}
		   }
		else if (http_request.readyState == 1 )
			{
			
			document.getElementById(tempTxt).innerHTML = "sorry";
			
			}
		}



function checkCheckboxes1(fObj)
{		
	if(is_any_check_box_checked(fObj)!=true)
	{
		if(confirm("Are you sure?"))
		{
			return true;  
		}
		else 
		{
			return false;  
		}
	}
}

function add_edit_prod_cat(formname)
{
	if(MM_validateForm(formname,  'cat_name','Category Name','RisAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}



function add_edit_prod_sub_cat(formname)
{
	if(MM_validateForm(formname,  'cat_parent_id','Category Name','RisAlphaNum', 'cat_name','Sub Category Name','RisAlphaNum', 'txtFile','Category Image','isExt'))
	{
		return true;
	} else{
		return false;
	}
}



function add_edit_prod_sub_sub_cat(formname)
{
	if(MM_validateForm(formname,  'cat_parent_id','Category Name','RisAlphaNum', 'sub_cat_parent_id','Sub Category Name','RisAlphaNum', 'cat_name','Sub Sub Category Name','RisAlphaNum', 'txtFile','Category Image','isExt'))
	{
		return true;
	} else{
		return false;
	}
}

function add_edit_manufacture(formname)
{
	if(MM_validateForm(formname,  'man_name','Manufacture Name','RisAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}

function valide_addedit_user(formname)
{
	if(MM_validateForm(formname,  'user_id','E-Mail ID','RisEmail', 'user_pwd', 'Password', 'RisEqualre_user_pwd:Verify Password', 'user_f_name','First Name','RisAlphaNum', 'user_l_name','Last Name','RisAlphaNum', 'user_country_id','Country','RisAlphaNum', 'user_state_id','State','RisAlphaNum', 'user_city','City','RisAlphaNum', 'user_post_code','Postal Code','RisAlphaNum', 'user_photo','Add Photo','isExt'))
	{
		return true;
	} else{
		return false;
	}
}



function addedit_vendor(formname)
{
	if(MM_validateForm(formname,  'vendor_id','E-Mail ID','RisEmail', 'vendor_pwd', 'Password', 'RisEqualre_vendor_pwd:Verify Password', 'vendor_f_name','First Name','RisAlphaNum', 'vendor_l_name','Last Name','RisAlphaNum', 'vendor_country_id','Country','RisAlphaNum', 'vendor_state_id','State','RisAlphaNum', 'vendor_city','City','RisAlphaNum', 'vendor_post_code','Postal Code','RisAlphaNum', 'vendor_photo','Add Photo','isExt'))
	{
		return true;
	} else{
		return false;
	}
}




/*

function addedit_user(newuser)
{
	if(MM_validateForm(newuser, 'user_id','User ID','R','user_name','User Name','R','user_pwd','Passwd','R','re_user_pwd','Re-Type-Passwd','R', 'user_type_auto_id','User Type','R','user_emailadd','Email ID','RisEmail'))
	{
		return true;
	} else{
		return false;
	}
}
*/

function check_banner1(formname) {
	 
		if(MM_validateForm(formname, 'banner_title','Banner Title','R', 'banner_url', 'Banner URL', 'isUrl')){
			return true;
		} else {
			return false;
		}
}
function check_banner(formname) {
	 
		if(MM_validateForm(formname, 'banner_title','Banner Title','R','banner_img1','Banner Image','isExt', 'banner_url', 'Banner URL', 'isUrl')){
			return true;
		} else {
			return false;
		}
}


function add_edit_prod(formname) {
	 
		if(MM_validateForm(formname, 'cat_parent_id','Category Name','R', 'sub_cat_parent_id','Sub Category Name','R', 'cat_level','Sub Sub Category Name','R', 'product_name','Product Name','RisAlphaNum', 'txtFile', 'Product Image', 'isExt')){
			return true;
		} else {
			return false;
		}
}




/*
function valide_checkoutorder(formname) {
	 
		if(MM_validateForm(formname, 'user_f_name','Sender First Name','RisAlphaNum', 'user_l_name','Sender Last Name','RisAlphaNum', 'user_address1', 'Sender Address1 ','RisAlphaNum', 'user_country_id','Sender Country','RisAlphaNum', 'user_state_id','Sender State','RisAlphaNum', 'user_city','Sender City','RisAlphaNum', 'user_post_code','Sender Postal Code','RisAlphaNum', 'con_phone','Sender Phone Country Code','R', 'st_phone','Sender Phone Std Code','R', 'user_phoneno','Sender Phone No','R', 'con_mobile','Sender Mobile Country Code','R', 'user_mobileno','Sender Mobile No','R', 'sender_user_email_id','Sender Email ID','RisEmail', 'res_user_f_name','Recipient First Name','RisAlphaNum', 'res_user_l_name','Recipient Last Name','RisAlphaNum', 'res_user_address1', 'Recipient Address1','RisAlphaNum', 'res_user_address2', 'Recipient Address2','RisAlphaNum', 'res_user_address3', 'Recipient Address3','RisAlphaNum', 'res_user_country_id','Recipient Country','RisAlphaNum', 'res_user_state_id','Recipient State','RisAlphaNum', 'res_user_city','Recipient City','RisAlphaNum', 'res_user_post_code','Recipient Postal Code','RisAlphaNum', 'res_con_phone','Recipient Phone Country Code','R', 'res_st_phone','Recipient Phone Std Code','R', 'res_user_phoneno','Recipient Phone No','R', 'res_con_mobile','Recipient Mobile Country Code','R', 'res_user_mobileno','Recipient Mobile No','R', 'res_user_email_id','Recipient Email ID','RisEmail')){
			return true;
		} else {
			return false;
		}
}
*/





function valide_checkoutorder(formname)
{
	if(!MM_validateForm(formname, 'user_f_name','Sender First Name','RisAlphaNum', 'user_l_name','Sender Last Name','RisAlphaNum', 'user_address1', 'Sender Address1 ','RisAlphaNum', 'user_country_id','Sender Country','RisAlphaNum', 'user_state_id','Sender State','RisAlphaNum', 'user_city','Sender City','RisAlphaNum', 'user_post_code','Sender Postal Code','RisAlphaNum', 'con_phone','Sender Phone Country Code','R', 'st_phone','Sender Phone Std Code','R', 'user_phoneno','Sender Phone No','R', 'con_mobile','Sender Mobile Country Code','R', 'user_mobileno','Sender Mobile No','R', 'sender_user_email_id','Sender Email ID','RisEmail', 'res_user_f_name','Recipient First Name','RisAlphaNum', 'res_user_l_name','Recipient Last Name','RisAlphaNum', 'res_user_address1', 'Recipient Address1','RisAlphaNum', 'res_user_address2', 'Recipient Address2','RisAlphaNum', 'res_user_address3', 'Recipient Address3','RisAlphaNum', 'res_user_country_id','Recipient Country','RisAlphaNum', 'res_user_state_id','Recipient State','RisAlphaNum', 'res_user_city','Recipient City','RisAlphaNum', 'res_user_post_code','Recipient Postal Code','RisAlphaNum', 'res_con_phone','Recipient Phone Country Code','R', 'res_st_phone','Recipient Phone Std Code','R', 'res_user_phoneno','Recipient Phone No','R', 'res_con_mobile','Recipient Mobile Country Code','R', 'res_user_mobileno','Recipient Mobile No','R', 'res_user_email_id','Recipient Email ID','RisEmail')){
	return false;
	}
	if(document.forms[formname].Agreement.checked == false) {
		alert("You must accept the acknowledge that I have read and agree to the freeclassifieds24x7.com agreement")
		return false;
	}
	return true;
}




function valid_query(formname)
{

	if(MM_validateForm(formname, 'textfield5','Name','RisAlphaNum', 'textfield22','Email ID','RisEmail', 'textfield32','Phone','RisNaN', 'textarea2','Address','R', 'textarea','Description','R'))
	{
		return true;
	} else{
		return false;
	}
}





function valid_add_red_post(formname)
{

	if(MM_validateForm(formname, 'product_name','Ad Title','RisAlphaNum','user_id','E-Mail ID','RisEmail', 'user_pwd', 'Password', 'isEqualre_user_pwd:Verify Password', 'l_name','Contact Name','RisAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}



function valid_add_post(formname)
{

	if(MM_validateForm(formname, 'product_name','Ad Title','RisAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}



function valid_search_prod(formname)
{

	if(MM_validateForm(formname, 'keyword','KeyWord','isAlphaNum'))
	{
		return true;
	} else{
		return false;
	}
}
