﻿/* Multi selection loop*/

var arSelected = new Array(); 
function getMultiple(ob) 
{ 
//var i = 0;
while (ob.selectedIndex != -1) 
{ 

arSelected.push(ob.options[ob.selectedIndex].value); 
ob.options[ob.selectedIndex].selected = false; 
var values = arSelected.join(",");
}
return values;

// You can use the arSelected array for further processing. 
}
/******************/

function chkEmail(eml)
{
	var re = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;
	if (!eml.match(re)) 
		return 0;
	else
		return 1;

}

  var captchaOK1 = 2; // 2 - not yet checked, 1 - correct, 0 - failed 
  function getHTTPObject() 
  { 
	  try 
		{ 
			req = new XMLHttpRequest(); 
		} 
	  catch (err1) 
	  { 
			try 
			  { 
				req = new ActiveXObject("Msxml12.XMLHTTP"); 
			  } 
			catch (err2) 
			{ 
				   try 
				   { 
				   req = new ActiveXObject("Microsoft.XMLHTTP"); 
				   } 
				   catch (err3) 
				   { 
				   req = false; 
				   } 
			}
	 	} 
 		return req; 
  } 
 var http = getHTTPObject(); // We create the HTTP Object 
 captchaOK1=0;
function handleHttpResponse1()
   {
		  if (http.readyState == 1)
		  {
			  //document.getElementById('sent1').innerHTML="Loading....";
		  }
		  if (http.readyState == 4) 
		  { 
			  captchaOK1 = http.responseText; 
			  //alert(captchaOK1);
			  if(captchaOK1 != 'yes')
			   { 
				    document.getElementById('sent1').innerHTML ='';
				   alert('The entered code was not correct. Please try again');
				   /*
				   document.subs.codenewsletter.value=''; 
				   document.subs.codenewsletter.focus();
				   */
				   return false; 
			   } 
			   else
			   {
//			    document.getElementById('sent1').innerHTML="You information has been sent.";
				//window.location = "thanks.html";
				alert("You information has been sent");
			   	return true;		   
			   }
		   //document.contact.submit(); 
		   } 
   }






function LTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...

    var j=0, i = s.length;

    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;


    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  return s;
}



//2------------------------------------------------------------------------------*/






//////////////////////



 var captchaOK = 2; // 2 - not yet checked, 1 - correct, 0 - failed 
  function getHTTPObject() 
  { 
	  try 
		{ 
			req = new XMLHttpRequest(); 
		} 
	  catch (err1) 
	  { 
			try 
			  { 
				req = new ActiveXObject("Msxml12.XMLHTTP"); 
			  } 
			catch (err2) 
			{ 
				   try 
				   { 
				   req = new ActiveXObject("Microsoft.XMLHTTP"); 
				   } 
				   catch (err3) 
				   { 
				   req = false; 
				   } 
			}
	 	} 
 		return req; 
  } 

  
  function checkcode(thecode)
  { 
  
  	var email 	= LTrim(document.getElementById('email').value);	
	var name		= LTrim(document.getElementById('name').value);
	var phone 	= LTrim(document.getElementById('phone').value);
 	var comments 	= LTrim(document.getElementById('comments').value);
	//http://www.boltinhousejewelers.com
    var url = "/sendemail.php?name="+name+"&phone="+phone+"&email="+email+"&comments="+comments+"&code="; 
 // alert(url + escape(thecode))	;
  http.open("GET", url + escape(thecode), true); 
  http.onreadystatechange = handleHttpResponse1; 
  http.send(null); 
  } 
  

  function checkform() { // First the normal form validation 
   
  if(LTrim(document.contactfrm.email.value)=='') {
   alert('Please complete the "required" field.'); 
   document.contactfrm.email.focus(); return false; 
   }
  if(chkEmail(document.contactfrm.email.value)==0) {
   alert('Please enter valid email address.'); 
   document.contactfrm.email.focus(); return false; 
   }
  
  var name = LTrim(document.getElementById('name').value);
  if(name=="" || name=='Name:') {
   alert('Please enter your name.'); 
   document.contactfrm.name.focus(); return false; 
   }
     
  var phone = LTrim(document.getElementById('phone').value);
   if(phone=="" || phone=='Phone:') {
   alert('Please enter your phone number.'); 
   document.contactfrm.phone.focus(); return false; 
  
   }

    if(document.contactfrm.code.value=='') {
	 alert('Please enter the string from the displayed image.'); 
	 document.contactfrm.code.value='';
	 document.contactfrm.code.focus(); 
	 return false; 
	 } // Now the Ajax CAPTCHA validation
	 //alert(document.contactfrm.code.value);

   checkcode(document.contactfrm.code.value); 
   return false;
   } 
