//============ index page ==========================
function validate_login(th)
{ 
  if(th.username.value=='' || th.username.value==' ')
  { alert("Enter Username..");
    th.username.focus();
	return false;
  }
  else if(th.username.value.length<5)
  { alert("Username must be of min 5 characters..");
    th.username.focus();
	return false;
  }
  else if(th.password.value=='' || th.password.value==' ')
  { alert("Enter Password..");
    th.password.focus();
	return false;
  }
  else if(th.password.value.length<7)
  { alert("Password must be of min 7 characters..");
    th.password.focus();
	return false;
  }
}  

//=============== add email =====================
function validate_email(th)
{
  var regex=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;	
  var test_email=regex.test(th.email.value);
  if(!(th.Upload.value=='' || th.Upload.value==' '))
  { var a=th.Upload.value;
    var p=a.lastIndexOf('.');
    var ext=a.substr(p+1);
	if(ext.toLowerCase()!="csv")
	{ alert("Invalid file !! \nOnly files with '.csv' extension allowed");
	  th.Upload.focus();
	  return false;
	}
  }
  else if(!test_email)
  { alert("Please enter a valid email address..");
    th.email.focus();
	return false;
  }
} 

//============ change password page ==========================
function validate_pass(th)
{
  if(th.value=='' || th.value==' ')
  { alert("Enter Old Password..");
    th.focus();
	return false;
  }
  else if(th.value=='' || th.value==' ')
  { alert("Enter New Password..");
    th.focus();
	return false;
  }
  else if(th.value=='' || th.value==' ')
  { alert("Enter Confirm New Password..");
    th.focus();
	return false;
  }
  else if(th.value != th.value)
  { alert("Password not confirmed..");
    th.select();
	return false;
  }
}  

//============ edit info ===============//
function validate_edit_info(th)
{
	/*//alert("chk1");//	alert("chk2");*/
 var regex=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;	
 var test_email1=regex.test(th.email1.value);
 var test_email2=regex.test(th.email2.value);
 var test_email3=regex.test(th.email3.value);
 if(th.logo.value)
 {var a=th.logo.value;
  var p=a.lastIndexOf('.');
  var e=a.substr(p+1);
  var ext=e.toLowerCase();
  if(!(ext=="png" || ext=="gif" || ext=="jpg" || ext=="jpeg"))
  {alert("Invalid file type !! \nOnly '.jpg', '.png', ',gif' files allowed");
   th.logo.focus();
   return false;
  }
 }
 else if(th.image_path.value)
 {var a=th.image_path.value;
  var p=a.lastIndexOf('.');
  var e=a.substr(p+1);
  var ext=e.toLowerCase();
  if(!(ext=="png" || ext=="gif" || ext=="jpg" || ext=="jpeg"))
  {alert("Invalid file type !! \nOnly '.jpg', '.png', ',gif' files allowed");
   th.image_path.focus();
   return false;
  }
 }
 else if(th.image1.value)
 {var a=th.image1.value;
  var p=a.lastIndexOf('.');
  var e=a.substr(p+1);
  var ext=e.toLowerCase();
  if(!(ext=="png" || ext=="gif" || ext=="jpg" || ext=="jpeg"))
  {alert("Invalid file type !! \nOnly '.jpg', '.png', ',gif' files allowed");
   th.image1.focus();
   return false;
  }
 }
 else if(th.image2.value)
 {var a=th.image2.value;
  var p=a.lastIndexOf('.');
  var e=a.substr(p+1);
  var ext=e.toLowerCase();
  if(!(ext=="png" || ext=="gif" || ext=="jpg" || ext=="jpeg"))
  {alert("Invalid file type !! \nOnly '.jpg', '.png', ',gif' files allowed");
   th.image2.focus();
   return false;
  }
 }
 else if(th.image3.value)
 {var a=th.image3.value;
  var p=a.lastIndexOf('.');
  var e=a.substr(p+1);
  var ext=e.toLowerCase();
  if(!(ext=="png" || ext=="gif" || ext=="jpg" || ext=="jpeg"))
  {alert("Invalid file type !! \nOnly '.jpg', '.png', ',gif' files allowed");
   th.image3.focus();
   return false;
  }
 }
 else if(th.web_image.value)
 {var a=th.web_image.value;
  var p=a.lastIndexOf('.');
  var e=a.substr(p+1);
  var ext=e.toLowerCase();
  if(!(ext=="png" || ext=="gif" || ext=="jpg" || ext=="jpeg"))
  {alert("Invalid file type !! \nOnly '.jpg', '.png', ',gif' files allowed");
   th.web_image.focus();
   return false;
  }
 }
 else if(th.broch_path.value)
 {var a=th.broch_path.value;
  var p=a.lastIndexOf('.');
  var ext=a.substr(p+1);
  if(!(ext.toLowerCase()=="pdf"))
  {alert("Invalid file type !! \nOnly '.pdf' files allowed");
   th.broch_path.focus();
   return false;
  }
 }
 else if(th.broch_image.value)
 {var a=th.broch_image.value;
  var p=a.lastIndexOf('.');
  var e=a.substr(p+1);
  var ext=e.toLowerCase();
  if(!(ext=="png" || ext=="gif" || ext=="jpg" || ext=="jpeg"))
  {alert("Invalid file type !! \nOnly '.jpg', '.png', ',gif' files allowed");
   th.broch_image.focus();
   return false;
  }
 }
 else if(!test_email1 && th.email1.value)
 { alert("Please enter a valid email address..");
  th.email1.focus();
  return false;  
 }
 else if(!test_email2 && th.email2.value)
 { alert("Please enter a valid email address..");
  th.email2.focus();
  return false;  
 }
 else if(!test_email3 && th.email3.value)
 { alert("Please enter a valid email address..");
  th.email3.focus();
  return false;  
 }
 else if(document.getElementById('ch_pass').style.display != 'none') 
 {
  if(th.old_pass.value=='' || th.old_pass.value==' ')
  { alert("Enter Old Password..");
    th.old_pass.focus();
	return false;
  }
  else if(th.pass.value=='' || th.pass.value==' ')
  { alert("Enter New Password..");
    th.pass.focus();
	return false;
  }
  else if(th.pass.value.length<7)
  { alert("Password must be of min 7 characters..");
    th.pass.focus();
	return false;
  }
  else if(th.cnf_pass.value=='' || th.cnf_pass.value==' ')
  { alert("Enter Confirm New Password..");
    th.cnf_pass.focus();
	return false;
  }
  else if(th.cnf_pass.value.length<7)
  { alert("Password must be of min 7 characters..");
    th.cnf_pass.focus();
	return false;
  }
  else if(th.pass.value != th.cnf_pass.value)
  { alert("Password not confirmed..");
    th.cnf_pass.select();
	return false;
  }
 }   
} 