﻿/// <reference path="/shared/jQuery.intellisense.js" />

// enable ABBR for IE
//document.createElement("abbr");



// let's be unobtrusive, shall we?	
$(document).ready(function(){ 
    if (dotIR != null) {
        dotIR.replaceElement ("h1", "BLACK", "transparent", 410, "left", 58, "LunaITC.ttf");
		dotIR.replaceElement ("h2", "BLACK", "transparent", 300, "left", 36, "LunaITC.ttf");
		dotIR.replaceElement ("h4", "BLACK", "transparent", 300, "left", 27, "LunaITC.ttf");
    }
  
   
	// more links
	$('DL.more').mouseup(function() {
		// if(this.tagName=='A'){return false}; // TODO: make this exception work
		$('DT', this).html($('DT', this).html()!='«' ? '«' : '»');
		$('DT', this).attr('title', $('DT', this).attr('title')!='hide this' ? 'hide this' : 'show more');
		$('DD', this).toggle();
		return false;
	});

  $("#frmContact").addClass("jqmWindow");
	$('BODY').addClass('js');
	$('DL.more>DD').hide();
	$('DL.more>DT').show();





	$('#from').focus(function(){
		activateField(this);
		validateSubmit();
	});
	$('#from').blur(function(){
		initField(this);
		validateSubmit();
	});
	$('#body').focus(function(){
		activateField(this);
		validateSubmit();
	});
	$('#body').blur(function(){
		initField(this);
		validateSubmit();
	});

	$('#from').blur();
	$('#body').blur();
	validateSubmit();



	$('.jqmWindow').jqm();  //initialize jqModal
  
  
  $('FORM#frmContact').submit(function() { 
		$('FORM#frmContact, FORM#frmContact *').css('cursor', 'wait');
		$('#frmContactMsg').html('Sending message.  Please wait...');
		$(this).ajaxSubmit(function(data) { 
			if(data.toString().substring(0,7)=='SUCCESS'){		// thanks & close
				$('#frmContactMsg').html('Message sent.  Thanks!');
				window.setTimeout("	$('#frmContactMsg').html('');  $('.jqmWindow').jqmHide()	", 1500);
			}else if(data.toString().substring(0,2)=='UCE'){		// handle
				$('#frmContactMsg').html('No thanks, we\'ve had enough spam.');
				window.setTimeout("	$('#frmContactMsg').html('');  $('.jqmWindow').jqmHide()	", 1500);
			}else{									// server email failed, offer mail link
				var htmlLink = ' <a href="mai'+'lto\:www' + '@' + 'slingfive\.com\?body\=' + $('#body').val() + '">Please try email.</a>';
				g_lastErrMsg = data;
				var htmlDebug = ' <a href="#debug" onclick="alert(g_lastErrMsg)" title="debug" style="float:right;">.<a/>';
				$('#frmContactMsg').html('Sorry, I couldn\'t send your message.&nbsp; ' + htmlDebug + htmlLink);
			}
			$('FORM#frmContact, FORM#frmContact *').css('cursor', '');
			return false; 
		}); 
		return false; 
	});
  
  
});




function activateField(f){
	if(f.value==f.defaultValue){
		f.value = '';
		f.style.color = '#000';
	}else{
		f.select();
	}
}

function initField(f){
	if(f.value=='' || f.value==f.defaultValue){
		f.value = f.defaultValue;
		f.style.color = '#666';
	}
}


function validateSubmit(){
	var oFrom = $('#from');
	var oBody = $('#body');	
	var bNotReady = (
		oFrom.val()=='' || oFrom.val()==oFrom.attr('defaultValue') 
		|| 
		oBody.val()=='' || oBody.val()==oBody.attr('defaultValue')
	);
	$('#btnSubmit').attr('disabled', bNotReady);
	$('#btnSubmit').css('color', bNotReady ? '#999' : '#33c');

}

