$(document).ready(function(){
		
	if($("#notes_from_dealstork").length >0){
		$("#notes_from_dealstork").jScrollPane({showArrows:false,scrollbarWidth:15,dragMaxHeight:30,dragMinHeight:30});
	}

})





//function parses mysql datetime string and returns javascript Date object
//input has to be in this format: 2007-06-05 15:26:02
var mysqlTimeStampToDate = function(timestamp) {
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
	
	//console.log(timestamp);
	//console.log(parts);
	var d = new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
	//console.log(d.getFullYear());
    return d;
  }

var stillrunning = true;
function updateHomeDate(date1, date2) {
	diff  = new Date();
	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24);
	days = Math.floor(timediff / (1000 * 60 * 60 * 24));
	
	
	//timediff -= days * (1000 * 60 * 60 * 24);
	timediff -= days * (1000 * 60 * 60);
	
	hours = Math.floor(timediff / (1000 * 60 * 60));
	timediff -= hours * (1000 * 60 * 60);
	mins = Math.floor(timediff / (1000 * 60));
	timediff -= mins * (1000 * 60);
	secs = Math.floor(timediff / 1000);
	timediff -= secs * 1000;
	
	if (stillrunning) {
		//$("#deal_days").html(days);
		$("#deal_hours").html(hours);
		$("#deal_minutes").html(mins);
		$("#deal_seconds").html(secs).hide();
		$('#deal_seconds').fadeIn("fast");
	}	
	if(days==0 && hours==0 && mins==0 && secs <=1){
		stillrunning = false;
		clearInterval(dealTimer);
		alert("This Deal is Over! Sorry, ya missed it!");
		location.href = "/";
	}
}

function checkEmail(email) {
var filter = /^([a-zA-Z+0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email)) {
	return false;
}else{
	return true;
}
}


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;
}
