﻿// JScript 文件
// swg，2007-9-18: find frame object
function getFrameNode(aFrameName, aDocument)
{
   var doc = aDocument;
   if (doc == null) doc = document;
   return doc.frames ? doc.frames[aFrameName] : doc.getElementById(aFrameName).contentWindow;
}

function ViewObj(obj)
{
    s = new Array();
	s.push(obj + " \n");
	try
	{
	    for(i in obj)
	    {
	        if(typeof(eval("obj." + i)) == "function")
		        s.push("\n" + i + ": function");
            else
  		        s.push("\n" + i + ": " + eval("obj." + i));
        }
    }
    catch(e)
    {
      s.push("\n" + e);
    }
    return s.toString();
}

function PrintObj(obj)
{    
    alert(ViewObj(obj));
}

function BoundTextByWidth(text, width){

    var newtext = '<div style="white-space:nowrap; width:'+width+';overflow:hidden; text-overflow: ellipsis;">' + text +  '</div>';

    return newtext;
}


function BoundTextByTagWidth(text, tagName, width){

    var newtext = '<'+tagName+' style="white-space:nowrap; width:'+width+';overflow:hidden; text-overflow: ellipsis;">' + text +  '</'+tagName+'>';

    return newtext;
}

function BoundTagByWidth(obj, width){

    if(obj){
        obj.style.whiteSpace = "nowrap";
        obj.style.overflow = "hidden";
        obj.style.textOverflow = "ellipsis";
        obj.style.width = width;    
    }
}


function TruncateText(text, length){
    if(text!=null&&text!=''&&text.length>length){
        return text.substring(0,length)+'...';
    
    }else{
        return text;        
    }
}

function   nocontextmenu(evt)     
{   
    evt.cancelBubble   =   true   
    evt.returnValue   =   false;   
        
    return   false;   
}   
    


function GenerateGUID(){
    var guid = "";
    for(var   i = 1; i <= 32; i++)
    {
      var n = Math.floor(Math.random() * 16.0).toString(16);
      guid += n;
    }
    return guid;
}



function ResizePageDiv(namePrefix, indexList, width)
{
    var s = indexList.split(',');
    var i;
    for(i=0; i<s.length; i++)
    {     
        var divObj = document.getElementById(namePrefix + s[i]);
        if(divObj)
        {
            divObj.style.width = width;
        }
    }
}


function DownloadFile(aURL)
{
  var id = 0;
  while (document.getElementById("_downloadFrame" + id) != null)
  {
    id += 1;
    if (id > 100)
    {
      // 防止死循环
      return;
    }
  }
  
  var frm = document.createElement("iframe");
  frm.id = "_downloadFrame" + id;
  frm.style.visibility = "hidden";
  frm.style.display = "none";
  //frm.onload=function(){document.body.removeChild(frm);};
  frm.src = aURL;
  document.body.appendChild(frm);
}

function getEvtClientX(evt)
{
    evt = evt ? evt : (window.event ? window.event : null);
    if(null == evt) return 0;
    var temp = 0;
    if(null != window.scrollMaxY)  //是firefox
    {
        temp = evt.pageX;
    }
    else  // 是Opera和IE
    {
        temp = evt.clientX;
    }
	return temp;
}

function getEvtClientY(evt)
{
    evt = evt ? evt : (window.event ? window.event : null);
    if(null == evt) return 0;
    var temp = 0;
    if(null != window.scrollMaxY)  //是firefox
    {
        temp = evt.pageY;
    }
    else  // 是Opera和IE
    {
        temp = evt.clientY;
    }
	return temp;
}
//获得keypress事件的keycode
function GetKeyCode(aEvent)
{
    if (!aEvent) return;
    if (typeof (aEvent.which) == "number" && aEvent.which != 0)
    {
        return aEvent.which;
    }
    else if (typeof (aEvent.keyCode) == "number" && aEvent.keyCode != 0)
    {
        return aEvent.keyCode;
    }
    else if (typeof (aEvent.charCode) == "number" && aEvent.charCode != 0)
    {
        return aEvent.charCode;
    }
    else
    {
        return;
    }
}

function checkNaN(evt)
{
    var keycode = GetKeyCode(evt);
    if (keycode >= 48 && keycode <= 57)
        return true;
    return false;
}
