function addEvent( obj, type, fn ) {
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function old_browser() {
	var ie6 = document.all && /MSIE\s?6/.test(navigator.userAgent)
	var ie7 = document.all && /MSIE\s?7/.test(navigator.userAgent)
	var ie8 = document.all && /MSIE\s?8/.test(navigator.userAgent)
	var quirksmode = document.compatMode == "BackCompat"
	return ie6 || ((ie7 || ie8) && quirksmode)
}

var jltmobile = {
	get_fixed_style: function() {
		style = ""
		if (old_browser()) {
			style = "position: absolute;";
		}
		else {
			style = "position: fixed;";
		}
		return style
	},
	slug: "http://jltmobile.zendesk.com/external/zenbox/index?x=5&set_tags=dropbox%2C%20ask_us",
	create_box: function() {
	    if (!document.getElementById("jltmobile_container")){
			var body = document.getElementsByTagName("body")[0];
			var jltmobile_container = document.createElement('div');
			jltmobile_container.id = "jltmobile_container"
			body.appendChild(jltmobile_container);

			jltmobile.create_overlay(jltmobile_container, body);
			jltmobile.create_frame(jltmobile_container);
		}
		else {
			document.getElementById("jltmobile_container").style.display = "block";
		}
	},
	create_overlay: function(jltmobile_container, body) {
		var style =
			"top: 0; bottom:0; min-height:400px; left: 0;" +
			"background: #000; filter: alpha(opacity=50); opacity: 0.5; z-index: 1000; width: 100%;";
		style += jltmobile.get_fixed_style()
		if (old_browser()) {
			var body_height = Math.max(document.body.clientHeight,
									   document.documentElement.clientHeight);
			style += "height:" + body_height + "px;";
		}
		jltmobile_container.innerHTML +=
			'<div id="jltmobile_overlay" style="' + style + '"></div>';
	},
	create_button: function() {
		var body = document.getElementsByTagName("body")[0];
		var jltmobile_button_container = document.createElement('div');
		jltmobile_button_container.id = "jltmobile_button_container"
		body.appendChild(jltmobile_button_container);

		var style =
			"top: 200px; left: 0; z-index: 999; cursor: pointer;";
		style += jltmobile.get_fixed_style()

		
			jltmobile_button_container.innerHTML +=
				'<img src="http://www.jltmobile.com/jlt/sd_files/askus_flik.jpg" ' +
				'alt="" id="jltmobile_feedback" style="' + style + '" onclick="jltmobile.create_box()">';
		

	},
	create_frame: function(jltmobile_container) {
		var style =
			"top: 15px; left: 50%; margin-left: 279px; " +
			"height: 22px; width: 23px; cursor: pointer; z-index:1100;";
		style += jltmobile.get_fixed_style()
		jltmobile_container.innerHTML +=
			'<img src="http://www.jltmobile.com/jlt/sd_files/close.png" alt="" ' +
			'id="jltmobile_close" style="' + style + '" onclick="jltmobile.hide_iframe()">';
	        
                if (old_browser()) {	
		var style2 ="background-color:#eeeeee; border-right: solid 2px #000; border-left: solid 2px #000; border-top: solid 2px #000; top: 40px; left: 50%; margin-left:-358px; height: 90px; width: 660px; z-index:1100;";
	}else {
	var style2 ="background-color:#eeeeee; border-right: solid 2px #000; border-left: solid 2px #000; border-top: solid 2px #000; top: 40px; left: 50%; margin-left:-358px; height: 90px; width: 656px; z-index:1100;";
		}
               
                style2 += jltmobile.get_fixed_style();	

		var innerHTMLText = '<div style="'+style2+'"><br><span class="TITLE" style="padding-left:20px;color:#000;">Ask Us</span><br><span class="NORMAL" style="padding-left:20px;">If you have any questions</span> <br/><span class="NORMAL" style="padding-left:20px;">to us at JLT Mobile Computers feel free to submit them through this Dropbox. We </span><br/><span class="NORMAL" style="padding-left:20px;">will make sure that the right person gets back to you as soon as possible.</span></div>';	
		if (old_browser()) {
			innerHTMLText = innerHTMLText.replace('position: fixed;','position:absolute !important;');
		}
		
		jltmobile_container.innerHTML += innerHTMLText;

		if (old_browser()) {	
			var iframeHTML = ' <iframe src="http://jltmobile.zendesk.com/external/zenbox/index?x=5&set_tags=dropbox%2C%20ask_us" id="jltmobile_iframe" scrolling="no" frameborder="no"    style="border: none;    height: 342px;    left: 50%;    margin-left: -358px;    position: fixed;    top: 130px;    width: 660px;    z-index: 2000;"></iframe>'
		}else {
			var iframeHTML = ' <iframe src="http://jltmobile.zendesk.com/external/zenbox/index?x=5&set_tags=dropbox%2C%20ask_us" id="jltmobile_iframe" scrolling="no" frameborder="no"    style="border: none;    height: 355px;    left: 50%;    margin-left: -358px;    position: fixed;    top: 130px;    width: 660px;    z-index: 2000;"></iframe>'
		}
		if (old_browser()) {
			iframeHTML = iframeHTML.replace('position: fixed;','position:absolute !important;')
		}
		jltmobile_container.innerHTML += iframeHTML;
	},
	hide_iframe: function() {
		var element = document.getElementById("jltmobile_container");
		if (element) {
			element.parentNode.removeChild(element);
		}
	},
	init: function() {
		jltmobile.create_button();
	},

	check_close: function(e) {
		var evt = e || window.event;
		if (evt && evt.keyCode == 27) {
			jltmobile.hide_iframe();
		}
	}
}

addEvent(window, 'load', jltmobile.init)
addEvent(document, 'keydown', jltmobile.check_close)
