Date.firstDayOfWeek = 7;
Date.format = 'mm/dd/yyyy';

jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};

function formatItem(row) {
	return row[0];
}

$(document).ready(function() {
	$('.date-pick').datePicker();
	$('.dptr').dpSetPosition($.dpConst.POS_TOP, $.dpConst.POS_RIGHT).click(function() {
		if ($(this).val() == 'MM/DD/YYYY') $(this).val('');
	});
	$('#svalue').focus(function() {
		if($(this).val() == 'Enter a store \'Amazon.com\' or keyword \'shoes\'...') $(this).val('');
	}).blur(function() {
		if($(this).val() == '') $(this).val('Enter a store \'Amazon.com\' or keyword \'shoes\'...');
	});
	$('#ssubmit').click(function() {
		if($('#svalue').val() == 'Enter a store \'Amazon.com\' or keyword \'shoes\'...') return false;
		else $('#sform').submit();
	});
	$('#uname').focus(function() {
		if($(this).val() == 'username') $(this).val('');
	}).blur(function() {
		if($(this).val() == '') $(this).val('username');
	});
	$('#upass').focus(function() {
		if($(this).val() == 'password') $(this).val('');
	}).blur(function() {
		if($(this).val() == '') $(this).val('password');
	});
    var optionscpn = {
        target: '#cpnstat',
		beforeSubmit: function() {
			$("#cpnfield").slideFadeToggle();
			$("#cpnstat").html("<img src=\"/images/ajax_loader.gif\" /> Submitting. Please Wait...").slideFadeToggle();
		}
	}
	$("#cform").submit(function() {
		$(this).ajaxSubmit(optionscpn);
		return false;
	});
	if ($("#mcoup").text().indexOf("no coupons") > -1 || $("#mdeals").text().indexOf("no deals") > -1) {
		$("#mdeals").css({clear:"both","margin-left":"0"}).width(660);
		$("#mcoup").css({clear:"both","margin-right":"0"}).width(660);
	}
//	$.clipboardReady(function(){
//		$(".c2c").click(function(){
//			$.clipboard($(this).attr("ccode"));
//			var linkr = 'http:\/\/www.smashdeals.com'+$(this).attr('href');
//			$(this).fadeIn("slow").css({"color":"red","background":"#FF6"}).text("Code Copied!");
//			setTimeout("window.open('"+linkr+"','')", 1150);
//			return false;
//		});
//	});
	$("a[id^='cz'],a[id^='cx']").click(function(){
		var sid = $(this).attr("id").substring(2);
		var ccode = $("#cx"+sid).attr("ccode");
		var linkr = 'http:\/\/www.smashdeals.com'+$(this).attr('href');
		if ($("#cx"+sid).text() == "Click to View") $("#cx"+sid).hide().css({"color":"red"}).text(ccode).fadeIn("slow");
		setTimeout("window.open('"+linkr+"','')", 1200);
		return false;
	});
	$("#addni,#addcpnlbl,#adddellbl").click(function() {
		$("#addnif").slideFadeToggle("slow");
	});
	$("#addnis").autocomplete(
		"/ajax_res_stores.php",
		{
			delay:10,
			minChars:2,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			formatItem:formatItem,
			autoFill:false
		}
	);
	$("#addnis").result(function(event, data, formatted) {
		var sValue = data[1];
		$("#storeid").val(sValue);
	});
});