$(function(){
	if($('#yuanyun').val()!=''){
		var dyt=$('#yuanyun option[selected]').html();
		var dyid=$('#yuanyun').parent('.select').find('.s_tit span')
		dyid.html(dyt);
	}
	if($('#lyear').val()!=''){
		var lyt=$('#lyear option[selected]').html();
		var lyid=$('#lyear').parent('.select').find('.s_tit span')
		lyid.html(lyt);
	}
	if($('#lmonth').val()!=''){
		var lmt=$('#lmonth option[selected]').html();
		var lmid=$('#lmonth').parent('.select').find('.s_tit span')
		lmid.html(lmt);
	}
	if($('#birthyear').val()!=''){
		var byt=$('#birthyear option[selected]').html();
		var byid=$('#birthyear').parent('.select').find('.s_tit span')
		byid.html(byt);
	}
})

/*弹出定位*/
var scT='';
function scTop(){
    var top=$(window).scrollTop()
    return {top:top}
}
function bodyStyle(){
    scT = scTop().top;
    $('body').css({position:'fixed',top:-scT,left:0,right:0});
}
function bodyRemovStyle(){
    $('body').removeAttr('style');
    $('html,body').scrollTop(scT);
    
}

/*单选美化label,隐藏radio靠label点击*/
$('.checked label').click(function(){
      if($(this).find('input').is(':checked')){
          $(this).addClass('on').siblings().removeClass('on'); 
      }
});
/*复选美化label,隐藏checkbox靠label点击*/
$('.checkbox label').click(function(){
        if ($(this).find('input').is(':checked')) {
            $(this).find('input').attr("checked",true).prop("checked","checked").parent().siblings().removeClass('on').find('input').removeAttr("checked");
            $(this).parent().addClass('on')
        } else {
            $(this).parent().removeClass('on')
        }
    });

/*自定义SELECT*/
$('.select select').change(function(){
        var text = $(this).children('option:selected').text(), val = $(this).children('option:selected').val();
        $(this).prev().find('span').text(text)
})
$('.morechecked label').click(function(){
      if($(this).find('input').is(':checked')){
          $(this).addClass('on').siblings().removeClass('on'); 
      }
});
$('input[name="isti"]').change(function(){
	var n=$(this).val();
	var obj=$('.kedubox');
	if(n==2){
		obj.addClass('dis_flex');
	}else{
		if(obj.hasClass('dis_flex')) obj.addClass('none').removeClass('dis_flex');
	}
});
$('#pailong').click(function(){
	var obj=$('.shuikouid');
	if($(this).is(':checked')){
		obj.addClass('flex').removeClass('none');
	}else{
		obj.addClass('none').removeClass('flex');
	}
});
$('#minggua').click(function(){
	var obj=$('.mgbox');
	if($(this).is(':checked')){
		obj.addClass('dis_flex').removeClass('none');
	}else{
		obj.addClass('none').removeClass('dis_flex');
	}
});
var shanxiang=[["0","壬","丙"],["1","子","午"],["2","癸","丁"],["3","丑","未"],["4","艮","坤"],["5","寅","申"],
			   ["6","甲","庚"],["7","卯","酉"],["8","乙","辛"],["9","辰","戌"],["10","巽","乾"],["11","巳","亥"],
               ["12","丙","壬"],["13","午","子"],["14","丁","癸"],["15","未","丑"],["16","坤","艮"],["17","申","寅"],
               ["18","庚","甲"],["19","酉","卯"],["20","辛","乙"],["21","戌","辰"],["22","乾","巽"],["23","亥","巳"]];
var sxtype;
$('.cdesx').click(function(){
	set_sxlist(1);
	sxtype=1;
	$('.pick_box.sxbox').addClass('show');
});
$('.shuikou').click(function(){
	set_sxlist(2);
	sxtype=2;
	$('.pick_box.sxbox').addClass('show')
});
function set_sxlist(n){
	var tc=$('.sx_list .con ul');
	var htm='';
	tc.html('');
	for(var i=0;i<24;i++){
		var v=shanxiang[i][0]+'-'+shanxiang[i][1]+'-'+shanxiang[i][2];
		var t=(n==1)? shanxiang[i][1]+'山'+shanxiang[i][2]+'向' : shanxiang[i][1];
		htm+='<li><a onclick="return check_shan(this,'+n+', \''+v+'\');">'+ t +'</a></li>';
	}
	tc.append(htm);
}
function check_shan(obj,n,v) {
    var obj = $(obj);
	if(n==1){
        $("input[name='sxtit']").val(obj.html());
        $("input[name='sx']").val(v);
	}else{
		$("input[name='sktit']").val(obj.html());
        $("input[name='pljsx']").val(v);
	}
    $('.sxbox').removeClass("show");
}
function shutdown_shan() {
    $('.sxbox').removeClass("show");
    if(sxtype=1){
        $("input[name='sxtit']").val('');
        $("input[name='sx']").val('');
	}else{
		$("input[name='sktit']").val('');
        $("input[name='pljsx']").val('');
	}
}
function checkpxk(){
	var isti=$('input[name="isti"]:checked').val();
	var flag=true;
	if($('input[name="sx"]').val()==''){
		flag=false;
		point('请选择山向');
	}
	else if(isti=='2'){
		var kd=$('input[name="kedu"]').val();
		if(kd==''){
			flag=false;
			point('请填写坐山罗盘刻度');
		}else{
			var kds=parseFloat(kd);
			var sxarr=$('input[name="sx"]').val().split('-');
			var sxid=sxarr[0];
			var zckedu=(345+parseInt(sxid)*15)%360;
			if(kds>zckedu+7.5 || kds<zckedu-7.5){
				flag=false;
				point('坐山刻度超出此山刻度范围');
			}
		}
	}
	else if($('#pailong').is(':checked')){
		if($('input[name="pljsx"]').val()==''){
			flag=false;
			point('排龙诀必须选择水口');
		}
	}
	if(flag==true){
		$('#pxkform').submit();
	}
}
function point(a){
        var point = $('<div class="point">'+a+'</div>');
        $("body").append(point);
        var left = ($(window).width()-point.outerWidth())/2,
            top = ($(window).height()-point.outerHeight())/2;
        point.css({left:left,top:top}).addClass('show');
        setTimeout(function(){
            point.removeClass('show');
            setTimeout(function(){
                point.remove()
            },200)
        },2000)
 }