/**
 * @author Joverms
 */
function favorite(){
    try {
        window.external.addFavorite("http://www.3322.org", "希网域名");
    } 
    catch (e) {
        try {
            window.sidebar.addPanel("希网域名", "http://www.3322.org", "");
        } 
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}


function homePage(obj, val){
    try {
        obj.style.behavior = 'url(#default#homepage)';
        obj.setHomePage(val);
    } 
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } 
            catch (e) {
                alert("此操作被浏览器拒绝！");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', val);
        }
    }
}







	        var yyyy;
            var mm;
            var dd;
            var birthday;
            var sex;
            
            function getYear(){
                return yyyy;
            }
            
            function getMonth(){
                return mm;
            }
            
            function getDate(){
                return dd;
            }
            
            function getBirthday(){
                return birthday;
            }
            
            function getSex(){
                return sex;
            }
            
            function getAge(){
                var mm = getMonth();
                if (mm < 10) 
                    mm = mm.substring(1, 2);
                return Math.floor((parseInt(_getYear()) * 12 + parseInt(_getMonth()) - parseInt(getYear()) * 12 - parseInt(mm)) / 12);
            }
            
            //判断是否大龄,男50,女40
            function isBigAge(){
                if (parseInt(getAge()) >= 40 && parseInt(getSex()) == 2) 
                    return "1";
                if (parseInt(getAge()) >= 50 && parseInt(getSex()) == 1) 
                    return "1";
                return "0";
            }
            
            //校验身份证号码
            function CheckValue(rname,idCards){
		rnames=document.getElementById(rname).value;
		if(rnames.length==0){
			alert("请输入真实姓名！");
			document.getElementById(rname).focus();
			return false;
		}
		idCard=document.getElementById(idCards).value;
                var id = idCard;
                var id_length = id.length;
                
                if (id_length == 0) {
                    alert("请输入身份证号码!");
					document.getElementById(idCards).focus();
                    return false;
                }
                
                if (id_length != 15 && id_length != 18) {
                    alert("身份证号码错误，请重新输入！");
					document.getElementById(idCards).focus();
                    return false;
                }
                
                if (id_length == 15) {
		          if (isNaN(idCard)) {
		        	alert("输入的不是数字！");
		        	document.getElementById(idCards).focus();
        			return false;
	              	}
                    yyyy = "19" + id.substring(6, 8);
					ss=id.substring(6,8);
                    mm = id.substring(8, 10);
                    dd = id.substring(10, 12);
					if(ss==mm&&ss==dd&&mm==dd){
						alert("身份证号码错误，请重新输入！")
						return false;
					}
                    
                    if (mm > 12 || mm <= 0) {
                        alert("身份证号码错误，请重新输入！");
						document.getElementById(idCards).focus();
                        return false;
                    }
                    
                    if (dd > 31 || dd <= 0) {
                        alert("身份证号码错误，请重新输入！");
						document.getElementById(idCards).focus();
                        return false;
                    }
                    
                    birthday = yyyy + "-" + mm + "-" + dd;
                    
                    if ("13579".indexOf(id.substring(14, 15)) != -1) {
                        sex = "1";
                    }
                    else {
                        sex = "2";
                    }
                }
                else 
                    if (id_length == 18) {
                        if (id.indexOf("X") > 0 && id.indexOf("X") != 17 || id.indexOf("x") > 0 && id.indexOf("x") != 17) {
                            alert("身份证号码错误，请重新输入！");
							document.getElementById(idCards).focus();
                            return false;
                        }
                        
                        yyyy = id.substring(6, 10);
                        if (yyyy > 2200 || yyyy < 1900) {
                            alert("身份证号码错误，请重新输入！");
							document.getElementById(idCards).focus();
                            return false;
                        }
                        
                        mm = id.substring(10, 12);
                        if (mm > 12 || mm <= 0) {
                            alert("身份证号码错误，请重新输入！");
							document.getElementById(idCards).focus();
                            return false;
                        }
                        
                        dd = id.substring(12, 14);
                        if (dd > 31 || dd <= 0) {
                            alert("身份证号码错误，请重新输入！");
							document.getElementById(idCards).focus();
                            return false;
                        }
                        
                        if (id.charAt(17) == "x" || id.charAt(17) == "X") {
                            if ("x" != GetVerifyBit(id) && "X" != GetVerifyBit(id)) {
                                alert("身份证号码错误，请重新输入！");
								document.getElementById(idCards).focus();
                                return false;
                            }
                            
                        }
                        else {
                            if (id.charAt(17) != GetVerifyBit(id)) {
                                alert("身份证号码错误，请重新输入！");
								document.getElementById(idCards).focus();
                                return false;
                            }
                        }
                        
                        birthday = id.substring(6, 10) + "-" + id.substring(10, 12) + "-" + id.substring(12, 14);
                        if ("13579".indexOf(id.substring(16, 17)) > -1) {
                            sex = "1";
                        }
                        else {
                            sex = "2";
                        }
                    }
                return true;
            }
            
            //15位转18位中,计算校验位即最后一位
            function GetVerifyBit(id){
                var result;
                var nNum = eval(id.charAt(0) * 7 + id.charAt(1) * 9 + id.charAt(2) * 10 + id.charAt(3) * 5 + id.charAt(4) * 8 + id.charAt(5) * 4 + id.charAt(6) * 2 + id.charAt(7) * 1 + id.charAt(8) * 6 + id.charAt(9) * 3 + id.charAt(10) * 7 + id.charAt(11) * 9 + id.charAt(12) * 10 + id.charAt(13) * 5 + id.charAt(14) * 8 + id.charAt(15) * 4 + id.charAt(16) * 2);
                nNum = nNum % 11;
                switch (nNum) {
                    case 0:
                        result = "1";
                        break;
                    case 1:
                        result = "0";
                        break;
                    case 2:
                        result = "X";
                        break;
                    case 3:
                        result = "9";
                        break;
                    case 4:
                        result = "8";
                        break;
                    case 5:
                        result = "7";
                        break;
                    case 6:
                        result = "6";
                        break;
                    case 7:
                        result = "5";
                        break;
                    case 8:
                        result = "4";
                        break;
                    case 9:
                        result = "3";
                        break;
                    case 10:
                        result = "2";
                        break;
                }
                //document.write(result);
                return result;
            }
            
            //15位转18位
            function Get18(idCard){
                if (CheckValue(idCard)) {
                    var id = idCard;
                    var id18 = id;
                    if (id.length == 0) {
                        alert("身份证号码错误，请重新输入！");
						document.getElementById(idCards).focus();
                        return false;
                    }
                    if (id.length == 15) {
                        if (id.substring(6, 8) > 20) {
                            id18 = id.substring(0, 6) + "19" + id.substring(6, 15);
                        }
                        else {
                            id18 = id.substring(0, 6) + "20" + id.substring(6, 15);
                        }
                        
                        id18 = id18 + GetVerifyBit(id18);
                    }
                    
                    return id18;
                }
                else {
                    return false;
                }
            }
            

