﻿String.prototype.remove=function(str)
{
    if(this == str) return "";
    var s='';
    var len = str.length;
    var index = this.indexOf(str);
    if(index>-1)
    {
        if(index==0)
            s=this.substring(len,this.length);  
        else
        {
            index = this.indexOf(";" + str);
            s=this.substring(0,index + 1);
            if(index + len + 1<=this.length) 
                s+=this.substring(index + len + 1,this.length);                
        }
        return s;
        
    }
    else
        return this;
};

String.prototype.EpointAddStr=function(str,div)
{
    var index = this.indexOf(str);
    
    if(index==-1)
       return this + str;
    
    if(index==0)
        return this;
    else
    {
        if(div==null)
            return this + str;
        else
        {
            if(this.indexOf(div + str) > -1)
                return this;
            else
                return this + str;
        }                   
    }        
};

var bgcolor = "#AEF3F0";
var curID;
function InitTree()
{
    var aGuid = window.parent.document.all("ctl00_ContentPlaceHolder1_sourceValue").value.split(';');
    var hml ="";
    for(var i=0;i<aGuid.length - 1;i++)
    {
        if(i==0)
        {
            curID = aGuid[i];
            window.parent.document.all("main").src="PositionInfoView_For_User_NoMasterPage.aspx?PositionID=" + aGuid[i];
        }
        hml += toString(aGuid[i],i==0);   
    }    
    return hml;
}


function toString(id,bl)
{
    var ret = PositionInfoViewTree.GetPositionInfo(id);
    if(ret.value =="") return;
    var positionname = ret.value.split('\b')[0];
    var adddate = ret.value.split('\b')[1];
    var companyname = ret.value.split('\b')[2];
    var html = "<tr height=40px>";
    html +="<td id=\"td" + id + "\" width=\"100%\" style=\"padding-left:2px;border-bottom-style: solid;border-bottom-color: #E8E8E8;border-bottom-width: 1px;\" onclick=\"SetCurTD(this);\""
    
    if(bl)
        html +=" curTD = \"1\"   bgcolor=" + bgcolor + " ";
    else
        html +="  curTD = \"0\" onmouseover=\"this.className = 'PositionTreeOnMouse'\" onmouseout=\"this.className = ''\" ";
    html +=" >"
    
    html +="<table width=\"100%\" cellpadding=0 height=40px cellspacing=0>";
    html +="<tr>";
    html +="<td valign=top width=30px><input onclick=\"javascript:checkBoxClick(this);\" type=checkbox id=\"\" value=\"" + id + "\" /></td>";
    html +="<td><font style=\"font-weight:bolder\">" + positionname + "</font></td>";
    html +="<td align=right>" + adddate + "</td>";
    html +="</tr>";
    html +="<tr><td colspan=3 width=\"100%\">" + companyname + "</td></tr>";
    html +="</table>";
    html +="</td>";
    html +="</tr>";
    return html;
}

function SetCurTD(obj)
{
   
    if(obj.curTD=="1") return;
    window.parent.document.all("main").src="PositionInfoView_For_User_NoMasterPage.aspx?PositionID=" + obj.id.substr(2);
    document.all("td" + curID).bgColor ="White"
    document.all("td" + curID).curTD = "0";
    document.all("td" + curID).onmouseover =function() { this.className = 'PositionTreeOnMouse'; };
    document.all("td" + curID).onmouseout = function() { this.className = ''; };
    obj.className="";
    obj.onmouseover = null;
    obj.onmouseout = null;
    obj.bgColor = bgcolor;
    obj.curTD = "1";
    curID = obj.id.substr(2);
    //TODO:加上右边区域的链接
    //window.parent.document.all("ctl00_ContentPlaceHolder1_selectValue").value.split(';')
}

//判断Grid中是否选中了CheckBox
function CheckSelect(Msg)
{
    var participants = document.getElementsByTagName("input");
	for ( var i=0; i < participants.length; i++ ) 
	{
		//if(participants[i].name.indexOf('Check_RowSelect')!=-1  || participants[i].name.indexOf('chkAdd')!=-1)
		if(participants[i].type == "checkbox" && participants[i].name.indexOf("chkAdd")!=-1 && participants[i].checked)
		{				
			return true;
		}
	}
	if(Msg)
	    alert("请选择"  + Msg + "！");
	else
	    alert("请选择！");
	return false;
}

function SelectAll(obj)
{
    var input = document.getElementsByTagName('INPUT');
    for(var i=0;i<input.length;i++){
        if(input[i].type == "checkbox" && input[i]!= obj)
        {
            input[i].checked= obj.checked;
            AddOrRemoveStr(input[i].value,input[i].checked);
        }
    }
}

function checkBoxClick(obj)
{   
    AddOrRemoveStr(obj.value,obj.checked);   
}

function AddOrRemoveStr(str,bl)
{
    if(bl)
        window.parent.document.all("ctl00_ContentPlaceHolder1_hidSelectValue").value = window.parent.document.all("ctl00_ContentPlaceHolder1_hidSelectValue").value.EpointAddStr(str + ";",";");
    else
       window.parent.document.all("ctl00_ContentPlaceHolder1_hidSelectValue").value = window.parent.document.all("ctl00_ContentPlaceHolder1_hidSelectValue").value.remove(str+ ";");
}

function ConfirmLogout()
{
	if (confirm("注销当前用户,并以其它身份登录？"))
	{
	    window.document.location.href="../Regist/logout.aspx";
    }
    return false;
}

function tips(id,str)
{
	var obj=document.getElementById(id);
	var x=getX(obj);
	var y=getY(obj);
	var l=x;var t=y;
	var popObj=document.getElementById("tips");
	if(popObj!=null)
	{
		popObj.innerHTML="<div class=\"tipcon\">"+str+"</div>";
		popObj.style.display="inline";
		var menu_h=popObj.offsetHeight;
		t-=menu_h;popObj.style.left=l+"px";
		popObj.style.top=t+"px";
	}
}

function outtips()
{
	document.getElementById("tips").style.display='none';
}

function getX(el)
{
    var x=0;
    while(el)
    {
        x+=el.offsetLeft;
        el=el.offsetParent;
    }
    return x;
}

function getY(el)
{
	var y=0;
	for(var e=el;e;e=e.offsetParent)
		y+=e.offsetTop;
	for(e=el.parentNode;e&&e!=document.body;e=e.parentNode)
		if(e.scrollTop)
			y-=e.scrollTop;
	return y;
}