// BEGIN DOM
$(document).ready(function()
{
	//Dropdown function
	$('#nav').droppy();
	// Tiger Stipe table
	$('tr').filter(':odd').addClass('odd');
    $('tr:even').addClass('even');
    $('td').addClass('check');
	
	// make sure the last element does not show the hr
	$('.executiveHR:last').css('display','none');
	
	
	// image slider
	$('div.html, div.jquery').next().css('display', 'none').end().click(function() {
		$(this).next().toggle('fast');
	  });
	$('a.false').click(function() {
		return false;
	  });
	
	//Facebox lightbox effect
	$('a[rel*=facebox]').facebox();
	
	// Any link with the rel of backlink will go back history -1
	$('a[rel="backlink"]').click( function() {
		parent.history.back(-1);		
        return false;
    });
	
	// Any External Link will open up a new window.
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
	// Will handle any PDF to open up without sending you to a new page	
	$("a[href*=.pdf]").click(function(){
		window.open(this.href);
		//$(this).attr({"target":"_self"});
		return false;
	});
	
	// tooltip
	//$.cluetip.setup({insertionType: 'insertBefore', insertionElement: 'div:first'});
 
	//default theme
	  $('a.title').cluetip({splitTitle: '|'});
	  $('a.basic').cluetip();
	  $('a.custom-width').cluetip({width: '200px', showTitle: false});
	  $('h4').cluetip({attribute: 'id', hoverClass: 'highlight'});
	  $('#sticky').cluetip({'sticky': true,'closePosition': 'title'});
	  $('#examples a:eq(5)').cluetip({
		hoverClass: 'highlight',
		sticky: true,
		closePosition: 'bottom',
		closeText: '<img src="cross.png" alt="close" width="16" height="16" />',
		truncate: 60
	  });
	  $('a.load-local').cluetip({local:true, hideLocal: false, arrows: true, cursor: 'pointer'});
	  $('#clickme').cluetip({activation: 'click', width: 650});
	  
	  $("a[href*=.pdf]").click(function()    {
      	$(this).attr({"target":"_self"});
      	 return false;});
	
	
	// VALIDATE : DOWNTIME CALCULATOR SO ALL VALUES ARE REQUIRED
	$("#downtime_calculator").validate({
		rules: {
			Office_RSF: "required",
			Employees: "required",
			employee_cost: "required",
			expected_downtime:"required"
		},
		messages: {
			Office_RSF: "",
			Employees: "",
			employee_cost: "",
			expected_downtime: ""
		}
	});
	$("#calculate").click(downtimeCalculator);
	
	
	// Creating spam fighting emails
	$('#email_e').spemail('|,:','mailbase');
	
	
	
	


}); // END DOM


// Confirm the click...to make sure that there are no mistakes
function confirmTheClick($iName)
{
	var agree="Are you sure you wish to perform this action?\nCheck your work!";
	if ( confirm( agree ) )
		return true;
	else
		return false;
}
// Safety feature to make sure nobody clicked on delete by mistake.
function confirmDelete($iName)
{
	var agree=confirm("Are you sure you wish to delete?\nThis CANNOT be undone Name!");
	if (agree)
		return true;
	else
		return false;
}
function displayState(titleValue)
{
   document.getElementById("txtStateName").innerHTML = titleValue
}

function downtimeCalculator()
{
	var rsf;
	var emp;
	var emp_cost;
	var ex_dtime;
	var sub_total;
	var total;
	var sub_dtwages;
	var dtwages;
	var sub_psf;
	var psf;
	rsf = parseInt($("#Office_RSF").val().replace(/\,/g,''));
	emp = parseInt($("#Employees").val().replace(/\,/g,''));
	emp_cost = parseInt($("#employee_cost").val().replace(/\,/g,''));
	ex_dtime = parseInt($("#expected_downtime").val().replace(/\,/g,''));
	sub_dtwages = Math.round( ((emp * emp_cost)/260) * ex_dtime);
	dtwages = numberFormat(sub_dtwages.toFixed(2),"$");
	sub_psf = (sub_dtwages / rsf);
	psf = numberFormat(sub_psf.toFixed(2),"$");
	
	function numberFormat(nStr,prefix)
	{
		var prefix = prefix || '';
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1))
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		return prefix + x1 + x2;
	}
	
	$(".form_result").html("<strong>"+dtwages+" | "+psf+" psf/yr</strong>");
	return false;
}



