
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 = "inline";
		document.getElementById('sendmail_err').innerHTML = "<span class='errormsg'>Please enter the email</span>";
		err += 'sendmail';	
	} 
	else if(emailCheck(sendmail) == false) 
			{
				document.getElementById("sendmail_err").style.display = "block";
				document.getElementById("msg_box").style.display = "none";
				document.getElementById("sendmail_err").innerHTML = "<span class='errormsg'>Invalid email.</span><br>";
				
				//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==1) {				 
						$("#msg_box").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('sendmail').value='';
							setTimeout('hide_fade_msg()',1000);	

						  });
						});
					  } else {		
						$("#msg_box").fadeTo(200,0.1,function() {
						  $(this).html('Invalid email.').addClass('messagebox').fadeTo(900,1);
						});		
					  }
			});
		//////////////
		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("sendemail2.php",{ sendmail:$('#sendmail2').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 myClose_inq_new()
	{
                googlewin_inq.close();
    }
	

	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 myClose_inq_new2()
	{
                googlewin_inq2.close();
				return false;
    }
	
	// form validation
	function validateUSPhone(str)
	{
		var chk=true;
		if(str.value.charAt('3')!= '-' || str.value.charAt('7') !='-')
		{
			chk=false;
		}
		if(str.value.indexOf('-')<0)
		{
			chk=false;
		}
		if(str.value.search(/^\(?(\d{3})\)?[-]?(\d{3})[-]?(\d{4})$/)==-1)
		{
			chk=false;
		}
		if(chk==false)
		{
			str.focus();
		}
		
			return  chk;
	}
	// end form validation

  function ValidateAddContactNew(frm)
{

	var namediv=document.getElementById('your_name_req');
	var emaildiv=document.getElementById('your_email_req');	
	var phonediv=document.getElementById('your_tel_req');	
	//alert(document.getElementById('howcontact').value);
	
	namediv.innerHTML='';
	emaildiv.innerHTML='';
	
	phonediv.innerHTML='';
	
	var noerror=true;
	
	
	if(frm.your_name.value=='')
	{	
		namediv.innerHTML='<font color="red"  size="2px">Your Name is required.</font>';
		noerror=false;
	}
	
	if(frm.your_email.value=='')
	{	
		emaildiv.innerHTML='<font color="red" size="2px">Your Email is required.</font>';
		noerror=false;
	}
	if(frm.your_email.value!='')
	{
		var check = emailCheck(frm.your_email.value);
		if(check==false)
		{			
			emaildiv.innerHTML='<font color="red" size="2px">Invalid Email Address.</font>';
			return false;
		}
		
	}
	if(frm.your_tel.value=='')
	{	
		phonediv.innerHTML='<font color="red" size="2px">Your Phone Number is required.</font>';
		noerror=false;
	}
	
	if(frm.your_tel.value!='')
	{
		var check = isValidPhoneNONew(frm.your_tel.value);
		if(check==false)
		{			
			phonediv.innerHTML='<font color="red" size="2px">Invalid Phone Number(<i>Enter as 123-234-3456</i>).</font>';
			return false;
		}
		
	}	
		
	
	return 	noerror;
}


// RETURNS TRUE IF IT IS A VALID PHONE NUMBER
function isValidPhoneNONew(objname, msg)
{

	
	var str = objname;
  	var chk = true;
    if (str.charAt('3') != '-' || str.charAt('7') != '-') {
        chk = false;
    }
    if (str.indexOf('-') < 0) {
        chk = false;
    }
    if (str.search(/^\(?(\d{3})\)?[-]?(\d{3})[-]?(\d{4})$/) == -1) {
        chk = false;
    }    
    
    return chk;
}


function validZip(zip)
{
	if (zip.match(/^[0-9]{5}$/)) {
		return true;
	}
	zip=zip.toUpperCase();
	if (zip.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) {
		return true;
	}
	if (zip.match(/^[A-Z][0-9][A-Z].[0-9][A-Z][0-9]$/)) {
		return true;
	}
	
		return false;
}
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					
	}

/** TO REMOVE BLACK SPACE FROM LEFT AND RIGHT */
function checkTrim(txtString) {

	txtString = lTrim(txtString);
	txtString = lTrim(txtString);
	return txtString;
}

/** RETURNS THE STRING AFTER DELETING THE TRAILING SPACES */
function lTrim(txtString) {
	ctr = 0;
	while( ctr < txtString.length && (txtString.substring(ctr,ctr+1) == " "))
	{
		ctr=ctr+1;
	}
	return txtString.substring(ctr);
}

/** RETURNS THE STRING AFTER DELETING THE LEADING SPACES */
function rTrim(txtString) {
	ctr = txtString.length;
	while( ctr > 0  && (txtString.substring(ctr,ctr-1) == " "))
	{
		ctr = ctr - 1;
	}
	return txtString.substring(0,ctr);
}



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;
   }
}

function submitFormWithEnter2(myfield,e)
{

   var keycode;
   if (window.event)
   {
      keycode = window.event.keyCode;
   }
   else if (e)
   {
      keycode = e.which;
   }
   else
   {
      return true;
   }

   if (keycode == 13)
   {
	
      send_email2();
      return false;
   }
   else
   {
      return true;
   }
}

