﻿// JScript 文件

//参数页面不同
var page="";

$(
    function() {
// 设置默认时间 线上环境可以使用服务器端时间
				var d = new Date();
				var to_date = d.getDate();
				var to_month = d.getMonth() + 1;
				var to_year = d.getFullYear();
				d.setDate(d.getDate() + 1);
				var tomo_date = d.getDate();
				var tomo_month = d.getMonth() + 1;
				var tomo_year = d.getFullYear();
				
				var newd = null;
				
				if($('#date1')[0].value =="")
				{
				    $('#date1').val( to_year + '-' + ((to_month < 10) ? '0' + to_month : to_month) + '-' + ((to_date < 10) ? '0' + to_date : to_date));
				    $('#date2').val( tomo_year + '-' + ((tomo_month < 10) ? '0' + tomo_month : tomo_month) + '-' + ((tomo_date < 10) ? '0' + tomo_date : tomo_date));
				    newd = new Date();
				}
				else
				{
//				    var stmp = $('#date1')[0].value;
//				    var arr = stmp.split('-');
//				    newd = new Date(arr[0],(parseInt(arr[1]) - 1).toString() ,arr[2]);
                    newd =new Date();
				}
				
				// 日历 
				$('#date1, #date2').datepicker({dateFormat : 'yy-mm-dd', numberOfMonths: 2, showAnim:'', minDate: newd, dayNames: ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'], monthNames : ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], monthNamesShort:['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], 
				onSelect : function (dateText, inst) { 
					if (inst.id == 'date1') {
					    if(page !="modify_my_order")
					    {
						    window.setTimeout("$('#date2').focus();", 10);
						}
						//Date1后续处理
						afterDate1Fun();
					}
					if(inst.id == 'date2'){
					    //Date2后续处理
					    afterDate2Fun();
					}
				}, beforeShow : function ( input ,inst ) {
					if (inst.id == 'date2') {
						var tmp_d = new Date();
						tmp_d.setDate(1); 
						tmp_d.setFullYear($('#date1').datepicker('getDate').getFullYear());
						tmp_d.setMonth($('#date1').datepicker('getDate').getMonth());
						tmp_d.setDate($('#date1').datepicker('getDate').getDate() + 1);
						$('#date2').datepicker('option', 'minDate', tmp_d);
					}
					

				},onClose :function(dateText, inst){
				    //Date2后续处理
					afterDate2Fun();
				}
				});


	    // 自动完成效果
	    /*var o_top,o_left = 0;
        if($.browser.msie) {
		    o_left = -188;
		    o_top = 16;
	    } else {
		    o_left = 0;
		    o_top = 0;
	    }
	    $('#city').autocomplete('city.php', {minChars: 0, max:20, scroll: false, width: 192,
	    clickDo: function () {$('#city_select').show();},
	    blurDo : function () {$('#city_select').fadeOut();},
	    beforeShow : function () {$('#city_select').fadeOut();},
	    afterClose : function () {$('#city_select').fadeOut();}
	    });
	    $('#city').click(function () {$('#city_select').show();});
	    $('#keyword').autocomplete('keyword.php', {minChars: 0, max:20, scroll: false, width: 192,
	    clickDo: function () {$('#keyword_select').show();},
	    blurDo : function () {$('#keyword_select').fadeOut();},
	    beforeShow : function () {$('#keyword_select').fadeOut();},
	    afterClose : function () {$('#keyword_select').fadeOut();}
	    });
	    $('#keyword').click(function () {$('#keyword_select').show();});
	    $('#city_select a').click(function () {$('#city').val(this.innerHTML)});
	    $('#keyword_select a').click(function () {$('#keyword').val(this.innerHTML);});*/

	    // 输入提示效果
        $('input[title]').each(function() {
            if($(this).val() === '') {
                $(this).val($(this).attr('title'));
            }
            $(this).focus(function() {
                if($(this).val() == $(this).attr('title')) {
                    $(this).val('').addClass('focused');
                }
            });
            $(this).blur(function() {
                if (!$(this).hasClass('focused')) {
                    $('#info').dialog('close');
                }
                if($(this).val() === '') {
                    $(this).val($(this).attr('title')).removeClass('focused');
                }
            });
        });    
     });
     
     function afterDate1Fun()
     {
        try
        {
            Date1Fun();
            return;
        }
        catch(Err)
        {
            return;
        }
     }
     
     function afterDate2Fun()
     {
        try
        {
            Date2Fun();
            return;
        }
        catch(Err)
        {
            return;
        }
     }
