var myImage = new Array();
var isNav4 = ((navigator.appName.toLowerCase() == 'netscape') && (parseInt(navigator.appVersion) == 4));
var currentMenu;
var popUp;
var blnFormSubmitted = false;


function imageLoad(imgName, imgOut, imgOver) {
	//Add an element.
	myImage[myImage.length] = imgName;

	//Assign values to the Array.
	var subArray = new Array();
	subArray["over"] = new Image().src = imgOver;
	subArray["out"] = new Image().src = imgOut;
	myImage[imgName] = subArray;

//  mouseOut(imgName);
}

function mouseOver(imgName) {
	document.images[imgName].src = myImage[imgName]["over"];
}

function mouseOut(imgName) {
	document.images[imgName].src = myImage[imgName]["out"];
}

function mouseOver1(imgName){
	//need to swap the off with the on.
	strsrc = document.images[imgName].src
	var newString = strsrc.replace("_off","_on");
	document.images[imgName].src = newString
}

function mouseOut1(imgName){
	//need to swap the on with the off.
	strsrc = document.images[imgName].src
	var newString = strsrc.replace("_on","_off");
	document.images[imgName].src = newString
}

// Next 3 functions added (02/08/01) by Gavyn Dowst. Used by inc_main_product_nav for
// mouseover on menu links.
function mouseOverLink(linkObj, bgColour) {
//	linkObj.style.cursor = 'hand';
	linkObj.style.background = bgColour;
}

function mouseOutLink(linkObj, bgColour){
//	linkObj.style.cursor = 'default';
  linkObj.style.background = bgColour;
}

function mouseClkLink(linkObj){
  if (document.all) {
    linkObj.children(0).click();
  }
}
// End mods by GD.

function submit(formName) {
//	document.form[formName].submit();
//	Changed by Adie Briggs to work in netscape
  if (!blnFormSubmitted) {
  	frmSub = eval(document.forms[formName]);
  	frmSub.submit();
  	blnFormSubmitted = true;
  }
}

function submitFormName(formName, newFormName) {
	//Set the new name to the form, then submit it.
  if (!blnFormSubmitted) {
  	eval(document.forms[formName]).name = newFormName;
  	eval(document.forms[formName]).submit();
  	blnFormSubmitted = true;
  }
}

function submitFormWithAction(formName, actionValue) {
	//Set the action property of the form, then submit it.
  if (!blnFormSubmitted) {
  	var strAction = eval(document.forms[formName]).action;
  	var strLast4Chars = strAction.substring(strAction.length, strAction.length - 4);
  	if (strLast4Chars != '.jsp') {
  			// Replace the ? with and &
  			actionValue = '&' + actionValue.substring(actionValue.length,1);
  	}
  	eval(document.forms[formName]).action = eval(document.forms[formName]).action + actionValue;
  	eval(document.forms[formName]).submit();
  	blnFormSubmitted = true;
  }
}

function submitFormWithSubRequests(formName, request) {
  if (!blnFormSubmitted) {
  	var strAction = eval(document.forms[formName]).action;
  	var strLast4Chars = strAction.substring(strAction.length, strAction.length - 4);
  	if (strLast4Chars != '.jsp') {
  			// Replace the ? with and &
  		var paramIdentifier = '&';
  	} else {
  		var paramIdentifier = '?';
  	}
  	eval(document.forms[formName]).bmSubmit.value = request;
  	eval(document.forms[formName]).action = eval(document.forms[formName]).action + paramIdentifier + request + '=' + request;
  	eval(document.forms[formName]).submit();
    blnFormSubmitted = true;
  }
}

function submitWizardForm(formName, redirectURL) {
  if (!blnFormSubmitted) {
  	eval(document.forms[formName]).CCA_next_wizard_step.value = redirectURL;
  	eval(document.forms[formName]).submit();
  	blnFormSubmitted = true;
  }
}

function standardPopup(openPage) {
	popUp =  window.open(openPage, 'Popup', 'scrollbars=yes, fullscreen=no, toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=no,height=450,innerHeight=450,width=400,innerWidth=400,top=5,left=5');
}

function sizeablePopup(openPage, width, height) {
	popUp =  window.open(openPage, 'Popup', 'scrollbars=yes, fullscreen=no, toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=no,height=' + height + ',innerHeight=' + height + ',width=' + width + ',innerWidth=' + width + ',top=5,left=5');
}

function refreshPage(){
    popUp.close();
    self.document.location = self.document.location;
}

function toggleAddInput(formName, valueToCheckFor, instructionText) {

	var isNetscape = ((navigator.appName.toLowerCase()) == 'netscape');
	var deliverToElement;
	var someoneElseElement;

	if (isNetscape)
	{
		deliverToElement = document.forms[formName].elements["ADD_CART_ITEM<>deliverToAlias"];
		someoneElseElement = document.forms[formName].elements["ADD_CART_ITEM<>someoneElse"];
	}
    else
	{
		deliverToElement = eval('document.' + formName + '["ADD_CART_ITEM<>deliverToAlias"]');
    	someoneElseElement = eval('document.' + formName + '["ADD_CART_ITEM<>someoneElse"]');
	}

    if (deliverToElement.style)
	{
  		if (deliverToElement.value.toLowerCase() == valueToCheckFor.toLowerCase())
		{
  	  		someoneElseElement.style.visibility = 'visible';

  		}
		else {
  	  		someoneElseElement.style.visibility = 'hidden';
  		}
    }

    if (deliverToElement[deliverToElement.selectedIndex].value.toLowerCase() == valueToCheckFor.toLowerCase())
	{
        if (someoneElseElement.value == "")
		{
            someoneElseElement.value = instructionText;
        }

    }
    else
    {
        if (someoneElseElement.value == instructionText)
		{
         	someoneElseElement.value = "";
        }
    }
}

function toggleSomeoneElse(formName, triggerFieldName, objectFieldName, valueToCheckFor, instructionText) {

	var isNetscape = ((navigator.appName.toLowerCase()) == 'netscape');
	var deliverToElement;
	var someoneElseElement;

	if (isNetscape)
	{
		someoneElseElement = document.forms[formName].elements[objectFieldName];
		deliverToElement = document.forms[formName].elements[triggerFieldName];
	}
    else
	{
    someoneElseElement = eval('document.' + formName + '.' + objectFieldName);
    deliverToElement = eval('document.' + formName + '.' + triggerFieldName);
	}

    if (deliverToElement.style)
	{
  		if (deliverToElement.value.toLowerCase() == valueToCheckFor.toLowerCase())
		{
  	  		someoneElseElement.style.visibility = 'visible';

  		}
		else {
  	  		someoneElseElement.style.visibility = 'hidden';
  		}
    }

    if (deliverToElement[deliverToElement.selectedIndex].value.toLowerCase() == valueToCheckFor.toLowerCase())
	{
        if (someoneElseElement.value == "")
		{
            someoneElseElement.value = instructionText;
        }

    }
    else
    {
        if (someoneElseElement.value == instructionText)
		{
         	someoneElseElement.value = "";
        }
    }
}

function blurCheck(formName, elementToBlurName, elementToCheckName, stringToCheckSelectFor, stringToCheckInputFor)
{
    var elementToBlur;
    var elementToCheck;
	var isNetscape = ((navigator.appName.toLowerCase()) == 'netscape');

	if (isNetscape)
	{
		elementToBlur = document.forms[formName].elements[elementToBlurName];
		elementToCheck = document.forms[formName].elements[elementToCheckName];
	}
	else
	{
		elementToBlur = eval('document.' + formName + '["' + elementToBlurName + '"]');
		elementToCheck = eval('document.' + formName + '["' + elementToCheckName + '"]');
	}

	if (elementToCheck[elementToCheck.selectedIndex].value.toLowerCase().indexOf(stringToCheckSelectFor.toLowerCase()) == -1)
	{
        elementToBlur.blur();
    }
   	 else
    {
		if (elementToBlur.value.toLowerCase()==stringToCheckInputFor.toLowerCase())
        {
			elementToBlur.value ="";
        }
	}

}



function enableOther(formName, elementName, elementOtherName, elementFocusName)
{
    oTitle = eval('document.' + formName + '["' + elementName + '"][0]');
    if (!oTitle.options)
    {
        oTitle = eval('document.' + formName + '["' + elementName + '"][1]');
    }


    if (!oTitle.options)
    {
            oTitle = eval('document.' + formName + '["' + elementName + '"]');
    }

    if(oTitle.options[oTitle.selectedIndex].value.toLowerCase() != "other"){
       eval('document.' + formName + '["' + elementOtherName + '"]').blur();
		eval('document.' + formName + '["' + elementFocusName + '"]').focus();
    }
}

function clearOther(formName, elementName, elementOtherName)
{

        oTitle = eval('document.' + formName + '["' + elementName + '"][0]');
        if (!oTitle.options)
        {
            oTitle = eval('document.' + formName + '["' + elementName + '"][1]');
        }

        if (!oTitle.options)
        {
            oTitle = eval('document.' + formName + '["' + elementName + '"]');
        }

        if(oTitle.options[oTitle.selectedIndex].value.toLowerCase() != "other"){
           eval('document.' + formName + '["' + elementOtherName + '"]').value="";
        }
}

function checkForHidden(formName, elementName)
{
    var theForm = eval('document.' + formName);
    for (i = 0; i < theForm.length; i++)
    {
        if ((theForm.elements[i].name == elementName) && (theForm.elements[i].type == 'hidden'))
        {
            return true;
        }
    }
    return false;
}

function findElement(formName, elementName, ref)
{
    // Used to reference specified element from a form containg multiple elements of the same name
    // Written specifically for navigator 4 (see comment in getElementFromArray)
    var theForm = eval('document.' + formName);
    var counter = 0;
    for (i = 0; i < theForm.length; i++)
    {
        if (theForm[i].name == elementName)
        {
            if (counter == ref)
            {
                //alert(i + ": " + theForm[i].name + ", " + theForm[i].type + ", counter: " + counter);
                return theForm[i];
                break;
            }
            counter++;
        }
    }
}

function getElementFromArray(formName, elementName, i, hiddenExists)
{
    // In this function, the check for hiddenExists is designed to circumvent a Blue Martini 'feature' that
    // for each select box adds a hidden element of the same name
    if (isNav4)
    {
        // Nav 4 can't seem to cope properly with an array of elements of the same name, so take a different approach.
        // Only use this approach for Nav 4 since it is less efficient
        if (hiddenExists)
        {
            return findElement(formName, elementName, (i*2)+1);
        }
        else
        {
            return findElement(formName, elementName, i);
        }
    }
    else
    {
        if (hiddenExists)
        {
            return eval('document.' + formName + '["' + elementName + '"][(i*2)+1]');
        }
        else
        {
            return eval('document.' + formName + '["' + elementName + '"][i]');
        }
    }
}

// used for pages where there may be multiple title select box of the same name
function enableOtherArray(formName, elementName, elementOtherName, elementFocusName, i)
{
    var hiddenExists = checkForHidden(formName, elementName);

    oTitle = getElementFromArray(formName, elementName, i, hiddenExists);

    oTitleOther = eval('document.' + formName + '["' + elementOtherName + '"][' + i + ']');
	oFocus = eval('document.' + formName + '["' + elementFocusName + '"][' + i + ']');
	if (oTitleOther == null) {
		oTitleOther = eval('document.' + formName + '["' + elementOtherName + '"]');
		oFocus = eval('document.' + formName + '["' + elementFocusName + '"]');
	}

    if(oTitle.options[oTitle.selectedIndex].value.toLowerCase() != "other"){
       oTitleOther.blur();
		oFocus.focus();
    }
}

// used for pages where there may be multiple title select box of the same name
function clearOtherArray(formName, elementName, elementOtherName, i)
{
    var hiddenExists = checkForHidden(formName, elementName);

    oTitle = getElementFromArray(formName, elementName, i, hiddenExists);

    oTitleOther = eval('document.' + formName + '["' + elementOtherName + '"][' + i + ']');
	if (oTitleOther == null) {
		oTitleOther = eval('document.' + formName + '["' + elementOtherName + '"]');
	}

    if(oTitle.options[oTitle.selectedIndex].value.toLowerCase() != "other"){
       oTitleOther.value = "";
    }
}

function triggerSubmit(object) {
  // The document.all check is because this code breaks NS. Needs to be fixed but not urgently!
  if ((document.all) && (event.keyCode == 13) && (object)) {
    object.click();
  }
}

function givePopupFocus()
{
    if (popUp != null)
	{
		if (!popUp.closed)
		{
			 popUp.focus();
		}
	}
}

function limitLength(formName, elementName, maxlength)
{
    var element = eval("document." + formName + "[elementName]");
    if (element.value.length > maxlength)
    {
      element.value = element.value.substring(0, maxlength)
    }
}

//from VR global.js

function rollMe(myObj, myFile){
	myObj.src=myFile;
}
