function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function trimM(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
//Function to Select Records Using Checkbox
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 for Confirmation to Delete a record
function del()
{
var x=confirm("Do you want to delete the selected record?");
if(x)
  {
return true;
  }
else
   {
return false;
   }
}

// function to validate admin login
function adminLogin(form_p)
{
	
	
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(trim(form_p.userName.value)=='')
		{
		errorstr+="- Please Enter Username.\n"
		}
		if(trim(form_p.password.value)=='')
		{
		errorstr+="- Please Enter Password.\n"
		}
		
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
} 
// function to validate admin form
function adminForm(form_p)
{
	
	var emailStr=form_p.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(trim(form_p.userName.value)=='')
		{
		errorstr+="- Please Enter Username.\n"
		}
		if(trim(form_p.password.value)=='')
		{
		errorstr+="- Please Enter Password.\n"
		}
		if(trim(form_p.email.value)=='')
		{
		errorstr+="- Please Enter Email.\n"
		}
		else if(!filter.test(emailStr))
		{
		errorstr+="- Please Enter a Valid  Email.\n"
		}
		
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
} 

//Function to validate  adminForgotPassword
function adminForgotPassword(adminFrmPass)
{	
	
	if(trim(adminFrmPass.userName.value)=='')
	{
			alert("Please Enter Username.");
			adminFrmPass.userName.focus();
			return false;
	}
	else
	{
		return true;
	}
	
}

function validateForgotPassword(frmForgotPassword)
{	
	var email_str = document.frmForgotPassword.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	if(document.frmForgotPassword.email.value=='')
	{
		errorstr += "Please enter an email-id.\n";	
	}
	else if(!(filter.test(email_str)))
		{
    	 errorstr +="- Please enter valid email-id .\n";
		}   
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}
	
}

//Function to validate MailAe
function validateMailAe(frm)
{
	var email_str =frm.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	if(trim(frm.subject.value)== '')
	{
	  errorstr +=  "- Please Enter Mail Subject.\n"; 
	 }
	if(trim(frm.email.value)== '')
	{
	  errorstr +=  "- Please Enter Email.\n"; 
	}
	else if(!(filter.test(email_str)))
		{
		errorstr +=  "- Please Enter a valid Email.\n";
		}
	if(trim(frm.fromText.value)== '')
	{
	  errorstr +=  "- Please Enter text for Mail.\n"; 
	}
	if(trim(frm.content.value)== '')
	{
	  errorstr +=  "- Please Enter Content for Mail.\n"; 
	}
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
	
}


//Function to validate Faq
function validateFaq(frm)
{
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	

		if(trim(frm.faqQues.value)=='')
		 { 
		 errorstr += "- Please Enter Question.\n";
		 }
		if(trim(frm.faqAns.value)=='') 
		{ 
		errorstr += "- Please Enter Any Answer.\n";
		}		
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}

//Function to validate Category
function validateCategory(frm)
{
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	

		if(trim(frm.categoryName.value)=='')
		 { 
		 errorstr += "- Please Enter Category Name.\n";
		 }
		if(trim(frm.description.value)=='') 
		{ 
		errorstr += "- Please Enter Any Description.\n";
		}		
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}



function validateArticle(articleFrm)
{
  	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(trim(articleFrm.articleTitle.value) == '')
		{
	  	errorstr +=  "- Please Enter Article Title.\n"; 
		}
		if(trim(articleFrm.article.value) == '')
		{
	  	errorstr +=  "- Please Enter Article.\n"; 
		}
			
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}
function validateTestimonial(testimonialFrm)
{
  	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(trim(testimonialFrm.testimonialTitle.value) == '')
		{
	  	errorstr +=  "- Please Enter Testimonial Title.\n"; 
		}
		if(trim(testimonialFrm.testimonial.value) == '')
		{
	  	errorstr +=  "- Please Enter Testimonial.\n"; 
		}
		if(trim(testimonialFrm.customerName.value) == '')
		{
	  	errorstr +=  "- Please Enter Customer Name.\n"; 
		}
		if(trim(testimonialFrm.cutomerAddress.value) == '')
		{
	  	errorstr +=  "- Please Enter Customer Address.\n"; 
		}
			
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}
function validateContact(contactFrm)
{ 
	var email_str = contactFrm.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(trim(contactFrm.name.value)=='') 
		{ 
			errorstr += "- Please Enter Your Name.\n";
		}
		if(trim(contactFrm.email.value)=='') 
		{ 
			errorstr += "- Please Enter Email.\n";
		}
		else if(!filter.test(email_str))
		{
			errorstr += "- Please Enter a Valid Email.\n";
		}
		if(trim(contactFrm.contact.value)=='') 
		{ 
			errorstr += "- Please Enter Phone Number.\n";
		}
/*		else if(isNaN(contactFrm.contact.value))
		{
				errorstr += "- Please Enter Valid Phone Number.\n";
		}
*/		if(trim(contactFrm.message.value)=='') 
		{ 
			errorstr += "- Please Enter Comments.\n";
		}
		
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
}
function validateConsultant(frmConsultant)
{ 
	
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	var email_str = frmConsultant.emailaddress.value;
	var filter=/^.+@.+\..{2,3}$/;
		if(trim(frmConsultant.fname.value)=='') 
		{ 
			errorstr += "- Please Enter Your First Name.\n";
		}
		if(trim(frmConsultant.lname.value)=='') 
		{ 
			errorstr += "- Please Enter Your Second Name.\n";
		}
		if(trim(frmConsultant.phone.value)=='') 
		{ 
			errorstr += "- Please Enter Phone Number.\n";
		}
		/*
		else if(isNaN(frmConsultant.phone.value))
		{
				errorstr += "- Please Enter Valid Phone Number.\n";
		}
		if(trim(frmConsultant.altphone.value)) 
		{
			if(isNaN(frmConsultant.altphone.value))
			{
				errorstr += "- Please  Valid Alternate Phone Number.\n";
			}
		}
		*/
		if(trim(frmConsultant.emailaddress.value)=='') 
		{ 
			errorstr += "- Please Enter Email.\n";
		}
		else if(!filter.test(email_str))
		{
			errorstr += "- Please Enter a Valid Email.\n";
		}
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
}

//Function to validate Contact Us Page
function validateContactus(frm)
{
	var email_str =frm.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	if (trim(frm.address.value)=='') { errorstr += "- Please Enter Contact Address.\n";}
	if (trim(frm.phone1.value)=='') { errorstr += "- Please Enter Contact First Phone.\n";}
	if (trim(frm.website.value)=='') { errorstr += "- Please Enter Contact Website.\n";}
	if (trim(frm.email.value)=='') { errorstr += "- Please Enter Contact Email Address.\n";}
	else if(!(filter.test(email_str)))
	{
    	 errorstr +="- Please Enter Valid Email Address .\n";
	}   

	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}
//Function to validate Thank  Page
function validateThank(frm)
{
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	if (trim(frm.thankTitle.value)=='') { errorstr += "- Please Enter Thank Title.\n";}
	if (trim(frm.thanksContent.value)=='') { errorstr += "- Please Enter thank Content.\n";}
	else if(!(filter.test(email_str)))
	{
    	 errorstr +="- Please Enter Valid Email Address .\n";
	}   

	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}

