AIM = {

	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
		f.submit();
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}

		function startCallback() {
			$('h2-block').innerHTML = 'Thank You';
			$('switch-block').setStyle('display', 'none');
			$('start').setStyle('display', 'none');
			$('progress_bar2').setStyle('display', 'block');								
			return true;
		}

		function completeCallback(response) {
		if (response=="invalidemail")
			{
				$('alert').removeClass('success');
				$('alert').addClass('error');								
				$('alert').setHTML("<span>The following information has to be corrected before you can get in touch with us:</span><ul><li>Your email address doesn't contain a valid format (E.g. user@domain.com)</li></ul>");
				$('alert').setStyle('display', 'block');				
				$('oemail').addClass('invalid');				
			}
			
		else
			{		
				$('alert').removeClass('error');
				$('alert').addClass('success');	
				$('alert').setStyle('display', 'block');								
				$('alert').setHTML(response);				
				$('orderForm').setStyle('display','none');
				
			}
		$('alert').setStyle('display', 'block');								
		$('start').setStyle('display', 'block');
		$('progress_bar2').setStyle('display', 'none');											
		}

window.addEvent('domready', function(){
updateTotal();
$('oname').addEvent('blur', function() {
										 	var a=$('oname').getValue();
											//document.forms[0].bname.value=a;
										 	});

$('oemail').addEvent('blur', function() {
										 	var a=$('oemail').getValue();
											//document.forms[0].bemail.value=a;
										 	});

$('oturnaround').addEvent('change', updateTotal);
$('osubpages').addEvent('change', updateTotal);
//$('ointegration').addEvent('change', updateTotal);

$('start').addEvent('click', function(e) {

	new Event(e).stop();
	$$('input').removeClass('invalid');
	$$('textarea').removeClass('invalid');				
	var oname=$('oname').getValue();
	var oemail=$('oemail').getValue();
	//var bcname=$('bcname').getValue();	
	//var bsa1=$('bsa1').getValue();		
	//var bcity=$('bcity').getValue();			
	//var bstate=$('bstate').getValue();		
	//var bzip=$('bzip').getValue();		
	if (oname=="" || oemail==""/* || bcname=="" || bsa1=="" || bcity=="" || bstate=="" || bzip==""*/)
		{
		$('alert').addClass('error');
		$('alert').removeClass('success');
		var msg="<span>The following information has to be corrected before you can get in touch with us:</span><ul>";
		if (oname=="")
			{
			msg = msg + "<li>You need to enter your name</li>";
			$('oname').addClass('invalid');
			}
		if (oemail=="")
			{
			msg = msg + "<li>You need to enter your email</li>";
			$('oemail').addClass('invalid');						
			}	
		/*
		if (bcname=="")
			{
			//msg = msg + "<li>You need to enter your company's name</li>";
			//$('bcname').addClass('invalid');						
			}						
		if (bsa1=="")
			{
			//msg = msg + "<li>You need to enter your street address</li>";
			//$('bsa1').addClass('invalid');						
			}									
		if (bcity=="")
			{
			//msg = msg + "<li>You need to enter your city</li>";
			//$('bcity').addClass('invalid');						
			}									
		if (bstate=="")
			{
			//msg = msg + "<li>You need to enter your state</li>";
			//$('bstate').addClass('invalid');						
			}									
		if (bzip=="")
			{
			//msg = msg + "<li>You need to enter your ZIP/postal code</li>";
			//$('bzip').addClass('invalid');						
			}	
		*/																											
		msg = msg + "</ul>";
		$('alert').setHTML(msg);
		$('alert').setStyle('display', 'block');

		return false;

		}
	else
		{		
		return AIM.submit($('orderForm'), {'onStart' : startCallback, 'onComplete' : completeCallback})
		}


});
}); 

var _total = 0

function updateTotal()
	{
		var a=$('oturnaround').getValue();
		var b=$('osubpages').getValue();
		//var c=$('ointegration').getValue();		
		if (a==1)
			{
				_total=350;
			}
		if (a==2)
			{
				_total=200;
			}
		_total += b*75;			

	/*switch(c)
		{
		case 'None':
			_total += 0;
			break;
		case 'EE':
			_total += 275;
			break;
		case 'TP':
			_total += 350;
			break;		
		case 'WP':
			_total += 300;
			break;					
		}
		*/
		msg="Total: $"+_total+" USD";
		$('total').setHTML(msg);
	}