﻿/// <reference path="../jquery/jQuery.intellisense.js" />

function Get_Object(name) {
  var fobj
  if (document.getElementById) {
    fobj = document.getElementById(name);
  } else if (document.all) {
    fobj = document.all[name];
  } else if (document.layers) {
    if (document.layers[name]) {
      fobj = document.layers[name];
    } else {
      fobj = document.layers.testP.layers[name];
    }
  }
  return fobj
}

var curItem;
var setCurItem = false;
function changeVisibility(id)
{
	if ($("#"+id).css("display") == "none") {
		$("#"+id).show();
		$("#img_"+id).attr("src", "/images/icons/collapse_all_dark.gif");
	} else {
		$("#"+id).hide();
		$("#img_"+id).attr("src", "/images/icons/expand_all_dark.gif");
	}
	
	if ((curItem) && (curItem != id) && setCurItem) {changeVisibility(curItem);}
	curItem = id;
}

function setVisibility(id, value)
{
	$(id).css("display", value);
}

function startPopUp(url) {
    remote = window.open(url, "Remote", "resizable,toolbar,status,scrollbars,width=780,height=700");
    window.remote.focus();
}

function varPopUp(url, height, width, options) {
    theremote = window.open(url, "theremote", options + ",width=" + width + ",height=" + height);
    window.theremote.focus();
}

function MyImagePopUp(url) {
	preview = window.open(url, "Preview", "scrollbars=yes,resizable=yes,width=350,height=300");
	window.preview.focus();
}

function PreviewPopUp(url, Mech) {
	remote = window.open("/TRO/Includes/viewimage.asp?ID=" + url, "Preview", "scrollbars,resizable=yes,width=350,height=300");
	window.remote.focus();
}

function adminAlertPopUp(url)
{
    if (confirm('Do you want to report this design to the Moderators?'))
    {
    alert = window.open(url, "Alert", "width=200,height=200");
    window.alert.focus();
    }
}

function updateFloat(element, add_y)
{
    //var y = 0;
    //var floater = Get_Object(element);
    //if (document.documentElement.scrollTop) {y=document.documentElement.scrollTop; }
    //if (document.body.scrollTop) { y=document.body.scrollTop; }
    //floater.style.top = y + add_y;
    //alert(y);
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var dsoctop=document.all? iebody.scrollTop : pageYOffset
    //alert(dsoctop);
    $(element).scrollTop(dsoctop);
}

var ns6 = (document.getElementById)? true:false;
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;

function getPageCoords (element) {
  var coords = {x: 0, y: 0};
  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
  }
  return coords;
}

function ShowPopup(sDivName){
	var Marker;
	var DivToShow;
	var MarkerPos;

	if (ns4) DivToShow=document.layers[sDivName]
		else if (ie4) DivToShow=document.all[sDivName]
	else if (ns6) DivToShow=document.getElementById(sDivName);

	if (ns4) Marker=document.layers["DivMarker"]
		else if (ie4) Marker=document.all["DivMarker"]
	else if (ns6) Marker=document.getElementById("DivMarker");

	MarkerPos=getPageCoords(Marker);

	//DivToShow.style.top = MarkerPos.y;
	//DivToShow.style.left = MarkerPos.x;

	if (ns4) {
		getStyleRef(sDivName).top = MarkerPos.y + 230;
		getStyleRef(sDivName).left = MarkerPos.x + 520;
	}
	else {
		DivToShow.style.top = MarkerPos.y;
		DivToShow.style.left = MarkerPos.x;
	}

	if (ns4) DivToShow.visibility = "show"
		else if (ie4) DivToShow.style.visibility = "visible"
	else if (ns6) DivToShow.style.visibility="visible";

}

function getStyleRef(id)
{
  var value = false;

  if(document.layers)
    value = document.layers[id];
  else
  {
    if(document.all)
      value = document.all[id];
    else
    {
      if(document.getElementById)
        value = document.getElementById(id);
    }
    if(value)
      value = value.style;
  }  //  end else

  return value;
}  //  end function

function HidePopup(sDivName){
	if (ns4) document.layers[sDivName].visibility = "hidden"
	else if (ie4) document.all[sDivName].style.visibility = "hidden"
	else if (ns6) document.getElementById(sDivName).style.visibility="hidden";
}

function setupSearchForm()
{
	$(".Label").Tooltip({top: -30, left: 20, track: true, showBody: " - "}).addClass("Help");
	$("#Search").corner();
	if ($("#SearchFrm").css("display") == "block") {
		$("#SearchBtn").css("display","none");
	} else {
		$("#SearchBtn").css("display","block");
		$("#Search").css("width", "150px");
	}
	$("#SearchBtn a").click(function() {toggleSearchForm()});
}

function toggleSearchForm()
{
	if ($("#SearchFrm").css("display") == "block") {
		$("#SearchBtn").show("fast");
		$("#SearchFrm").hide("fast");
		$("#Search").css("width", "150px"); 
	} else {
		$("#SearchBtn").hide("fast");
		$("#Search").css("width", "100%"); 
		$("#SearchFrm").show("slow");
	}
}

function validateFileForm(Extensions)
{
    // For this function to work the form must contain a field with the an ID of File!
    Extensions = Extensions.toLowerCase();
    var Input = $("#File").val().toLowerCase();
    if (Input == "") {
        alert('FileName is a required field');
        return false;
    } else {
        if (Extensions.indexOf(Input.substring(Input.indexOf('.')+1, Input.length)) < 0) {
            alert('FileName must be one of the following file types:\n'+Extensions);
            $("#File").val("")
            return false;
        }
    }
}

function Overlay(Caption, ID) {
	tb_show(Caption, "/TRO/HTMLBattleMech/Detail.asp?ID=" + ID + "&Src=TB&width=800&height=700", "");
}

function cancelBubble()
{
	event.cancelBubble = true;
}

function formDropDownReset(current, alternate) {
	$("#" + alternate).val($("#" + current).val());
}

$(document).ready(function() {
	sidebar.validate();
	$("h4").click(function() { $(this).toggle(); });
	$("h1").click(function() { $("h4").toggle(); });
	$("img[title]").Tooltip({ top: -30, left: 20, track: true, showBody: " - ", showURL: false });
	$("div.MainRow").corner();
	$("div.AltRow").corner();

	$("#AccountDiv").click(
	  function() {
	  	$("#MyAccount").toggle();
	  }
	);

	$("#Tabs > ul").tabs();

	$(".Round").corner();

	$(".CurUsers:odd").addClass("odd");

	$("a.thickbox").fancybox();
});