
// Variables needed for Rollovers
var finished = 'yes';
var over = 'no';
var styleSheetElement;
var oldElement;
var lastDisplayedMenu;
var lastMenu = "";
var beenCalled;

// Image Objects
corporateOn = new Image();
corporateOn.src = "/images/nav_button_main_corporate_on.gif";
corporateOff = new Image();
corporateOff.src = "/images/nav_button_main_corporate_off.gif";

productsOn = new Image();
productsOn.src = "/images/nav_button_main_products_on.gif";
productsOff = new Image();
productsOff.src = "/images/nav_button_main_products_off.gif";

solutionsOn = new Image();
solutionsOn.src = "/images/nav_button_main_solutions_on.gif";
solutionsOff = new Image();
solutionsOff.src = "/images/nav_button_main_solutions_off.gif";

servicesOn = new Image();
servicesOn.src = "/images/nav_button_main_services_on.gif";
servicesOff = new Image();
servicesOff.src = "/images/nav_button_main_services_off.gif";

supportOn = new Image();
supportOn.src = "/images/nav_button_main_support_on.gif";
supportOff = new Image();
supportOff.src = "/images/nav_button_main_support_off.gif";

partnersOn = new Image();
partnersOn.src = "/images/nav_button_main_partners_on.gif";
partnersOff = new Image();
partnersOff.src = "/images/nav_button_main_partners_off.gif";

purchaseOn = new Image();
purchaseOn.src = "/images/nav_button_main_purchase_on.gif";
purchaseOff = new Image();
purchaseOff.src = "/images/nav_button_main_purchase_off.gif";

quickLinksOn = new Image();
quickLinksOn.src = imagePath + "side_headers/home_quick_links.gif";
quickLinksOff = new Image();
quickLinksOff.src = imagePath + "side_headers/home_quick_links.gif";

// MyPeek Image Objects
contractsOn = new Image();
contractsOn.src = imagePath + "navigation/mypeek/nav_mycontracts_on.gif";
contractsOff = new Image();
contractsOff.src = imagePath + "navigation/mypeek/nav_mycontracts_off.gif";

profileOn = new Image();
profileOn.src = imagePath + "navigation/mypeek/nav_myprofile_on.gif";
profileOff = new Image();
profileOff.src = imagePath + "navigation/mypeek/nav_myprofile_off.gif";

resourcesOn = new Image();
resourcesOn.src = imagePath + "navigation/mypeek/nav_resources_on.gif";
resourcesOff = new Image();
resourcesOff.src = imagePath + "navigation/mypeek/nav_resources_off.gif";

plusOn = new Image();
plusOn.src = imagePath + "buttons/button_plus_hover.png";
plusOff = new Image();
plusOff.src = imagePath + "buttons/button_plus.png";

minusOn = new Image();
minusOn.src = imagePath + "buttons/button_minus_hover.png";
minusOff = new Image();
minusOff.src = imagePath + "buttons/button_minus.png";

// home page download buttons 

downloadDemoOn = new Image();
downloadDemoOn.src = imagePath + "buttons/download_demo_on.png";
downloadDemoOff = new Image();
downloadDemoOff.src = imagePath + "buttons/download_demo_off.png";

downloadEvalOn = new Image();
downloadEvalOn.src = imagePath + "buttons/download_eval_on.png";
downloadEvalOff = new Image();
downloadEvalOff.src = imagePath + "buttons/download_eval_off.png";


// function that turns on the main nav graphics as well as the menus
function menuOn(whichMenu) {
	// Make sure the page has loaded
	if (finished == 'yes') {
		// set over to show that the user is now over a menu
		over = 'yes';
		
		// check to see if the user is on a wc3 css compliant browser(i.e Netscape4.x
		if (cssOK == 'yes') {

			// This section of code is executed for wc3 css compliant browsers
			// Execute the following if this is not the first time this function has been called
			if (beenCalled == 'yes')  {
										
				// These lines gather the menu element which we want to access
				lastDisplayedMenu = lastMenu + 'Menu';
				oldElement = document.getElementById(lastDisplayedMenu);
				
				// Turn off any currently displayed menu and image
				if((lastMenu != 'quickLinks') && (lastMenu != 'intlSites')) {
					if (currentSection != lastMenu) eval('document.images[lastMenu].src = ' + lastMenu + 'Off.src');
				}
				oldElement.style.visibility = "hidden";	
						
			}
			
			// These lines gather the menu element which we want to access
			layerName = whichMenu + 'Menu';
			styleSheetElement = document.getElementById(layerName);	
			
			// Turn on the menu and image which need now need to be displayed		
			styleSheetElement.style.visibility = "visible";
			if ((whichMenu != 'quickLinks') && (whichMenu != 'intlSites')) {
				if (currentSection != whichMenu) eval('document.images[whichMenu].src = ' + whichMenu + 'On.src');
			}

			// set lastDisplayed Array to hold names of menus turned on for use next time function is called
			lastMenu = whichMenu;	
		}
		beenCalled = 'yes';
	}
}


// Timer function that is run to give the user time to get to the menu from the button
function overChecker(whichMenu) {
	if ((over == 'yes') && (finished == 'yes')) {
	
		//gather the names of all the menus that you want on into the currentMenus Array
		lastMenu = whichMenu;
		over = 'no';
		setTimeout("menuOff()", 900);
	}
}

// function that turns off the main nav graphics as well as the menus
function menuOff() {
	if (over == 'no')  {
		if (cssOK == 'yes') {
			// These lines gather the menu element which we want to access			
			lastDisplayedMenu = lastMenu + 'Menu';
			oldElement = document.getElementById(lastDisplayedMenu);
					
			// Turn off any currently displayed menu and image
			oldElement.style.visibility = "hidden";	
			if ((lastMenu != 'quickLinks') && (lastMenu != 'intlSites')) {
				if (currentSection != lastMenu) eval('document.images[lastMenu].src = ' + lastMenu + 'Off.src');
			}
		}
	}	
}

// Image replace On Function	
function on(pic) {
	if (document.images) { 
			eval('document.images[pic].src = ' + pic + 'On.src');
	}
}
        
// Image replace Off Function	
function off(pic) {     
	if(document.images) {
		eval('document.images[pic].src = ' + pic + 'Off.src');
	}	
}


// Plus/Minus image replace On Function	
function toggleImageOn(pic, type) {
	var imageID = pic + "_toggle";
	eval('document.images[imageID].src = ' + type + 'On.src');

}
        
// Plus/Minus image replace Off Function	
function toggleImageOff(pic, type) {     
	var imageID = pic + "_toggle";
	eval('document.images[imageID].src = ' + type + 'Off.src');
}


// Function for Customer Logos Home Animation

function get_random() {
    var ranNum= Math.floor(Math.random()*6);
    return ranNum;
}

function getCustomers()
{
	var whichCustomers=get_random();
	
	var customers=new Array(6)
	customers[0]="<img src=\"/images/home_page/home_customer_logos_0.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[1]="<img src=\"/images/home_page/home_customer_logos_1.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[2]="<img src=\"/images/home_page/home_customer_logos_2.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[3]="<img src=\"/images/home_page/home_customer_logos_3.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[4]="<img src=\"/images/home_page/home_customer_logos_4.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[5]="<img src=\"/images/home_page/home_customer_logos_5.png\" width=\"608\" height=\"74\" alt=\"\">";
	
	
	document.write(customers[whichCustomers]);
}
  
// Function for UK Customer Logos Home Animation
function get_randomUK() {
    var ranNum= Math.floor(Math.random()*4);
    return ranNum;
}

function getCustomersUK() {
	
	var whichCustomers=get_randomUK();
	
	var customers=new Array(4)
	customers[0]="<img src=\"/images/home_page/home_customer_logos_UK_0.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[1]="<img src=\"/images/home_page/home_customer_logos_UK_1.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[2]="<img src=\"/images/home_page/home_customer_logos_UK_2.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[3]="<img src=\"/images/home_page/home_customer_logos_UK_3.png\" width=\"608\" height=\"74\" alt=\"\">";
	
	document.write(customers[whichCustomers]);
}

// Function for Korean Customer Logos Home Animation
function get_randomKR() {
    var ranNum= Math.floor(Math.random()*3);
    return ranNum;
}

function getCustomersKR() {
	
	var whichCustomers=get_randomKR();
	
	var customers=new Array(3)
	customers[0]="<img src=\"/images/home_page/customer_logos_korea1.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[1]="<img src=\"/images/home_page/customer_logos_korea2.png\" width=\"608\" height=\"74\" alt=\"\">";
	customers[2]="<img src=\"/images/home_page/customer_logos_korea3.png\" width=\"608\" height=\"74\" alt=\"\">";

	
	document.write(customers[whichCustomers]);
}

// Pop-up window function
function windowOpener(url, picWidth, picHeight, scrolling) {
	demoWindow=eval("window.open(url,'newWin','menubar=no,resizable=yes,scrollbars="+scrolling+",toolbar=no,height="+picHeight+",width="+picWidth+"')");
}

// Page Changer function
function pageChanger(location) {
	window.opener.location= location;
	window.close();
}

// Search URL Builder Function
function searchBuilder() {
		var searchUrl = "http://" + document.domain + "/search/";
		searchUrl += document.searchForm.zoom_query.value + "/";
		searchUrl += document.searchForm.zoom_per_page.options[document.searchForm.zoom_per_page.selectedIndex].value + "/";
		
		if (document.searchForm.zoom_and[0].checked) {
			searchUrl += "0/";
		} else {
			searchUrl += "1/";	
		}
		searchUrl += document.searchForm.zoom_sort.value;
		document.location = searchUrl;
}

// Search URL Builder Function
function navSearchBuilder() {
		var searchUrl = "http://" + document.domain + "/search/";
		searchUrl += document.navSearchForm.zoom_query.value + "/";
		searchUrl += document.navSearchForm.zoom_per_page.value + "/";
		searchUrl += document.navSearchForm.zoom_and.value + "/";
		searchUrl += document.navSearchForm.zoom_sort.value;
		document.location = searchUrl;
}

//function to open smaller window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// Checks Number of "upgrade" engines in cart before adding more
function checkEngines(whichEngine, numWrkEngines, numEntEngines, productID) {
	cartEngines = numWrkEngines + numEntEngines;
	if(productID == 'odnxep_dl') {
		newNum = numWrkEngines + parseInt(eval('document.' + whichEngine + '.product_quantity.options[document.' + whichEngine + '.product_quantity.selectedIndex].value'));
	} else if (productID == 'oewgp_dl') {
		newNum = numEntEngines + parseInt(eval('document.' + whichEngine + '.product_quantity.options[document.' + whichEngine + '.product_quantity.selectedIndex].value'));
	}
	if(newNum <= 3) {
		eval('document.' + whichEngine + '.submit()');
	} else {
		alert('You already have ' + cartEngines + ' OmniEngine(s) in your cart. Your selection will put you above the limit of 3 OmniEngines for this transaction.');
	}	
}

// Checks for presence of Upgrade in cart when other promo items are detected
function checkForUpgrades(hasUpgrades) {
		if(hasUpgrades == '9107333') {
			document.location='/address_form.php';
		} else {
			alert('You have items in your cart that require the selection of an AiroPeek/EtherPeek to OmniPeek Software Upgrade');
	}	
}


// ajax junction
var request;
var dest;

// Function to display short description for product listings
function show_product_info(productID) {
	var contentElement = document.getElementById(productID);
	var URL = '/content/product_descriptions/short_descriptions.php?pid=' + productID;
	loadHTML(URL, productID);
}

// Function to hide short description for product listings
function hide_product_info(productID) {
	var contentElement = document.getElementById(productID);
	var URL = '/content/product_descriptions/hide_descriptions.php?pid=' + productID;
	loadHTML(URL, productID);
}


// Function to display form for registration
function show_form(URL) {
	var contentElement = document.getElementById('regForm');
	loadHTML(URL, 'regForm');
}

// Function to submit form registration
function submit_form(URL) {
	var getVars = "/";
	getVars += "firstname=" + document.registrationForm.firstname.value;
	getVars += ";;lastname=" + document.registrationForm.lastname.value;
	getVars += ";;email=" + document.registrationForm.email.value;
	getVars += ";;phone=" + document.registrationForm.phone.value;
	getVars += ";;company=" + document.registrationForm.company.value;
	getVars += ";;address1=" + document.registrationForm.address1.value;
	getVars += ";;address2=" + document.registrationForm.address2.value;
	getVars += ";;city=" + document.registrationForm.city.value;
	getVars += ";;zip=" + document.registrationForm.zip.value;
	getVars += ";;state=" + document.registrationForm.state.options[document.registrationForm.state.selectedIndex].value;
	getVars += ";;country=" + document.registrationForm.country.options[document.registrationForm.country.selectedIndex].value
	for (var i=0; i < document.registrationForm.opt_in.length; i++)   {
  	if (document.registrationForm.opt_in[i].checked)      {
   		var rad_val = document.registrationForm.opt_in[i].value;
  	}
  }
	getVars += ";;opt_in=" + rad_val;
	getVars += ";;action=" + document.registrationForm.action.value;
	
	URL += getVars
	loadHTML(URL, 'regForm');
}
	
function processStateChange(){
    if (request.readyState == 4){
        contentDiv = document.getElementById(dest);
        if (request.status == 200){
            response = request.responseText;
            contentDiv.innerHTML = response;
        }  else {
            contentDiv.innerHTML = "Error: Status "+request.status;
        }
    }
}

function loadHTML(URL, destination){
    dest = destination;
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
        request.onreadystatechange = processStateChange;
        request.open("GET", URL, true);
        request.send(null);
    } else if (window.ActiveXObject) {
        request = new ActiveXObject("Microsoft.XMLHTTP");
        if (request) {
            request.onreadystatechange = processStateChange;
            request.open("GET", URL, true);
            request.send();
        }
    }
}
