function openContactPanel() {
	var cssHTML ='<style type="text/css">#panelContainer{position:absolute;top:180px;left:180px;}</style>';
	var headers = '';
	var pagename = document.URL;
	var panelHTML = '<div id="panelContainer"><div id="panelContents"><table width="360" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td><div class="closePanel" onclick="closePanel();"><img src="/uploads/images/close.gif" alt="close window" /> Close</div></td></tr><tr><td><div id="formContainer"><h1>Contact Canyon Services</h1><div id="contactFormArea"><form action="" method="post" id="cForm"><label for="posName">Name:</label><input class="text" type="text" size="40" name="posName" id="posName" /><br /><label for="posEmail">Email:</label><input class="text" type="text" size="40" name="posEmail" id="posEmail" /><br /><label for="posPhone">Phone Number:</label><input class="text" type="text" size="40" name="posPhone" id="posPhone" /><br /><label for="posText">Message:</label><textarea cols="30" rows="4" name="posText" id="posText"></textarea><br /><label for="selfCC"><input type="checkbox" name="selfCC" id="selfCC" value="send" /> Send a copy to self</label><br /><input name="posRegard" type="hidden" id="posRegard" value="' + pagename + '" /><label><input name="Send" type="button" value="Send" id="send" onclick="contactMail();" /></label></form></div></div></td></tr><tr><td><div class="closePanel" onclick="closePanel();"><img src="/uploads/images/close.gif" alt="close window" /> Close</div></td></tr></table></div></div><div id="panelMask"></div>' + cssHTML + headers;
	document.getElementById('showPanel').innerHTML = panelHTML;
  
}

function closePanel() {
	document.getElementById('showPanel').innerHTML = '';
}

function captureTheClick(){
	var contactLink = document.getElementById('contactcs');
	contactLink.onclick = function () {openContactPanel(); return false;}
	
	
}

addLoadEvent(captureTheClick);

//do some ajax deep cleaning to send the email

var urlMail = "processMail.php?param="; // The server-side script
var param2 = "&param2=";
var param3 = "&param3=";
var param4 = "&param4=";
var param5 = "&param5=";
var param6 = "&param6=";
var param7 = "&param7=";
//HANDLING

function handleHttpResponse() {
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      // Split the comma delimited response into an array
      results = http.responseText.split(",");
      //document.getElementById('city').value = results[0];
      //document.getElementById('state').value = results[1];
      isWorking = false;
	  if (results[0] == 5) {
	  
	  	if (results[1] == 'success') {
		// Start Options for Class Option Search
	  	document.getElementById('contactFormArea').innerHTML = '<h2>Success!</h2><p>Your message has been sent.</p>';
	  	// End Options for Class Option Search
		}
		if (results[1] == 'fail') {
		// Start Options for Class Option Search
	  	document.getElementById('contactFormArea').innerHTML = '<h2>Error!</h2><p>Your message has not been sent.</p><p>Please call 1.888.546.5707 instead or visit or contact page for more options.</p>';
	  	// End Options for Class Option Search
		}
	  }
    }
  }
}
var isWorking = false;

// FUNCTIONS

function contactMail() {
  if (!isWorking && http) {
    var name = document.getElementById("posName").value;
	var email = document.getElementById("posEmail").value;
	var phone = document.getElementById("posPhone").value;
	var text = document.getElementById("posText").value;
	var selfCC = document.getElementById("selfCC").value;
	var regard = document.getElementById("posRegard").value;
	
   http.open("GET", urlMail + escape(name) + param2 + escape(email) + param3 + escape(phone) + param4 + escape(text) + param5 + escape(selfCC) + param6 + escape(regard), true);
	document.getElementById('contactFormArea').innerHTML = '<h2>Transmitting message to Canyon Services</h2><p align="center"><img src="/images/loading.gif" /></p>';
    http.onreadystatechange = handleHttpResponse;
    isWorking = true;
    http.send(null);
  }
}

/*function sendContactMail() {
	if(!isWorking && http) {
		var name = "contactMail.php";
		
		http.open("POST", name, true);
		http.onreadystatechange = handleHttpResponse;
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		http.send("name=" + escape(name) + 
		"&param2=" + escape(email) + 
		"&param3=" + escape(phone) + 
		"&param4=" + escape(mailFor) + 
		"&param5=" + escape(regard) + 
		"&param6=" + escape(text));
	}

}*/

// No need to touch this code
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;
}
var http = getHTTPObject(); // We create the HTTP Object


/*
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=400,left = 376,top = 282');");
}*/