﻿/****************************************************
Antics Utility Javascript functions
Updated 5/24/06 KW
Updated 6/25/07 KW & AH
***************************************************/

/****************************************************
   OPEN POP-UP WINDOW
***************************************************/

// Open the popup window to the specified URL
function openPopup(theURL, theWidth, theHeight) {
	var winProperties = "resize=no,toolbar=no,directories=no,menubar=no,status=no,noresize,scrollbars=auto,width=" + theWidth + ",height=" + theHeight;
	var mainWin = self;
	if( window.popupWin == null )	   // If the window has never been opened
		popupWin=window.open(theURL,"popupWin", winProperties);
	else {
		if( window.popupWin.closed )	// If the window was open but has been closed
			popupWin=window.open(theURL,"popupWin", winProperties);
		else {								   // The window is already open
			popupWin.close();
			popupWin=window.open(theURL,"popupWin", winProperties);
		}
	}
	popupWin.opener = mainWin;
	popupWin.focus();
}

/****************************************************
   HIDE EMAIL ADDRESS
***************************************************/

function sendMail(emailName) {
	document.location='mailto:' + emailName + '@antics.com';
}
function writeMail(emailName, fullName) {
	document.open();
	document.write("<a href=\"javascript:sendMail('" + emailName + "');\">" + fullName + "</a>");
	document.close();
}


/****************************************************
   SHOW/HIDE CONTENT FIELDS
***************************************************/
//Array of classes to show or hide
tArray = new Array();
tArray[0] = "new";
tArray[1] = "old";
tArray[2] = "approved";
tArray[3] = "download";
tArray[4] = "strikethrough";

// Show just the one deliverable class
function show(classname) {
	if( classname == "all" ) {
		showAll();
	}
	else {
		for( var i = 0; i < tArray.length; i++ ) {
			var e = getElement(tArray[i]);
			if( tArray[i] == classname ) { //Class name of element to be shown
				showBlock(classname);
				e.style.textDecoration = "none";
			}
			else {
				hideBlock(tArray[i]); //All other elements with classnames in the array are hidden
				if( e != null ) e.style.textDecoration = "underline"; // Set the higlight state of the link
			}
		}
		e = getElement("all");
		e.style.textDecoration = "underline"; // Set the higlight state of the showall link
	}
}

// Show all of the deliverable classes
function showAll() {
	for( var i = 0; i < tArray.length; i++ ) {
		showBlock(tArray[i]); // Make them all visible
		e = getElement(tArray[i]); // And set the highlighted state for the links
		if( e != null ) e.style.textDecoration = "underline";
	}
	e = getElement("all");
	e.style.textDecoration = "none";
}

// Global vars
var c = null; // Array of elements of a particular class
	
function hideBlock(classname) {
	c = new Array(); // Array of elements of a particular class
 	 getElementbyClass(classname);	 
	for( var i = 0; i < c.length; i++ ) {
       	var e = c[i];
        e.style.display = 'none';
	}
}

function showBlock(classname) {
	c = new Array(); // Array of elements of a particular class
 	getElementbyClass(classname);	 
	for( var i = 0; i < c.length; i++ ) {
		var e = c[i];
        e.style.display = '';
	}
}

function toggleBlock(classname) {
	c = new Array(); // Array of elements of a particular class
 	 getElementbyClass(classname);	 
	for( var i = 0; i < c.length; i++ ) {
       	// var e = getElement(elementId);
		var e = c[i];
        if( e.style.display == 'none' )
          e.style.display = 'block';
        else
          e.style.display = 'none';
	}
}

function toggleIDBlock(id) {
 	var e = getElement(id);	 
	if( e != null ) {
        if( e.style.display == 'none' )
          e.style.display = 'block';
        else
          e.style.display = 'none';
	}
}

// Get the element by id (works with IE or Firefox DOMs)
function getElement(id) {
	if( document.getElementById && !document.all )
		return document.getElementById(id);
	else
		return document.all[id];
}

// Build an array of all elements of a particular class
function getElementbyClass(classname) { 
	var inc = 0;
	var alltags = document.all? document.all : document.getElementsByTagName("*");
		for( var i = 0;  i < alltags.length;  i++ ) {
		if( alltags[i].className==classname )
    			c[inc++] = alltags[i];
		}
} 
