// Image Preload & Swap

var imgInicioOn = new Image();
var imgInicioOff = new Image();
var imgProductosOn = new Image();
var imgProductosOff = new Image();
var imgArchiveOn = new Image ();
var imgArchiveOff = new Image ();
var imgAcercaOn = new Image ();
var imgAcercaOff = new Image ();
var imgContactenosOn = new Image ();
var imgContactenosOff = new Image ();

var imgHomeOn = new Image();
var imgHomeOff = new Image();
var imgProductsOn = new Image();
var imgProductsOff = new Image();
var imgKnowledgeOn = new Image();
var imgKnowledgeOff = new Image();
var imgOFSLabsOn = new Image();
var imgOFSLabsOff = new Image();
var imgAboutOn = new Image();
var imgAboutOff = new Image();
var imgContactOn = new Image();
var imgContactOff = new Image();
var imgSelAppOn = new Image();
var imgSelAppOff = new Image();
var imgSelMarketOn = new Image();
var imgSelMarketOff = new Image();
var imgSelProductOn = new Image();
var imgSelProductOff = new Image();

var imgAvon_minus = new Image();
var imgAvon_plus = new Image();
var imgCarrollton_minus = new Image();
var imgCarrollton_plus = new Image();
var imgDenmark_minus = new Image();
var imgDenmark_plus = new Image();
var imgNorcross_minus = new Image();
var imgNorcross_plus = new Image();
var imgSomerset_minus = new Image();
var imgSomerset_plus = new Image();
var imgLabs_minus = new Image();
var imgLabs_plus = new Image();
var imgSturbridge_minus = new Image();
var imgSturbridge_plus = new Image();
var imgAugsburg_minus = new Image();
var imgAugsburg_plus = new Image();


strSection = "";
strRootPath = "";
strCurrentAddToCart = "";

function fPreloadImages(strPath, sSection) {
	strSection = sSection;
	strRootPath = strPath;
	
	imgAvon_minus.src = strPath + "img/divAvon_minus.gif";
	imgAvon_plus.src = strPath + "img/divAvon_plus.gif";
	imgCarrollton_minus.src = strPath + "img/divCarrollton_minus.gif";
	imgCarrollton_plus.src = strPath + "img/divCarrollton_plus.gif";
	imgDenmark_minus.src = strPath + "img/divDenmark_minus.gif";
	imgDenmark_plus.src = strPath + "img/divDenmark_plus.gif";
	imgNorcross_minus.src = strPath + "img/divNorcross_minus.gif";
	imgNorcross_plus.src = strPath + "img/divNorcross_plus.gif";
	imgSomerset_minus.src = strPath + "img/divSomerset_minus.gif";
	imgSomerset_plus.src = strPath + "img/divSomerset_plus.gif";
	imgLabs_minus.src = strPath + "img/divLabs_minus.gif";
	imgLabs_plus.src = strPath + "img/divLabs_plus.gif";
	imgSturbridge_minus.src = strPath + "img/divSturbridge_minus.gif";
	imgSturbridge_plus.src = strPath + "img/divSturbridge_plus.gif";
	imgAugsburg_minus.src = strPath + "img/divAugsburg_minus.gif";
	imgAugsburg_plus.src = strPath + "img/divAugsburg_plus.gif";
	
	imgContactenosOn.src = strPath + "img/spanish/img_contactenos_white.gif";
	imgContactenosOff.src = strPath + "img/spanish/img_contactenos_red.gif";
	imgAcercaOn.src = strPath + "img/spanish/img_acerca_white.gif";
	imgAcercaOff.src = strPath + "img/spanish/img_acerca_red.gif";
	imgArchiveOn.src = strPath + "img/spanish/img_archive_white.gif";
	imgArchiveOff.src = strPath + "img/spanish/img_archive_red.gif";
	imgProductosOn.src = strPath + "img/spanish/img_productos_white.gif";
	imgProductosOff.src = strPath + "img/spanish/img_productos_red.gif";	
	imgInicioOn.src = strPath + "img/spanish/img_inicio_white.gif";
	imgInicioOff.src = strPath + "img/spanish/img_inicio_red.gif";
	
	imgHomeOn.src = strPath + "img/NavHome/img_home_white.gif";
	imgHomeOff.src = strPath + "img/NavHome/img_home_red.gif";
	imgProductsOn.src = strPath + "img/NavHome/img_products_white.gif";
	imgProductsOff.src = strPath + "img/NavHome/img_products_red.gif";
	imgKnowledgeOn.src = strPath + "img/NavHome/img_knowledge_white.gif";
	imgKnowledgeOff.src = strPath + "img/NavHome/img_knowledge_red.gif";
	imgOFSLabsOn.src = strPath + "img/NavHome/img_OFSlab_white.gif";
	imgOFSLabsOff.src = strPath + "img/NavHome/img_OFSlab_red.gif";

	imgAboutOn.src = strPath + "img/NavHome/img_about_white.gif";
	imgAboutOff.src = strPath + "img/NavHome/img_about_red.gif";
	imgContactOn.src = strPath + "img/NavHome/img_contact_white.gif";
	imgContactOff.src = strPath + "img/NavHome/img_contact_red.gif";
	imgSelAppOn.src = strPath + "img/img_selectapplication.gif";
	imgSelAppOff.src = strPath + "img/img_selectapplication.gif";
	imgSelMarketOn.src = strPath + "img/img_selectmarket.gif";
	imgSelMarketOff.src = strPath + "img/img_selectmarket.gif";
	imgSelProductOn.src = strPath + "img/img_selectproduct.gif";
	imgSelProductOff.src = strPath + "img/img_selectproduct.gif";
}

function fImageSwap(strImageTarget, strImageSource, strAdditional) {
	if (strAdditional == null) {
		strAdditional = "";
	}
	if (eval(strImageTarget + strImageSource) && (document.images[strImageTarget + strAdditional])) {
		if (eval(strImageTarget + strImageSource).complete) {
			document.images[strImageTarget + strAdditional].src = eval(strImageTarget + strImageSource).src;
		}
	}
}

// DHTML Menu Code
var arrMenus = new Array("Products", "Knowledge", "OFSLabs", "About", "Contact", "SelApp", "SelMarket", "SelProduct");
var oTimer = null;
var oFadeInTimer = null;

function fShowMenu(strMenuName) {
	fKeepMenus();
	if (oParentRow) {
		oParentRow.className = 'cssMenuItemOff';
		
	}
	for (i=0;i<arrMenus.length;i++) {
		if (arrMenus[i] != strMenuName) {
			if (document.getElementById("divMenu" + arrMenus[i])) {
				document.getElementById("divMenu" + arrMenus[i]).style.visibility = "hidden";
			}
			if (arrMenus[i].toLowerCase() != strSection) {
				if (eval(document.images["img" + arrMenus[i]])) {
					fImageSwap("img" + arrMenus[i], "Off");
				}
			}
		} else {
			if (document.getElementById("divMenu" + arrMenus[i])) {
				if (document.getElementById("divMenu" + arrMenus[i]).style.visibility != "visible") {
					fAlphaInMenu("divMenu" + arrMenus[i], 0);
				} else {
					document.getElementById("divMenu" + arrMenus[i]).style.MozOpacity = "0.9";
					document.getElementById("divMenu" + arrMenus[i]).style.filter = "alpha(Opacity=90)";
				}
			}
			if (eval(document.images["img" + arrMenus[i]])) {
				fImageSwap("img" + arrMenus[i], "On");
			}
		}
	}
}

function fHideMenus() {
	oTimer = window.setTimeout("fHideAllMenus();", 500);
}

function fHideAllMenus() {
	window.clearTimeout(oTimer);
	for (i=0;i<arrMenus.length;i++) {
		if (document.getElementById("divMenu" + arrMenus[i])) {
			document.getElementById("divMenu" + arrMenus[i]).style.visibility = "hidden";
		}
		if (arrMenus[i].toLowerCase() != strSection) {
			fImageSwap("img" + arrMenus[i], "Off");
		}
	}	
	
}


function fKeepMenus() {
	window.clearTimeout(oTimer);
}

function fAlphaInMenu(strMenu, intAlpha) {
	var strStyleChange = "";
	if (intAlpha == 0) {
		document.getElementById(strMenu).style.visibility = "visible";
	}
	strStyleChange = "alpha(Opacity=" + intAlpha + ")"; // -moz-opacity: " + (intAlpha / 100) + ";"
	document.getElementById(strMenu).style.MozOpacity = intAlpha / 100;
	document.getElementById(strMenu).style.filter = strStyleChange;
	if (intAlpha < 90) { 
		if ((intAlpha + 10) > 90) {
			oFadeInTimer = window.setTimeout("fAlphaInMenu(\"" + strMenu + "\", 90);", 1);
		} else {
			oFadeInTimer = window.setTimeout("fAlphaInMenu(\"" + strMenu + "\", " + (intAlpha + 10) + ");", 1);
		}
	} else {
		oFadeInTimer = null;
		window.clearTimeout(oFadeInTimer);	
	}	
}

var oParentRow, iParentNumber

function fMouseOverItem(oRow, iNumber) {
	fKeepMenus();
	if (oParentRow) {
		oParentRow.className = 'cssMenuItemOff';
	}
	oRow.className='cssMenuItemOn';
	oParentRow = oRow;
}

function fMouseOutItem(oRow, iNumber) {
	fHideMenus();
}

// This is for tracking the mouse cursor
if (document.layers) { // Netscape
 //   document.captureEvents(Event.MOUSEMOVE);
 //   document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
 //   document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
 //   document.onmousemove = captureMousePosition;
}
// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page
var sFollowBrand = null;

function captureMousePosition(e) {
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
    if (sFollowBrand != null) {
    	fShowBrand(sFollowBrand);
    }
}

function fShowBrand(strBrand) {
	if (document.getElementById("divBrand" + strBrand)) {
		document.getElementById("divBrand" + strBrand).style.visibility = "visible";
		document.getElementById("divBrand" + strBrand).style.display = "block";
		if (((xMousePos + 320) > 760) && ((xMousePos - 320) > 0)) {
			document.getElementById("divBrand" + strBrand).style.left = xMousePos - 320;
		} else {
			document.getElementById("divBrand" + strBrand).style.left = xMousePos + 20;
		}
		document.getElementById("divBrand" + strBrand).style.top = yMousePos;
		sFollowBrand = strBrand;
	}
}

function fHideBrand(strBrand) {
	sFollowBrand = null;
	if (document.getElementById("divBrand" + strBrand)) {
		document.getElementById("divBrand" + strBrand).style.visibility = "hidden";
		document.getElementById("divBrand" + strBrand).style.display = "none";	
	}
}

function fShow(strID) {
	document.getElementById(strID).style.visibility = "visible";
	document.getElementById(strID).style.display = "block";
}

function fHide(strID) {
	document.getElementById(strID).style.visibility = "hidden";
	document.getElementById(strID).style.display = "none";
}

function fToggle(strID) {
	if(document.getElementById(strID).style.visibility == "hidden") {
		fShow(strID);
	} else {
		fHide(strID);
	}
}

function fToggleDiv(strDiv) {
	var objDiv = document.getElementById(strDiv);
	if(objDiv.style.visibility == "hidden") {
		objDiv.style.visibility = "visible";
		objDiv.style.display = "block";
		if(document.getElementById(strDiv + "plus")) {
			document.getElementById(strDiv + "plus").src = strRootPath + "img/img_minus.gif";
		}
		if(document.getElementById(strDiv + "Header")) {
			document.getElementById(strDiv + "Header").className = "cssLeftNavRed";
		}
	} else {
		objDiv.style.visibility = "hidden";
		objDiv.style.display = "none";
		if(document.getElementById(strDiv + "plus")) {
			document.getElementById(strDiv + "plus").src = strRootPath + "img/img_plus.gif";
		}
		if(document.getElementById(strDiv + "Header")) {
			document.getElementById(strDiv + "Header").className = "cssLeftNav";
		}
	}
}

function fToggleImgDiv(strDiv) {
	var objDiv = document.getElementById(strDiv);
	if(objDiv.style.visibility == "hidden") {
		objDiv.style.visibility = "visible";
		objDiv.style.display = "block";
		if(document.getElementById(strDiv + "plus")) {
			document.getElementById(strDiv + "plus").src = strRootPath + "img/" + strDiv + "_minus.gif";
		}
		if(document.getElementById(strDiv + "Header")) {
			document.getElementById(strDiv + "Header").className = "cssLeftNavRed";
		}
	} else {
		objDiv.style.visibility = "hidden";
		objDiv.style.display = "none";
		if(document.getElementById(strDiv + "plus")) {
			document.getElementById(strDiv + "plus").src = strRootPath + "img/" + strDiv + "_plus.gif";
		}
		if(document.getElementById(strDiv + "Header")) {
			document.getElementById(strDiv + "Header").className = "cssLeftNav";
		}
	}
}

function fAddToCart(strID) {
	var strDiv = "divAddToCart"+strID;
	
	if(strCurrentAddToCart != "") {
		document.getElementById(strCurrentAddToCart).innerHTML = "";
		fHide(strCurrentAddToCart);
	}
	fShow(strDiv);
	//document.title = "get_quantity.php?txtID=" + strID;
	fAJAXRequest(strDiv, "get_quantity.php?txtID=" + strID);
	strCurrentAddToCart = strDiv;
	//fAJAXRequest("divCart","add_cart.php?txtID=" + strID);
	//alert("That item has been added to your cart.");
}

function fAJAXRequest(strTarget, strURL) {
	if(window.XMLHttpRequest) {
		oRequest = new XMLHttpRequest();
		oTarget = strTarget;
		oRequest.onreadystatechange = fAJAXChangeWhenReady;
		oRequest.open("GET", strURL, true);
		oRequest.send(null);
	} else if(window.ActiveXObject) {
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
		if(oRequest) {
			oTarget = strTarget;
			oRequest.onreadystatechange = fAJAXChangeWhenReady;
			oRequest.open("GET", strURL, true);
			oRequest.send();
		}
	}
}

function fAJAXChangeWhenReady() {
//document.title = oTarget;
    if(oRequest.readyState == 4) {
    	if(document.getElementById(oTarget)) {
    		document.getElementById(oTarget).innerHTML = oRequest.responseText;
    	}
    }
}

function fSendToCart() {
	strQuantity = document.getElementById("txtQuantity").value;
	strMinimumQuantity = document.getElementById("txtMinimumQuantity").value;
	strID = document.getElementById("txtID").value;
	if(strQuantity < strMinimumQuantity) {
		alert("You have specified an amount less than the minimum order quantity. Please correct the amount before you add it to your basket.");
		document.getElementById("txtQuantity").focus();
	} else {
		strURL = "add_cart.php?txtID=" + strID + "&txtQuantity=" + strQuantity;
		fAJAXRequest("divCart", strURL);
		fHide("divAddToCart"+strID);
	}
	return false;
}

function fLeaveSpanish(section, url) {
	if(confirm("Ud está dejando nuestro sitio en Español. En este momento la sección  " +section+ " sólo se encuentra disponible en Inglés.")) {
		location.href = '../' +url+ '.php';
	}
}

function openOC(sFile, sPath, strHeight, strWidth)
      { 
	  strPath = "/products/OG/" + sPath + "/" + sFile;
	  strSetup = 'height=' + strHeight + ', width=' + strWidth + ', top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no';
	  window.open (strPath, "OGwindow", strSetup);
	  }

function openPDF(sFile, sPath, strHeight, strWidth)
      { 
	  window.close ("OGwindow")
	  strPath = "/products/OG/" + sPath + "/" + sFile;
	  strSetup = 'height=' + strHeight + ', width=' + strWidth + ', top=110, left=110, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no';
	  window.open (strPath, "OGwindow1", strSetup);
	  }

function openPDF2(sFile, sPath, strHeight, strWidth)
      { 
	  strPath = "/products/OG/" + sPath + "/" + sFile;
	  strSetup = 'height=' + strHeight + ', width=' + strWidth + ', top=110, left=110, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no';
	  window.open (strPath, "OGwindow2", strSetup);
	  }
	  