var email_pattern = /[\w\-]+\@[\w\-]+\.\w{2,3}/; 

function sameSame()	{

	if (document.getElementById('same').checked)	 {
		
		document.getElementById('shipping_info').style.display = 'none';
		document.getElementById('x_Ship_To_First_Name').value = '';
		document.getElementById('x_Ship_To_Last_Name').value = '';
		document.getElementById('x_Ship_To_Address').value = '';
		document.getElementById('x_Ship_To_City').value = '';
		document.getElementById('x_Ship_To_Country').selectedIndex = 0;
		document.getElementById('ship_us_info').style.display = 'none';
		document.getElementById('ship_f_info').style.display = 'none';
		document.getElementById('x_Ship_To_State').selectedIndex = 0;
		document.getElementById('x_Ship_To_Zipcode').value = '';
		document.getElementById('ship_f_state').value = '';
		document.getElementById('ship_f_zip').value = '';

		}
	else	{
		document.getElementById('shipping_info').style.display = 'block';

		}

	}


function show_state_info(which)	{
	if (which == 1)	{
		
		if (document.getElementById('x_Country').selectedIndex == 1)	 {
			document.getElementById('us_info').style.display = 'block';
			document.getElementById('f_info').style.display = 'none';
			}
		else	{
			document.getElementById('f_info').style.display = 'block';
			document.getElementById('us_info').style.display = 'none';
			}
		
		}
	else	{
		
		if (document.getElementById('x_Ship_To_Country').selectedIndex == 1)	 {
			document.getElementById('ship_us_info').style.display = 'block';
			document.getElementById('ship_f_info').style.display = 'none';
			}
		else	{
			document.getElementById('ship_f_info').style.display = 'block';
			document.getElementById('ship_us_info').style.display = 'none';
			}

		}
	}

function trim(str)	{  
	while(str.charAt(0) == " ")	{  
		str = str.substring(1);
		}
	while(str.charAt(str.length-1) == " " )	{  
		str = str.substring(0,str.length-1);
		}
	return str;
	}

function add_to_cart(id, lang)	 {

	if (!isNaN(document.getElementById('quantity_' + id).value))	{

		variables = "product_id=" + document.getElementById('prod_id_' + id).value;
		
		if (document.getElementById('formula_' + id))	{
			variables += "&formula=" + document.getElementById('formula_' + id).value;
			}
		variables += "&quantity=" + document.getElementById('quantity_' + id).value;
		variables += "&add=1";

		send_request(variables, lang);
		
		}
	else	{
		alert("Please enter numeric values only");
		}


	return false;
	}

function send_request(variables, lang) {
	http = getHTTPObject();

	var h_text = new Array();
	h_text['eng'] = 'items';
	h_text['esp'] = 'artículos';

	http.onreadystatechange = function()	{
		if (http.readyState == 4) {
			var text = http.responseText;
			document.getElementById('side_info_cart').innerHTML = text.substring(0, text.indexOf('|'));
			document.getElementById('cart_nums').innerHTML = '(' + text.substring(text.indexOf('|') + 1, text.length) + ' ' + h_text[lang] + ')';
			}
		}

	http.open('POST', 'includes/side_cart.php', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", variables.length);
	http.setRequestHeader("Connection", "close");
	http.send(variables);
	return false;
	}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

