function yuiNavigation(p_sType, p_aArgs, p_oValue) {
  // ../admin_old/
  if (p_oValue.substr(0,13) == '../admin_old/') {
    location.href = p_oValue;
  } else {
    location.href = "index.php?page=" + p_oValue;
  }
}
function tableDate(oData) {
  if (oData.length > 0) {
    return new Date(oData);
  } else {
    return null;
  }
}
var menu_loaded = false;
var input_panel = assignment_panel = false;
function customInitializePage() {
  if (document.getElementById('inputpanel')) {
    input_panel = new YAHOO.widget.Panel("inputpanel", {
  		draggable: true,
  		fixedCenter: true,
  		close: false,
  		autofillheight: "body", // default value, specified here to highlight its use in the example
  		constraintoviewport:true,
  		context: ["showbtn", "tl", "bl"],
  		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration: 1}
  	});
   input_panel.render();
   input_panel.hide();
  }
  if (document.getElementById('assignmentpanel')) {
    assignment_panel = new YAHOO.widget.Panel("assignmentpanel", {
  		draggable: true,
  		fixedCenter: true,
  		close: false,
  		autofillheight: "body", // default value, specified here to highlight its use in the example
  		constraintoviewport:true,
  		context: ["showbtn", "tl", "bl"],
  		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration: 1}
  	});
   assignment_panel.render();
   assignment_panel.hide();
  }
  if (!document.getElementById('resizablepanel')) {
    return;
  }
  YAHOO.widget.DateCellEditor.prototype.resetForm = function() {
    if (!this.value) {
      //Handle empty values
      this.value = new Date();
    }
    var value = this.value;
    if (value.length == 0) {
      this.value = new Date();
    }
    var selectedValue = (value.getMonth()+1)+"/"+value.getDate()+"/"+value.getFullYear();
    this.calendar.cfg.setProperty("selected",selectedValue,false);

   // This is the missing line:
    this.calendar.cfg.setProperty("pagedate",(value.getMonth()+1)+"/"+value.getFullYear());
    this.calendar.render();
  };
	var inner_window_settings = YAHOO.util.Cookie.get("iwp");
	if (inner_window_settings == null) {
		iw_width = (getWidth()*.8);
		iw_height = (getHeight()*.8);
		iw_x = Math.floor((getWidth() - iw_width)/2);
		iw_y = Math.floor((getHeight() - iw_height)/2);
		YAHOO.util.Cookie.set("iwp", iw_x + "," + iw_y + "," + iw_width + "," + iw_height, { expires: new Date("January 12, 2025") });  //inner_window_position x, y, width, height
	} else {
		iws_pieces = inner_window_settings.split(',');
		iw_x = iws_pieces[0];
		iw_y = iws_pieces[1];
		iw_width = iws_pieces[2];
		iw_height = iws_pieces[3];
	}

	/*
	Initialize and render the MenuBar when the page's DOM is ready
	to be scripted.
	*/
	YAHOO.util.Event.onDOMReady(function () {
    if (menu_loaded) {
      return;
    }
    menu_loaded = true;
	/*
		 Define an array of object literals, each containing
		 the data necessary to create the items for a MenuBar.
	*/

	/*
	  Instantiate a Menu:  The first argument passed to the constructor
	  is the id for the Menu element to be created, the second is an
	  object literal of configuration properties.
	*/
 if (!document.getElementById('login_admin_username')) {
 var oMenuBar = new YAHOO.widget.MenuBar("teratask_menu_bar", {
											lazyload: true,
											itemdata: aItemData,
											zIndex: 10
											});

 /*
		 Since this MenuBar instance is built completely from
		 script, call the "render" method passing in a node
		 reference for the DOM element that its should be
		 appended to.
	*/
	oMenuBar.render(document.body);

	// Add a "show" event listener for each submenu.

	function onSubmenuShow() {
	  var oIFrame, oElement, nOffsetWidth;

	  // Keep the left-most submenu against the left edge of the browser viewport
	  if (this.id == "yahoo") {
		YAHOO.util.Dom.setX(this.element, 0);
		oIFrame = this.iframe;
		if (oIFrame) {
		  YAHOO.util.Dom.setX(oIFrame, 0);
		}
		this.cfg.setProperty("x", 0, true);
	  }

	  /*
		Need to set the width for submenus of submenus in IE to prevent the mouseout
		event from firing prematurely when the user mouses off of a MenuItem's
		text node.
	  */

	  if ((this.id == "emails_sub_menu" || this.id == "settings_menu"  || this.id == "loyalty_lock_sub_menu" || this.id == "report_menu" || this.id == "admin_sub_menu" || this.id == "agent_sub_menu" || this.id == "user_menu" || this.id == "karingtongroup") && YAHOO.env.ua.ie) {
		  oElement = this.element;
		  nOffsetWidth = oElement.offsetWidth;

		  /*
			  Measuring the difference of the offsetWidth before and after
			  setting the "width" style attribute allows us to compute the
			  about of padding and borders applied to the element, which in
			  turn allows us to set the "width" property correctly.
		  */

		  oElement.style.width = nOffsetWidth + "px";
		  oElement.style.width = (nOffsetWidth - (oElement.offsetWidth - nOffsetWidth)) + "px";
	  }
	}

	// Subscribe to the "show" event for each submenu

	oMenuBar.subscribe("show", onSubmenuShow);
	/*
	var oPanel = new YAHOO.widget.Panel("welcomewindow", { constraintoviewport: true, fixedcenter: true, width: "400px", zIndex: 2});

	oPanel.setHeader("Welcome");
	oPanel.setBody("Welcome to the new Karington Marketing Group, Inc Administration Panel!  Menu options are now along the top and tips will be provided throughout to help guide you through getting the most from the new system.");
	oPanel.render(document.body);
	*/
  }
	// Create a panel Instance, from the 'resizablepanel' DIV standard module markup
	//alert(iw_x + "," + iw_y + "," + iw_width + "," + iw_height);
	var panel = new YAHOO.widget.Panel("resizablepanel", {
		draggable: true,
		fixedCenter: false,
		close: false,
		width: iw_width + "px",
		height: iw_height + "px",
		autofillheight: "body", // default value, specified here to highlight its use in the example
		constraintoviewport:true,
		x: parseInt(iw_x),
		y: parseInt(iw_y),
		context: ["showbtn", "tl", "bl"],
		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration: 1}
	});
	panel.render();

	panel.dd.subscribe('endDragEvent', function(args) {
		iw_x = panel.cfg.config.x.value;
		iw_y = panel.cfg.config.y.value;
		YAHOO.util.Cookie.set("iwp", iw_x + "," + iw_y + "," + iw_width + "," + iw_height, { expires: new Date("January 12, 2025") });  //inner_window_position x, y, width, height
	}, panel, true);

	// Create Resize instance, binding it to the 'resizablepanel' DIV
	var resize = new YAHOO.util.Resize("resizablepanel", {
		handles: ["br"],
		autoRatio: false,
		minWidth: 300,
		minHeight: 100,
		status: false
	});

	// Setup startResize handler, to constrain the resize width/height
	// if the constraintoviewport configuration property is enabled.
	resize.on("startResize", function(args) {

	if (this.cfg.getProperty("constraintoviewport")) {
			var D = YAHOO.util.Dom;

			var clientRegion = D.getClientRegion();
			var elRegion = D.getRegion(this.element);

			resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
			resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
	  } else {
			resize.set("maxWidth", null);
			resize.set("maxHeight", null);
	}

	}, panel, true);

	// Setup resize handler to update the Panel's 'height' configuration property
	// whenever the size of the 'resizablepanel' DIV changes.

	// Setting the height configuration property will result in the
	// body of the Panel being resized to fill the new height (based on the
	// autofillheight property introduced in 2.6.0) and the iframe shim and
	// shadow being resized also if required (for IE6 and IE7 quirks mode).
	resize.on("resize", function(args) {
		var panelHeight = args.height;
		this.cfg.setProperty("height", panelHeight + "px");
	}, panel, true);

	resize.on("endResize", function(args) {
		iw_height = args.height;
		iw_width = args.width;
		YAHOO.util.Cookie.set("iwp", iw_x + "," + iw_y + "," + iw_width + "," + iw_height, { expires: new Date("January 12, 2025") });  //inner_window_position x, y, width, height
	}, panel, true);
	});
}
function toggleSearchBox() {
  if (document.getElementById('search_box').className == "closed") {
    document.getElementById('search_box').className = "open";
  } else {
    document.getElementById('search_box').className = "closed";
  }
}
onLoadCalls.push(new onLoadCall('customInitializePage',''));
function toggleBox(target) {
  if (document.getElementById(target).style.display == 'none') {
    document.getElementById(target).style.display = 'block';
  } else {
    document.getElementById(target).style.display = 'none';
  }
}
function showInputPanel(work_assignment_id, product_id, admin_account_id) {
  var current_select, i;
  
  current_select = document.getElementById('work_log_work_assignment_id').options;
  if (current_select && current_select.length > 0) {
    for(i=0;i<current_select.length;i++) {
      if (current_select[i].value == work_assignment_id) {
        current_select.selectedIndex = i;
      }
    }
  }
  current_select = document.getElementById('work_log_product_id').options;
  if (current_select && current_select.length > 0) {
    for(i=0;i<current_select.length;i++) {
      if (current_select[i].value == product_id) {
        current_select.selectedIndex = i;
      }
    }
  }
  current_select = document.getElementById('work_log_admin_account_id').options;
  if (current_select && current_select.length > 0) {
    for(i=0;i<current_select.length;i++) {
      if (current_select[i].value == admin_account_id) {
        current_select.selectedIndex = i;
      }
    }
  }
  //document.getElementById('inputpanel').innerHTML = setPanelPrimaryKey(primary_key, document.getElementById('inputpanel').innerHTML);
  input_panel.show();
}
function addAssignment(admin_account_id, account_id) {
  //document.getElementById('assignmentpanel').innerHTML = setPanelPrimaryKey(primary_key, document.getElementById('assignmentpanel').innerHTML);
  
  var current_select = document.getElementById('work_assignment_admin_account_id').options;
  if (current_select && current_select.length > 0) {
    for(i=0;i<current_select.length;i++) {
      if (current_select[i].value == admin_account_id) {
        current_select.selectedIndex = i;
      }
    }
  }
  current_select = document.getElementById('work_assignment_account_id').options;
  if (current_select && current_select.length > 0) {
    for(i=0;i<current_select.length;i++) {
      if (current_select[i].value == account_id) {
        current_select.selectedIndex = i;
      }
    }
  }
  
  assignment_panel.show();
}

function setPanelPrimaryKey(new_key, html) {
  return html;
  
  if (!new_key) {
    new_key = -1;
  }
  var current_key = html.search(/\[/);
  if (current_key) {
    var end_pos = html.search(/\]/,current_key);
    if (end_pos) {
      current_key = parseInt(html.substr(current_key+1, end_pos-current_key-1));

      var my_reg_ex = new RegExp(current_key,"g");
      console.log(html.replace(my_reg_ex, new_key));
      return html.replace(my_reg_ex, new_key);
    }
  }
}
