function send_email() {
	var sendmail = document.getElementById('sendmail').value;
	String.prototype.trim = function() {  return this.replace(/^\s+|\s+$/g, '');  }

	sendmail = sendmail.trim();
	
	var err = '';
	
	if(sendmail == "") {
		document.getElementById('sendmail').value = '';
		document.getElementById('sendmail_err').style.display = "";
		document.getElementById('sendmail_err').innerHTML = "";
		alert("Please enter the email");
		err += 'sendmail';	
	} 
	else if(emailCheck(sendmail) == false) 
			{

				document.getElementById("sendmail_err").innerHTML = "";
				alert("Invalid email");
				
				//alert('Invalid email');
				 document.getElementById('sendmail').focus();
				 document.getElementById('sendmail').select();



				 err += 'sendmail';	
	} else {
		document.getElementById('sendmail_err').innerHTML = "";
		document.getElementById('sendmail_err').style.display = "none";
		err += '';
	}

	if(err == '') {
		//$("#msg_box").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
		///////////////////////////
		//http://10.0.0.78/rose_jeweler/catalog/sendemail.php
		//http://www.rosejewelers.net.php5-14.dfw1-1.websitetestlink.com
		
		$.post("sendemail.php",{ sendmail:$('#sendmail').val()} ,function(data)
					{					
					   if(data=="success") {				 
						$("#msg_box").fadeTo(200,0.1,function() { 
						  alert("You are successfully subscribed to The News Letters.");
						  document.getElementById('sendmail').value='';
						 
						});
					  } else {				  
						alert("Invalid email.");
					  }
			});
		//////////////
		return false;
	}
} // EO candidate_details()

function send_email2() {
	var sendmail = document.getElementById('sendmail2').value;
	String.prototype.trim = function() {  return this.replace(/^\s+|\s+$/g, '');  }

	sendmail = sendmail.trim();
	
	var err = '';
	
	if(sendmail == "") {
		document.getElementById('sendmail2').value = '';
		document.getElementById('sendmail_err2').style.display = "inline";
		document.getElementById('sendmail_err2').innerHTML = "<span class='errormsg' style='margin:0px 0 0 169px; font-size:13px;'>Please enter the email</span>";
		err += 'sendmail';	
	} 
	else if(emailCheck(sendmail) == false) 
			{
				document.getElementById("sendmail_err2").style.display = "block";
				document.getElementById("msg_box2").style.display = "none";
				document.getElementById("sendmail_err2").innerHTML = "<span class='errormsg' style='margin:-2px 0 0 169px; font-size:13px;'>Invalid email.</span><br>";
				
				//alert('Invalid email');
				 document.getElementById('sendmail2').focus();
				 document.getElementById('sendmail2').select();



				 err += 'sendmail';	
	} else {
		document.getElementById('sendmail_err2').innerHTML = "";
		document.getElementById('sendmail_err2').style.display = "none";
		err += '';
	}

	if(err == '') {
		$("#msg_box2").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
		///////////////////////////
		//http://10.0.0.78/rose_jeweler/catalog/sendemail.php
		//http://www.rosejewelers.net.php5-14.dfw1-1.websitetestlink.com
		
		$.post("sendemail.php",{ sendmail:$('#sendmail').val()} ,function(data)
					{					
					   if(data==1) {				 
						$("#msg_box2").fadeTo(200,0.1,function() { 
						  $(this).html('Email sending in.....').addClass('messagebox').fadeTo(900,1,
						  function() { 
							
							$(this).html('Succussfully subscribed to Newsletter.').addClass('messagebox').fadeTo(900,1);
							document.getElementById('sendmail2').value='';
							setTimeout('hide_fade_msg2()',1000);	

						  });
						});
					  } else {				  
						$("#msg_box2").fadeTo(200,0.1,function() {
						  $(this).html('Invalid email.').addClass('messagebox').fadeTo(900,1);
						});		
					  }
			});
		//////////////
		return false;
	}
} // EO candidate_details()

function hide_fade_msg() {
	$('#msg_box').fadeOut();
}

function hide_fade_msg2() {
	$('#msg_box2').fadeOut();
}


function clear_text()	
{
	document.frm_maillist.sendmail.value = "";
	return false;
}

function clear_text2()	
{
	document.frm_maillist2.sendmail2.value = "";
	return false;
}


	function getDirection1(url, pname)
			{
                var zipcode = document.frm_direction1.zipcode1.value;
				if(zipcode == '')
				{
					alert("Please enter the zipcode.");
					return false;
				}
				if(isNaN(zipcode))
				{
					alert("Please enter valid zipcode.");
					return false;
				}
				if(zipcode.length > 5)
				{
					alert("Please enter valid zipcode.");
					return false;
				}
				
				url = url+"?zipcode="+zipcode;
				
				googlewin_inq = dhtmlwindow.open("Get direction  " + pname, "iframe", url, "Get direction  " + pname, "width=470px,height=280px,resize=0,scrolling=0,center=1,border=0px;", "recal")
              return false;
			   googlewin_inq.onclose = function(){ //Run custom code when window is being closed (return false to cancel action):
                return true;
                }
            
			}
		

	function getDirection2(url, pname)
	{
				var zipcode = document.frm_direction2.zipcode2.value;
				if(zipcode == '')
				{
					alert("Please enter the zipcode.");
					return false;
				}
				if(isNaN(zipcode))
				{
					alert("Please enter valid zipcode.");
					return false;
				}
				if(zipcode.length > 5)
				{
					alert("Please enter valid zipcode.");
					return false;
				}
				/*var zipcode = document.frm_direction2.zipcode2.value;
				if(zipcode == '')
				{
					alert("Please enter the zipcode.");
					return false;
				}
				*/
				url = url+"?zipcode="+zipcode;
				googlewin_inq2 = dhtmlwindow.open("Get direction  " + pname, "iframe", url, "Get direction  " + pname, "width=470px,height=280px,resize=0,scrolling=0,center=1,border=0px;", "recal")
                 return false;
			    googlewin_inq2.onclose = function(){ //Run custom code when window is being closed (return false to cancel action):
              	return true;
               }
	
	}
	

 
function emailCheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
		return true					
	}

function submitFormWithEnter(myfield,e)
{
	
   var keycode;
   if (window.event)
   {
      keycode = window.event.keyCode;
   }
   else if (e)
   {
      keycode = e.which;
   }
   else
   {
      return true;
   }

   if (keycode == 13)
   {
      send_email();
      return false;
   }
   else
   {
      return true;
   }
}

