function selects(){	
	var allClassZ = $('#all_class_z');
	var allClassY = $('#all_class_y');
	$(document).click(					 
	function(event){
		 
			if($(event.target)!=$(".selects ul")){	
			$(".selects ul").hide();
			}
		}	
	);
	$('.selects').find('ul').hide().end().click(function() {	
														
         var answer = $(this).find('ul');
		
         if (answer.is(':visible')) {
             answer.hide();				 
         } else {
             answer.slideDown('fast');
         }
		
		
     });
	$('#z_btn').click(function() {		 
	 if (allClassZ.is(':visible')) {
             allClassZ.hide();				 
         } else {
             allClassZ.show();
         }
	 });	
	 allClassZ.find('.btns_s:last').click(function() {
		allClassZ.hide();								
													
	});
	 $('#y_btn').click(function() {		 
	 if (allClassY.is(':visible')) {
             allClassY.hide();				 
         } else {
             allClassY.show();
         }
	 });	
	 allClassY.find('.btns_s:last').click(function() {
		allClassY.hide();								
													
	});
	 
	$('.selects li').click(function(){
		$(this).parent().siblings('a').html($(this).html()).attr({rel:$(this).attr('rel')})		
		$(this).parent().siblings('select').val($(this).attr('rel'));
		$(this).parent().siblings('input').val($(this).attr('rel'));
		$(this).parent().siblings('input').trigger("change");
		$(this).parent().siblings('select').trigger('change');
		});
	
}

function s_change() {
	var uNum = $('.selects').length
	var sNum = $('select').length
	for (i=0;i<sNum;i++) {		
		var pNum = $('select:eq('+i+')').find('option').length
		var selectObj =$('select:eq('+i+')');
		selectObj.parent().css({"z-index":90+sNum-i})
		selectObj.after('<ul></ul>')
		selectObj.next().addClass('select_list')
		selectObj.after('<a>'+$('select:eq('+i+')').find('option:selected').html()+'</a>')
		/*$('select:eq('+i+')').after('<ul></ul>')
		$('select:eq('+i+')').next().addClass('select_list')
		$('select:eq('+i+')').after('<a>'+$('select:eq('+i+')').find('option:selected').html()+'</a>')*/
		for (j=0;j<pNum;j++){
			var innerHtml = $('select:eq('+i+')').find('option:eq('+j+')').html()
			var value = $('select:eq('+i+')').find('option:eq('+j+')').val()			
			$('select:eq('+i+')').next().next().append('<li rel='+value+'>'+innerHtml+'</li>')			
			
			}		
		}
		$('select').hide();
		for (i=0;i<uNum;i++){
			var uObj =$('.selects:eq('+i+')');
			uObj.css({"z-index":100+uNum-i})
			}
		
		
		$('.selects li').hover(
  function () {
    $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);
}
	
function op () {		
	$('.add').click(function(){							
							  if ( $('.lines_on:visible').length>0)
							  {
								 $('.lines_on:visible').next().show();	
							  }
							  else
							  {
								  $('.lines:visible').next().show();	
							   }
							 })
	$('.cut').click(function(){		
							 if ( $('.lines_on:visible').length>1){
								 $('.lines_on:visible:last').find('input[type=text]').attr("value",'');
								 $('.lines_on:visible:last').hide();
								 
								 }			
							 })
	}
$(function(){
    datelistadd()
	s_change();
	selects();
	op();
});

function datelistadd()
{
	var myDate = new Date();
	var minyear = 1989;
	var maxyear = myDate.getFullYear();
	var temphtml='';
	var i=0;
	if($("#y_year1").length>0)
	{
		$("#y_year1 option").remove();
		for(i=minyear;i<=maxyear;i++)
		{
			$("#y_year1").append("<option value='"+i+"'>"+i+"</option>");
		}
	}
	
	if($("#b_year1").length>0)
	{
		temphtml='';
		for(i=minyear;i<=maxyear;i++)
		{
			temphtml+="<li rel=\""+i+"\">"+i+"</li>"
		}
		$("#b_year1").val(minyear);
		$("#ab_year1").html(minyear);
		$("#ub_year1").html(temphtml);
	}
	
	if($("#y_year2").length>0)
	{
		$("#y_year2 option").remove();
		for(i=maxyear;i>=minyear;i--)
		{
			$("#y_year2").append("<option value='"+i+"'>"+i+"</option>");
		}
	}
	
	if($("#b_year2").length>0)
	{
		temphtml='';
		for(i=maxyear;i>=minyear;i--)
		{
			temphtml+="<li rel=\""+i+"\">"+i+"</li>"
		}
		$("#b_year2").val(maxyear);
		$("#ab_year2").html(maxyear);
		$("#ub_year2").html(temphtml);
	}
}

function csg(obj)
{
	if($("#cfg_suid").val()=="" || $("#cfg_suid").val()=="EGBNBFDHDNCBCOPIBOLGEMCBCDOIPNFP")
	{
		alert("请先登陆!");
	}
	else
	{
		if(Number(obj)==2)
		{
			gotoyw("/");
		}
		else if(Number(obj)==3)
		{
			gotozb("/");
		}
		else
		{
			$("#bigguide").attr("className","s"+obj);
			for(var i=1;i<=4;i++)
			{
				$("#guideplan"+i).hide();
			}
			$("#guideplan"+obj).show();
		}
	}
}

function iscankao(obj)
{
	if(obj.value=="Y")
	{
		$("#guideplan1").find('.lines_on').each(function()
		{
			$(this).find('input[type=text]').attr("value","");
		    $(this).hide();
	    });
		$("#guideplan1").find('.sel_op').each(function()
		{
			$(this).find('input[type=text]').attr("value","");
		    $(this).hide();
	    });
	}
	else
	{
		$("#guideplan1").find('.sel_op').each(function()
		{
			$(this).show();
	    });
		$("#guideplan1").find('.lines_on:first').show();
	}
}

function downpaper(theURL)
{
	var winName ="new";
	var theW =700;
	var theH =400;
	var showAsModal=false;
    theTop = (window.screen.height-theH)/2;
    theLeft = (window.screen.width-theW)/2;
    var features = "toolbar=0,scrollbars=yes,left=" + theLeft + ",top=" + theTop + ",width=" + theW + ",height=" + theH;
    
    window.SubWin = window.open(theURL,winName,features);
    window.SubWin.focus();
    
    if(showAsModal){
        window.CtrlsDisabled = new Array();
        DisableCtrls("INPUT;SELECT;TEXTAREA;BUTTON");
    }

    function DisableCtrls(tagNameStr){
        var arrTags = tagNameStr.split(";");
        for(var i=0;i<arrTags.length;i++){
            var arrEle = document.getElementsByTagName(arrTags[i]);
            PushToCtrlsDisabled(arrEle);
        }

        for(var i=0;i<window.CtrlsDisabled.length;i++){
            window.CtrlsDisabled[i].disabled = true;
            window.CtrlsDisabled[i].readOnly = true;
        }
    }

    function PushToCtrlsDisabled(arrEle){
        for(var i=0;i<arrEle.length;i++){
            if(!arrEle[i].disabled){
                window.CtrlsDisabled.push(arrEle[i]);
            }
        }
    }
    
    window.onfocus = function(){
        if(window.SubWin && showAsModal){
            if(window.SubWin.closed == true || typeof(window.SubWin.closed) == "undefined"){
                for(var i=0;i<window.CtrlsDisabled.length;i++){
                    window.CtrlsDisabled[i].disabled = false;
                    window.CtrlsDisabled[i].readOnly = false;
                }
            }else{
                window.SubWin.focus();
            }
        }
    }
}

