var cagbcFields = Array();

function cagbc_field(thisId) {
 cagbcFields[cagbcFields.length] = thisId.name;
}

function cagbc_submit(Action, Form) {
 var Form  = document[Form];
 if(cagbcFields.length) {
  Form.action_str.value = cagbcFields.join(",");
 }
 Form.action = Action;
 Form.submit();
}

function errorFocus(Field, Form) {
 var Form  = document[Form];
 Form[Field].focus();
}

function cagbcPhone(thisId, Event) {
 var valid = 0;
 if(browser[0] == 'ie')
  var Key = Event.keyCode;
 else
  var Key = Event.charCode;


 var bob = "abc";
 Valid = new Array();
 Valid[37] = 1;
 Valid[38] = 1;
 Valid[39] = 1;
 Valid[40] = 1;
 Valid[8] = 1;
 Valid[9] = 1;
 Valid[46] = 1;
if(thisId.value.length == 14 && !Valid[Event.keyCode])
  thisId.value+=' ';
 if(thisId.value.length >= 15)
  return true;
 if((Key >=48 && Key <= 57) || Valid[Event.keyCode]) {
  valid = 1;
  if(thisId.value.length == 0)
   thisId.value = '(';

  if(thisId.value.substr(0,1)!='(')
   thisId.value = '(' + thisId.value;


  if(thisId.value.length == 3 && !Valid[Event.keyCode]) {
   thisId.value += String.fromCharCode(Key);
   thisId.value+= ') ';
   return false;
  }
  if(thisId.value.length == 4 && !thisId.value.substr(5,1)!=')' && !Valid[Event.keyCode]) {
   thisId.value+= ')';
  }
  if(thisId.value.length == 5 && !thisId.value.substr(5,1)!=' ' && !Valid[Event.keyCode]) {
   thisId.value+= ' ';
  }
 if(thisId.value.length == 8 && !Valid[Event.keyCode]) {
   thisId.value += String.fromCharCode(Key);
   thisId.value+= '-';
   return false;
  }
  if(thisId.value.length==9 && !thisId.value.match(/-$/) && !Valid[Event.keyCode])
   thisId.value+= '-';
 }
 if(valid)
  return true;
 else
  return false;
}

function cagbc_trash(evt, Link) {
 evt = evt ? evt : event;
 evt.cancelBubble = true;

 var str = "Are you sure you wish to remove this user?";
 if(confirm(str)) {
  window.location.href = Link;
 }
}

function edit_button(thisId, ON) {
 if(ON) {
  thisId.className = 'edit_buttonOn';
 }
 else {
  thisId.className = 'edit_button';
 }
}

var clearedValue = Array();
function clearValue(thisId) {
 if(!clearedValue[thisId.name]) {
  thisId.value = '';
  clearedValue[thisId.name] = 1;
 }
}

function cagbcEnter(evt, Action) {
 E = evt ? evt : event;
 if(E && E.keyCode==13) {
  cagbc_submit(Action);
 }
}

function getPos(thisId) {
 var pos  = new Object();
 pos.left = 0;
 pos.top  =  0;
 while(thisId.offsetParent) {
  pos.top+= thisId.offsetTop;
  pos.left+= thisId.offsetLeft;
  thisId=thisId.offsetParent;
 }
 return pos;
}



var escape_node;
function  escapeNode(Node) {
 escape_node = Node;
 document['onkeypress']=clearEscapeNode;
}

function clearEscapeNode(evt)
{
 if(evt) {
  if(evt.keyCode==27)
   escapeClear();
 }
 else if(event) {
  if(event.keyCode==27)
   escapeClear();
 }
}

function escapeClear() {
 escape_node.style.display = 'none';
}

function number_pad(Num, Len) {
 str = ""+Num;
 while(str.length < Len) {
  str = '0' + str;
 }
 return str;
}

function show_image(Img, width, height) {
 Win = window.open('', '', 'width='+width+',height='+height);
 str = '<html>\n';
 str+= "<head>\n";
 str+= "<body style='background:red;margin:0;padding:0;'>\n";
 str+= "<a href='javascript:window.close();'><img src='"+Img+"' border=0></a>\n";
 str+= "</body>\n";
 str+= "</head>\n";  
 str+= "</html>\n";


 Win.document.write(str);
 Win.document.close();
}
