/**********************************
   Generic Global Variables
**********************************/
// globals for browser version branching
var Ver4 = parseInt(navigator.appVersion) >= 4;
var Nav4 = ((navigator.appName == "Netscape") && Ver4);
var IE4 = ((navigator.userAgent.indexOf("MSIE") != -1) && Ver4);
var reEmail = /^.+\@.+\..+$/
var whitespace = " \t\n\r";
var defaultEmptyOK = false

// to open a new window: (Amgen's global usage)
function newWindow(page)
{
msgWindow=window.open(page,"windowName","width=640,height=480,menubar=yes,status=yes,scrollbars=yes,scrollable=yes,toolbar=yes,resizable=yes,location=yes");
}

function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function openReferencesPopup(page) {
	OpenWin = this.open(page, "References", "scrollbars=yes,resizable=yes,width=500,height=600");
}	

// New readable version of the Browser-independent
// object finder function
// 2 arguments - 1. objName => the name of the obj to find
//		2. rootElement => the root element to start the search from

function findObj(objName, rootElement) {
	var frameIdentifier,obj;
	var i;

	// Identify presence of frames and root element
	if(!rootElement)
		rootElement=document;
	if((frameIdentifier=objName.indexOf("?"))>0&&parent.frames.length) {
		rootElement=parent.frames[objName.substring(frameIdentifier+1)].document;
		objName=objName.substring(0,frameIdentifier);
	}

	// First do a direct search
	if(!(obj=rootElement[objName]) && rootElement.all)
		obj=rootElement.all[objName];

	// Second look for object within forms, if any
	for (i=0;!obj&&i<rootElement.forms.length;i++)
		obj=rootElement.forms[i][objName];

	// Recursively search layers if object is still not found
	for(i=0;!obj && rootElement.layers && i<rootElement.layers.length;i++)
		obj=findObj(objName,rootElement.layers[i].document);

	return obj;
}

// New readable version of the browser-independent dynamic image
// swapper function
// 2 (or multiples of 2) arguments - img1 name, img1.newSrc, img2 name, img2.newSrc, ..
function imgSwap() {
	var obj;

	var argv = imgSwap.arguments;
	var argc = argv.length;
	var i,j=0;

	if ((argc % 2) != 0)
		return;
	for(i=0; i<argc; i+=2) {
		if ((obj=findObj(argv[i]))!=null){
			if(!obj.origSrc)
				obj.origSrc=obj.src;
			obj.src=argv[i+1];
		}
	}
}

// an image pre-loader.  variable is used within the pre-loader for the array.
var CalledImages = new Array();
function imgCall(Root)
	{
	if (document.images && CalledImages)
		{
		for (var xx=1; xx < imgCall.arguments.length; xx++)
			{
			var oo               = CalledImages.length;
			CalledImages[oo]     = new Image();
			CalledImages[oo].src = Root + imgCall.arguments[xx];
			}
		}
	}

function sendPage(url) {
	sendWindow=window.open(url + "&url=" + escape(document.URL),"send","width=440,height=540,menubar=no,status=no,scrollbars=yes,scrollable=yes,toolbar=no,resizable=no,location=no");
} 

function popLegal(url) {
	legal=window.open(url,"legal","width=440,height=540,menubar=no,status=no,scrollbars=yes,scrollable=yes,toolbar=no,resizable=no,location=no");
}

function popProDisclaimer(url) {
	legal=window.open(url,"legal","width=440,height=240,menubar=no,status=no,scrollbars=no,scrollable=no,toolbar=no,resizable=no,location=no");
}

function popPrinter(url) {
	printer=window.open(url,"print","width=565,height=485,menubar=yes,status=no,scrollbars=yes,scrollable=yes,toolbar=yes,resizable=yes,location=no");
}

function popDefinition(url) {
	glossary=window.open(url,"glossary","width=300,height=250,menubar=no,status=no,scrollbars=yes,scrollable=yes,toolbar=no,resizable=no,location=no");
}

function popReferences(url) {
	printer=window.open(url,"print","width=440,height=485,menubar=yes,status=no,scrollbars=yes,scrollable=yes,toolbar=yes,resizable=yes,location=no");
}

/*******************************************************/
/* General purpose utility functions used primarily for CSV
of site-wide feedback forms*/
/*******************************************************/


/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkString (theField, emptyOK) {
	// Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkString.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) {
		return false;
    } else return true;
}

// Check whether string s is empty.

function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or
// whitespace characters only.

function isWhitespace (s) {
	var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Check Email (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// If emptyOK == true then value cannot be null

function checkEmail (theField, emptyOK) {
    if (checkEmail.arguments.length == 1) {
        emptyOK = defaultEmptyOK;
    }   
    if ((emptyOK == true) && (isEmpty(theField.value))) {
		return true;
    } else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theField.value))) {
		return false;
    } else {
        return true;
    }
}

// Check Email (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// If emptyOK == true then value cannot be null

function checkEmail2 (theField, emptyOK) {
    if (checkEmail2.arguments.length == 1) {
        emptyOK = defaultEmptyOK;
    }
    if ((emptyOK == true) && (isEmpty(theField.value))) {
		return true;
    } else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theField.value))) {
		return false;
    } else {
        return true;
    }
}


// isEmail (STRING s [, BOOLEAN emptyOK])
//
// Email address must be of form a@b.c -- in other words:
// * there can be no embedded white-space
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s) {

	if (isEmpty(s))
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);

    var i;
    var sLength = s.length;

    // s cannot have embedded whitespace
    for (i = 0; i < sLength; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) != -1) return false;
    }

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
	i = 1;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function checkPhoneSuffix(theField, emptyOK) {

	if (checkPhoneSuffix.arguments.length == 1) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) {
		return true;
	} else {
		if (!isInteger(theField.value) || theField.value.length != 4) {
			return false;
		}
	}

	return true;
}

function checkPhonePrefix(theField, emptyOK) {

	if (checkPhonePrefix.arguments.length == 1) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) {
		return true;
	} else {
		if (!isInteger(theField.value) || theField.value.length != 3) {
			return false;
		}
	}

	return true;
}

function checkPhoneAreaCode(theField, emptyOK) {

	if (checkPhoneAreaCode.arguments.length == 1) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) {
		return true;
	} else {
		if (!isInteger(theField.value) || theField.value.length != 3) {
			return false;
		}
	}

	return true;
}

function checkPhoneExtension(theField, emptyOK) {

        if (checkPhoneExtension.arguments.length == 1) emptyOK = defaultEmptyOK;
        if ((emptyOK == true) && (isEmpty(theField.value))) {
                return true;
        } else {
                if (!isInteger(theField.value)) {
                        return false;
                }
        }

        return true;
}


// check5DigitZIP(TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid ZIP code.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function check5DigitZIP(theField, emptyOK) {
	if (check5DigitZIP.arguments.length == 1) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) {
		return true;
	} else {
		if (!isInteger(theField.value) || theField.value.length != 5) {
			return false;
		}
	}

	return true;
}


// Returns true if character c is a digit
// (0 .. 9).

function isDigit(c) {
	return ((c >= "0") && (c <= "9"))
}

// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger(s) {

	var i;

	if (isEmpty(s)) {
		if (isInteger.arguments.length == 1) {
			return defaultEmptyOK;
		} else {
			return (isInteger.arguments[1] == true);
		}
	}

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++) {

        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}



/*******************************************************/
// Search form Client-side validation and functionality
/*******************************************************/
function submitSearch()
{
        if(validSearchForm()) {
            document.searchBox.submit();
        }
}
function validSearchForm()
{
    var searchArg;

    searchArg = document.searchBox.elements[3];
    if(!checkString(searchArg)){
        alert("Please input search argument");
        searchArg.select();
        return false;
    }
    searchArg.value = searchArg.value.toLowerCase();
    return true;
}

/*******************************************************/
/* (end search functionality)                          */
/*******************************************************/

// Auto tab functionality
var isNN = ( navigator.appName.indexOf( "Netscape" ) != -1 ); 
 
function autoTab( input,len, e ) { 
	var keyCode	= ( isNN ) ? e.which : e.keyCode; 
	var filter	= ( isNN ) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; 
	if( input.value.length >= len && !containsElement( filter, keyCode )) { 
	input.value = input.value.slice( 0, len ); 
	input.form[( getIndex( input ) + 1 ) % input.form.length].focus(); 
	} 
	return true; 
} 
 
function containsElement( arr, ele ) { 
	var found = false, index = 0; 
	while( !found && index < arr.length ) 
	if( arr[index] == ele ) { 
		found = true; 
	} else { 
		index++; 
	} 
	return found; 
} 
 
function getIndex( input ) { 
	var index = -1, i = 0, found = false; 
	while ( i < input.form.length && index == -1 ) 
	if ( input.form[i] == input ) { 
		index = i; 
	} else { 
		i++; 
	} 
	return index; 
} 

function openNewWindow(page,name,width,height,top,left,propSet) {

	var windowProps = new Array (8);

	windowProps[0] = "resizable=yes";
	windowProps[1] = "scrollbars=yes";
	windowProps[2] = "titlebar=yes";
	windowProps[3] = "toolbar=yes";
	windowProps[4] = "menubar=yes";
	windowProps[5] = "location=yes";
	windowProps[6] = "status=yes";
	windowProps[7] = "directories=yes";
	
	var myProps = "";
	var mySize = "";
	
	if (propSet == 'one') {
		 myProps = ',' + windowProps[0] + ',' + windowProps[1] + ',' + windowProps[3];
	} else if (propSet == "full") {
		myProps = ',' + windowProps.join(",");
	} else {
		myProps = "";
	}	
	
	if ((width > 50)||(height > 50)) {
		var mySize = 'width=' + width + ',' + 'height=' + height + ',' + 'top=' + top + ',' + 'left=' + left;
	}
	
	var myString = mySize + myProps;
	window.open(page,name,myString);
	
}
function openOutsideLink(theURL,winName,features) {
	window.open(theURL,winName,features);
}
