function send_form()	{

	var email_pattern = /[\w\-]+\@[\w\-]+\.\w{2,3}/; 
	var phone_pattern = /\d{3}\-\d{3}\-\d{4}/;
	var send = true;
	
	if (!email_pattern.test(document.getElementById('c_email').value))	{
		document.getElementById('email_err').innerHTML = 'The email address you have entered does not appear to be formated correctly';
		document.getElementById('email_err').style.display = 'block';
		send = false;
		}
	else if (trim(document.getElementById('c_phone').value).length != 0 && !phone_pattern.test(document.getElementById('c_phone').value))	{
		document.getElementById('phone_err').innerHTML = 'Please enter your phone number in xxx-xxx-xxxx format';
		document.getElementById('phone_err').style.display = 'block';
		}
	else	{
		document.getElementById('email_err').style.display = 'none';
		}

	if (strip_tags(document.getElementById('e_content').value).length != document.getElementById('e_content').value.length)	{
		document.getElementById('message_err').innerHTML = 'Message may not contain HTML tags';
		document.getElementById('message_err').style.display = 'block';
		send = false;
		}
	else	{
		document.getElementById('message_err').style.display = 'none';
		}

	if (send)	{

		http = getHTTPObject();

		http.onreadystatechange = function()	{
			
			if (http.readyState == 4) {

				//alert(http.responseText);
				if (http.responseText == 'done')	{
					document.getElementById('con_form').style.display = 'none';
					document.getElementById('success').style.display = 'block';
					}
				else	{

					}
				
				} // end if ready state
			
			} // end inner function

		var phone = '';

		// need this until all the sites get updated
		if (document.getElementById('c_phone'))	{
			phone = '&c_phone=' + document.getElementById('c_phone').value;
			}

		variables = "o_id=" + document.getElementById('o_id').value + "&subject=" + document.getElementById('subject').value + "&c_email=" + document.getElementById('c_email').value + "&message=" + document.getElementById('e_content').value + phone;

	//	alert(variables);

		http.open('POST', '/send_remote_contact.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 check_status()	{
	
	if ((trim(document.getElementById('subject').value).length != 0 && document.getElementById('subject').value != 'subject') && (trim(document.getElementById('c_email').value).length != 0 && document.getElementById('c_email').value != 'your email') && (trim(document.getElementById('e_content').value).length != 0 && document.getElementById('e_content').value != 'your message'))	 {
		document.getElementById('send_button').disabled = false;
		}
	else	{
		document.getElementById('send_button').disabled = true;
		}
	
	}

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 strip_tags (str, allowed_tags) {
    // Strips HTML and PHP tags from a string  
    // 
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/strip_tags    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Eric Nagel
    // +      input by: Bobby Drake
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Tomasz Wesolowski    // *     example 1: strip_tags('<p>Kevin</p> <b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    // *     example 4: strip_tags('1 < 5 5 > 1');
    // *     returns 4: '1 < 5 5 > 1'
    var key = '', allowed = false;
    var matches = [];    var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = ''; 
    var replacer = function (search, replace, str) {
        return str.split(search).join(replace);
    };
     // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
    }
     str += '';
 
    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);
     // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;        }
 
        // Save HTML tag
        html = matches[key].toString();
         // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {                allowed = true;
                break;
            }
        }
         if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
     return str;
}

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;
}

