// JavaScript Document
var original_row_color = "#FFFFCC"; // Defines the original base row color
var main_content_layer = "content"; // Defines the layer where the main content portion of the page is loaded
var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE

/** 
- array.indexOf() method is not support by IE, so following code enables method for IE. 
*/
if(!Array.indexOf){
  Array.prototype.indexOf = function(obj){
   for(var i=0; i<this.length; i++){
    if(this[i]==obj){
     return i;
    }
   }
   return -1;
  }
}
/** end indexOf() */

// function creates a new XML-HTTP request and stores it into xhr, retrieved by index xi
function xhrRequest() {
	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length;
	
	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {
		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}	
	
	xi[xhrsend] = 0; // SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xhr[xhrsend] = GetXmlHttpObject(); // CREATES THE XMLHTTP OBJECTS AND PUTS INTO XML-HTTP REQUESTS ARRAY
	
	return (xhrsend);
}

// Code from W3SCHOOL, creates a new XML-HTTP object
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
  	{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  		// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	
	if(xmlHttp == null)
		alert ("Your browser is not supported, please update to IE or Firefox");
	
	return xmlHttp;
}

// function loads the reponse text from the XML-HTTP requests
	// v: URL of the PHP page to be passed
	// xi_i: the index of the XML-HTTP object in the global object array
function loadContentPage (v, xi_i, div)
{
	
	xhr[xi_i].open("GET",v,true);
	if (typeof(xhr[xi_i].onprogress)=='object') // hack for FF3.5 issue: http://www.nczonline.net/blog/2009/07/09/firefox-35firebug-xmlhttprequest-and-readystatechange-bug/
	{
		xhr[xi_i].onload = xhr[xi_i].onerror = xhr[xi_i].onabort = function()
		{
		
			if (div != "")
			{	
				hideLoading(); // Hide the loading cursor
				//alert(v + "|" + div);
				document.getElementById(div).innerHTML=xhr[xi_i].responseText; // updates main content layer w/ response
				
				xi[xi_i] = 1; //resets the XML-HTTP request object status
				xhr[xi_i] = null; //resets the XML-HTTP request array
				 
			 } else
			 {
				hideLoading(); // Hide the loading cursor
				xi[xi_i] = 1; //resets the XML-HTTP request object status
				xhr[xi_i] = null; //resets the XML-HTTP request array
 			 }
		}
	} else
	{
		xhr[xi_i].onreadystatechange=function() 
		{
			if (div != "")
			{	
				
			//alert(xi_i + " , " + v + " , " + xhr[xi_i].readyState + " , " + xhr[xi_i].status)
				if ((xhr[xi_i].readyState==4) && (xhr[xi_i].status==200)) 
				{
					hideLoading(); // Hide the loading cursor
					//alert(v + "|" + div);
					document.getElementById(div).innerHTML=xhr[xi_i].responseText; // updates main content layer w/ response
					xi[xi_i] = 1; //resets the XML-HTTP request object status
					xhr[xi_i] = null; //resets the XML-HTTP request array
				 }
			 } else
			 {
				if ((xhr[xi_i].readyState==4) && (xhr[xi_i].status==200)) 
				{
					hideLoading(); // Hide the loading cursor
					xi[xi_i] = 1; //resets the XML-HTTP request object status
					xhr[xi_i] = null; //resets the XML-HTTP request array
				 }		 
			 }			 
		}
	}
	
	xhr[xi_i].send(null);
}

function getProvince (province, p_loc)
{
	document.getElementById("loading").style.visibility = 'visible'; // unhides the page loading layer
	var xmlHttp1=xhrRequest(); // gets new XML-HTTP object for this action
	var url = "location_province.php?province=" + province + "&loc=" + p_loc;
	loadContentPage(url, xmlHttp1, "province_city");
}

function loadFlag(item_id, flag_id)
{
	document.getElementById("loading").style.visibility = 'visible';
	// alert(item_id +" "+ flag_id);
	var xmlHttp1=xhrRequest();
	var url= "item_flag.php?item_id=" + item_id + "&flag_id=" + flag_id;
	
	loadContentPage(url, xmlHttp1, "item_other");
}

function loadItemEmail(item_id)
{
	document.getElementById("loading").style.visibility = 'visible'; // loading indicator ON

	var xmlHttp1=xhrRequest(); // gets new XML-HTTP object for this action
	var url= "item_email.php?item_id=" + item_id;
	loadContentPage(url, xmlHttp1, "item_other");	

}

function loadPricing(item_id, width)
{
	var div_pricing = "pricingDiv" + item_id; // pricing div layer is named pricing[catalogID];
	var divPriceIndicator = document.getElementById(div_pricing).style.display;
	document.getElementById("loading").style.visibility = 'visible'; // loading indicator ON
	
	if (divPriceIndicator == "block")
	{
		document.getElementById(div_pricing).style.display = 'none'; 
		hideLoading();
	} else
	{
		document.getElementById(div_pricing).style.display = 'block'; // loading indicator ON
		var xmlHttp1=xhrRequest(); // gets new XML-HTTP object for this action
		var url= "pricing.php?cat=" + item_id + "&width=" + width;
		loadContentPage(url, xmlHttp1, div_pricing);	
	}
	
}

// add item, quantity and package size to shopping cart
function addItem(item_id, pak, price)
{
	document.getElementById("loading").style.visibility = 'visible'; // loading indicator ON
	var xmlHttp1=xhrRequest(); // gets new XML-HTTP object for this action
	var xmlHttp2=xhrRequest();
	
	var q = "quantity" + item_id + "_" + pak;
	var quantity = document.getElementById(q).value;
	
	if(validateQuantity(quantity)) // strip quantity of all special characters
	{	
		var url= "cart_preview.php?cat=" + item_id + "&quantity=" + quantity + "&package=" + pak + "&price=" + price;
		loadContentPage(url, xmlHttp1, "layer_cart");
		setTimeout('loadSubtotal()',1000); // need to recalculate total when new item added or quantity changed
		
		var layer_avail = "avail" + item_id + "_" + pak;
		if(document.getElementById(layer_avail) != null)
		{
			var url_avail = "avail.php?cat=" + item_id + "&quantity=" + quantity + "&package=" + pak;
			loadContentPage(url_avail, xmlHttp2, layer_avail);
		}
	}
	hideLoading();
}

function validateQuantity(q)
{
	while(q.indexOf(" ") != -1) // loops until all instances found, better use than replace "GI";
			q = q.replace(" ", ""); // removes all special character from search key
	
	if (q.length==0) // checks for empty entries
	{
		alert("Please enter a value.");
		return false;
	}
	
	//var remove = "`~!@#$%^&*()_+-={}[]\|;:',<.>/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // prohibited characters
	//for (i=0;i<q.length;i++) // checks for prohibited values.
	//{
		//var q1 = q.charAt(i);
		//if (remove.indexOf(q1) != -1)
		//{\
		if (!isInteger(q))
		{
			alert ("Please only enter numerical values.");
			//i = q.length;
			return false;
		}
		//}
	
	
	return true;
}

var isInteger_re     = /^\s*(\+|-)?\d+\s*$/;
function isInteger (s) 
{
	return String(s).search (isInteger_re) != -1
}

function loadSubtotal()
{
	if(document.getElementById("layer_subtotal") != null)
	{
		document.getElementById("loading").style.visibility = 'visible'; // loading indicator ON
		var xmlHttp1=xhrRequest(); // gets new XML-HTTP object for this action
		loadContentPage("cart_subtotal.php", xmlHttp1, "layer_subtotal");
	}
}

function deleteItem(item_id, pak)
{
	document.getElementById("loading").style.visibility = 'visible'; // loading indicator ON
	var xmlHttp1=xhrRequest(); // gets new XML-HTTP object for this action
	var url= "cart_preview.php?cat=" + item_id + "&quantity=0&package=" + pak + "&action=delete";
	loadContentPage(url, xmlHttp1, "layer_cart");
	setTimeout("loadSubtotal()",1000); // need to recalculate total when item deleted
	var rowPackage = item_id + "-" + pak;
	hideRow(rowPackage); // when the row is removed, checks if last row, if so, refreshes entire page
}

function loadItemPicture(url_pic,pic_div,w,h)
{
	var picInnerHTML = "<table border=0 cellpadding=5 cellspacing=1 bgcolor=#FF0000>"
	+ "<tr>"
	+	"<td bgcolor=#FFFFFF><img src=" + url_pic + "  width=" + w + " height=" + h + " border=0></td>"
  	+ "</tr>"
	+ "</table>";

	document.getElementById(pic_div).innerHTML = picInnerHTML;
}

// function calls bookmark_set.php
// function DOES NOT update any div layers, so call loadContentPage() no layer ID is passed in 3rd parameter
// header info of the list is also passed to the cookie
	// row_id: item ID
	// type: not used yet...
// PHP passes:
	// id: the row id that represent an item
function setBookmarks(row_id, type)
{
	document.getElementById("loading").style.visibility = 'visible'; // loading indicator ON

	if (type == "b") // if the type = b, meaning call came from favorites.php and the initial row will be hidden 
	{
		//if (confirm("Are you sure you want to delete item from favorites?"))
		//{
			hideRow(row_id);
			
			var pricingLayer = "pricing" + row_id; // if pricing layer is open while deleted favorites
			document.getElementById(pricingLayer).style.display = 'none';
			
		 	var xmlHttp1=xhrRequest();
			var url_bookmark= "bookmark_set.php" + "?cat=" + row_id + "&type=" + type;
			loadContentPage(url_bookmark, xmlHttp1, "bookmark");	
		//} else
			//hideLoading();
	} else
	{
		var xmlHttp1=xhrRequest();
		var url_bookmark= "bookmark_set.php" + "?cat=" + row_id + "&type=" + type;
		loadContentPage(url_bookmark, xmlHttp1, "bookmark");	
	}
}

// function sends an email
function sendEmail()
{
	if(validateSendEmail()) // only send email of it passes validation
	{
		var from = document.getElementById("email_address_from").value;
		var name = document.getElementById("email_name").value;
		var to = document.getElementById("email_address_to").value;
		var message = document.getElementById("email_message").value;
		var subject = name + " has messaged you from AKSCI.com";
		
		// alert (name + from + message + to);
		
		var xmlHttp1=xhrRequest();
		swapVisibility("email_processing","email_form");
		// document.getElementById("email").reset(); // don't reset the email content
		
		var url_email= "email.php?from=" + from + "&message=" + message + "&to=" + to + "&subject=" + subject;
		xhr[xmlHttp1].open("GET",url_email,true);
		xhr[xmlHttp1].onreadystatechange=function() 
		{
			if ((xhr[xmlHttp1].readyState==4) && (xhr[xmlHttp1].status==200)) 
			{
				swapVisibility("email_processing","email_sent");
			xi[xmlHttp1] = 1; //resets the XML-HTTP request object status
			xhr[xmlHttp1] = null; // resets the XML-HTTP request array to null
		 }
	}
	xhr[xmlHttp1].send(null);
	}
}

// function sends an inquiry
function sendInquiry()
{
	if(validateSendInquiry()) // only send email of it passes validation
	{
		var from = document.getElementById("inquiry_email").value; // need to swap value w/ from when go-live
		var name = document.getElementById("inquiry_name").value;
		var to = "sales@aksci.com";
		var org = document.getElementById("inquiry_org").value;
		var phone = document.getElementById("inquiry_phone").value;
		var fax = document.getElementById("inquiry_fax").value;
		var subject = "Inquiry from AKSci.com: " + document.getElementById("inquiry_subject").value;
		var message = document.getElementById("inquiry_message").value;
		
		//var tbody = "Name: " + name + " |Org: " + org + " |Phone: " + phone + " |Fax: " + fax + " |Message:" + message;
		
		var tbody = "<table border='0' width='100%'><tr><td width='8%'>Name:</td><td width='92%'>"+name+"</td></tr> \
		  <tr><td>Email:</td><td>" + from + "</td></tr> \
		  <tr><td>Organization:</td><td>"+org+"</td></tr>\
		  <tr><td>Phone:</td><td>"+phone+"</td></tr>\
		  <tr><td>Fax:</td><td>"+fax+"</td></tr>\
		  <tr><td>Subject:</td><td>"+subject+"</td></tr>\
		  <tr><td>Message:</td><td>"+message+"</td></tr>\
		</table>";
		
		
		
		// alert (name + from + message + to);  \r\n
		
		var xmlHttp1=xhrRequest();
		swapVisibility("inquiry_processing","inquiry_form");
		//document.getElementById("inquiry").reset(); // don't reset the content
		
		var url_email= "email.php?from=" + from + "&message=" + tbody + "&to=" + to + "&subject=" + subject;
		xhr[xmlHttp1].open("GET",url_email,true);
		xhr[xmlHttp1].onreadystatechange=function() 
		{
			if ((xhr[xmlHttp1].readyState==4) && (xhr[xmlHttp1].status==200)) 
			{
				swapVisibility("inquiry_processing","inquiry_sent");
			xi[xmlHttp1] = 1; //resets the XML-HTTP request object status
			xhr[xmlHttp1] = null; // resets the XML-HTTP request array to null
		 }
	}
	xhr[xmlHttp1].send(null);
	}
}

// function sets the location selected to session and to the header display
function setLocation(loc1)
{
	var xmlHttp_session = xhrRequest();
	var url_session = "session.php?loc=" + loc1;
	loadContentPage(url_session, xmlHttp_session, "");
}	

function highlight(object1, object2)
{
	original_row_color = document.getElementById(object1).style.backgroundColor;
	document.getElementById(object1).style.backgroundColor="yellow";
	if (object2 != "")
		document.getElementById(object2).style.backgroundColor="yellow";
}

function unhighlight(object3, object4)
{
	document.getElementById(object3).style.backgroundColor=original_row_color;
	if (object4 != "")
		document.getElementById(object4).style.backgroundColor=original_row_color;
}

function highlightCell(object, color)
{
	original_row_color = document.getElementById(object).style.backgroundColor;
	document.getElementById(object).style.backgroundColor=color;
}

function unhighlightCell(object)
{
	document.getElementById(object).style.backgroundColor=original_row_color;
}

function changeRowBaseColor (row_id)
{
	// retrieves the combo box form object
	// retrieves only if the trigger came from the list pages, and not the bookmark
	var checkboxid = "cb" + row_id; // in item_list.php the row's combo box is id'ed as "cb[item_id]"
	
	var cb_row = document.getElementById(checkboxid); // retrieves checkbox obj for that row
	
	if(cb_row.checked == true)
	{
		document.getElementById(row_id).style.backgroundColor = "#CCFFFF"; // sets the row color to blue
		original_row_color = "#CCFFFF";
	}
	else
	{
		document.getElementById(row_id).style.backgroundColor = "#FFFFCC"; // sets the row color to original yellow/tan
		original_row_color = "#FFFFCC"; 
	}	
}

// hides the div id = loading where the loading animation is placed
function hideLoading()
{
	document.getElementById("loading").style.visibility = 'hidden';
}


// simply checks the display parameter of a layer and changes the display property
function changeLayerDisplay(divID,divCall,topOffset,leftOffset)
{
	var display = document.getElementById(divID).style.visibility;
	var topValue= 0,leftValue= 0;
	var divCall2;
	
	if (divCall != "")
	{
		divCall2 = divCall; // store divCall ID layer before it's reset
		// below is the code to grab the absolute position of a div layer
		divCall = document.getElementById(divCall);

		while(divCall)
		{
			leftValue+= divCall.offsetLeft;
			topValue+= divCall.offsetTop;
			divCall= divCall.offsetParent;
		}
		
		/** setups the subject line for inquiries only */
		var tempArray = divCall2.split('_'); // splits the divCall object into the div_quantity_id_quantity array
		if (tempArray[0] == "div" && tempArray[1] == "quantity")
		{
			var productID = tempArray[2];
			var quantity = tempArray[3];
			
			if (quantity == null)
				quantity = "";
			else
				quantity = " package size " + quantity;
			
			document.getElementById("inquiry_subject").value = "Inquiry about product " + productID + quantity;
		}
		/** end **/
	}

	
	if (display == "hidden")
	{
		document.getElementById(divID).style.visibility = "visible";
		//document.getElementById("darkBackgroundLayer").style.display = "";
		
		if (divCall != "")
		{
			document.getElementById(divID).style.left = leftValue + leftOffset;
			document.getElementById(divID).style.top = topValue + topOffset;
		}
	} else
	{
		document.getElementById(divID).style.visibility = "hidden";
		//document.getElementById("darkBackgroundLayer").style.display = "none";
	}
}


var resultCount;
var isRowSet = false;

/** IE fix for getElementsByName bug */
/** tag = i.e. TR, name = attribute name*/
function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function hideRow(divNum) 
{
	
	//var resultRow = document.getElementsByName("resultRow"); // FF
	var resultRowIE =  getElementsByName_iefix("tr","resultRow"); // IE
	
	if(!isRowSet)
	{
		resultCount = resultRowIE.length;

		isRowSet = true;
	}
	if (resultCount == 1) //written exclusively for cart_view refresh function, if only 1 line left, deleting / hiding row should refresh page to eliminate checkout link
	{
		setTimeout("window.location.reload(false)", 500);
	}
	else
	{
		// in the bookmark page each row is a grey line separator given the id [rownumber]_separate, this row should be hidden as well
		var separator = divNum + "_separator";
		var row1 = document.getElementById(divNum);
		var row_separator = document.getElementById(separator);
		row1.style.display = 'none';
		if (row_separator != null)
			row_separator.style.display = 'none';
	}
	resultCount--;
}

function swapVisibility(div1, div2)
{
	var d1 = document.getElementById(div1).style.display;
	var d2 = document.getElementById(div2).style.display;
	
	//alert (div1 + ": " + d1 + " " + div2 +": " + d2);
	
	// some odd reason, if the div.style.display = visible, the friggin thing won't pick it up and returns NULL
	if (d2 != "none")
	{
		document.getElementById(div1).style.display = "block";
		document.getElementById(div2).style.display = "none";
	} else
	{
		document.getElementById(div1).style.display = "none";
		document.getElementById(div2).style.display = "block";
	} 
}



function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


var startX = f_clientWidth() / 2 - 10; //set x offset of bar in pixels
var startY = 0 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function submitForm (form)
{
	document.getElementById(form).submit();
}	


<!-- Begin
var ShipName = "";
var ShipAddress1 = "";
var ShipAddress2 = "";
var ShipCity = "";
var ShipRegion = "";
var ShipZip = "";
var ShipCountry = "";
var ShipCountryIndex = 0;
var ShipPhone = "";
var ShipFax = "";

function InitSaveVariables(form) 
{
	ShipName = form.shipName.value;
	ShipAddress1 = form.shipAddress1.value;
	ShipAddress2 = form.shipAddress2.value;
	ShipCity = form.shipCity.value;
	ShipZip = form.shipZip.value;
	ShipRegion = form.shipRegion.value;
	ShipCountryIndex = form.shipCountry.selectedIndex;
	ShipCountry = form.shipCountry[ShipCountryIndex].value;
	ShipPhone = form.shipPhone.value;
	ShipFax = form.shipFax.value;
	
}

var error_wrapper_left = "<font color=red> < ";
var error_wrapper_right = "</font>";
var error_radio1 = "Please select if your new or existing customer.";
var error_companyName1 = "Please enter company name.";
var error_email1a = "Please enter in email address.";
var error_email1b = "Please enter email in format name@domain.com.";
var error_email2a = "Please re-enter in email address.";
var error_email2b = "Email entered does not match.";
var error_billAddress1 = "Please enter in a billing address.";
var error_billCity1 = "Please enter in a billing city.";
var error_billRegion1 = "Please enter in a billing region.";
var error_billZip1 = "Please enter in a billing zip.";
var error_billCountry1 = "Please enter in a billing country.";
var error_billName1 = "Please enter in a billing name.";
var error_billPhone1 = "Please enter in a billing phone number.";
var error_billFax1 = "Please enter in a billing fax number.";

var error_shipAddress1 = "Please enter in a shipping address.";
var error_shipCity1 = "Please enter in a shipping city.";
var error_shipRegion1 = "Please enter in a shipping region.";
var error_shipZip1 = "Please enter in a shipping zip.";
var error_shipCountry1 = "Please enter in a shipping country.";
var error_shipName1 = "Please enter in a shipping name.";
var error_shipPhone1 = "Please enter in a shipping phone number.";
var error_shipFax1 = "Please enter in a shipping fax number.";

var error_shipping1 = "Please select shipping method.";

var error_cart1 = "Your cart is empty.";


function validateSendEmail()
{
	var sendEmail = new Array();
	sendEmail.push(validateEmpty("email_name", "Please enter name"));
	sendEmail.push(validateEmail("email_address_from", error_email1a, error_email1b));
	sendEmail.push(validateEmail("email_address_to", error_email1a, error_email1b));
	if (sendEmail.indexOf(false) == -1)
		return true;
	else
		return false;
}

function validateSendInquiry()
{
	var sendInquiry = new Array();
	sendInquiry.push(validateEmpty("inquiry_name", "Please enter name"));
	sendInquiry.push(validateEmail("inquiry_email", error_email1a, error_email1b));
	sendInquiry.push(validateEmpty("inquiry_org", error_companyName1));
	sendInquiry.push(validateEmpty("inquiry_phone", "Please enter in a phone number."));
	sendInquiry.push(validateEmpty("inquiry_subject", "Please enter in a subject."));
	
	if (sendInquiry.indexOf(false) == -1)
		return true;
	else
		return false;
}

function validateCart()
{
	var formPass = new Array();
	
	// radio button validation for if checked
	var radio_choice = false;
	for (counter = 0; counter < document.form1.radiobutton.length; counter++)
	{
		if (document.form1.radiobutton[counter].checked)
			radio_choice = true; 
	}
	if (!radio_choice)
	{
		document.getElementById("error_radio").innerHTML = error_wrapper_left + error_radio1 + error_wrapper_right;
		document.getElementById("error_radio").style.display = "block";
		formPass.push(false);
	} else
		document.getElementById("error_radio").style.display = "none";
	
	// email 1 validations, first empty, then check for format
	formPass.push(validateEmail("email1", error_email1a, error_email1b));
	
	// email 2 validations, first empty, then check for same email
	formPass.push(validateEmail("email2", error_email2a, error_email2b));
	if (!validateEmpty("email2", error_email2a))
		formPass.push(false);
	else
	{
		if (document.form1.email2.value != document.form1.email1.value)
		{
			document.getElementById("error_email2").innerHTML = error_wrapper_left + error_email2b + error_wrapper_right;
			document.getElementById("error_email2").style.display = "block";
			formPass.push(false);
		} else
			document.getElementById("error_email2").style.display = "none";
	}
	
	formPass.push(validateEmpty("companyName", error_companyName1)); //company name address validations
	formPass.push(validateEmpty("billAddress1", error_billAddress1)); // bill 1 address validations
	formPass.push(validateEmpty("billCity", error_billCity1)); // city address validations
	formPass.push(validateEmpty("billRegion", error_billRegion1)); // region address validations
	formPass.push(validateEmpty("billZip", error_billZip1)); // billZip validation
	formPass.push(validateEmpty("billCountry", error_billCountry1)); // billCountry validation
	formPass.push(validateEmpty("billName", error_billName1)); // billName validation
	formPass.push(validateEmpty("billPhone", error_billPhone1)); // billPhone validation
	formPass.push(validateEmpty("billFax", error_billFax1)); // billFax validation
	
	formPass.push(validateEmpty("shipAddress1", error_shipAddress1)); // ship 1 address validations
	formPass.push(validateEmpty("shipCity", error_shipCity1)); // city address validations
	formPass.push(validateEmpty("shipRegion", error_shipRegion1)); // region address validations
	formPass.push(validateEmpty("shipZip", error_shipZip1)); // shipZip validation
	formPass.push(validateEmpty("shipCountry", error_shipCountry1)); // shipCountry validation
	formPass.push(validateEmpty("shipName", error_shipName1)); // shipName validation
	formPass.push(validateEmpty("shipPhone", error_shipPhone1)); // shipPhone validation
	formPass.push(validateEmpty("shipFax", error_shipFax1)); // shipFax validation
	
	formPass.push(validateShipping()); // shipping method validation
	

	if(document.form1.cartStatus) // check fi cart is empty
	{
		document.getElementById("error_cart").innerHTML = error_wrapper_left + error_cart1 + error_wrapper_right;
		document.getElementById("error_cart").style.display = "block";
		formPass.push(false);
	} 
	
	//alert(formPass);
	
	if (formPass.indexOf(false) == -1)
	{
		document.form1.confirmValidate.value = true;
		return true;
	} else
	{
		document.form1.confirmValidate.value = false;
		return false;
	}
}

function validateEmpty(form, error)
{
	var layer = "error_" + form;
	if (document.getElementById(form).value.length == 0)
	{
		document.getElementById(layer).innerHTML = error_wrapper_left + error + error_wrapper_right;
		document.getElementById(layer).style.display = "block";
		return false;
	} else
	{
		document.getElementById(layer).style.display = "none";
		return true;		
	}
}

function validateEmail(form, error1, error2)
{
	if (!validateEmpty(form, error1))
		return false;
	else
	{
		var layer = "error_" + form;
		if (document.getElementById(form).value.indexOf("@") == -1)
		{
			document.getElementById(layer).innerHTML = error_wrapper_left + error2 + error_wrapper_right;
			document.getElementById(layer).style.display = "block";
			return false;
		} else
		{
			document.getElementById(layer).style.display = "none";
			return true;
		}
	}
}

function validateShipping()
{
	if (document.getElementById("shipping").value == "Other")
		return validateEmpty("shipping_other", error_shipping1);
	else
		return validateEmpty("shipping", error_shipping1);
}

function validateCheckOther()
{
	var shipMethod = document.getElementById("shipping").value; 
	if (shipMethod == "Other") // if Other chosen, display layer, all other shipping option error should be hidden
	{
		document.getElementById("layer_shipping_other").style.display = "block";
		document.getElementById("error_shipping").style.display = "none";
	} else // if other option is not chosen, hide layer and hide error layer as well
	{
		document.getElementById("layer_shipping_other").style.display = "none";
		document.getElementById("error_shipping_other").style.display = "none";
	}
	validateCart();
}

function validateSearch()
{
	var remove = "<>`~!@#$%^&_+=./\|{}"; // prohibited characters
	var keyword = document.keySearch.search.value;
	for (i=0;i<remove.length;i++)
	{
		var character = remove.charAt(i);
		while(keyword.indexOf(character) != -1) // loops until all instances found, better use than replace "GI";
			keyword = keyword.replace(character, ""); // removes all special character from search key
	}
	
	var temp = keyword;
	
	// if after removing all spaces and the keyword is empty, page should be redirected to index.php, else submited
	while(temp.indexOf(" ") != -1) // loops until all instances found, better use than replace "GI";
			temp = temp.replace(" ", ""); // removes all space character from search key
	if (temp.length == 0)
	{
		location.href="http://www.aksci.info/home.php";
		return false;
	}
	else
	{
		document.keySearch.search.value = keyword;
		return true;
	}
}

function ShipToBillPerson(form) 
{
	if (form.copy.checked) 
	{
		InitSaveVariables(form);
		form.shipName.value = form.billName.value;
		form.shipAddress1.value = form.billAddress1.value;
		form.shipAddress2.value = form.billAddress2.value;
		form.shipCity.value = form.billCity.value;
		form.shipZip.value = form.billZip.value;
		form.shipRegion.value = form.billRegion.value;
		form.shipCountry.selectedIndex = form.billCountry.selectedIndex;
		form.shipPhone.value = form.billPhone.value;
		form.shipFax.value = form.billFax.value;
	} else 
	{
		form.shipName.value = ShipName;
		form.shipAddress1.value = ShipAddress1;
		form.shipAddress2.value = ShipAddress2;
		form.shipCity.value = ShipCity;
		form.shipZip.value = ShipZip;       
		form.shipRegion.value = ShipRegion;
		form.shipCountry.selectedIndex = ShipCountryIndex;
		form.shipPhone.value = ShipPhone;
		form.shipFax.value = ShipFax;
   }
   
   validateCart();
}
//  End -->

<!-- // Updated version available at: http://www.echoecho.com/toolfloatinglayer.htm
floatX=0;
floatY=0;
layerwidth=100;
layerheight=20;
halign="left";
valign="top";
delayspeed=0;

NS6=false;
IE4=(document.all);
if (!IE4) {NS6=(document.getElementById);}
NS4=(document.layers);

function adjust() {
if ((NS4) || (NS6)) {
if (lastX==-1 || delayspeed==0)
{
lastX=window.pageXOffset + floatX;
lastY=window.pageYOffset + floatY;
}
else
{
var dx=Math.abs(window.pageXOffset+floatX-lastX);
var dy=Math.abs(window.pageYOffset+floatY-lastY);
var d=Math.sqrt(dx*dx+dy*dy);
var c=Math.round(d/10);
if (window.pageXOffset+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (window.pageXOffset+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (window.pageYOffset+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (window.pageYOffset+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
if (NS4){
document.layers['floatlayer'].pageX = lastX;
document.layers['floatlayer'].pageY = lastY;
}
if (NS6){
document.getElementById('floatlayer').style.left=lastX;
document.getElementById('floatlayer').style.top=lastY;
}
}
else if (IE4){
if (lastX==-1 || delayspeed==0)
{
lastX=document.body.scrollLeft + floatX;
lastY=document.body.scrollTop + floatY;
}
else
{
var dx=Math.abs(document.body.scrollLeft+floatX-lastX);
var dy=Math.abs(document.body.scrollTop+floatY-lastY);
var d=Math.sqrt(dx*dx+dy*dy);
var c=Math.round(d/10);
if (document.body.scrollLeft+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (document.body.scrollLeft+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (document.body.scrollTop+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (document.body.scrollTop+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
document.all['floatlayer'].style.posLeft = lastX;
document.all['floatlayer'].style.posTop = lastY;
}
setTimeout('adjust()',50);
}

function define()
{
	if ((NS4) || (NS6))
	{
	if (halign=="left") {floatX=ifloatX};
	if (halign=="right") {floatX=window.innerWidth-ifloatX-layerwidth-20};
	if (halign=="center") {floatX=Math.round((window.innerWidth-20)/2)-Math.round(layerwidth/2)};
	if (valign=="top") {floatY=ifloatY};
	if (valign=="bottom") {floatY=window.innerHeight-ifloatY-layerheight};
	if (valign=="center") {floatY=Math.round((window.innerHeight-20)/2)-Math.round(layerheight/2)};
	}
	if (IE4)
	{
	if (halign=="left") {floatX=ifloatX};
	if (halign=="right") {floatX=document.body.offsetWidth-ifloatX-layerwidth-20}
	if (halign=="center") {floatX=Math.round((document.body.offsetWidth-20)/2)-Math.round(layerwidth/2)}
	if (valign=="top") {floatY=ifloatY};
	if (valign=="bottom") {floatY=document.body.offsetHeight-ifloatY-layerheight}
	if (valign=="center") {floatY=Math.round((document.body.offsetHeight-20)/2)-Math.round(layerheight/2)}
	}
}
//-->

