// JavaScript Document
var ie4 = false;
if (document.all) { ie4 = true; }
function getObject(id) {
    if (ie4) { return document.all[id]; }
    else { return document.getElementById(id); }
}

//Create a boolean variable to check for a valid MS instance.
var xmlhttp = false;

//Check if we are using IE.
try { //If the javascript version is greater than 5.
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) { //If not, then use the older active x object.
    try { //If we are using IE.
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) { //Else we must be using a non-IE browser.
        xmlhttp = false;
    }
}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    xmlhttp = new XMLHttpRequest();
}

function myAjaxPost(source, destination, params, ondone) {
    var obj = getObject(destination);
    xmlhttp.open("POST", source, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if (ondone != null) ondone(xmlhttp.responseText);
			else obj.innerHTML = xmlhttp.responseText;
        } else if (xmlhttp.readyState == 4 && xmlhttp.status == 500) {
            obj.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.send(params);
}

var currentBanner = 1;
var bannersPlaying = true;
function rotateIn(newBannerNum) {
	if (newBannerNum != currentBanner) {
		
		$("#banner"+currentBanner).fadeOut(500);
		//$("#banner"+newBannerNum).css("left", "-1024px");
		$("#banner"+newBannerNum).css("opacity", "0");
		$("#banner"+newBannerNum).css("display", "block");
		//$("#banner"+newBannerNum).animate({opacity: 1.0, left: '+=1024px'}, 600, function () {});
		$("#banner"+newBannerNum).animate({opacity: 1.0}, 600, function () {});
		
		$("#bannerButton"+currentBanner).toggleClass("active");
		$("#bannerButton"+newBannerNum).toggleClass("active");
		currentBanner = newBannerNum;
	}
}

function rotateInClick(newBannerNum) {
	bannersPlaying = false;
	rotateIn(newBannerNum);
	return false;
}

function playTheBanners () {
	if (bannersPlaying) {
		var nextBanner = currentBanner + 1;
		if (currentBanner == 6) nextBanner = 1;
		rotateIn(nextBanner);
		setTimeout("playTheBanners()", 8000);
	}
}

function submitTheForm() {
	$("#loading").show();
	$("#responseArea").slideUp(500);
	setTimeout("submitTheForm2()", 500);
}

function submitTheForm2() {
	var myParams = "";
	myParams += "name=" + escape($("#name").val());
	myParams += "&position=" + escape($("#position").val());
	myParams += "&company=" + escape($("#company").val());
	myParams += "&city=" + escape($("#city").val());
	myParams += "&state=" + escape($("#state").val());
	myParams += "&zip=" + escape($("#zip").val());
	myParams += "&email=" + escape($("#email").val());
	myParams += "&phone=" + escape($("#phone").val());
	myParams += "&typeofContactForm=" + escape($("#typeOfContactForm").val());
	myParams += "&message=" + escape($("#message").val());
	//myParams += "&country=" + escape($("#country").val());
	//myParams += "&preferred_method_of_contact=" + escape($("#preferred_method_of_contact").val());
	//if ($("#preferred_method_of_contact_email").is(":checked")) myParams += "&preferred_method_of_contact=email";
	//else if ($("#preferred_method_of_contact_phone").is(":checked")) myParams += "&preferred_method_of_contact=phone";
	//myParams += "&subject=" + escape($("#subject").val());
	myAjaxPost("/ajaxContactForm.aspx", "contactFormForm", myParams, function(responseText) {
		$("#loading").hide();
		if (responseText.indexOf("success") > 0) {
			// process successful thingy
			$("#successResponseArea").html(responseText);
			$("#contactForm").css("height", $("#contactForm").height());
			$("#contactFormForm").fadeOut(500);
			$("#successResponseArea").fadeIn(500);
			setTimeout("$.modal.close()", 2000);
		} else {
			// process oops thingy
			if (responseText.indexOf("Please enter your name") > 0) $("#name").css("background-color", "#ffcccc"); 
			else $("#name").css("background-color", "#eff1f3"); 
			if (responseText.indexOf("company name") > 0) $("#company").css("background-color", "#ffcccc"); 
			else $("#company").css("background-color", "#eff1f3"); 
			if (responseText.indexOf("city") > 0) $("#city").css("background-color", "#ffcccc"); 
			else $("#city").css("background-color", "#eff1f3"); 
			if (responseText.indexOf("state") > 0) $("#state").css("background-color", "#ffcccc"); 
			else $("#state").css("background-color", "#eff1f3"); 
			if (responseText.indexOf("zipcode") > 0) $("#zip").css("background-color", "#ffcccc"); 
			else $("#zip").css("background-color", "#eff1f3"); 
			if (responseText.indexOf("email address") > 0) $("#email").css("background-color", "#ffcccc"); 
			else $("#email").css("background-color", "#eff1f3"); 
			if (responseText.indexOf("phone number") > 0) $("#phone").css("background-color", "#ffcccc"); 
			else $("#phone").css("background-color", "#eff1f3"); 
			$("#responseArea").html(responseText);
			$("#responseArea").slideDown(500);
		}
	});
}

