function validateNewsletterForm( )
{
	if(document.frmNewsletter.txtName.value=="" || document.frmNewsletter.txtName.value=="Enter Your Full Name")
	{
		alert("Please Enter your Full Name.");
		return false;
	}
	else if(document.frmNewsletter.txtEmail.value=="" || document.frmNewsletter.txtEmail.value=="Enter Your Email")
	{
		alert("Please Enter your Full Name.");
		return false;
	}

	return true;
}

function validateEmailFormat(sEmail)
{
	var iLength = sEmail.length;

	if (iLength == 0)
		return true;

	if (iLength < 5)
		return false;

	var sValidChars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";

	for (var i = 0; i < iLength; i++)
	{
		var sLetter = sEmail.charAt(i).toLowerCase( );

		if (sValidChars.indexOf(sLetter) != -1)
			continue;

		return false;
	}

	var iPosition = sEmail.indexOf('@');

	if (iPosition == -1 || iPosition == 0)
		return false;

	var sFirstPart = sEmail.substring(0, iPosition);

	sEmail = sEmail.substring((iPosition + 1));

	iPosition = sEmail.indexOf('.');

	if (iPosition == -1 || iPosition == 0)
		return false;

	var sSecondPart = sEmail.substring(0, iPosition);

	var sThirdPart = sEmail.substring((iPosition + 1));

	if(sSecondPart.indexOf('@') != -1 || sSecondPart.indexOf('_') != -1)
		return false;

	if(sThirdPart.indexOf('@') != -1 || sThirdPart.indexOf('_') != -1 || sThirdPart.indexOf('-') != -1 || sThirdPart.length < 2)
		return false;

	return true;
}


function validReg(){
	var passVal = document.reg.password.value;
	/*alert(passVal.length);*/
	  if(document.reg.username.value==""){
		alert("Please Enter User Name.");   
		document.reg.username.focus();
		return false;
	  }else if(passVal==""){
		alert("Please Enter Password.");   
		document.reg.password.focus();
		return false;
	  }else if(passVal.length < 6){
		alert("Password must contain more than 6 character.");   
		document.reg.password.focus();
		return false;
	  }else if(document.reg.password_confirmed.value==""){
		alert("Please Enter Confirm Password.");   
		document.reg.password_confirmed.focus();
		return false;
	  }else if(document.reg.password.value != document.reg.password_confirmed.value){
		alert("Password and Confirm Password did not match.");   
		document.reg.password_confirmed.focus();
		return false;
	  }else if(document.reg.email.value==""){
		alert("Please Enter Email Address.");   
		document.reg.email.focus();
		return false;
	  }else if(validateEmailFormat(document.reg.email.value)==false){
		alert("Please Enter Valid Email Address.");  
	    document.reg.email.focus();
		return false;
	  }else if(document.reg.fullname.value==""){
		alert("Please Enter Your Full Name.");   
		document.reg.fullname.focus();
		return false;
	  }else if(document.reg.companyName.value==""){
		alert("Please Enter Your Company Name.");   
		document.reg.companyName.focus();
		return false;
	  }else if(document.reg.country.value==""){
		alert("Please Enter Your Country Name.");   
		document.reg.country.focus();
		return false;
	  }else if(document.reg.phone.value==""){
		alert("Please Enter Your Phone No.");   
		document.reg.phone.focus();
		return false;
	  }
	
	}

function validProfile(){
	  
	  if(document.edit.fullname.value==""){
		alert("Please Enter Your Full Name.");   
		document.edit.fullname.focus();
		return false;
	  }else if(document.edit.companyName.value==""){
		alert("Please Enter Your Company Name.");   
		document.edit.companyName.focus();
		return false;
	  }
	  
	}

function validSignIn(){
	 
	 if(document.signIn.username.value==""){
		alert("Please Enter Your User Name.");   
		document.signIn.username.focus();
		return false;
	  }else if(document.signIn.password.value==""){
		alert("Please Enter Your Password.");   
		document.signIn.password.focus();
		return false;
	  }
	 
	}
	
function validForget(){
	
	if(document.frmForget.txtForgetEmail.value==""){
		alert("Please Enter Email Address.");   
		document.frmForget.txtForgetEmail.focus();
		return false;
	}else if(validateEmailFormat(document.frmForget.txtForgetEmail.value)==false){
		alert("Please Enter Valid Email Address.");  
	    document.frmForget.txtForgetEmail.focus();
		return false;

	}else{
	
	   document.frmForget.submit();
	}
	  
}	

function enablefields(searchtab)
{
	if(searchtab=='Products')
	{
		document.frmsearch.txtsearch.value="Enter Product Name";
		document.frmsearch.hdval.value='P';
	}
	else if(searchtab=='Services')
	{
		document.frmsearch.txtsearch.value="Enter Service Name";
		document.frmsearch.hdval.value='S';
	}
	else if(searchtab=='Buyers_Supplier')
	{
		document.frmsearch.txtsearch.value="Enter Buyer/Supplier Name";
		document.frmsearch.hdval.value='BS';
	}
	else
	{
		document.frmsearch.txtsearch.value="Enter Product Name";
		document.frmsearch.hdval.value='P';
	}
}
function chkvalonfocus()
{
	if(document.frmsearch.txtsearch.value=="Enter Product Name" || document.frmsearch.txtsearch.value=="Enter Service Name" || document.frmsearch.txtsearch.value=="Enter Buyer/Supplier Name")
	{
		document.frmsearch.txtsearch.value="";
	}
}

function chkvalonblur()
{
	if(document.frmsearch.txtsearch.value=="" )
	{
		document.frmsearch.txtsearch.value="Enter Product Name";
	}
}

function validatesearch()
{
	if(document.frmsearch.txtsearch.value=="" || document.frmsearch.txtsearch.value=="Enter Product Name" || document.frmsearch.txtsearch.value=="Enter Service Name" || document.frmsearch.txtsearch.value=="Enter Buyer/Supplier Name" )
	{
		alert("Please Enter Value in Search Field.");
		return false;
	}
	else
	{
		document.frmsearch.action="leads-list.php?stype="+document.frmsearch.hdval.value+"&searchtxt="+document.frmsearch.txtsearch.value;
		document.frmsearch.submit();
	}
}

function validateorg(){
  if(document.frmorg.username.value==""){
   alert("Please Enter Full Name.");
   document.frmorg.username.focus();
   return false;  
  }else if(document.frmorg.email.value==""){
   alert("Please Enter Your Email Address.");
   document.frmorg.email.focus();
   return false;
  }else if(validateEmailFormat(document.frmorg.email.value)==false){
   alert("Please Enter Valid Email Address.");
   document.frmorg.email.focus();
   return false;
  }else{
	document.frmorg.submit();
	return true; 
  }	
}
function validSignIn(){
	 
	 if(document.signIn.username.value==""){
		alert("Please Enter Your User Name.");   
		document.signIn.username.focus();
		return false;
	  }else if(document.signIn.password.value==""){
		alert("Please Enter Your Password.");   
		document.signIn.password.focus();
		return false;
	  }
	 
	}
	
function purchasecredits()
{
 document.frmPurchase.hdval.value='do';
 document.frmPurchase.submit();
}

function validateAdForm(){
  var adfrm = document.frmAds;
  
  if(adfrm.person.value==""){
   alert("Please Enter Your Name.");
   adfrm.person.focus();
   return false;
  }else if(adfrm.designation.value==""){
   alert("Please Enter Your Designation.");
   adfrm.designation.focus();
   return false;
  }else if(adfrm.comp_name.value==""){
   alert("Please Enter Your Company Name.");
   adfrm.comp_name.focus();
   return false;
  }else if(adfrm.email.value==""){
   alert("Please Enter Your Email Address.");
   adfrm.email.focus();
   return false;
  }else if(validateEmailFormat(adfrm.email.value)==false){
   alert("Please Enter Valid Email Address.");
   adfrm.email.focus();
   return false;
  }else if(adfrm.phone.value==""){
   alert("Please Enter Your Phone.");
   adfrm.phone.focus();
   return false;
  }else if(adfrm.country.value==""){
   alert("Please Select Your Country Name.");
   adfrm.country.focus();
   return false;
  }else if(adfrm.txtCode.value==""){
   alert("Please Enter Spam Code.");
   adfrm.txtCode.focus();
   return false;
  }
}

function ValidateAdvanceSearch()
{
	
	var myform=document.frmAdvSearch;
	
	  if(myform.txtName.value=="" &&  myform.txtType.value=="" && myform.txteOrganizer.value=="" && myform.txteVanue.value=="" &&  myform.txteCity.value=="" && myform.startDate.value=="" && myform.endDate.value=="")
	  {
		alert("Please Enter in Any Field .");   
		myform.txteName.focus();
		return false;
	  }
}

function validateLeadAdd()
{
	
	var flag = 'No';

	  if(document.frmProduct.leadType.value=="")
	  {
		alert("Please Enter Lead Type.");   
		document.frmProduct.leadType.focus();
		return false;
	  }
	  else if(document.frmProduct.cmbCategory.value=="")
	  {
		alert("Please Select Lead Category.");   
		document.frmProduct.cmbCategory.focus();
		return false;
	  }
	  else if(document.frmProduct.ddSubCategory.value=="")
	  {
		alert("Please Select Lead Sub Category.");   
		document.frmProduct.ddSubCategory.focus();
		return false;
	  }
	  
	  else if(document.frmProduct.txtTitle.value=="")
	  {
		alert("Please Enter Lead Title .");   
		document.frmProduct.txtTitle.focus();
		return false;
	  }
	 
	 if(document.getElementById('forP').style.dispaly!=undefined){
	  
	  for(i=1; i<=11; i++){ 
		var pack = 'pack'+i;
		
		if(document.getElementById(pack).checked==true){
		flag = "Yes";
		break;
		}
		
		}
		if(flag == "No"){
		alert("Please Select Packaging");
		document.getElementById("pack1").focus();
		return false;
		}
	  }
	  else if(document.frmProduct.txtminOrderQty.value!="" && document.frmProduct.cmbPqtyUnit.value=="")
	  {
		alert("Please Select Any Unit.");   
		document.frmProduct.cmbPqtyUnit.focus();
		return false;
	  }
	  else if(document.frmProduct.txtPrice.value=="")
	  {
		alert("Please Enter Lead Price.");   
		document.frmProduct.txtPrice.focus();
		return false;
	  }
	  else if(document.frmProduct.cmbCurrency.value=="")
	  {
		alert("Please Select Any Currency.");  
	    document.frmProduct.cmbCurrency.focus();
		return false;
	  }
	  else if(document.frmProduct.cmbCountry.value=="")
	  {
		alert("Please Enter Lead Country.");  
	    document.frmProduct.cmbCountry.focus();
		return false;
	  }
	  else if(document.frmProduct.txtContactPerson.value=="")
	  {
		alert("Please Enter Contact Person Name.");   
		document.frmProduct.txtContactPerson.focus(); 
		return false;
	  }
	  else if(document.frmProduct.txtPersonEmail.value=="")
	  {
		alert("Please Enter Contact Person Email.");   
		document.frmProduct.txtPersonEmail.focus();
		return false;
	  }
	  else if(validateEmailFormat(document.frmProduct.txtPersonEmail.value)==false)
	  {
		alert("Please Enter Valid Email.");   
		document.frmProduct.txtPersonEmail.focus();
		return false;
	  }
	   else if(document.frmProduct.txtPhone.value=="")
	  {
		alert("Please Enter Contact Person Phone.");   
		document.frmProduct.txtPhone.focus();
		return false;
	  }
	  else
	  {
		document.frmProduct.action='add-your-lead.php?cmd=Add';
	 	document.frmProduct.submit();
	  	return true;
	  }
}

function validateLeadEdit()
{
	   if(document.frmProduct.leadType.value=="")
	  {
		alert("Please Enter Lead Type.");   
		document.frmProduct.leadType.focus();
		return false;
	  }
	  	
	  else if(document.frmProduct.cmbCategory.value=="")
	  {
		alert("Please Select Lead Category.");   
		document.frmProduct.cmbCategory.focus();
		return false;
	  }
	  else if(document.frmProduct.ddSubCategory.value=="")
	  {
		alert("Please Select Lead Sub Category.");   
		document.frmProduct.ddSubCategory.focus();
		return false;
	  }
	  
	  else if(document.frmProduct.txtTitle.value=="")
	  {
		alert("Please Enter Lead Title .");   
		document.frmProduct.txtTitle.focus();
		return false;
	  }
	  
	  if(document.getElementById('forP').style.dispaly!=undefined){
	  
	  for(i=1; i<=11; i++){ 
		var pack = 'pack'+i;
		
		if(document.getElementById(pack).checked==true){
		flag = "Yes";
		break;
		}
		
		}
		if(flag == "No"){
		alert("Please Select Packaging");
		document.getElementById("pack1").focus();
		return false;
		}
	  }

	  else if(document.frmProduct.txtminOrderQty.value!="" && document.frmProduct.cmbPqtyUnit.value=="")
	  {
		alert("Please Select Any Unit.");   
		document.frmProduct.cmbPqtyUnit.focus();
		return false;
	  }
	  else if(document.frmProduct.txtPrice.value=="")
	  {
		alert("Please Enter Lead Price.");   
		document.frmProduct.txtPrice.focus();
		return false;
	  }
	  else if(document.frmProduct.cmbCurrency.value=="")
	  {
		alert("Please Select Any Currency.");  
	    document.frmProduct.cmbCurrency.focus();
		return false;
	  }
	  else if(document.frmProduct.cmbCountry.value=="")
	  {
		alert("Please Enter Lead Country.");  
	    document.frmProduct.cmbCountry.focus();
		return false;
	  }
	  else if(document.frmProduct.txtContactPerson.value=="")
	  {
		alert("Please Enter Contact Person Name.");   
		document.frmProduct.txtContactPerson.focus(); 
		return false;
	  }
	  else if(document.frmProduct.txtPersonEmail.value=="")
	  {
		alert("Please Enter Contact Person Email.");   
		document.frmProduct.txtPersonEmail.focus();
		return false;
	  }
	  else if(validateEmailFormat(document.frmProduct.txtPersonEmail.value)==false)
	  {
		alert("Please Enter Valid Email.");   
		document.frmProduct.txtPersonEmail.focus();
		return false;
	  }
	   else if(document.frmProduct.txtPhone.value=="")
	  {
		alert("Please Enter Contact Person Phone.");   
		document.frmProduct.txtPhone.focus();
		return false;
	  }
	  else
	  {
		document.frmProduct.action='edit-lead.php?cmd=Update&LeadId='+document.frmProduct.lID.value;
	 	document.frmProduct.submit();
	  	return true;
	  }
}
function showP(){
  
  var val = document.getElementById('leadType').value;
  
  if(val=='P'){
	  document.getElementById('forP').style.display ='block';
	  document.getElementById('forS').style.display ='none';
  }else if(val=='S'){
	  document.getElementById('forS').style.display ='block';
	  document.getElementById('forP').style.display ='none';
  }	
}


