/*
 * Date Format 1.2.3
 * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
 * MIT license
 *
 * Includes enhancements by Scott Trenda <scott.trenda.net>
 * and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

function convertDate(orgDate){
	var mydate = new Date(orgDate);
	
	return mydate;	
}


function filterDates(){
	
	var minDate = $('#min').val();
	var maxDate = $('#max').val();
	
if (minDate == null || minDate == ''){
	minDate = '01/01/1900';
}

if (maxDate == null || maxDate == ''){
	maxDate = '12/31/2079';
}
	
$('#tblMyWarranties').find('td.date').each(function(i){
													
	var text = $(this).html();
	var newdate = convertDate(text);
   
	 
	var x = Date.parse(newdate);
	var maxdate = Date.parse(maxDate);
	var mindate = Date.parse(minDate);
	
	

	
	if (x > maxdate || x < mindate){
	   
		$(this).parent().hide();	
	}
	else{
		$(this).parent().show();
	}

});




}
function isDate(str)
	    {
		    var regex = /^((0?[13578]|10|12)(-|\/)((0[0-9])|([12])([0-9]?)|(3[01]?))(-|\/)((\d{4})|(\d{2}))|(0?[2469]|11)(-|\/)((0[0-9])|([12])([0-9]?)|(3[0]?))(-|\/)((\d{4}|\d{2})))$/;
		    return regex.test(str);
	    }
function setScrollingDiv(){
 var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
  if (!msie6 && $('#totals_control').length) {
    var top = $('#totals_control').offset().top - parseFloat($('#totals_control').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('#totals_control').addClass('fixed');
      } else {
        // otherwise remove it
        $('#totals_control').removeClass('fixed');
      }
    });
  } 
}



function sorting(){

var ascImg = '<a <img class="sortBtn" src=\"../App_Themes/images/buttons/sort_asc.png\"/></a>';
var descImg = '<a <img class="sortBtn" src=\"../App_Themes/images/buttons/sort_desc.png\"/></a>';

var ascImg2 = '<img class="sortBtn" src=\"../App_Themes/images/buttons/sort_asc.png\"/>';
var descImg2 = '<img class="sortBtn" src=\"../App_Themes/images/buttons/sort_desc.png\"/>';
    

    if ($('th.sorting_desc').length){
        $('th.sorting_desc').find('a').remove();
        $('th.sorting_desc').append(descImg);
  
    }
    if ($('th.sorting_asc').length){
     $('th.sorting_asc').find('a').remove();
       $('th.sorting_asc').append(ascImg);
    }
    if ($('th.sorting').length){
    
     $('th.sorting').find('a').remove();
        $('th.sorting').append(descImg);
    }
    

}

function aboutTabs(){
	
	$('#tab1').click(function () {
		$('#tabContent1').show();
		$('#tabContent2').hide();
		$('#tabContent3').hide();
		$('#tabContent4').hide();
		
		$('#tab1').addClass('active');
		$('#tab2').removeClass('active');
		$('#tab3').removeClass('active');
		$('#tab4').removeClass('active');
		

	});
$('#tab2').click(function () {
		$('#tabContent2').show();
		$('#tabContent1').hide();
		$('#tabContent3').hide();
		$('#tabContent4').hide();
		
		$('#tab2').addClass('active');
		$('#tab1').removeClass('active');
		$('#tab3').removeClass('active');
		$('#tab4').removeClass('active');

	});
$('#tab3').click(function () {
		$('#tabContent3').show();
		$('#tabContent2').hide();
		$('#tabContent1').hide();
		$('#tabContent4').hide();
		
		$('#tab3').addClass('active');
		$('#tab2').removeClass('active');
		$('#tab1').removeClass('active');
		$('#tab4').removeClass('active');

	});
$('#tab4').click(function () {
		$('#tabContent4').show();
		$('#tabContent2').hide();
		$('#tabContent3').hide();
		$('#tabContent1').hide();
		
		$('#tab4').addClass('active');
		$('#tab2').removeClass('active');
		$('#tab3').removeClass('active');
		$('#tab1').removeClass('active');

	});
}

function changeHomePageClass(){
if ($('#homeFlash').length)
    {
        $('body').addClass('home')
       
    }
else {
        $('body').removeClass('home');
       
    }
}

function changeActiveTabs(){
	
var pathname = window.location.pathname;

if (pathname.indexOf("Company") >= 0)
    {
        $('.primaryNav li.nav_06').addClass('active')
        $('.primaryNav li.nav_05').removeClass('active')
    }
else if (pathname.indexOf("Why-2-10") >= 0){
         $('.primaryNav li.nav_05').addClass('active')
        $('.primaryNav li.nav_06').removeClass('active')
       
    }
}

function alertOverlay() {
	
var win = $(window).width();

if (win < 1125){
	$("#primaryNavContainer").css("width", 1125);
$("#frame").css("width", 1125);
$("#homeFlashContainer").css("width", 1125);
$("#footerHomeContainer").css("width", 1125);
}
else{

$("#primaryNavContainer").css("width", win);
$("#frame").css("width", win);
$("#homeFlashContainer").css("width", win);
$("#footerHomeContainer").css("width", win);
}
           
        //var windowWidth = document.documentElement.clientWidth;
       
       
           
          //  $("#frame").css({
//                    "width": 100,
//                   
//            });
           
//            var frameWidth = $("#frame").width();
//            //alert(frameWidth);
//           
//            $("#footerHome").css({
//                    "width": frameWidth
//            });
           


           
           
        }

function animateBar() {


        // Setup
        var bar = $('#slider');



        bar.css('background-position', '0px 0px');



        bar.animate({
                backgroundPosition: '-2200px 0px'


        }, 100000, 'linear', function() {


                animateBar();
        });
}


		
//when the DOM is ready
$(document).ready(function(){	
						   
$('#homeSlider').easySlider({
				continuous: true,
				prevId: 'homeSlider_prev',
				nextId: 'homeSlider_next',
				prevText:'<img src="App_Themes/Homepage/images/hero/arrow_left.png" alt="Scroll Left" width="35" height="35" />',
				nextText:'<img src="App_Themes/Homepage/images/hero/arrow_right.png" alt="Scroll Right" width="35" height="35" />'
			});
			setInterval("jQuery('#homeSlider_next a').click()", 8000);
			
			var run = setInterval("jQuery('#homeSlider_next a').click()", 8000);
							
			//Mouse over, pause it, on mouse out, resume the slider
			$('#homeSlider').mouseover(
				function() {
				clearInterval(run);
			});
		
			$('#homeSlider').mouseout(
				function() {
				
				run = setInterval("jQuery('#homeSlider_next a').click()", 8000);
			});
			
			$(".navImage img").mouseover(function()
			{
				$(this).animate({top:"-=10px"},200).animate({top:"+=10px"},200);
			});		
			
			$(".homeHeroNavItem p").hover(function () {
				$(this).css({'color' : '#e1d39a', 'font-weight' : 'bolder'});
				}, function () {
				var cssObj = {
				  'color' : '#fff'
				}
				$(this).css(cssObj);
			});
			
			$('.navIcon p').hover(function() {
				$(this).css({'color' : '#fff'});
				$(this).toggleClass('showSelected');
				$('.navIcon p').text("+");
				$('.navIcon p.showSelected').text("-");
			});
	
			$("div.homeHeroNavItem").click(function () {
				$(this).children('div.showNav').toggle("slide", { direction: "down" }, 500);
			});
			
			$(".close").click(function () {
				  $(this).parent('div.showNav').toggle("slide", { direction: "down" }, 500);
			});						   
						   
						   
	animateBar();
alertOverlay();	
//$(body).onresize = function (){
// alertOverlay();
//}

$(window).resize(function() {
alertOverlay();
});

			 						   
	changeActiveTabs();
	changeHomePageClass();

	//Jquery PNG fix					   
	$(document).pngFix(); 
	$("#HST").easySlider({
		continuous: true,
		prevId: 'HST_prev',
		nextId: 'HST_next'
	});
	$("#DYK").easySlider({
		continuous: true,
		prevId: 'DYK_prev',
		nextId: 'DYK_next'
	});
	
	$("#TSML").easySlider({
		continuous: true,
		prevId: 'TSML_prev',
		nextId: 'TSML_next'
	});
	
	
	
	$('#convertPopup').hide();
	$('#convertLinkPopup').click(function () {
		$('#convertPopup').show();

	});
	
	$('#convertPopupClose').click(function () {
		$('#convertPopup').hide();

	});
	
	
	
	$('.paginate_button').click(function () {
		var mindate = $('#min').val();
		var maxdate = $('#max').val();
		filterDates(mindate, maxdate);

	});
	
	$('a.statusTip').click(function () {
		$(this).next('div.asdf').slideToggle(10);
		$('div.asdf').hide();
	});
	
	
	
	$('a.statusTipClose').click(function () {
		$('div.asdf').hide();
	});
	
	$('.contentColManageRight h3 a.propertyOwnerLink').click(function () {
		$(this).hide();
		$('div.propertyOwnerEdit').toggle();
		$('div.propertyOwnerInfo').toggle();
	});
	
	$('.contentColManageRight .cancelUpdate').click(function () {
		$('a.propertyOwnerLink').show();
		$('div.propertyOwnerEdit').toggle();
		$('div.propertyOwnerInfo').toggle();
	});
	
	$('.mainTable tr:even').addClass('alt'); 
	$('.leftTable tr:even' ).addClass('alt'); 
	
	//$('#tblOptions tr:odd' ).addClass('alt'); 
	
	$('.mainTable td').addClass('border');
	$('.mainTable tr').find('td:last').removeClass('border');
	
	$('.mainTable tr td:last').addClass('last');

	
	    
	
		  
	 });	

