/*var scrolling = function(obj,subobj,t1,t2){       /////// 由于ie bug,替换原有滚动显示js 2011.10.8 wzx
    var el = obj;
    this.getEl = function(){
        return el;
    }
    el.html(function(idx,html){
        return html + html;
    });
    this._offset = parseInt(el.height())/subobj.size()/2;
    this.t1 = t1;
    this.t2 = t2;
}
scrolling.prototype.start = function(delay){
    var el = this.getEl();
    var height = parseInt(el.height());
    if(el.css('top')=='auto'){
        el.css('top','0px');
    }
    var top = Math.abs(parseInt(el.css('top')));
    if(top>=height/2){
        el.css('top','0px');
    }
    top = parseInt(el.css('top'));
    var that = this;
    var fn = arguments.callee;
    setTimeout(function(){
        el.animate({top:top-that._offset+'px'},that.t1,function(){
            fn.call(that,that.t2);
        })
    },delay);
}*/

$(function(){
    var ScrollLeft = function(){
        var speed = 30;
        var scroll_begin = document.getElementById("scroll_begin");
        var scroll_end = document.getElementById("scroll_end");
        var scroll_div = document.getElementById("scroll_div");
        scroll_end.innerHTML = scroll_begin.innerHTML;
        function Marquee() {
            if(scroll_end.offsetWidth - scroll_div.scrollLeft <= 0) {
                scroll_div.scrollLeft -= scroll_begin.offsetWidth;
            } else {
                scroll_div.scrollLeft++;
            }
        };
        var MyMar = setInterval(Marquee, speed);
        scroll_div.onmouseover = function() {
            clearInterval(MyMar);
        };
        scroll_div.onmouseout = function() {
            MyMar = setInterval(Marquee, speed);
        };
    }();

/*    var scrol = new scrolling($('#scroll_warp'),$('#scroll_warp tr'),1000,3000);     /////// 由于ie bug,替换原有滚动显示js 2011.10.8 wzx
    scrol.start(3000);
*/
    $('.decorate ul li').mouseover(function(){
        $(this).find('.gy_box').css("display","block");
    })
	$('.decorate ul li').mouseout(function(){
        $(this).find('.gy_box').css("display","none");
    })

  //  $('#slider').nivoSlider({effect:'fade', animSpeed:500, pauseTime:4000});    //2011.9.28 wzx del

    $('#tdcase_warp').css('width',function(){
        var children = $(this).find('a').size();
        return children*parseInt($(this).css('width'))+children*10+'px';
    });

    var cur = 1;
    $('.topic').html($('#tdcase_warp a').eq(cur-1).attr('title'));
    $('.down a').click(function(){
        if(cur==$('#tdcase_warp a').size()) {
            cur=0;
        }
        cur++;
        var left = parseInt($('#tdcase_warp').css('left'));
        $('#tdcase_warp').animate({left:0-(cur-1)*200+'px'},500);
        $('.topic').html($('#tdcase_warp a').eq(cur-1).attr('title'));
    })
    $('.up a').click(function(){
        if(cur==1){
            cur = $('#tdcase_warp a').size();
        }else{
            cur--;
        }
        var left = parseInt($('#tdcase_warp').css('left'));
        $('.topic').html($('#tdcase_warp a').eq(cur-1).attr('title'));
        $('#tdcase_warp').animate({left:0-(cur-1)*200+'px'},500);
    });

    $('#show_hx').click(function(){
        $('#list_hx').toggle();
        return false;
    });
    $('#list_hx li a').click(function(){
        $('#list_hx').hide();
        $('#show_hx').html($(this).html());
        $('#thisdiqu').val($(this).attr('value'));
        return false;
    });
    $(document).click(function(event){
        var target = event.target || event.srcElement;
        var parent1 = $(target);
        var parent = $('#list_hx');
        while(parent1.length!=0 && parent1!==parent){
            parent1 = parent1.parent();
        }
        if(parent1 !== parent){
            $('#list_hx').hide();
        }
    })

    var days = [31,28,31,30,31,30,31,31,30,31,30,31];
    var now = new Date();
    var nowyear = now.getFullYear(),nowmonth = now.getMonth(),nowday = now.getDate();
    $('#year option').each(function(){
        if($(this).val()==nowyear){
            $(this).prop('selected',true);
            return;
        }
    });
    $('#month option').each(function(){
        if($(this).val()==nowmonth){
            $(this).prop('selected',true);
            return;
        }
    });
    $('#date').html('');
    for(var i=1;i<=days[nowmonth];i++){
        $('#date').append('<option value="'+i+'"'+'>'+i+'</option>');
    }
    $('#date option').each(function(){
        if($(this).val()==nowday){
            $(this).prop('selected',true);
            return;
        }
    });
    $('#month,#year').change(function(){
        $('#date').html('');
        var year = $('#year option:selected').val();
        var month = $('#month option:selected').val();
        if(year%400==0){
            days[1] = 29;
        }else if(year%4==0 && year%100!==0){
            days[1] = 29;
        }else{
            days[1] = 28;
        }
        for(var i=1;i<=days[month];i++){
            $('#date').append('<option value="'+i+'"'+'>'+i+'</option>');
        }
        $('#date option:eq(0)').prop('selected',true);
    })
})

//2011.9.28 wzx add js
$(document).ready(function(){
	$(".wtab-a").click(function(){
		$(".wtab a").css("color","#4E7D10");
		$(".zxrjtab1").css("background-position","-365px 0");
		$(this).css("color","#565656");
		$("#nl-a").css("display","block");
		$("#nl-b").css("display","none");
	})
	$(".wtab-b").click(function(){
		$(".wtab a").css("color","#4E7D10");
		$(".zxrjtab1").css("background-position","-365px -30px");
		$(this).css("color","#565656");
		$("#nl-b").css("display","block");
		$("#nl-a").css("display","none");
	})
	//最近发布预约滚动js
function startmarquee(lh,speed,delay,index){
	var t;
	var p=false;
	var o=document.getElementById("wzx");
	o.innerHTML+=o.innerHTML;
	o.onmouseover=function(){p=true};
	o.onmouseout=function(){p=false};
	o.scrollTop = 0;
	function start(){
    	t=setInterval(scrolling,speed);
    	if(!p){ o.scrollTop += 1;}
	}
	function scrolling(){
   		if(o.scrollTop%lh!=0){
    		o.scrollTop += 1;
    		if(o.scrollTop>=o.scrollHeight/2) o.scrollTop = 0;
  		}else{
    		clearInterval(t);
    		setTimeout(start,delay);
  		}
	}
	setTimeout(start,delay);
}

startmarquee(25,30,1000,0);
//最近发布预约滚动js结束
	
})

function checkfix(){
	var company_adminid= getCookie('company_adminid');
	var company_userid= getCookie('company_userid');
	company_adminid = parseInt(company_adminid);
	company_userid = parseInt(company_userid);
	if (company_adminid>0 || company_userid>0 ){
		alert('很抱歉，只有业主才能发布预约');
		return false;
	}

	if($("#thisdiqu").val()==0){
		alert("请选择所在地区！");
		return false;
	}

	if(!cas("area","请填写房屋面积！")){return false;};
	if(!cas("ys","请填写预算价格！")){return false;};
	if(!cas("realName","请填写您的称呼！")){return false;};
	if(!casIni("realName","请填写您的称呼！","如:陈先生")){return false;};
	$tel = $("#tel").val();
	if(!$tel.match(/^1[3589][0-9]{9}$/g)){
		alert("手机号码格式不正确!");
		$("#tel").val("");
		$("#tel").focus();
		return false;
	}

	//$(".t-wrapper").css("display","block");
	//return false;

}

function casIni(idstr,showstr,iniStr){
	$obj = $("#"+idstr);
		$thisval = $obj.val();
		if($thisval == iniStr){
			alert(showstr);
			$obj.val('');
			$obj.focus();
			return false;
		}else{
			return true;
		}
}
function cas(idstr,showstr){
	$obj = $("#"+idstr);
	$thisval = $obj.val();
	if($thisval == ""){
		alert(showstr);
		$obj.focus();
		return false;
	}else{
		return true;
	}
}

function getCookie(name)//取cookies函数
{
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null) return unescape(arr[2]); return '';
}
	function set_day(){
		$month = $("#month_num").val();
		$("#day_num").val("1");
		if($month < 8){
			if($month%2==1){
				$("#day_num").children("span").each(function(){
					 $(this).children().clone().replaceAll($(this));
				});
			}else{
				if($month != 2){
					$("#day_select_31").wrap("<span style='display:none;'></span>");
				}else{
					$year =  $("#year_num").val();
					if($year%4==0){
						$("#day_select_30").wrap("<span style='display:none;'></span>");
						$("#day_select_31").wrap("<span style='display:none;'></span>");
					}else{
						$("#day_select_29").wrap("<span style='display:none;'></span>");
						$("#day_select_30").wrap("<span style='display:none;'></span>");
						$("#day_select_31").wrap("<span style='display:none;'></span>");
					}
				}
			}
		}else{
			if($month%2==0){
				$("#day_num").children("span").each(function(){
					 $(this).children().clone().replaceAll($(this));
				});
			}else{
				$("#day_select_31").wrap("<span style='display:none;'></span>");
			}
		}
	}

	function reset_month(){
		$("#month_num").val("1");
	}

	function check_select(){
		$("#form_zxjd").submit();
	}


