function newin(){    var openwin;    if (openwin)        if (!openwin.closed)            openwin.close();    openwin=window.open("login.htm",'客户进度查询','toolbar=0,menubar=0,scrollbars=0,resizable=0,status=0,location=0,directories=0,top=220,left=250,height=200,width=350');    openwin.focus();}
function getCookieVal (offset) {   var endstr = document.cookie.indexOf (";", offset);   if (endstr == -1)      endstr = document.cookie.length;   return unescape(document.cookie.substring(offset, endstr));}
function GetCookie (name) {   var arg = name + "=";   var alen = arg.length;   var clen = document.cookie.length;   var i = 0;   while (i < clen)    {      var j = i + alen;      if (document.cookie.substring(i, j) == arg)         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0)          break;     }
   return null;}
function SetCookie (name, value) {    var t=new Date();    t=Date.parse(t);    t=new Date(t+6000000);       //2005.7.14:the previous value is 100000   var argv = SetCookie.arguments;   var argc = SetCookie.arguments.length;   var expires = (2 < argc) ? argv[2] : null;   var path = (3 < argc) ? argv[3] : null;   var domain = (4 < argc) ? argv[4] : null;   var secure = (5 < argc) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +"; expires=" + t.toGMTString()                + ((path == null) ? "" : ("; path=" + path)) +                ((domain == null) ? "" : ("; domain=" + domain)) +                ((secure == true) ? "; secure" : "");}

function chk_auth()
{
if (GetCookie("login")==null || GetCookie("login")=="")
{
    alert("请先登录！");
    return (0);
}
else
    return (1);
}

function chk_agt()
{
if (GetCookie("login").search("agt") != 0)
{
    alert("只有本公司顾问才可以使用该功能");
    return (0);
}
else
    return (1);
}

function MenuClick(menuid)
{
    
    //alert("已登录！");
    //alert("cookie: !" + GetCookie('login') + "已登录！");
    switch (menuid)
    {
        case "1":                   //直接写入了href;实时在线评估
            window.location="real_ass.asp";
            break;
        case "2":                   //登录客户查看本人信息;
            window.location="assess.asp";
            break;
        case "3":                   //查询临时客户信息
            if(chk_auth()==1)
            {
                if (GetCookie("login").search("agt") != 0)      //非代理查询
                {
                    /*
                    var openwin;
                    if (openwin)
                        if (!openwin.closed)
                            openwin.close();
                    openwin=window.open ("cstm_inf_self.asp");
                    openwin.focus();
                    */
                    window.location="cstm_inf_self.asp";
                }
                else
                {
                    window.location="cstm_cond.asp";
                }
            }
            break;
        case "4":                   //回复评估申请
            if(chk_auth()==1)
            {
                if(chk_agt()==1)
                {
                    window.location="reply.asp";
                }
            }
            break;
        case "5":                   //查询评估结果
            if(chk_auth()==1)
            {
                if (GetCookie("login").search("agt") != 0)      //非代理查询
                {
                    /*var openwin;
                    if (openwin)
                        if (!openwin.closed)
                            openwin.close();
                    openwin=window.open ("ass_result.asp");
                    openwin.focus();*/
                    window.location="ass_result.asp";
                }
                else
                {
                    window.location="ass_result_cond.asp";
                }
            }
            break;
        case "6":                   //查询用户进度
            if(chk_auth()==1)
            {
                if (GetCookie("login").search("agt") != 0)      //非代理查询
                {
                    window.location="progress_qry.asp";
                }
                else
                {
                    window.location="progress_qrycond.asp";
                }
            }
            break;
        case "7":                   //修改用户进度
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    window.location="progress_mod.asp";
                }
            }
            break;
        case "8":                   //正式客户查询；(原为评估客户清单)
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    //SetCookie ("fm_clt_srch", "fm_clt_srch_clicked");        //to ensure can only be accessed through clicked; 20050713 added
                    window.top.location="fm_clt_srch.php";
                }
            }
            break;
        case "9":                   //回访客户清单
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    /*var openwin;
                    if (openwin)
                        if (!openwin.closed)
                            openwin.close();
                    openwin=window.open ("query_list.asp");
                    openwin.focus();*/
                    window.top.location="query_list.asp"
                }
            }
            break;
        case "10":                   //正式客户录入(原为客户访问统计)
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    //原为userlog_list.asp
                    //SetCookie ("fm_clt_add", "fm_clt_add_clicked");        //to ensure can only be accessed by click the link; 20050713 added
                    window.top.location="fm_clt_add.php";
                }
            }
            break;
        case "11":                   //正式客户memo查询处理
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    SetCookie ("fm_memo_srch", "fm_memo_srch_clicked");        //to ensure can only be accessed by click the link;
                    window.top.location="fm_memo_srch.php";
                }
            }
            break;
        default:
            break;
    }   
}

/*MenuClick_Main() is only for Menu_sub_main.asp which is only for default.asp;when clicking the menu about formal client on default.asp, 
call MenuClick_Main() instead of MenuClick() such that a new windows will open; but in other pages other than default.asp,clicking the
menu will open in the same window*/

function MenuClick_Main(menuid)
{
    
    //alert("已登录！");
    //alert("cookie: !" + GetCookie('login') + "已登录！");
    switch (menuid)
    {
        case "1":                   //直接写入了href;实时在线评估
            window.location="real_ass.asp";
            break;
        case "2":                   //登录客户查看本人信息;
            window.location="assess.asp";
            break;
        case "3":                   //查询临时客户信息
            if(chk_auth()==1)
            {
                if (GetCookie("login").search("agt") != 0)      //非代理查询
                {
                    /*
                    var openwin;
                    if (openwin)
                        if (!openwin.closed)
                            openwin.close();
                    openwin=window.open ("cstm_inf_self.asp");
                    openwin.focus();
                    */
                    window.location="cstm_inf_self.asp";
                }
                else
                {
                    window.location="cstm_cond.asp";
                }
            }
            break;
        case "4":                   //回复评估申请
            if(chk_auth()==1)
            {
                if(chk_agt()==1)
                {
                    window.location="reply.asp";
                }
            }
            break;
        case "5":                   //查询评估结果
            if(chk_auth()==1)
            {
                if (GetCookie("login").search("agt") != 0)      //非代理查询
                {
                    /*var openwin;
                    if (openwin)
                        if (!openwin.closed)
                            openwin.close();
                    openwin=window.open ("ass_result.asp");
                    openwin.focus();*/
                    window.location="ass_result.asp";
                }
                else
                {
                    window.location="ass_result_cond.asp";
                }
            }
            break;
        case "6":                   //查询用户进度
            if(chk_auth()==1)
            {
                if (GetCookie("login").search("agt") != 0)      //非代理查询
                {
                    window.location="progress_qry.asp";
                }
                else
                {
                    window.location="progress_qrycond.asp";
                }
            }
            break;
        case "7":                   //修改用户进度
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    window.location="progress_mod.asp";
                }
            }
            break;
        case "8":                   //正式客户查询；(原为评估客户清单)
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    //SetCookie ("fm_clt_srch", "fm_clt_srch_clicked");        //to ensure can only be accessed through clicked; 20050713 added
                    window.open("fm_clt_srch.php");
                }
            }
            break;
        case "9":                   //回访客户清单
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    /*var openwin;
                    if (openwin)
                        if (!openwin.closed)
                            openwin.close();
                    openwin=window.open ("query_list.asp");
                    openwin.focus();*/
                    window.top.location="query_list.asp"
                }
            }
            break;
        case "10":                   //正式客户录入(原为客户访问统计)
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    //原为userlog_list.asp
                    //SetCookie ("fm_clt_add", "fm_clt_add_clicked");        //to ensure can only be accessed by click the link; 20050713 added
                    window.open("fm_clt_add.php");
                }
            }
            break;
        case "11":                   //正式客户memo查询处理
            if(chk_auth()==1)
            {
                if(chk_agt()==1)    //代理查询
                {
                    SetCookie ("fm_memo_srch", "fm_memo_srch_clicked");        //to ensure can only be accessed by click the link;
                    window.top.location="fm_memo_srch.php";
                }
            }
            break;
        default:
            break;
    }   
}


function emailcheck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
return false
}
if (str.indexOf(at,(lat+1))!=-1){
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
return false
}
if (str.indexOf(dot,(lat+2))==-1){
return false
}
if (str.indexOf(" ")!=-1){
return false
}
return true 
}

//无提示关闭窗口使用
function CloseWin()
{
var ua=navigator.userAgent
var ie=navigator.appName=="Microsoft Internet Explorer"?true:false
if(ie){
    var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
 if(IEversion< 5.5){
    var str  = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
    str += '<param name="Command" value="Close"></object>';
    document.body.insertAdjacentHTML("beforeEnd", str);
    document.all.noTipClose.Click();
    }
    else{
    window.opener =null;
    window.close();
    }
}
else{
window.close()
}
}

//交互式按钮使用
function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function AdjustDay(dob_day, dob_month, dob_year){
// validate the date of birth to fix the leap year,
// different in number of day for each month

    // get the current selected month and year
    var dayIndex=dob_day.selectedIndex;
    var theMonth=parseInt(dob_month[dob_month.selectedIndex].value,10);
    var theYear=parseInt(dob_year[dob_year.selectedIndex].value,10);
    if (theMonth==0 || theYear==0){
        return;
    }
    //alert(theMonth+"--"+theYear);
    // JavaScript uses month index from 0-11, while the list is 1-12
    theMonth--;

    // remove old day list
    var k;
    for(k=dob_day.length-1;k>0;k--){
        dob_day.options[k]=null;
    }

    // add new options for the day list
    k=1;
    var theDay=1;
    var dob_date;
    var currMonth=theMonth;
    while(theDay<=31){
        dob_date=new Date(theYear,theMonth,theDay);
        //alert(dob_date);
        theMonth=dob_date.getMonth();
        if (currMonth==theMonth){
            if (theDay<10){
                dob_day.options[k]=new Option(theDay,theDay, 0, 0);
            }
            else{
                dob_day.options[k]=new Option(theDay, theDay, 0, 0);
            }
        }
        else{
            break;
        }
        theDay++;
        k++;
    }

    // keep the current selected day
    //alert(dayIndex +"--"+theDay);
    if (dayIndex<theDay){
        dob_day.selectedIndex = dayIndex;
    }
    else{
        // select the last item in th list
        dob_day.selectedIndex = dob_day.length-1;
    }
}


//  取得RADIO对象的值
function getRadioValue(radioObject){
 var rad_val=null;
 if (typeof radioObject=='object'){
    if (radioObject.length==null){      //if radioObject is an object and its length==null, it means only one radio
        radioObject.checked=true;       //force the only one radio to be checked
        rad_val=radioObject.value;
        return rad_val;
    }
    else{
         var leng=radioObject.length;
         for(var i=0;i<leng;i++){
            if(radioObject[i].checked){
               rad_val=radioObject[i].value;
               break;
            }
        }
        return rad_val;
    }
  }
  else{     //if radioObject is not an object, it means that there's no radio, so there's no progess record
    return false;
  }
}      

function showtip(text)  //显示链接的说明
{
  if (document.all&&document.readyState=="complete")//针对IE
  {
  //显示跑马灯,内容就是提示框的内容
  document.all.tooltip.innerHTML="<div vAlign=center><font SIZE=2>"+text+"</font></div>";
  document.all.tooltip.style.pixelLeft=event.clientX+document.body.scrollLeft;
  document.all.tooltip.style.pixelTop=event.clientY+document.body.scrollTop+20;
   if (event.clientX>600)
  {
  document.all.tooltip.style.pixelLeft=(screen.width-700)/2+230;
  document.all.tooltip.style.pixelTop=event.clientY+document.body.scrollTop+20;}
   document.all.tooltip.style.visibility="visible";
  }
}
document.write(
"<div id='tooltip' style='position:absolute;visibility:hidden; padding:3px;border:1px solid #C0C0C0; background-color:#FFFFE7; height: 19px; left:77;top: 96px;z-index:10;'></div>");
function hidetip()  //隐藏链接的说明{    if (document.all)        document.all.tooltip.style.visibility="hidden";}
/*
==================================================================
isDigit(objStr):验证是否为数字，包括0
==================================================================
*/
function isDigit(objStr){
    reg=/^\+?[0-9]*[0-9][0-9]*$/;
    var r=objStr.match(reg);
    if(r==null)
        return false;
    else
        return true;
}

/*
==================================================================
isName(objStr):surnmae & given name can only be english letters and space
==================================================================
*/
function isName(objStr)
{
    var reg;
    if(Trim(objStr)=="")
    {
        return false;
    }
    else
    {
        objStr=objStr.toString();
    }    

    reg=/^[A-Za-z ]+$/;

    var r=objStr.match(reg);
    if(r==null)
    {
        return false;
    }
    else
    {        
        return true;     
    }
}

/*
==================================================================
isName(objStr):surnmae & given name can only be english letters and space
==================================================================
*/
function isLogin(objStr)
{
    var reg;
    if(Trim(objStr)=="")
    {
        return false;
    }
    else
    {
        objStr=objStr.toString();
    }    

    reg=/^[A-Za-z0-9_\-.@]+$/;

    var r=objStr.match(reg);
    if(r==null)
    {
        return false;
    }
    else
    {        
        return true;     
    }
}

/*
==================================================================
字符串操作
Trim(string):去除字符串两边的空格
==================================================================
*/
/*
==================================================================
LTrim(string):去除左边的空格
==================================================================
*/
function LTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}
/*
==================================================================
RTrim(string):去除右边的空格
==================================================================
*/
function RTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}
/*
==================================================================
Trim(string):去除前后空格
==================================================================
*/
function Trim(str)
{
    return RTrim(LTrim(str));
}
function isTime(s)
{
    var pat=/(\d){0,3}[.]{0,1}(\d){1}+$/;
    if (!pat.exec(s)) return false;
    return true;
}

//校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-”
function isTel(s)
{
    //var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    if (!patrn.exec(s)) return false;
    return true;
}

/********************************** checkIsValidDate ******************************************/
/**
*校验字符串是否为日期型
*返回值：
*如果为空，定义校验通过，           返回true
*如果字串为日期型，校验通过，       返回true
*如果日期不合法，                   返回false
*/
function checkIsValidDate(str)
{
    //如果为空，则通过校验
    if(str == "")
        return true;
    var pattern = /\d{2}\/\d{2}\/\d{4}/;
    //var pattern =/^((\\d{4})|(\\d{2}))-(\\d{1,2})-(\\d{1,2})$/g;

    if(!pattern.test(str))
        return false;
return true;
}

/********************************** checkDateEarlier ******************************************/
/**
*校验两个日期的先后
*返回值：
*如果其中有一个日期为空，校验通过,          返回true
*如果起始日期早于等于终止日期，校验通过，   返回true
*如果起始日期晚于终止日期，                 返回false    参考提示信息： 起始日期不能晚于结束日期。
*/
function checkDateEarlier(strStart,strEnd)
{
    if(checkIsValidDate(strStart) == false || checkIsValidDate(strEnd) == false)
        return false;
    //如果有一个输入为空，则通过检验
    if (( strStart == "" ) || ( strEnd == "" ))
        return true;
    var arr1 = strStart.split("/");
    var arr2 = strEnd.split("/");
    if(arr1[1].length == 1)
        arr1[1] = "0" + arr1[1];
    if(arr1[0].length == 1)
        arr1[0] = "0" + arr1[0];
    if(arr2[1].length == 1)
        arr2[1] = "0" + arr2[1];
    if(arr2[0].length == 1)
        arr2[0]="0" + arr2[0];
    var d1 = arr1[2] + arr1[1] + arr1[0];
    var d2 = arr2[2] + arr2[1] + arr2[0];
    if(parseInt(d1,10) > parseInt(d2,10))
       return false;
    else
       return true;
}

//以下用prototype为String 添加一些方法
//by david:调用方法示例：在javascript部分，"Hello String".compareTo("hello string")

String.prototype.trim = function() {
/**
 * 去掉字符串两端的空白字符
 */
    return this.replace(/(^\s+)|(\s+$)/g, "");
}

String.prototype.iEquals = function(str) {
/**
 * 忽略大小写比较字符串
 * 注：不忽略大小写比较用 == 号
 */
    return this.toLowerCase() == str.toLowerCase();
}

String.prototype.compareTo = function(str) {
/**
 * 比较字符串，根据结果返回 -1, 0, 1
 */
    if (this == str) {
        return 0;
    } else if (this < str) {
        return -1;
    } else {
        return 1;
    }
}

String.prototype.iCompareTo = function(str) {
/**
 * 忽略大小写比较字符串，根据结果返回 -1, 0, 1
 */
    return this.toLowerCase().compareTo(str.toLowerCase());
}

String.prototype.startsWith = function(str) {
/**
 * 判断字符串是否以指定的字符串开始
 */
    return this.substr(0, str.length) == str;
}

String.prototype.iStartsWith = function(str) {
/**
 * 判断字符串是否以指定的字符串开始，忽略大小写
 */
    return this.substr(0, str.length).iEquals(str);
}

String.prototype.endsWith = function(str) {
/**
 * 判断字符串是否以指定的字符串结束
 */
    return this.substr(this.length - str.length) == str;
}

String.prototype.iEndsWith = function(str) {
/**
 * 判断字符串是否以指定的字符串结束，忽略大小写
 */
    return this.substr(this.length - str.length).iEquals(str);
}

String.prototype.style = function(style) {
/**
 * 构造特定样式的字符串，用 <span></span> 包含
用法："Hello String".style("color: #FF0000; background-color: #DDEEFF;")
*/
    return "<span style=\"".concat(style, "\">", this, "</span>");
}

String.prototype.stripTags= function(str){
    return str.replace(/<\/?[^>]+>/gi, '');
}