﻿var ActiveRow=null;
var ActiveEditObject=null;

var xmlhttp=null;
function postAjax(url)
{
  if (!xmlhttp)
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp.Open("POST", url, false); //同步支持，太妙了。
  xmlhttp.onreadystatechange= HandleStateChange;
  xmlhttp.Send(null);
}

function postAjax1(url)
{
  if (!xmlhttp)
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp.Open("POST", url, false);//同步支持，太妙了。
  xmlhttp.onreadystatechange= HandleStateChange1;
  xmlhttp.Send(null);
}
function HandleStateChange1()
{
  if (xmlhttp.readyState == 4)
  {
  var str=xmlhttp.responseText;
 // alert(str.substring(0,str.lastIndexOf("</table>"))+"</table>");
  	 document.getElementById("tdmain").innerHTML=str.substring(0,str.lastIndexOf("</table>"))+"</table>";
  }
}
function HandleStateChange()
{
  if (xmlhttp.readyState == 4)
  {
	  eval(xmlhttp.responseText);
  }
}

  function   defaultKeyDown()   
  {   
  switch   (event.keyCode)   
  {   
  case   13:   
  //检测样式名,   确实是否为按钮  
  if(event.srcElement.className   ==   "fbtclass")   return   true;   
  if(event.srcElement.tagName != "TEXTAREA")event.keyCode   =   9;   
  return   true;   
  break;   
  case 116:
    event.keyCode = "0";
    top.handclose = true;
    top.location = top.location;
    return false;
    break; 
  }   
  }   

function getUrlBase(sType)
{
	if (sType == "Frame")
	{
		var protocol	= top.frames[2].location.protocol;
		var hostname	= top.frames[2].location.hostname;
		var port		= top.frames[2].location.port;
		var pathname	= top.frames[2].location.pathname;
	}
	else
	{
		var protocol	= window.location.protocol;
		var hostname	= window.location.hostname;
		var port		= window.location.port;
		var pathname	= window.location.pathname;			
	}		
	var path = pathname.split("/");	
	if (pathname.charAt(0) == "/")
	{
		var base = "/" + path[1];
	}
	else
	{
		var base = "/" + path[0];
	}
	if (port && port != "80")
	{
		var urlBase = protocol + "//" + hostname + ":" + port + base;
	}
	else
	{
		var urlBase = protocol + "//" + hostname + base;
	}				
	return urlBase;
}

function GetUrlBaseNew(sType)
{
	if (sType == "Frame")
	{
		var protocol	= top.Main.location.protocol;
		var hostname	= top.Main.location.hostname;
		var port		= top.Main.location.port;
		var pathname	= top.Main.location.pathname;
	}
	else
	{
		var protocol	= window.location.protocol;
		var hostname	= window.location.hostname;
		var port		= window.location.port;
		var pathname	= window.location.pathname;			
	}		
	var path = pathname.split("/");	
	if (pathname.charAt(0) == "/")
	{
		var base = "/" + path[1];
	}
	else
	{
		var base = "/" + path[0];
	}
	if (port && port != "80")
	{
		var urlBase = protocol + "//" + hostname + ":" + port + base;
	}
	else
	{
		var urlBase = protocol + "//" + hostname + base;
	}				
	return urlBase;
}

function showModal(page,width,height)
{				
	var select = getUrlBase() + "/"+page;	
    var result=window.showModalDialog(select, window, "dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:0;status:0;scroll:1;center:1;resizable=1");				
    return result=='okok';
}	

var subWin = null;
var interval = null;
function showOpen(page,width,height)
{
    var select = getUrlBase() + "/"+page;	
    subWin=window.open(select, "dadsadew", "height="+height+",width="+width+",menubar=no,resizable=no,status=no,titlebar=0");				
    subWin.focus();
    subWin.onunload=function aa()
                    {
                        opener.subWin=null;
                    };
    subWin.oncontextmenu=function bb()
                        {
                            return false;
                        };
    subWin.onkeydown=function cc()
                    {
                        if(event.keyCode=='116')
                        {
                            event.keyCode='0';
                            event.returnValue=false;
                        }
                    };
    interval = setInterval("refreshOpener()", 500);
}

function refreshOpener()
{
    //alert(subWin)
    if(subWin == null)
    {
        window.clearInterval(interval);
        window.location.href = window.location.href;
    }
}

function showModalScroll(page,width,height)
{				
	var select = getUrlBase() + "/"+page;	
    var result=window.showModalDialog(select, window, "dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:0;status:0;scroll:1;center:1;resizable=1");				
    return result=='okok';
}	


function openStdWin(sPath, sName, iX, iY)
{
	var select = getUrlBase() + "/"+sPath;	
	if (!iX) iX = 750;
	if (!iY) iY = 510;
	//try
	//{		
		window.open(select, sName, "width=" + iX + ",height=" + iY + ",status=1,resizable=0,menubar=0");
	//}
	//catch(e) {}
}

function openStdWinScroll(sPath, sName, iX, iY)
{
	var select = getUrlBase() + "/"+sPath;	
	if (!iX) iX = 750;
	if (!iY) iY = 510;
	//try
	//{		
		window.open(select, sName, "width=" + iX + ",height=" + iY + ",status=1,scroll=1,resizable=0,menubar=0");
	//}
	//catch(e) {}
}


function showModalDoNothing(page,width,height)
{
	var select = getUrlBase() + "/"+page;
	window.showModalDialog(select, window, "dialogWidth:"+width+"px;dialogHeight:"+
	  height+"px;help:0;status:0;scroll:1;center:1;resizable=0");
	return true;
}
function showModalDoNothingNew(page,width,height,gridId)
{
	var select = getUrlBase() + "/"+page;
	window.showModalDialog(select, window, "dialogWidth:"+width+"px;dialogHeight:"+
	  height+"px;help:0;status:0;scroll:1;center:1;resizable=0");
	  
	  //
	  var grid =wgGetGridById(gridId);
	 
	  if(grid!=null)
	  {
    	grid.Refresh(); 
      }
      
	return true;
}
function showModalDoNothingScroll(page,width,height)
{
	var select = getUrlBase() + "/"+page;
	window.showModalDialog(select, window, "dialogWidth:"+width+"px;dialogHeight:"+
	  height+"px;help:0;status:0;scroll:1;center:1;resizable=0");
	return true;
}

function selectAll(gridname,fieldindex)
{
  var grid = wgGetGridById(gridname);
  var rows = grid.GetRootTable().gettbTBElement().rows;
  for (var i=0; i< rows.length; i++) {
    if (rows[i].type == "Record") {
      var cell = wgGetCellByPosition(rows[i], fieldindex);
      cell.childNodes[0].checked = true; 
    }
  }
  //wgMarkEdit(grid);  
} 

function selectNone(gridname,fieldindex)
{
  var grid = wgGetGridById(gridname);
  var rows = grid.GetRootTable().gettbTBElement().rows;
  for (var i=0; i< rows.length; i++) {
    if (rows[i].type == "Record") {
      var cell = wgGetCellByPosition(rows[i], fieldindex);
      cell.childNodes[0].checked = false; 
    }
  }
} 

function doBeforeUpdate()
{
    //alert("updating");
    return true;
}

//========================handle the key down event modified by xlzhu @ 2005.12.20
function doEditKeyDown(gridId)
{	
	//Change Enter to Tab
	
	if(event.keyCode == 13)
	{
		event.keyCode = 9;
	}
	else
	{
	
		//handle the down arrow
		if (event.keyCode == 40)
		{
			event.returnValue = false;		
			var grid = wgGetGridById(gridId);		    
			var ac = grid.GetActiveEditCell();	
			
			if (ac.rowElement.type != "NewRow")
			{    
			
				var tbl = grid.Tables[ac.tblName];		
				grid.ExitEdit(0)			      
				var isParent = (tbl.ChildTables.length > 0)? true : false;				
				SelectDown(ac, isParent);						      
				return false;
			 }
		}
		else
		{
			//handle the up arrow
			if (event.keyCode == 38)
			{
				event.returnValue = false;		
				var grid = wgGetGridById(gridId);		    
				var ac = grid.GetActiveEditCell();		
				if (ac.rowElement.type != "NewRow")
				{      
					var tbl = grid.Tables[ac.tblName];									
					grid.ExitEdit(0)								      
					var isParent = (tbl.ChildTables.length > 0)? true : false;									
					SelectUp(ac, isParent);						      
					return false;
				}
			}
		}		
	}	
	return true;
}


function SelectDown(ac, isParent)
{
  var curRow = ac.rowElement;
  var tblElm = wgGetTable(curRow);
  var curRowIndex = curRow.rowIndex;		
  
  var i = (isParent)? 2 : 1;							
  
  // Check if current row is the last row of the table.
  if (curRowIndex < tblElm.rows.length - i)
  {
    // get the destination row
    var destRow = wgGetRowByPosition(tblElm, curRowIndex + i);					
    
    // highlight the destination row
    //wgHighlightRow(destRow);
							
    // get the column name
    var cellName = wgGetColNameByCell(ac.element);
		
    // get the destination cell
    var destCell = wgGetCellByName(destRow, cellName);
						
    // highlight the destination cell
    window.setTimeout(function() { MoveRow(destRow,destCell);}, 500);
  }
}


function SelectUp(ac, isParent)
{
  var curRow = ac.rowElement;
  var tblElm = wgGetTable(curRow);
  var curRowIndex = curRow.rowIndex;		
  
  var i = (isParent)? 2 : 1;							
  
  // Check if current row is the first row of the table.
  if (curRowIndex >= i)
  {
    // get the destination row
    var destRow = wgGetRowByPosition(tblElm, curRowIndex - i);					
    
    // highlight the destination row
   // wgHighlightRow(destRow);
							
    // get the column name
    var cellName = wgGetColNameByCell(ac.element);
		
    // get the destination cell
    var destCell = wgGetCellByName(destRow, cellName);
						
    // highlight the destination cell
   // wgHighlightEditCell(destCell);
     window.setTimeout(function() { MoveRow(destRow,destCell);}, 500);
  }
}

function MoveRow(destRow, destCell) 
 {  
  wgGetRowByElement(destRow).Select();  
  wgHighlightEditCell(destCell); 
 } 


function delBracket(sValue)
{
	var sReturn;
	var position1  = sValue.indexOf("[");
	var position2  = sValue.indexOf("]");	
	
	//邵世民加入第三个判断条件
	if (position1 >= 0 && position2 > 0 && position1 + 1 < position2)
	{
		sReturn = sValue.substring(position1 + 1,position2);
	}
	else
	{
		sReturn = sValue;
	}
	
	return sReturn;
} 
function SetKeyValue(keyvalue1)
	 {
	  var  keyvalue=	document.createElement("<input id='keyvalue' name='keyvalue' type='hidden'/>");
      document.body.appendChild(keyvalue);
	   postAjax(getUrlBase() + "/AjaxServ.aspx?Action=SetKeyValue&SearchValue="+keyvalue1+"&actionParams");  
     }
function GetKeyValue()
{
return  document.getElementById("keyvalue").value;
}

function getCtrlValue(id)
{
	var control = document.getElementById(id);	
	if (control)			
	{
		return id+"="+control.value;
	}
	else
	{
		return "";
	}	
}	

	function openStdDlg(sPath, oArgs, iX, iY)
{
	return window.showModalDialog(sPath, oArgs, "dialogWidth:" + iX + "px;dialogHeight:" + iY + "px;help:0;status:0;scroll:1;center:1");
}

	function openStdDlgScroll(sPath, oArgs, iX, iY)
{
	return window.showModalDialog(sPath, oArgs, "dialogWidth:" + iX + "px;dialogHeight:" + iY + "px;help:0;status:0;scroll:1;center:1");
}

function delBracket(sValue)
{
	var sReturn;
	var position1  = sValue.indexOf("[");
	var position2  = sValue.indexOf("]");	
	
	//邵世民加入第三个判断条件
	if (position1 >= 0 && position2 > 0 && position1 + 1 < position2)
	{
		sReturn = sValue.substring(position1 + 1,position2);
	}
	else
	{
		sReturn = sValue;
	}
	
	return sReturn;
}
 
function showpopup(control,maxLength)                                                
{
 var Message=""; 
 var max=maxLength.toString();
 var leftlen=control.value.length-parseInt(maxLength);
 var left=leftlen.toString();
     if(parseInt(maxLength)<control.value.length)
     {
     Message="请注意，最多可输入"+max+"个字符,已超出"+leftlen.toString()+"个字符"; 
     }
    else
    {          
    Message="还可以输入"+(parseInt(maxLength)-control.value.length)+"个字符";           
    }
    var oPopup = window.createPopup();
    var oPopBody = oPopup.document.body;                    
	oPopBody.style.backgroundColor = 'lightyellow'; 
	oPopBody.style.border = 'solid black 1px';                           
	oPopBody.innerHTML = '<FONT size=2>' + Message+ '</FONT>';
	var h=21;
	if(control.style.height!="")
	{
	h=control.style.height.replace("px","");
	}         
	oPopup.show(0, -40, 180, 30, control);   
return true;
}

function showpopup1(control,Message)                                                
{ 

    var oPopup = window.createPopup();
    var oPopBody = oPopup.document.body;                    
	oPopBody.style.backgroundColor = '#fefbe3'; 
	oPopBody.style.border = 'solid #ff8209 1px'; 
	oPopBody.style.padding = '5px'; 
	oPopBody.innerHTML =Message;
	var h=21;
	if(control.style.height!="")
	{
	h=control.style.height.replace("px","");
	}         
	oPopup.show(0, -40, 210, 90, control);   
return true;
}
function showpopup2(control,Message)                                                
{ 

    var oPopup = window.createPopup();
    var oPopBody = oPopup.document.body;                    
	oPopBody.style.backgroundColor = '#fefbe3'; 
	oPopBody.style.border = 'solid #ff8209 1px'; 
	oPopBody.style.padding = '5px'; 
	oPopBody.innerHTML =Message;
	var h=21;
	if(control.style.height!="")
	{
	h=control.style.height.replace("px","");
	}         
	oPopup.show(0, -40, 180, 40, control);   
return true;
}


function NavigateChannelList(POrganno)
{
    //alert("ChannelPriceList.aspx?ClsNo="+GetCookie('ClsNo')+"&OrganNo="+GetCookie('OrganNo')+"&POrganno="+POrganno+"&OrganName="+GetCookie('OrganName')+"&ProductNo="+GetCookie('ProductNo') );		
    parent.frmChannelPriceList.location ="ChannelPriceList.aspx?ClsNo="+GetCookie('ClsNo')+"&OrganNo="+GetCookie('OrganNo')+"&POrganno="+POrganno+"&OrganName="+GetCookie('OrganName')+"&ProductNo="+GetCookie('ProductNo') ;
}

function NavigateCyChannelList(POrganno)
{
    //alert("ChannelPriceList.aspx?ClsNo="+GetCookie('ClsNo')+"&OrganNo="+GetCookie('OrganNo')+"&POrganno="+POrganno+"&OrganName="+GetCookie('OrganName')+"&ProductNo="+GetCookie('ProductNo') );		
    parent.frmCyChannelPriceList.location ="CyChannelPriceList.aspx?ClsNo="+GetCookie('ClsNo')+"&OrganNo="+GetCookie('OrganNo')+"&POrganno="+POrganno+"&OrganName="+GetCookie('OrganName')+"&ProductNo="+GetCookie('ProductNo') ;
}
 
 
 
function GetCookieVal(offset) 
//获得Cookie解码后的值 
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value) 
//设定Cookie值
{ 
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}

function DelCookie(name)
//删除Cookie
{ 
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

function GetCookie(name) 
//获得Cookie的原始值
{ 
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;
}