//出生年月日下拉框
var y = new Date().getFullYear()-5; 
function $$(e){
		var element =  document.getElementById(e);
		return element;
}

function initymd(){
	//$$('birthdayYear').options.add(new Option('--',''));
    MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    //for (var i = (y - 70); i < (y + 1); i++) 
    for (var i = y ; i >= y-70 ; i--) 
    {
       $$('birthdayYear').options.add(new Option(i, i));
    }    
    if (document.attachEvent) {
		$$('birthdayYear').attachEvent("onchange", mchange);
        $$('birthdayMonth').attachEvent("onchange",dchange);       
        $$('birthdayDate').attachEvent("onchange",nchange);       
    }
    else {
       $$('birthdayYear').addEventListener('change', mchange, false);
	   $$('birthdayMonth').addEventListener('change', dchange, false);
	   $$('birthdayDate').addEventListener('change', nchange, false);
    }		
	//deleteCookie('birthdayYear')
//	if( getCookie("birthdayYear")!=null ){
//		$$('birthdayYear').selectedIndex = getCookie("birthdayYear");
//		mchange();
//		$$('birthdayMonth').selectedIndex = getCookie("birthdayMonth");
//		dchange();
//		$$('birthdayDate').selectedIndex = getCookie("birthdayDate");
//		nchange();
//	}else{
		//$$('birthdayYear').selectedIndex =8;
		//mchange();
		//$$('birthdayMonth').selectedIndex =1;
		//dchange();
		//$$('birthdayDate').selectedIndex =1;
		//nchange();
	//}
}

//设置月份 
function mchange(){	
    var obj = $$('birthdayMonth');
    optionclean(obj)
    optionclean($$('birthdayDate'))
    if (!$$('birthdayYear').value) {
        optionclean(obj)
    }
    else {
        for (var i = 1; i <= 12; i++) {         
          $$('birthdayMonth').options.add(new Option(i, i));
        }
    }
	  setCookie("birthdayYear",$$('birthdayYear').selectedIndex); 
}

function dchange(){
    var d = $$('birthdayMonth').options[$$('birthdayMonth').selectedIndex].value;
    var dd = MonHead[d - 1];
    optionclean($$('birthdayDate'))
    if (ispinyear($$('birthdayYear').options[$$('birthdayYear').selectedIndex].value) && d == 2) {
        dd++;
    }
    for (var i = 1; i <= dd; i++) {     
       $$('birthdayDate').options.add(new Option(i, i));
    }
	 setCookie("birthdayMonth",$$('birthdayMonth').selectedIndex); 
}
function nchange(){
	 setCookie("birthdayDate",$$('birthdayDate').selectedIndex); 
}
//润年 
function ispinyear(y){
    return (y % 4 == 0);
}

//清除选项 
function optionclean(obj){
    obj.options.length = 1;
}

if (document.attachEvent) {
    window.attachEvent('onload', initymd);
}
else {
    window.addEventListener('load', initymd, false);
    
}

function record(){
	$$('birRecrod').value;
	$$('birthdayYear').selectedIndex =5;
}

function setCookie(sName,sValue,oExpires,sPath,sDomain,bSecure){ 
	var sCookie = sName + "=" + encodeURIComponent(sValue);    
	//失效时间 
	if(oExpires){ 
		sCookie += "; expires= "+ oExpires.toGMTString(); 
	} else{
		var date=new Date();
		date.setTime(date.getTime()+60*1000);
		sCookie += "; expires= "+ date.toGMTString(); 
	}
	if(sPath){ 
		sCookie += "; path = "+ sPath; 
	} 
	if(sDomain){ 
		sCookie += "; domain = " +sDomain; 
	} 
	if(bSecure){ 
		sCookie += "; secure = " +bSecure; 
	} 
   document.cookie = sCookie; 
} 

function getCookie(sName){ 
	var sRE = "(?:; )?" + sName + "=([^;]*);?";        
	var oRE = new RegExp(sRE);       
	if(oRE.test(document.cookie)){ 
		return decodeURIComponent(RegExp["$1"]); 
	}else{ 
		return null; 
	} 
} 
function deleteCookie(sName,sPath,sDomain){ 
	var sCookie = sName + "=; expires =" + (new Date(0)).toGMTString(); 
	if(sPath){ 
		sCookie += ";path= "+ sPath; 
		} 
	if(sDomain){ 
		sCookie += ";path= "+ sDomain; 
	} 
	document.cookie = sCookie; 
} 





     
