/*$Id: common.js,v 1.1 2004/06/10 05:55:39 fifa2k Exp $*/
function xyDerupCommon(){};
xyDerupCommon.userLogin = function(actionUrl, gateway){
  var e = document.getElementById("userLoginForm");
  if(e){
    e.submit();
  }
}

document.onkeypress = function(e){
  if(!e){
    e = event;
  }

  if(13 == e.keyCode || 10 == e.keyCode){//ENTER ctrl-Enter is 10 in IE
		if (!e.srcElement) {
			var el = e.target;
			while (el != null && el.nodeType != 1)
				el = el.parentNode;
		}else{
      el = e.srcElement;
    }
    var t = String(el.type).toUpperCase();
    if(el.form && el.form.submit && ("TEXT"  == t || "PASSWORD" == t)){
      el.form.submit();
    }
    if(el.form && el.form.submit && ("TEXTAREA" == t) && e.ctrlKey){
      if(el.form.onsubmit){
        if(el.form.onsubmit()){
          el.form.submit();
          return true;
        }else{
          return false;
        }
      }
      el.form.submit();
    }
  }
}

function xyCheckBox(cn){
  this.className = cn;
}
xyCheckBox.prototype.onclick = function(o){
  var check = o.firstChild;
  if(check.checked){
    check.checked = false;
    o.className = this.className ;
  }else{
    check.checked = true;
    o.className = this.className + " " + this.className + "Checked";
  }
  return false;
}

xyCheckBox.prototype.onchange = function(o){
  var check = o;
  if(check.checked){
    o.parentNode.className = this.className + " " + this.className + "Checked";
  }else{
    o.parentNode.className = this.className ;
  }
  return false;
}
var _checkbox = new xyCheckBox("imgCheckbox");

xyDerupCommon.listCheckAll = function(o){
  var e = o.getElementsByTagName("INPUT");
  var l = e.length;
  var ac = true;
  var cbs = [];var n = 0;
  for(var i = 0;i < l;i ++){
    var inp = e.item(i);
    var tp = String(inp.type).toUpperCase();
    if(tp == "CHECKBOX"){
      ac = ac & inp.checked;
      cbs[n++] = inp;
    }
  }
  ac = ! ac;
  var l = cbs.length;
  for(var i = 0;i < l;i ++){
    cbs[i].checked = ac;
    if(typeof(cbs[i].onchange) == "function"){
      cbs[i].onchange();
    }
  }
}

xyDerupCommon.submitSelection = function(){
  o = document.forms["user_selection"];
  if(typeof o == "object" && null != o){
    o.submit();
  }
}

xyDerupCommon.checkPermission = function(code){
  var reg = new RegExp(code, "");
  return reg.test(gUserPermission) || /\*/.test(gUserPermission);
}

xyDerupCommon.openUpstar = function() {
	window.open("./page/upstar.php","upstar",
    	"height=400,width=320,status=yes,toolbar=no,scrollbars=yes," +
      "menubar=no,location=no");
}


function xyDerupLink(text,href){
  this.text = text;
  this.href = href;
}

xyDerupLink.prototype.toString = function(){
  return "<a href=\"" + this.href + "\">" + this.text + "</a>";
}


