/*/将Tab键转换为回车键
function window.document.onkeydown()
{
	if(event.keyCode==13)
		event.keyCode=9;
}
*/

var bSelect = false;	//ListPage页面 是否为选择模式，默认为 否
var oldCheck;			//原先选择的 CheckBox

//页面内复选框只能单选
function singleSelect(obj)
{
//alert(obj.tagName);
	if (obj.tagName.indexOf('INPUT') >= 0) obj = obj.parentElement;
	//alert(obj.tagName);
	//选中行背景色处理
	if (oldCheck != null )
	{		
		oldCheck.parentElement.parentElement.parentElement.className = "LineBgColor";
	}
	
	obj.parentElement.parentElement.className = "SelectedLineBgColor";
	
	//if (obj == null) return;
	//if (obj.children[0] == null) return;
	if (oldCheck != null && oldCheck == obj.children[0])
	{	
		obj.children[0].checked = obj.children[0].checked == true?true:false;
		obj.parentElement.parentElement.className = obj.children[0].checked == true?"SelectedLineBgColor":"LineBgColor";
	}else
	{
		for(var i=0; i<document.all.length; i++)
		{
			if (document.all[i] == null) continue;
			if (document.all[i].id.indexOf("chk") < 0) continue;
			document.all[i].checked = false;		
		}		
		obj.children[0].checked = true;
		
		oldCheck = 	obj.children[0];
	}
	
	
}

//检查是否已选择
function isSelected()
{
	for(var i=0; i<document.all.length; i++)
	{
		if (document.all[i] == null) continue;
		if (document.all[i].id.indexOf("chk") < 0) continue;
		if (document.all[i].checked == true) return true;
		continue;		
	}
	return false;
}

//全选和反选
function selectAll()
{
	for(var i=0; i<document.all.length; i++)
	{
		if (document.all[i] == null) continue;
		if (document.all[i].id.indexOf("chk") < 0) continue;
		document.all[i].checked = document.all[i].checked == false?true:false;
	}		
}

var modifyFrameHeight ;				//编辑　Frame 高度

/*响应功能按钮
url:点击增加按钮后，编辑页装载页面虚拟路径和文件名
height:编辑页Frame 初始高度
*/
function addData(url,height)
{	
	if (top.mainContent.rows != "45,*,0")
	{
		top.mainContent.rows = "45,*,0";
		return;
	}else
	{
		modifyFrameHeight　=　height;//alert(modifyFrameHeight);
		top.mainContent.rows = "45,*," + height;
		top.modifyFrame.location.href = url;
	}
	
}

/*响应编辑按钮
obj:触发本事件的对象
url:点击编辑按钮后，编辑页装载页面虚拟路径和文件名
type:触发本事件的对象的类型:Label,Button
height:编辑页Frame 初始高度
*/
function editData(obj,url,type,height)
{
	//检查是否有清除的选中Check，如果有，则去掉；有问题：选中项目失去选中状态
	for(var i=0; i<document.all.length; i++)
	{
		if (document.all[i] == null) continue;
		if (document.all[i].id.indexOf("chk") < 0) continue;
		document.all[i].checked = false;		
	}		
//alert("url:" + url);alert("bSelect:" + bSelect);
	if (bSelect == true)
	{
		 return false;
	}
	//alert("1:" + 1);
	var linkUrl;
	if (type == "Label")
	{		
		var chk = obj.id.replace('lbEditLink','chk');
		if (chk != null)
		{			
			if (oldCheck != null)
			{
				oldCheck.checked = false;
				oldCheck.parentElement.parentElement.parentElement.className = "LineBgColor";
			}
			oldCheck = eval("document.all." + chk);
			
			oldCheck.checked = true;
			oldCheck.parentElement.parentElement.parentElement.className = "SelectedLineBgColor";			
			
			
			top.mainContent.rows = "45,*," + height;
			//top.mainContent.rows = "45,0,*";		
			var id = oldCheck.parentElement.name;
			linkUrl = url + "?id=" + id;
		}
		
	}else if (type == "Button")
	{//alert("2:" + oldCheck);
		top.mainContent.rows = "45,*," + height;
		
		//服务器端调用此函数	
		if (oldCheck == null && url.indexOf("?") >= 0)
		{//alert("3:" + 3);			
			linkUrl = url;
		}else if (oldCheck != null && url.indexOf("?") < 0) 
		{//alert("4:" + 4);			
			var id = oldCheck.parentElement.name;
			linkUrl = url + "?id=" + id;
		}//alert("5:" + 5);		
	}
	//alert("url:" + LinkUrl);
	var prevUrl = document.location.href;
	prevUrl = prevUrl.substr(prevUrl.lastIndexOf("\/")+1);
	
	modifyFrameHeight　=　height;
				
	linkUrl += "&prevurl=" + prevUrl;
	top.modifyFrame.location.href = linkUrl;
	
	
}

//响应编辑页 向上向下收缩或伸长Frame
function toTopBottom(obj)
{
	if (obj.innerText == "Top")
	{//alert(modifyFrameHeight);
		top.mainContent.rows = "45,0,*";
		obj.innerText = "Down";		
	}else if (obj.innerText == "Down")
	{
	//alert(modifyFrameHeight);
		top.mainContent.rows = "45,*,200";// + modifyFrameHeight;
		obj.innerText = "Top";		
	}
}

//隐藏编辑页Frame 
function toHide()
{	
	top.mainContent.rows = "45,*,0";
}


//打开新窗口
function openWin(url,width,height,left,top)
{
	//600,380,220,200
	width = 600;
	height = 380;
	left = 220;
	top = 200;
	var prevUrl = document.location.href;
	prevUrl = prevUrl.substr(prevUrl.lastIndexOf("\/")+1);
	if (url.indexOf("?") < 0) url += "?prevurl=" + prevUrl;
	else url += "&prevurl=" + prevUrl;
	
	window.open(url,'','toolbar=no ,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + "'");
}


//关闭编辑Frame
function ChangeModifyFrame()
{
	var href = document.location.href.toLowerCase();
	if (href.indexOf("\?") > 0) href = href.substr(0,href.indexOf("\?"));
	if (href.indexOf("list") < 0) return;
	if (top.mainContent == null) return;
	if (event.srcElement.outerHTML.indexOf('add') <0 && event.srcElement.outerHTML.indexOf('edit') <0 && top.mainContent.rows != "45,*,0")	
		top.mainContent.rows = "45,*,0";
}

document.onclick = ChangeModifyFrame;

