function set_focus(form_name, elt_name) {
  var o_form
  var o_elt

  o_form = document.forms[form_name]
  if (!o_form) return

  o_elt = o_form[elt_name]
  if (!o_elt) return

  o_elt.focus()

  return
}

function set_text(form_name, elt_name, text, only_if_empty, css_class) {
  var o_form 
	var o_elt
	
	o_form = document.forms[form_name]
	if (!o_form) return
	
	o_elt = o_form[elt_name]
	if (!o_elt) return
	
	o_elt.className = css_class
	
	if (only_if_empty) {
	  if (o_elt.value == "") o_elt.value = text
	} else {
	  o_elt.value = text
		o_elt.focus()
	}
}

function show_image(file_name, w, h, name, path) {
  var oWnd = window.open(path + "show_image.php?filename=" + file_name, name, "width=" + w + ",height=" + h)
	return
}

function get_scroll_xy() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function show_popup_form(title, text, popup_form_elt_id, form_width, form_height, is_visible, is_draggable, is_fixed_center, is_modal, has_close_button) {
  // Set the defaults for parameters that are not passed in
  if ((typeof(popup_form_elt_id) == "undefined") || (popup_form_elt_id == "")) popup_form_elt_id = "popup_form";
	if ((typeof(form_width) == "undefined") || (form_width == "")) form_width = "450";
	if ((typeof(form_height) == "undefined") || (form_height == "")) form_height = "150";
	if ((typeof(is_visible) == "undefined") || (is_visible == "")) is_visible = false;
	if ((typeof(is_draggable) == "undefined") || (is_draggable == "")) is_draggable = false;
	if ((typeof(is_fixed_center) == "undefined") || (is_fixed_center == "")) is_fixed_center = true;
	if ((typeof(is_modal) == "undefined") || (is_modal == "")) is_modal = true;
	if ((typeof(has_close_button) == "undefined") || (has_close_button == "")) has_close_button = true;
	// Instantiate a Panel from script
  YAHOO.namespace("popup_form.popup_info");
	YAHOO.popup_form.popup_info.panel = new YAHOO.widget.Panel("panel", { width: (form_width + "px"), height: (form_height + "px"), visible:is_visible, draggable:is_draggable, fixedcenter:is_fixed_center, modal: is_modal,  close:has_close_button } );
	YAHOO.popup_form.popup_info.panel.setHeader(title);
	YAHOO.popup_form.popup_info.panel.setBody(text);
	YAHOO.popup_form.popup_info.panel.render(popup_form_elt_id);
	YAHOO.popup_form.popup_info.panel.show();
}

function show_popup_dialog(title, dialog_text, button_names, default_button_index, popup_form_elt_id, form_width, form_height, is_visible, is_draggable, is_fixed_center, is_modal, has_close_button) {
	var button_clicked = -1;
	var buttons_arr;
	var button_names_arr;
	
  // Set the defaults for parameters that are not passed in
  if ((typeof(popup_form_elt_id) == "undefined") || (popup_form_elt_id == "")) popup_form_elt_id = "popup_form";
	if ((typeof(form_width) == "undefined") || (form_width == "")) form_width = "450";
	if ((typeof(form_height) == "undefined") || (form_height == "")) form_height = "150";
	if ((typeof(is_visible) == "undefined") || (is_visible == "")) is_visible = false;
	if ((typeof(is_draggable) == "undefined") || (is_draggable == "")) is_draggable = false;
	if ((typeof(is_fixed_center) == "undefined") || (is_fixed_center == "")) is_fixed_center = true;
	if ((typeof(is_modal) == "undefined") || (is_modal == "")) is_modal = true;
	if ((typeof(has_close_button) == "undefined") || (has_close_button == "")) has_close_button = true;

  YAHOO.namespace("popup_form.popup_dialog");
	
	button_names_arr = button_names.split("|");
	buttons_arr = new Array(button_names_arr.length);
	for (var j = 0; j < button_names_arr.length; j++) { 
	  alert("in loop button clicked " + j);
	  if (j == default_button_index) { 
		  buttons_arr[j] = { text:button_names_arr[j], handler:function(){ alert("button clicked " + j + "\n" + this); this.hide();}, isDefault:true };
		} else {
		  buttons_arr[j] = { text:button_names_arr[j],  handler:function(){ alert("button clicked " + j + "\n" + this); this.hide();} };
		}
		alert(buttons_arr[j].handler);
	}

	// Instantiate the Dialog
	//																		 icon: YAHOO.widget.SimpleDialog.ICON_HELP,
	YAHOO.popup_form.popup_dialog.simple_dialog = new YAHOO.widget.SimpleDialog("simple_dialog", 
																			 { width: form_width,
																			   height: form_height,
																			   fixedcenter: is_fixed_center,
																			   visible: is_visible,
																			   draggable: is_draggable,
																			   close: has_close_button,
																				 modal: true,
																			   text: dialog_text,
																			   constraintoviewport: true,
																			   buttons: buttons_arr
																			 } );
	YAHOO.popup_form.popup_dialog.simple_dialog.setHeader(title);
	
	// Render the Dialog
	YAHOO.popup_form.popup_dialog.simple_dialog.render(popup_form_elt_id);
	YAHOO.popup_form.popup_dialog.simple_dialog.show();
	
	// Return the index of the button that was selected (it will be set by event handler for the dialog
	var cnt =  0;
	while (button_clicked == -1) {
	  cnt = cnt + 1;
	}
	alert(cnt);
	return button_clicked;
}

function popup_about_form(version, elt_id) { 
	show_popup_form("<p class=\"popup_header\">About SLK Administration Panel</p>", "<p class=\"popup_body about_text\"><strong>SLK Administration Panel<br>Version: " + version + "<br>Copyright: 2004-2011<br><a href=\"http://www.silwikdesign.com\" target=\"_blank\">SilwikDesign.com</a></p>", elt_id, 300, 150);
}
