//---------------------cookie---------------------------
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

var uploadFileOn=false;
function updateUploadFile(obj){
    var _tabs=document.getElementsByTagName("TABLE");
    var _tab=_tabs.item(0);
     var _file_tr;
    if(!uploadFileOn){
	    _file_tr=document.createElement("TR");
	   _file_tr.id="tr_uploadfile";
	   var _file_empty_td=document.createElement("TD");
	   _file_empty_td.innerText=" ";
	   var _file_td=document.createElement("TD");
	   var _file_input=document.createElement("INPUT");
	   _file_input.setAttribute("type","file");
	   _file_input.setAttribute("name","file");
	   
	   _file_td.appendChild(_file_input);
	   _file_tr.appendChild(_file_empty_td);
	  _file_tr.appendChild(_file_td);
	  
	   
	   var beforeTr=obj.parentNode.parentNode;
	   alert(beforeTr);
	   beforeTr.insertAdjacentElement("afterEnd",_file_tr);
	   
	  uploadFileOn=true;
	   
	
	}
	else{
	   _file_tr=document.getElementById("tr_uploadfile");
	   _file_tr.style.display="none";
	   alert(_file_tr);
	   _tab.removeChild(_file_tr);
	   uploadFileOn=false;
	   alert(uploadFileOn);
	}

	   
	
}

//===========????????????HTML??????????????????=============
function getElementOffset( objElement) {
  var iLeft = iTop = iWidth = iHeight = 0;
  if (objElement.getBoundingClientRect) {
    // IE
    var objRectangle = objElement.getBoundingClientRect();
    iLeft = objRectangle.left;
    iTop = objRectangle.top;
    iWidth = objRectangle.right - iLeft;
    iHeight = objRectangle.bottom - iTop;
    // getBoundingClientRect returns coordinates relative to the window
    iLeft += getPageScrollX() - 2;
    iTop += getPageScrollY() - 2;
  } else if (document.getBoxObjectFor) {
    // Mozilla
    try{
    var objRectangle = document.getBoxObjectFor(objElement);
    }
    catch(e){alert("getBoxObjectFor error");};
    iLeft = objRectangle.x;
    iTop = objRectangle.y;
    iWidth = objRectangle.width;
    iHeight = objRectangle.height;
  } else {
    // Others
    iWidth = objElement.offsetWidth;
    iHeight = objElement.offsetHeight;
    while (objElement.offsetParent) {
      iLeft += objElement.offsetLeft;
      iTop += objElement.offsetTop;
      objElement = objElement.offsetParent;
    }
  }
  return {
    left: iLeft,
    top: iTop,
    x: iLeft,
    y: iTop,
    width: iWidth,
    height: iHeight
  };
}; 	



function getPageScrollY() {
  if (window.pageYOffset) {
  //alert("window.pageYOffset");
    return window.pageYOffset;
  } else if (document.body && document.body.scrollTop) {
  //alert("document.body.scrollTop");
    return document.body.scrollTop;
  } else if (document.documentElement && document.documentElement.scrollTop) {
    //alert("document.documentElement.scrollTop");
    return document.documentElement.scrollTop;
  }
  //alert("null");
  return 0;
};

function getPageScrollX() {
  if (window.pageXOffset) {
    return window.pageXOffset;
  } else if (document.body && document.body.scrollLeft) {
    return document.body.scrollLeft;
  } else if (document.documentElement && document.documentElement.scrollLeft) {
    return document.documentElement.scrollLeft;
  }
  return 0;
};

var RadioUtil = new Object();
var CheckBoxUtil = new Object();
RadioUtil.getCheckedElement = function(objId){
try{
	var objs = document.getElementsByName(objId);
	for(var i=0; i<objs.length; i++){
		if(objs[i].checked == true){
			return objs[i];
		}
	}
}catch(e){return null;}
}

CheckBoxUtil.getCheckedElement = function(objId){
	var elements = new Array();
	var objs = document.getElementsByTagName("Input");
	for(var i=0; i<objs.length; i++){
		if(objs[i].getAttribute("type").trim()=="checkbox" && objs[i].getAttribute("id").trim()==objId){
			if(objs[i].checked == true)
				elements.push(objs[i]);
		}
	}
	return elements;
}