using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Xml;
using System.IO;
using xabaraCOM;

public partial class inClude_head : System.Web.UI.UserControl
{
    public string pcaUrl = "";
    public int pcaHeight = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        sqlServer sql = new sqlServer();
        xabara x = new xabara();

        if (!IsPostBack)
        {
            advertisement ad = new advertisement();
            ad960.Text = ad.read("", 960, 90, 1, false, true, "");

            string localUrlPath = Request.RawUrl;
            //Response.Write(localUrlPath); 
            string select = string.Empty;
            string teachSelect = string.Empty;

            if (this.getTreeName(localUrlPath, "/article/") && string.IsNullOrEmpty(teachSelect))   //家教资讯
            {
                articleLink.CssClass = "navWhiteLink";
                article.CssClass = "NavMenuWhite";
                select = "OK";
            }
            else
            {
                articleLink.CssClass = "navHuiLink";
                article.CssClass = "navMenuHui";
            }

            if (this.getTreeName(localUrlPath, "/student/"))   //学员库
            {
                studentLink.CssClass = "navWhiteLink";
                student.CssClass = "NavMenuWhite";
                select = "OK";
            }
            else
            {
                studentLink.CssClass = "navHuiLink";
                student.CssClass = "navMenuHui";
            }

            if (this.getTreeName(localUrlPath, "/teacher/") && this.getTreeName(localUrlPath, "teachTypeID=67"))   //在校大学生
            {
                dxsLink.CssClass = "navWhiteLink";
                dxs.CssClass = "NavMenuWhite";

                select = "OK";
                teachSelect = "OK";
            }
            else
            {
                dxsLink.CssClass = "navHuiLink";
                dxs.CssClass = "navMenuHui";
            }

            if (this.getTreeName(localUrlPath, "/teacher/") && this.getTreeName(localUrlPath, "teachTypeID=68"))   //在职老师
            {
                zzTeacherLink.CssClass = "navWhiteLink";
                zzTeacher.CssClass = "NavMenuWhite";

                select = "OK";
                teachSelect = "OK";
            }
            else
            {
                zzTeacherLink.CssClass = "navHuiLink";
                zzTeacher.CssClass = "navMenuHui";
            }

            if (this.getTreeName(localUrlPath, "/teacher/") && this.getTreeName(localUrlPath, "teachTypeID=70"))   //退休老师
            {
                txTeacherLink.CssClass = "navWhiteLink";
                txTeacher.CssClass = "NavMenuWhite";

                select = "OK";
                teachSelect = "OK";
            }
            else
            {
                txTeacherLink.CssClass = "navHuiLink";
                txTeacher.CssClass = "navMenuHui";
            }

            if (this.getTreeName(localUrlPath, "/teacher/") && string.IsNullOrEmpty(teachSelect))   //教员库
            {
                teacherLink.CssClass = "navWhiteLink";
                teacher.CssClass = "NavMenuWhite";

                select = "OK";
            }
            else
            {
                teacherLink.CssClass = "navHuiLink";
                teacher.CssClass = "navMenuHui";
            }

            if (this.getTreeName(localUrlPath, "/help/") && string.IsNullOrEmpty(teachSelect))   //帮助中心
            {
                helpLink.CssClass = "navWhiteLink";
                help.CssClass = "NavMenuWhite";

                select = "OK";
            }
            else
            {
                helpLink.CssClass = "navHuiLink";
                help.CssClass = "navMenuHui";
            }

            if (this.getTreeName(localUrlPath, "/onlineOrder/") && string.IsNullOrEmpty(teachSelect))   //在线预约
            {
                onlineOrderLink.CssClass = "navWhiteLink";
                onlineOrder.CssClass = "NavMenuWhite";

                select = "OK";
            }
            else
            {
                onlineOrderLink.CssClass = "navHuiLink";
                onlineOrder.CssClass = "navMenuHui";
            }
            if (xabara.isNum(xml.read("xabara.config", "orderFlag", 180)) < 1)   //关闭在线预约
            {
                onlineOrder.Visible = false;
            }

            if (this.getTreeName(localUrlPath, "/fee/") && string.IsNullOrEmpty(teachSelect))   //资费标准
            {
                feeLink.CssClass = "navWhiteLink";
                fee.CssClass = "NavMenuWhite";

                select = "OK";
            }
            else
            {
                feeLink.CssClass = "navHuiLink";
                fee.CssClass = "navMenuHui";
            }

            if (string.IsNullOrEmpty(select as string))   //默认首页
            {
                defaultNavLink.CssClass = "navWhiteLink";
                defaultNav.CssClass = "NavMenuWhite";
            }
            else
            {
                defaultNavLink.CssClass = "navHuiLink";
                defaultNav.CssClass = "navMenuHui";

                //ad960.Text = "<div class=\"height5px\"></div><div class=\"divWidth\">" + ad.getAdCode(0, 960, 90, 1, 0, true, "") + "</div>";
            }

            if (localUrlPath.IndexOf("/view/") < 0)
            {
                x.webMeta(this.Page, xml.read("xabara.config", "KeyWord", 180), xml.read("xabara.config", "metaStr", 180));
            }

            DataTable dt;
            int dtRow = 0;
            long p = 0;
            long c = 0;
            long a = 0;
            string pathFlie = HttpContext.Current.Server.MapPath("/xabara.config");
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(pathFlie);
            p = xabara.isNum(xmlDoc.DocumentElement.SelectSingleNode("//add[@key='province']").Attributes["value"].Value);
            c = xabara.isNum(xmlDoc.DocumentElement.SelectSingleNode("//add[@key='city']").Attributes["value"].Value);
            a = xabara.isNum(xmlDoc.DocumentElement.SelectSingleNode("//add[@key='area']").Attributes["value"].Value);
            xmlDoc = null;

            string treeUrl = "";
            if (p > 0)
            {
                if (a < 1 && c < 1)
                {
                    dt = sql.getDataTable("select * from selectProvince where provinceID=" + p.ToString());
                    if (dt.Rows.Count > 0)
                    {
                        treeUrl = "<a href='/city/" + p.ToString() + "-0-0.htm' style='font-weight:bold; font-size:14px; color:#000000;'>" + dt.Rows[0]["provinceTxt"].ToString().Trim() + "</a> - ";
                    }
                    dt.Dispose();
                }
            }
            else
            {
                treeUrl = "<a href='/city/0-0-0.htm' style='font-weight:bold; font-size:14px; color:#000000;'>全国导航</a> - ";
            }

            if (Request.Cookies["xabaraWhere"] != null)  //cookies检查
            {
                p = xabara.isNum(Request.Cookies["xabaraWhere"]["p"].ToString().Trim());
                c = xabara.isNum(Request.Cookies["xabaraWhere"]["c"].ToString().Trim());
                a = xabara.isNum(Request.Cookies["xabaraWhere"]["a"].ToString().Trim());

                if (treeUrl.IndexOf("全国") > -1)
                {
                    dt = sql.getDataTable("select * from selectProvince where provinceID=" + p.ToString());
                    if (dt.Rows.Count > 0)
                    {
                        treeUrl += "<a href='/city/" + p.ToString() + "-0-0.htm' style='font-weight:bold; font-size:14px; color:#000000;'>" + dt.Rows[0]["provinceTxt"].ToString().Trim() + "</a> - ";
                    }
                    dt.Dispose();
                }

                string cityTemp = HttpUtility.UrlDecode(Request.Cookies["xabaraWhere"]["city"].ToString().Trim());
                dt = sql.getDataTable("select * from selectCity where cityID=" + c.ToString());
                if (dt.Rows.Count > 0)
                {
                    cityTemp = dt.Rows[0]["cityTxt"].ToString().Trim();
                }
                dt.Dispose();

                if (c > 0)
                {
                    pcaUrl += "<p style='margin:1px; padding: 1px 1px 1px 12px; background:#FFF9DF;'>" + treeUrl + "<a href='/city/" + p.ToString() + "-" + c.ToString() + "-0.htm' style='font-weight:bold; font-size:14px; color:#000000;'>" + cityTemp + "</a></p>";
                }
            }

            if (c > 0)
            {
                dt = sql.getDataTable("select * from selectArea where aFather=" + c.ToString() + " order by areaID");
                pcaUrl += "<p style='margin:0px; padding:2px; background:#ffffff;'><table cellpadding='1' cellspacing='1' border='0' align='center' style='width:95%;'>";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if ((i + 1) % 5 == 1)
                    {
                        pcaUrl += "<tr>";
                        dtRow += 1;
                    }
                    pcaUrl += "<td style='texg-align:left;'><a href='/city/" + p.ToString() + "-" + c.ToString() + "-" + dt.Rows[i]["areaID"].ToString().Trim() + ".htm'>" + dt.Rows[i]["areaTxt"].ToString().Trim() + "</a></td>";
                    if ((i + 1) % 5 == 0)
                    {
                        pcaUrl += "</tr>";
                    }
                }
                pcaUrl += "</table></p>";
                pcaHeight = dtRow * 22 + 52;
            }
            else
            {
                if (p > 0)
                {
                    dt = sql.getDataTable("select * from selectCity where cFather=" + p.ToString() + " order by cityID");
                    pcaUrl += "<p style='margin:0px; padding:2px; background:#ffffff;'><table cellpadding='1' cellspacing='1' border='0' align='center' style='width:95%;'>";
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if ((i + 1) % 5 == 1)
                        {
                            pcaUrl += "<tr>";
                            dtRow += 1;
                        }
                        pcaUrl += "<td style='texg-align:left;'><a href='/city/" + p.ToString() + "-" + dt.Rows[i]["cityID"].ToString().Trim() + "-0.htm'>" + dt.Rows[i]["cityTxt"].ToString().Trim() + "</a></td>";
                        if ((i + 1) % 5 == 0)
                        {
                            pcaUrl += "</tr>";
                        }
                    }
                    pcaUrl += "</table></p>";
                    pcaHeight = dtRow * 22 + 52;
                }
                else
                {
                    dt = sql.getDataTable("select * from selectProvince order by provinceID");
                    pcaUrl += "<p style='margin:0px; padding:2px; background:#ffffff;'><table cellpadding='1' cellspacing='1' border='0' align='center' style='width:95%;'>";
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if ((i + 1) % 5 == 1)
                        {
                            pcaUrl += "<tr>";
                            dtRow += 1;
                        }
                        pcaUrl += "<td style='texg-align:left;'><a href='/city/" + dt.Rows[i]["provinceID"].ToString().Trim() + "-0-0.htm'>" + dt.Rows[i]["provinceTxt"].ToString().Trim() + "</a></td>";
                        if ((i + 1) % 5 == 0)
                        {
                            pcaUrl += "</tr>";
                        }
                    }
                    pcaUrl += "</table></p>";
                    pcaHeight = dtRow * 22 + 52;
                }
            }
            dt.Dispose();
        }
    }

    private bool getTreeName(string localUrl, string strName)
    {
        if (localUrl.IndexOf(strName) > -1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}