var isMinNS4 = document.layers
var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&!ie&&navigator.userAgent.indexOf("Opera")==-1
var isIMG = document.images;
var arrowOn;
var arrowOff;

/**
 * image preloader
 */
//if (isIMG) {
//   Arrowon = new Image(7,7);
//   Arrowon.src = contextRoot"/images/arrow_on.gif";
//   Arrowoff = new Image(7,7);
//   Arrowoff.src = "/images/arrow_off.gif";
//}

/**
 * Swaps arrow images on the main menu
 */
function swapImg(imgName){
	swapImg(imgName,null);
} 

/**
 * swapImg
 */
function swapImg(imgName,contextRoot) {
	if(contextRoot != null){
		arrowOn = contextRoot + "/images/arrow_on.gif";
  	arrowOff = contextRoot + "/images/arrow_off.gif";
	}
	else{
		arrowOn = "/images/arrow_on.gif";
  	arrowOff = "/images/arrow_off.gif";
	}
			
  if (document.images) { 
    document[imgName].src = (document[imgName].src.indexOf("arrow_on.gif") > 0) ? arrowOff:arrowOn;
	}
}

/**
 * findObject
 */
function findObject(name) {
	return document.getElementById(name);	
}


/**
 * Asks a user to confirm before deleting an object
 */
function confirmDelete(aForm,aName,aDesc){
	var bResult = confirm("This will delete " + aName + ': ' + aDesc + ".\nAre you sure?");
	if (bResult){
	  aForm.action += "?action=delete";
		aForm.method = "post";
		aForm.submit();
	}
}

/**
 * Calls the action to cause a document to be downloaded
 */
function getManual(strLocation){
	if(strLocation != "") {
		location.href = strLocation + "&download=manual";
	}
}

/**
 * Calls the update cart function
 */
function updateCart(oForm){
  oForm.action += "?action=UPDATE";
	oForm.method="post";
	oForm.submit();
}

/**
 * Hides email addresses from spam engines
 */
function sendEmail(sUser,sDomain){
	if(sUser != null && sDomain != null){
		location.href = "mailto:" + sUser + "@" + sDomain;
	}
}

/**
 * Sets hidden variable "edit_action" prior to processing
 */
function setAction(formObj,action) {
	if (formObj && action != "") {
		formObj.edit_action.value = action;	
	}
}

/**
 * Submits a form for processing
 */
function processForm(formObj,action) {
	setAction(formObj,action);
	formObj.method = "post";
	formObj.submit();	
}

/**
 * processFormDelete
 */
function processFormDelete(formObj,action,aName,aDesc) {
	setAction(formObj,action);
	var bResult = confirm("This will delete " + aName + ': ' + aDesc + ".\nAre you sure?");
	if (bResult){
		formObj.method = "post";
		formObj.submit();
	}
}

/**
 * showDialog
 */
function showDialog( frameSrc ) {
	newPolicyDialog = document.getElementById( "dialogFrame" );
	newPolicyDialog.src = frameSrc;
	emptyCoverFrame = document.getElementById( "emptyFrame" );
	emptyCoverFrame.style.display = "block";
	newPolicyDialog.style.display = "block";
}

/**
 * ShowDiv
 */
function ShowDiv(DivName)	{
	if	(document.layers) {
		document.layers[DivName].visibility="visible"; 
	} else if (document.getElementById) {
		document.getElementById(DivName).style.display="";
		document.getElementById(DivName).style.visibility="visible";
	} else if (document.all) {
		document.all(DivName).style.display="";
		document.all(DivName).style.visibility="visible";	
	}
}

/**
 * ShowIframe
 */
function ShowIframe(DivName, url)	{
	if	(document.layers) {
		document.layers[DivName].visibility="visible"; 
		document.layers[DivName].src = url;
	} else if (document.getElementById) {
		document.getElementById(DivName).style.display="";
		document.getElementById(DivName).style.visibility="visible";
		document.getElementById(DivName).src = url;
	} else if (document.all) {
		document.all(DivName).style.display="";
		document.all(DivName).style.visibility="visible";	
		document.all(DivName).src = url;		
	}
	
}

/**
 * HideDiv
 */
function HideDiv(DivName) {
	if	(document.layers) {
		parent.document.layers[DivName].visibility="hidden"; 
	} else if (document.getElementById) {
		parent.document.getElementById(DivName).style.display="none";
		parent.document.getElementById(DivName).style.visibility="hidden";
	} else if (document.all) {
		parent.document.all(DivName).style.display="none";
		parent.document.all(DivName).style.visibility="hidden";	
	}
}

/**
 * ShowProductDiv
 */
function ShowProductDiv(productID) {
	var url = "/test1.asp?product_id=" + productID;
	ShowIframe('ProductDetailsFrame',url);
}

/**
 * OpenProductPreviewWindow
 */
function OpenProductPreviewWindow(productId) {
	theURL = "/catalog/product_preview.asp?product_id="+productId;
	winName = "productPreviewWin";
	features = "resizable=yes,width=450,height=200";
  window.open(theURL,winName,features);
}

/**
 * lov
 */
function lov(strName,targetObj,targetType,features) {
	var url = "/lov/" + strName + "?target=" + targetObj + "&type=" + targetType;
	var winName = "lov_" + strName;
	features = (features) ? features : "resizable=yes,width=300,height=200";
	window.open(url,winName,features);
}

/**
 * Moves the selected item in the list up by 1 position
 */
function moveUp(selectName) {
	var selectObj = findObject(selectName);
	var options = new Array(selectObj.options.length);
	var selectedIndex = selectObj.selectedIndex;
	var newIndex = 	selectObj.selectedIndex - 1;
	
	if (selectedIndex == -1 || selectedIndex <= 0) {
		return;
	}
	
	for (var i=0; i<selectObj.options.length; i++) {
		options[i] = selectObj.options[i];
	}	
	options[newIndex] = selectObj.options[selectedIndex];
	options[selectedIndex] = selectObj.options[newIndex];
	
	removeAllOptions(selectObj);	
	
	for (var j=0; j<options.length; j++) {
		if (ie) {
			addOption(selectObj,options[j].text,options[j].value);
		}
		else {
			selectObj.options[j] = options[j];
		}
	}	
	selectObj.options.selectedIndex = newIndex;

}

/**
 * Moves the selected item in the list down by 1 position
 */
function moveDown(selectName) {
	var selectObj = findObject(selectName);
	var options = new Array(selectObj.options.length);
	var selectedIndex = selectObj.selectedIndex;
	var newIndex = 	selectObj.selectedIndex + 1;
	
	//alert("selectObj.options.length="+selectObj.options.length);	
	//alert("selectedIndex="+selectedIndex);
	if (selectedIndex == -1 || selectedIndex >= selectObj.options.length-1) {
		return;
	}
	
	for (var i=0; i<selectObj.options.length; i++) {
		options[i] = selectObj.options[i];
	}	
	options[newIndex] = selectObj.options[selectedIndex];
	options[selectedIndex] = selectObj.options[newIndex];
	
	removeAllOptions(selectObj);	
	
	for (var j=0; j<options.length; j++) {
		if (ie) {
			addOption(selectObj,options[j].text,options[j].value);
		}
		else {
			selectObj.options[j] = options[j];
		}
	}	
	selectObj.options.selectedIndex = newIndex;

}

/**
 * Creates a new option for the given select option
 */
function addOption(selectObj, oText, oValue, idx) {
	if (ie) {
		var oOption = document.createElement("OPTION");
		selectObj.options.add(oOption);
		oOption.innerText = oText;
		oOption.value = oValue;		
	}
	else {
		selectObj.options[idx] = new Option(oText,oValue);	
	}
}

/**
 * Removes all existing options from a list
 */
function removeAllOptions(selectObj) {
	for (var j=selectObj.options.length-1; j>=0; j--) {
		selectObj.remove(j);
	}
}

function disableObjects(objArray) {
	for (var i=0; i<objArray.length; i++) {
		var obj = findObject(objArray[i]);
		obj.disabled = true;
	}
}

function enableObjects(objArray) {
	for (var i=0; i<objArray.length; i++) {
		var obj = findObject(objArray[i]);
		obj.disabled = false;
	}
}

function disableSpan(o) {
	document.getElementById(o).style.color = "#CCCCCC";
}

function enableSpan(o) {
	document.getElementById(o).style.color = "#000000";
}

/////////////////////////////////////////////////////////////////
// Built-in Macromedia Functions
/////////////////////////////////////////////////////////////////
function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v5.0
  var newURL='', userAgent=navigator.userAgent, version=0;
  if (userAgent.indexOf('Netscape') != -1) {
  	version = parseFloat(userAgent.substring(userAgent.indexOf('Netscape')+9,userAgent.length));
    if (version >= NSvers) {if (NSpass>0) newURL=(NSpass==1)?URL:altURL;}
    else {if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;}
  } else if (userAgent.indexOf('MSIE') != -1) {
  	version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4,userAgent.length));
    if (version >= IEvers)
     {if (IEpass>0) newURL=(IEpass==1)?URL:altURL;}
    else {if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;}
  } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
  if (newURL) { window.location=unescape(newURL); document.MM_returnValue=false; }
}