var xmlHttp

function GetXmlHttpObject()  {
	xmlHttp=null;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function exec()
{
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}

	xmlHttp.onreadystatechange=stateChanged

	var url = terminal.ajaxurl;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function stateChanged()
{
	switch(xmlHttp.readyState) {

		case 1:
		break;

		case 2:
		break;

		case 3:
		break;

		case 4:
			terminal.method();
		break;

	}
}

// initiate object funciton
function terminalObject() {
	this.init = true;
}

// create object
terminal = new terminalObject;

function subscribe(option) {


	day = new Date();
	id = day.getTime();

	var email = document.getElementById("email").value;
	var fname = document.getElementById("fname").value;
	var lname = document.getElementById("lname").value;
	var acode = document.getElementById("acode").value;
	var phone1 = document.getElementById("phone1").value;
	var phone2 = document.getElementById("phone2").value;
	var state = document.getElementById("state").value;
	var text = encodeURI( document.getElementById("text").value );
	
	
	if(checkEmail(email)) {

	document.getElementById("form"+option).innerHTML = '<div align="center"><br /><br /><br /><span class="subsResponse"><img src="/img/ajax-loader.gif" alt="Loading..." align="middle" /></span></div>'
	terminal.ajaxurl = "/subscribe.php?fname="+fname+"&lname="+lname+"&acode="+acode+"&phone1="+phone1+"&phone2="+phone2+"&state="+state+"&desc="+text+"&email="+email+"&form="+option+"&sid="+id
	terminal.method = function() {
		document.getElementById("form"+option).innerHTML = '<div align="center"><br /><br /><br /><span class="subsResponse">Your Call Request Has Been Sent!</span></div>'
	}

	exec();
	}
}
function checkEmail( email)
    { var mailadr = email;
      var mailrgx = /^([\w-+]+[\.~'&=]?)*[\w-+]+@([^\W]+(\.|-)?)*[^\W]+\.[a-z]{2,6}$/i;

      if (mailadr.search( mailrgx) == -1)
      { alert( "Something's wrong with this email address. :( \n\n"+email);
        return false;
      }
      return true;
    }


  window.onresize = adjust;
  terminal.smallpage = false;
  function adjust() {
    var fade = document.getElementById('body');
    var bar = document.getElementById('bar');
    var footer = document.getElementById('bar');


	if(document.documentElement.clientWidth < 800) {
    	fade.style.width = document.body.parentNode.scrollWidth + 'px';
    	bar.style.width = document.body.parentNode.scrollWidth + 'px';
    	footer.style.width = document.body.parentNode.scrollWidth + 'px';
		terminal.smallpage = true;
	}
	else {
		if(terminal.smallpage) {
	    	fade.style.width = '100%';
	    	bar.style.width = '100%';
	    	footer.style.width = '100%';
			terminal.smallpage = false;
			}
	}
  }