//*****************************************************************************
// FUNCTION ACTIONWINDOW
//*****************************************************************************

function actionWindow(action,entity_id) {

 if (entity_id) {
   entity_string = "&entity_id=" + entity_id;
 }
 else {
   entity_string = "";
 }

 url = 'index.php?action=' + action + entity_string;

 var myWindow = window.open(url,
                            action,
                            'left=100,top=100,width=750,height=600,toolbar=0,scrollbars=1,resizable=1');

}

// END FUNCTION ACTIONWINDOW
//*****************************************************************************


//*****************************************************************************
// FUNCTION CREATEHIDDENFIELD
//*****************************************************************************

function createHiddenField(name,id,value) {
  var tmp = document.createElement("input");
  tmp.setAttribute("type","hidden");
  tmp.setAttribute("name",name);
  tmp.setAttribute("id",id);
  tmp.setAttribute("value",value);
  return tmp;
}

// FUNCTION CREATEHIDDENFIELD
//*****************************************************************************


//*****************************************************************************
// FUNCTION CREATEBUTTON
//*****************************************************************************

function createButton(name,id,value,className,onclick) {
  var tmp = document.createElement("input");
  tmp.setAttribute("type","button");
  tmp.setAttribute("name",name);
  tmp.setAttribute("id",id);
  tmp.setAttribute("value",value);
  if (className) {
    tmp.setAttribute("className",className);
  }

  if (onclick) {
    tmp.setAttribute("onclick",onclick);
  }
 
  return tmp;
}

// FUNCTION CREATEBUTTON
//*****************************************************************************


//*****************************************************************************
// FUNCTION CREATETEXTFIELD
//*****************************************************************************

function createTextField(name,id,value,size,maxlength,className) {
  var tmp = document.createElement("input");
  tmp.setAttribute("type","text");
  tmp.setAttribute("name",name);
  tmp.setAttribute("id",id);
  tmp.setAttribute("value",value);
  
  if (size) {
    tmp.setAttribute("size",size);
  }

  if (maxlength) {
    tmp.setAttribute("maxlength",maxlength);
  }

  if (className) {     
    tmp.setAttribute("className",className);     
  }
 
  return tmp;
}
 
// FUNCTION CREATETEXTFIELD
//*****************************************************************************


//*****************************************************************************
// FUNCTION CREATETEXTAREA
//*****************************************************************************

function createTextArea(name,id,text,rows,cols,className) {
  var tmp = document.createElement("textarea");
  tmp.setAttribute("name",name);
  tmp.setAttribute("id",id);
  
  if (text) {
    tmp.innerHTML = text;
  }

  if (rows) {
    tmp.setAttribute("rows",rows);
  }

  if (cols) {
    tmp.setAttribute("cols",cols);
  }

  if (className) {     
    tmp.setAttribute("className",className);     
  }
 
  return tmp;
}

// FUNCTION CREATETEXTAREA
//*****************************************************************************


//*****************************************************************************
// FUNCTION CREATECHECKBOX
//*****************************************************************************

function createCheckbox(name,id,value,checkedValue) {
  var tmp = document.createElement("input");
  tmp.setAttribute("type","checkbox");
  tmp.setAttribute("name",name);
  tmp.setAttribute("id",id);
  
  tmp.setAttribute("value",checkedValue);
  
  if (value == checkedValue) {
    tmp.checked = true;
  }

  return tmp;
}

// FUNCTION CREATECHECKBOX
//*****************************************************************************


//*****************************************************************************
// FUNCTION SETSTYLE
//*****************************************************************************

// takes a style string in the form of "attribute1:value1;attribute2:value2;"
// and applies each style element to the target object

function setStyle(target,style) {

  // split style string in array of attribute/value pairs
  var styleArray = style.split(";");

  // loop through each atribute/value pair, and assign to target
  for (s = 0; s < styleArray.length; s++) {
    styleElement = styleArray[s].split(":");
    // styleElement[0] = attribute
    // styleElement[1] = value
  }
}

// END FUNCTION SETSTYLE
//*****************************************************************************


//*****************************************************************************
// FUNCTION ENCODEHTML
//*****************************************************************************
  function encodeHtml(text) {
     var tmp;
     tmp = text.replace(/\//g,"%2F");
     text = tmp;
     tmp = text.replace(/\?/g,"%3F");
     text = tmp;
     tmp = text.replace(/=/g,"%3D");
     text = tmp;
     tmp = text.replace(/&/g,"%26");
     text = tmp; 
     tmp = text.replace(/@/g,"%40");
     return tmp; 
  } 
// END FUNCTION ENCODEHTML
//*****************************************************************************


//*****************************************************************************
// FUNCTION CONFIRMACTION
//*****************************************************************************

/*
   prompts a user to confirm before envoking the specified action

   required field 0 - formAction
   required field 1 - message
   optional field 2 - entityId
*/

function confirmAction() {

  var formAction = arguments[0];
  var message = arguments[1];
  var entityId;

  if (arguments.length > 2) {
    entityId = arguments[2]; 
    entityString = "&entity_id=" + entityId;
  } 
  else {
    entityId = "";
    entityString = "";
  }

  if (confirm(message)) {
    document.forms[0].action = "index.php?action=" + formAction + entityString;
    document.forms[0].submit();
  }

}

// END FUNCTION CONFIRMACTION
//*****************************************************************************

