function new_to_https(to_https_path, winName,features){
	var abs_url= get_https_path(to_https_path);
	window.open(abs_url,winName,features);     
}

function new_to_http(to_http_path, winName,features){
	var abs_url= get_http_path(to_http_path);
	window.open(abs_url, winName,features);
}

function to_https(to_https_path){
	location= getpath(to_https_path, "https");
}

function to_http(to_http_path){
	location= getpath(to_http_path, "http");
}

function get_https_path(to_https_path){
	return getpath(to_https_path, "https");
}

function get_http_path(to_http_path){
	return getpath(to_http_path, "http");
}

function getpath(rel_url, proto){
	var str = rel_url.substr(0,1);
	var abs_url;
	var rel_path= location.pathname.substring(0, location.pathname.lastIndexOf("/")+1);
	if(str=="/"){
		abs_url= proto+"://"+location.hostname+ rel_url;
	}else{
		abs_url= proto+"://"+location.hostname+ rel_path+ rel_url;
	}
	return abs_url;
}


var protype = "http";
var VERSION = "1.02";
var SESSION_VALUE = "LOGON_STATUS";
var DEAD_VALUE = "deleted";

function isLoggedOn() {
  var the_cookie = unescape(WM_getCookieValue(SESSION_VALUE));
  var logon = false;
  if (the_cookie != "") {                           // if the cookie is found then check what its value is
    logon = (the_cookie.indexOf(DEAD_VALUE) == -1); //   if the DEAD_VALUE is not found then logon is true
  } else 
    logon = false;                                  // otherwise logon is false

  return logon;
}

function WM_getCookieValue(name) {
  // Declare variables.
  var firstChar, lastChar;

  // Get the entire cookie string. (This may have other name=value pairs in it.)
  var theBigCookie = document.cookie;

  // Grab just this cookie from theBigCookie string.
  firstChar = theBigCookie.indexOf(name);               // Find the start of 'name'.

  if (firstChar != -1) {                                // If you found it,
    firstChar += name.length + 1;                       // skip 'name' and '='.
    lastChar = theBigCookie.indexOf(';', firstChar);    // Find the end of the value string (i.e. the next ';').
    if (lastChar == -1)                                 // Decide if the last char is the end of the string
      lastChar = theBigCookie.length;
    return theBigCookie.substring(firstChar, lastChar); // Return the value. 
  } else {
    return "";                                       // If there was no cookie, return false.
  }
}


function dspLogonStatus(){
	if (isLoggedOn()){
		 document.write("<a href='/general/res/logon/logoff.html'><font color='#CC0099'>退出</font></a>");
	}else{

		 document.write("<a href='javascript: doSubmit();'><font color='#0000FF'>登录</font></a>");
	}	
}

function doSubmit(){
	errfound = true;
  if (homeform.username.value==""){
	alert("请输入用户名!");
	homeform.username.focus();
	errfound = false;
  }
  if (homeform.password.value=="" && errfound != false){
	alert("请输入密码!");
	homeform.password.focus();
	errfound = false;
  }
  if (errfound) {
    homeform.username.value=homeform.username.value.toLowerCase();
	homeform.errorurl.value = "http://" + window.location.hostname + "/general/res/error/logonerror2.jsp";
	homeform.nexturl.value = "http://" + window.location.hostname + "/mypa18/docc/home.jsp";
	homeform.logonurl.value = "http://" + window.location.hostname + "/general/home.htm";
	homeform.logonokurl.value = "http://" + window.location.hostname + "/general/res/logon/logonok2.jsp";
	
	homeform.action="http://" + window.location.hostname + "/LogonServlet";
    homeform.submit();
  }
 }


function mail_login() {
window.open("/general/docc/maillogon.jsp","newwindow")
}
function mail_reg() {
window.open("/general/docc/mailreg.jsp","newwindow","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizeable=0,width=300,height=200")
}
function login() {
window.open("/general/res/logon/index.jsp","newwindow","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizeable=0,width=320,height=240")
}
function regist() {
window.open("/general/docc/g01.jsp","newwindow")
}
function account() {
window.open("/general/docc/s06.jsp","newwindow")
}


function Logon() {
var flashvar;
if (isLoggedOn())
  flashvar = 108;
else
  flashvar = 111;
window.document.login.SetVariable("pageid",flashvar);
displayLogon();
}

function Logout() {
var flashvar;
if (isLoggedOn())
  flashvar = 108;
else
  flashvar = 111;
  
window.document.login.SetVariable("pageid",flashvar);
window.document.location = "/general/res/logon/logoff.html";
//displayLogon();
}

function Title(){
  window.status=("这里是:" + self.document.title);
}



var VERSION = "1.02";
var SESSION_VALUE = "LOGON_STATUS";
var DEAD_VALUE = "deleted";

function showLogonLayers() {
  if ( isLoggedOn() ) {  	
    document.all( 'LoggedOn' ).style.visibility = "visible";
    document.all( 'LoggedOff' ).style.visibility = "hidden";
  } else {
    document.all( 'LoggedOn' ).style.visibility = "hidden";
    document.all( 'LoggedOff' ).style.visibility = "visible";
  }
}

function displayLogon() {
//  alert (document.cookie);
  var lo = isLoggedOn();
  if (lo) {  	
    window.document.login.SetVariable("pageid","108");
  } else {
    window.document.login.SetVariable("pageid","111");
  }
}

function isLoggedOn() {
  var the_cookie = unescape(WM_getCookieValue(SESSION_VALUE));
  var logon = false;
  if (the_cookie != "") {                           // if the cookie is found then check what its value is
    logon = (the_cookie.indexOf(DEAD_VALUE) == -1); //   if the DEAD_VALUE is not found then logon is true
  } else 
    logon = false;                                  // otherwise logon is false

  return logon;
}

function WM_getCookieValue(name) {
  // Declare variables.
  var firstChar, lastChar;

  // Get the entire cookie string. (This may have other name=value pairs in it.)
  var theBigCookie = document.cookie;

  // Grab just this cookie from theBigCookie string.
  firstChar = theBigCookie.indexOf(name);               // Find the start of 'name'.

  if (firstChar != -1) {                                // If you found it,
    firstChar += name.length + 1;                       // skip 'name' and '='.
    lastChar = theBigCookie.indexOf(';', firstChar);    // Find the end of the value string (i.e. the next ';').
    if (lastChar == -1)                                 // Decide if the last char is the end of the string
      lastChar = theBigCookie.length;
    return theBigCookie.substring(firstChar, lastChar); // Return the value. 
  } else {
    return "";                                       // If there was no cookie, return false.
  }
}

function process(e) 
{
	var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode
	if (((charCode >= 48) && (charCode <= 57)) || ((charCode >= 65) && (charCode <= 90)) || ((charCode >= 97) && (charCode <= 122)) || (charCode == 95))
	{
	  return true;
	}
	if ((charCode == 8) || (charCode == 13))
	{
      e.returnValue=false;
	  doSubmit();	
	}
}


function getpass() {
window.open("/general/docc/pass01.jsp","password","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizeable=0,width=515,height=370")
}

function clickURL(to_url){
	location.href=get_https_path(to_url);
	//return get_https_path(to_url);
}

function get_https_path(to_https_path){
	return getpath(to_https_path, protype);
}

function getpath(rel_url, proto){
	var str = rel_url.substr(0,1);
	var abs_url;
	var rel_path= location.pathname.substring(0, location.pathname.lastIndexOf("/")+1);
	if(str=="/"){
		abs_url= proto+"://"+location.hostname+ rel_url;
	}else{
		abs_url= proto+"://"+location.hostname+ rel_path+ rel_url;
	}
	return abs_url;
}

/**
 返回值为小写
 作用：得到网页所在的服务器名
 作者：向荣 2001-02-05
*/
function Clientinclude_getWebServerName()
{
  var value = document.domain;
  if (value == null)
  {
    return "";
  }

  return value.toLowerCase();
}



/**
 * 频道对象
 * 各属性含义:
 * name :   频道的中文名称
 * url  :   频道对应的url地址
 * popupstr:弹出窗口的参数.如果没有表示不弹出.
 * state:   该频道目前的状态,默认为1,即可用状态.否则,该频道目前不可用.
 */
function PA18ChannelURL(name,url,popupstr,state){
    function isEnabled(){
        return (this.state==1);
    }
    function enter(){
        if(this.popup){
            window.open(this.url,"",this.popup);
        }else{
            window.location=this.url;
        }
    }
   
    this.name = name;
    this.url = url;
    this.popup = popupstr;
    if(state){
        this.state = state;
    }else{
        this.state = 1;
    }
    this.isEnabled = isEnabled;
    this.enter = enter;
    return this;
}

function PA18ChannelURLGroup(groupURL){
    function isEnabled(){
        return this.groupURL.isEnabled();
    }
    function getChannelAt(index){
        if( index>=0 && index<this.channels.length){
            return this.channels[index];
        }
    }
    function getEnabledChannelAt(index){
        if(this.isEnabled() && index>=0 && index<this.channels.length && this.channels[index].isEnabled()){
            return this.channels[index];
        }
    }
    function filter(){
        var result = new PA18ChannelURLGroup(this.groupURL);
        for(var m=1,n=this.channels.length; m<n; m++){
            if(this.channels[i].isEnabled()){
                result.push(this.channels[i]);
            }
        }
        return result;
    }
    this.groupURL = groupURL;
    //arguments.shift(); // remove first argument: groupURL.
    this.channels = arguments;
    this.isEnabled = isEnabled;
    this.filter = filter;
    return this;
}

function enterChannel(ch){
    if(ch.indexOf("/")!=-1){
    	window.location = ch;
    	return;
    }
    var arr = ch.split(",");
    var group = PA18AllChannels[arr[0]];
    var channel = group.channels[arr[1]];
    channel.enter();
}

var PA18_CHANNEL_COOKIE_NAME = "PA18Channel";

function setPA18ChannelCookie(){
    var arr = document.getElementsByName("channelsCheckbox");
    var result = "";
    for(var m=0, n=arr.length; m<n; m++){
        if(arr[m].checked){
            if(result!=""){
                result = result + ";";
            }
            result = result + arr[m].value;
        }
    }
    var today = new Date();
    var expires = new Date();
    expires.setTime(today.getTime() + 1000*60*60*24*100);
    setCookie(PA18_CHANNEL_COOKIE_NAME,result,expires);
    alert("智能通道已经设置成功!");
	history.go(0);
}

function splitPA18ChannelCookie(value){
    var arr = value.split(";");
    var result = new Array(arr.length);
    for(var m=0,n=arr.length; m<n; m++){
        result[m] = arr[m].split(",");
    }
    return result;
}

function setCookie(name, value, expire) {
    document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + "; path=/" ;
}

function getCookie(Name) {
    var search = Name + "=";
    if (document.cookie.length > 0) { 
        offset = document.cookie.indexOf(search);
        if (offset != -1) { 
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1){
                end = document.cookie.length;
            }
            return unescape(document.cookie.substring(offset, end));
        }
    }
}

function writePA18Channel(){
    var cookieValue=getCookie(PA18_CHANNEL_COOKIE_NAME);
    document.write('<select name="PA18ChannelSelect" id="PA18ChannelSelect" onChange="var tmp=this.value; this.value=\'\'; if(tmp.length!=0){ enterChannel(tmp); }">');
    document.write('<option value="">**智能通道**</option>');
    document.write('<option value="/mypa18/docc/channels.jsp">**设置通道**</option>');
    if(cookieValue){
        var arr = splitPA18ChannelCookie(cookieValue);
        var arrChannel = new Array();
        
        for(var i=0,j=arr.length; i<j; i++){
            var channel ;
            if(arr[i][0]<PA18AllChannels.length){
                var group = PA18AllChannels[arr[i][0]];
                if(group.isEnabled() && arr[i][1]>=0 && arr[i][1]<group.channels.length){
                    channel = group.channels[arr[i][1]];
                    if(channel.isEnabled()){
                        document.write('<option value="' + arr[i][0] + "," + arr[i][1] + '">');
                        if(channel==group.groupURL){
                            document.write('==' + channel.name + '==');
                        }else{
                            document.write('' + channel.name);
                        }
                        document.write('</option>');
                    }
                }
            }
        }
    }
    document.write('</select>');
}

function writePA18ChannelSetupTable(){
    document.write('<table width="100%" border="0" cellspacing="1" cellpadding="1" align="center" valign="top">');
    for(var i=0,j=PA18AllChannels.length; i<j; i++){
        var group = PA18AllChannels[i];
        if(!group.isEnabled()) continue;
        document.write('<tr bgcolor="#FFAE88">');
        document.write('<td align="center" colspan ="4"><b> <input type="checkbox" name="channelsCheckbox" value="' + i + ',0' + '"> <a href="' + group.groupURL.url + '" target="_blank">' + group.groupURL.name + '</a> </b></td>');
        document.write('</tr>');
        var k=0;
        for(var m=1,n=group.channels.length; m<n; m++){
            var channel = group.channels[m];
            if(!channel.isEnabled()) continue;
            if(k==0){
                document.write('<tr bgcolor="#FFE9BB">');
            }else if(k%4==0){
                document.write('</tr><tr bgcolor="#FFE9BB">');
            }
            document.write('<td align="left"> <input type="checkbox" name="channelsCheckbox" value="' + i + ',' + m + '"> <a href="' + channel.url + '" target="_blank">' + channel.name + '</a> </td>');        
            k++;
        }
        if(k!=0 && k%4!=0){
            for(k=k%4; k<4; k++){
                document.write('<td>&nbsp;</td>');
            }
            document.write('</tr>');
        }
    }
    document.write('</table>');
    setCheckedChannelsFromCookie();
}

function setCheckedChannelsFromCookie(){
    var cookieValue=getCookie(PA18_CHANNEL_COOKIE_NAME);
    if(cookieValue){
        var arrCookie = splitPA18ChannelCookie(cookieValue);
        var arrCheckbox = document.getElementsByName("channelsCheckbox");
        for(var i=0,j=arrCheckbox.length; i<j; i++){
            for(var m=0,n=arrCookie.length; m<n; m++){
                if(arrCheckbox[i].value==(arrCookie[m][0] + "," + arrCookie[m][1])){
                    arrCheckbox[i].checked = true;
                    break;
                }
            }
        }
    }
}

/**
 * 频道数组
 * 当频道删除或因为其它原因不可用时,只要在构造频道对象时,在最后添加一个大于1的一个参数.
 * (注意,不能用0来作废,必须是大于1的数)
 * 例如: new PA18ChannelURL("新闻中心","/stock/docc/s01.jsp",'',2),
 * 但是不要将它删除.否则客户端配置就会不正确.
 */
var PA18AllChannels = new Array(
    new PA18ChannelURLGroup( 
            new PA18ChannelURL("新闻中心","/stock/docc/s01.jsp"),
            new PA18ChannelURL("时事快递","/stock/docc/s01-01.jsp?name=news&block=013&mark=1&title=t-sskd.gif"),
            new PA18ChannelURL("财经透视","/stock/docc/s01-01.jsp?name=news&block=010&mark=1&title=t-cjts.gif"),
            new PA18ChannelURL("国内财经","/stock/docc/s01-01.jsp?name=news&block=001&mark=1&title=t-gncj.gif"),
            new PA18ChannelURL("国际财经","/stock/docc/s01-01.jsp?name=news&block=002&mark=1&title=t-gjcj.gif"),
            new PA18ChannelURL("港台财经","/stock/docc/s01-01.jsp?name=news&block=003&mark=1&title=t-gtcj.gif"),
            new PA18ChannelURL("体坛快车","/stock/docc/s01-01.jsp?name=news&block=008&mark=1&title=t-ttkc.gif"),
            new PA18ChannelURL("科技前沿","/stock/docc/s01-01.jsp?name=news&block=007&mark=1&title=t-kjqy.gif"),
            new PA18ChannelURL("事件剖析","/stock/docc/s01-01b.jsp?name=special&block=005&mark=1&act=s01-04.jsp&title=t-sjpx.gif")
    ),
    new PA18ChannelURLGroup( 
            new PA18ChannelURL("证　　券","/stock/docc/home.jsp"),
            new PA18ChannelURL("市场分析","/stock/docc/s02.jsp"),
            new PA18ChannelURL("个股分析","/stock/docc/s03.jsp"),
            new PA18ChannelURL("研究推荐","/stock/docc/s04.jsp"),
            new PA18ChannelURL("机构专栏","/stock/docc/s08-1.jsp?organ=001&column=2&SimpleStyle=true&pageno=0&ItemsPerPage=6&author=null&datetime=null"),
            new PA18ChannelURL("交易中心","/stock/ssl/docc/s05.jsp","width=634,height=448,top=20,left=20,scrollbars=yes,resizable=yes"),
            new PA18ChannelURL("高速行情","/stock/docc/s09.jsp","width=760,height=520,top=20,left=20,scrollbars=no,resizable=no"),
            new PA18ChannelURL("开放式基金","/stock/fund/fund_home.jsp")
    ),
    new PA18ChannelURLGroup( 
            new PA18ChannelURL("保　　险","/insurance/docc/home.jsp"),
            new PA18ChannelURL("了解保险","/insurance/docc/lif01c.htm"),
            new PA18ChannelURL("选购保险","/insurance/docc/lif03.htm"),
            new PA18ChannelURL("享受服务","/insurance/docc/lif05.htm"),
            new PA18ChannelURL("选代理人","/insurance/docc/lif04.jsp"),
            new PA18ChannelURL("寿险分站","/insurance/docc/map-jigou.htm"),
            new PA18ChannelURL("业务员天地","/insurance/docc/agenton.jsp"),
            new PA18ChannelURL("走进平安","/insurance/docc/palif-01.htm")
    ),
    new PA18ChannelURLGroup( 
            new PA18ChannelURL("银　　行","/bank/docc/home.htm"),
            new PA18ChannelURL("签约帐户","/bank/docc/b06-01-w.htm"),
            new PA18ChannelURL("银证转帐","/bank/ssl/docc/s05-11a.jsp"),
            new PA18ChannelURL("银行帐户查询","/general/docc/g-03.jsp"),
            new PA18ChannelURL("银行帐户互转","/bank/ssl/docc/fund_transfer.jsp"),
            new PA18ChannelURL("信用卡开户申请","/bank/docc/b02-gf.htm"),
            new PA18ChannelURL("外汇买卖","http://pa18.my95588.com/home/main.jsp?corp_no=0001&func_no=0001")
    ),
    new PA18ChannelURLGroup( 
            new PA18ChannelURL("个人理财","/finance/docc/home.jsp"),
            new PA18ChannelURL("着手投资","/finance/docc/zstz01.htm"),
            new PA18ChannelURL("理财大计","/finance/docc/lcdj01.htm"),
            new PA18ChannelURL("理财顾问","/finance/docc/lcjys01.jsp"),
            new PA18ChannelURL("投资项目","/finance/docc/tzxm01.htm"),
            new PA18ChannelURL("资产绩效管理","/finance/docc/zcjxgl.htm"),
            new PA18ChannelURL("理财工具箱","/finance/docc/lcgjx.htm")
    ),
    new PA18ChannelURLGroup( 
            new PA18ChannelURL("我的PA18","/mypa18/docc/home.jsp"),
            new PA18ChannelURL("我的主页","/mypa18/docc/home.jsp"),
            new PA18ChannelURL("证券帐户","/general/ssl/docc/g-01-check.jsp"),
            new PA18ChannelURL("保险帐户","/general/ssl/docc/g-02.jsp"),
            new PA18ChannelURL("银行帐户","/general/docc/g-03.jsp"),
            new PA18ChannelURL("网站积分帐户","/general/docc/g-04.jsp"),
            new PA18ChannelURL("模拟帐户","/general/docc/g-05.jsp"),
            new PA18ChannelURL("帐户帮助","/mypa18/docc/help.jsp")
    ),
    new PA18ChannelURLGroup( 
            new PA18ChannelURL("论　　坛","/stock/docc/s07.jsp"),
            new PA18ChannelURL("最新文章","/stock/docc/s07.jsp?group=s01"),
            new PA18ChannelURL("精 华 区","/stock/docc/s07-jhq.jsp?group=s01"),
            new PA18ChannelURL("社区分析师","/stock/docc/workroom_home.jsp"),
            new PA18ChannelURL("擂 台 赛","/stock/docc/s07-lts.jsp"),
            new PA18ChannelURL("Ｂ股大家谈","/stock/docc/s07.jsp?group=s05"),
            new PA18ChannelURL("社区公告","/stock/docc/s07-sqzz.jsp"),
            new PA18ChannelURL("社区统计","/stock/docc/s07-jfb.jsp?group=s01"),
            new PA18ChannelURL("个人工具","/mypa18/docc/home.jsp")
    )    
);






