/*START: Google Analytics*/
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
	var pageTracker = _gat._getTracker("UA-6394846-3");
	pageTracker._trackPageview();
} catch(err) {}
/*END: Google Analytics*/

var PO=[];

jQuery(function() {
	if ($.browser.msie) {
		$("#frm_login").next().css({"background":"transparent url(/Graphics/ie-min-order-bg.jpg) no-repeat","height":"50px"});
	}
});

function mouseOver(id) {
	var tag=document.getElementById(id);
	var graphicFileName=tag.src;
	if (graphicFileName.indexOf('_ro')>0) {
		tag.src=graphicFileName.replace('_ro.gif','.gif');
	}
	else {
		tag.src=graphicFileName.replace('.gif','_ro.gif');
	}
}
function open_po_v1() {
//	alert('The Purchase order screen is under development.');
	try {
		var height=768;
		var width=1024;

		try {
			if (screen.availHeight) {
				height=(screen.height) 
					? (screen.availHeight-33) //if IE
					: screen.availHeight; //if not IE
			} else { height=600; }
			if (screen.availWidth) {
				width=(screen.width)
					? (screen.availWidth-33) //if IE
					: screen.availWidth; //if not IE
			} else { width=800; }
		} 
		catch(e) { 
//			alert('1 '+e); 
		}

		var uid='PO_'+Math.random();
		uid=uid.replace('.','');
		var properties=[
			'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,height=' //fullscreen,
			,height
			,',width='
			,width
		].join('');
//		PO.push(window.open('/customer/purchaseorder/default.aspx', uid, properties));
//		window.open('https://www.aquatropic.com/customer/purchaseorder/default.aspx', uid, properties);
//		window.open('http://www.aquatropic.com/po/index.asp', uid, properties);
	}
	catch(e) {
		alert(e);
	}
}
function open_po() {
//	alert('The Purchase order screen is under development.');
	try {
		var height=768;
		var width=1024;

		try {
			if (screen.availHeight) {
				height=(screen.height) 
					? (screen.availHeight-33) //if IE
					: screen.availHeight; //if not IE
			} else { height=600; }
			if (screen.availWidth) {
				width=(screen.width)
					? (screen.availWidth-33) //if IE
					: screen.availWidth; //if not IE
			} else { width=800; }
		} 
		catch(e) { 
//			alert('1 '+e); 
		}

		var uid='AquatropicWebPO_'+Math.random();
		uid=uid.replace('.','');
		var properties=[
			'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,height=' //fullscreen,
			,height
			,',width='
			,width
		].join('');
//		PO.push(window.open('/customer/purchaseorder/default.aspx', uid, properties));
//		window.open('https://staging.aquatropic.com/customer/purchaseorder/', uid, properties);
		window.open('https://www.aquatropic.com/customer/purchaseorder/', uid, properties);
//		window.open('/customer/purchaseorder', uid, properties);
	}
	catch(e) {
		alert(e);
	}
}
function closePOs(obj) {
	if (obj==null) obj=PO;
	for (var i=0; i<obj.length; i++) {
		if (obj[i].length>0) closePOs(obj[i]);
		obj[i]=null;
		delete obj[i];
	}
	delete obj;
	PO=null;
}
function XmlHttpObject() {
	this.xmlHttp;

	this.setXmlHttp=function() {
		/*@cc_on
		@if (@_jscript_version >= 5)
			try { this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
			catch (e) {
				try { this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
				catch (E) { this.xmlHttp = false; }
			}
		@else
		this.xmlHttp = false;
		@end @*/
		if (!this.xmlHttp && typeof XMLHttpRequest != 'undefined') {
			try { this.xmlHttp = new XMLHttpRequest(); } 
			catch (e) { this.xmlHttp = false; }
		}
	};
	
	this.handler=function() {
		try {
			UI.innerHTML=this.xmlHttp.responseText; 
		} 
		catch(e) { 
			alert('error @ XmlHttpObject.Handler\n'+e); 
		};
	};
	
	this.errHandler=function() {
		alert('error @ XmlHttpObject.errHandler()\n'+e);
	};
	
	this.enableUI=function() { ; };
	
	this.disableUI=function() { ; };
	
	this.serverErrorPrompt=function(msg) {
		try {
			var ans=confirm(msg);
			if (ans==true) {
				var newWin=window.open('blank.htm');
				newWin.document.write(this.xmlHttp.responseText);
			}
		}
		catch(e) {
			alert('error @ XmlHttpObject.serverErrorPrompt()\n'+e);
		}
	};
}
function server_error_detail_prompt(msg, detail) {
	try {
		var ans=confirm(msg+'\n\n'+'Click OK for the error detail; otherwise, CANCEL.');
		if (ans==true) {
			var newWin=window.open('blank.htm');
			newWin.document.write(detail);
		}
	}
	catch(e) {
		alert('error @ server_error_detail_prompt()\n'+e);
	}
}
function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
		try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e) {
			try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
			catch (E) { xmlhttp = false; }
		}
	@else
	xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try { xmlhttp = new XMLHttpRequest(); } 
		catch (e) { xmlhttp = false; }
	}
	return xmlhttp;
}
function get_keycode(e) {
	try {
		if(document.all) e=window.event; // for IE
		var charCode;
		if (charCode=='' || charCode==null) try {charCode=e.which;} catch(e) {;}
		if (charCode=='' || charCode==null) try {charCode=e.keyCode;} catch(e) {;};
		if (charCode=='' || charCode==null) try {charCode=e.charCode;} catch(e) {;};
	}
	catch(e) { ; }
//	var msg=document.getElementById('MSG');
//	msg.innerHTML+=charCode;
//	Barcode.focus();
	return(charCode);
}
function GoTo(url) {
	document.location=url;
	return(false);
}

/* Previous Version of main.js*/
var previous_element_id;
var previous_element_order;
var previous_element_cls;
var previous_element_scls;
var previous_element_cat;

//load_images();

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function load_images() {
	var cur_image;
	var nav_images=new Array(
		'static/navigation/about.gif',
		'static/navigation/about_ro.gif',
		'static/navigation/contact.gif',
		'static/navigation/contact_ro.gif',
		'static/navigation/faq.gif',
		'static/navigation/faq_ro.gif',
		'static/navigation/home.gif',
		'static/navigation/home_ro.gif',
		'static/navigation/inventory.gif',
		'static/navigation/inventory_ro.gif',
		'static/navigation/links.gif',
		'static/navigation/links_ro.gif',
		'static/navigation/news.gif',
		'static/navigation/news_ro.gif',
		'static/navigation/pending.gif',
		'static/navigation/pending_ro.gif',
		'static/navigation/pinvoice.gif',
		'static/navigation/pinvoice_ro.gif',
		'static/navigation/products.gif',
		'static/navigation/products_ro.gif',
		'static/navigation/stock.gif',
		'static/navigation/stock_ro.gif',
		'static/navigation/uinvoice.gif',
		'static/navigation/uinvoice_ro.gif',
		'static/navigation/memberNavCreateOrder.gif',
		'static/navigation/memberNavCreateOrderOn.gif',
		'static/navigation/memberNavResumeOrder.gif',
		'static/navigation/memberNavResumeOrderOn.gif',
		'static/po/buttonAdd.gif',
		'static/po/buttonDelete.gif'
	);
	for (var i in nav_images) {
		cur_image=new Image;
		cur_image.src=nav_images[i];
	}
}
function open_order_form() {
//    alert('The Purchase order screen is currently undergoing maintenance.\nThis service will be available at noon PST');
	var height;
	var width;
	if (screen.availHeight) {
		if (screen.height) { //if IE
			height=(screen.availHeight-33);
		}
		else { //if not IE
			height=screen.availHeight;
		}
	}
	else {
		height=600;
	}
	if (screen.availWidth) {
		if (screen.width) { //if IE
			width=(screen.availWidth-33);
		}
		else { //if not IE
			width=screen.availWidth;
		}
	}
	else {
		width=800;
	}
	var uid='Aquatropic';//envURL.replace(/\./g,'_');
	//var uid='_'+Math.random();
	//uid=uid.replace('.','');
	//alert(uid);
	//window.open('po/index.asp','order','toolbar=1,scrollbars=1,location=1,menubar=1,resizable=1');
	var properties='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,height='+height+',width='+width; //fullscreen,
	window.open('/po/index.asp', 'order_'+uid, properties);
	//window.open('po/order.asp', 'order', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,'+height);
}
function open_popup(page, name, width, height) {
	window.open(page, name, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height);
}
function open_window(page, name, width, height) {
	window.open(page, name, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width='+width+',height='+height);
}
function open_popup_return(page, name, width, height) {
	window.open(page, name, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height);
	return(false);
}
function set_prev_ids(cls, scls, cat) {
	if (document.getElementById(cls)!=null)
		previous_element_cls=cls;
	if (document.getElementById(scls)!=null)
		previous_element_scls=scls;
	if (document.getElementById(cat)!=null)
		previous_element_cat=cat;
}
function show_hide(element_id) {
	var cur_display=document.getElementById(element_id);
	if(previous_element_id!=null && previous_element_id!=element_id) {
		document.getElementById(previous_element_id).style.display='none';
	}
	if (cur_display.style.display=='block') {
		cur_display.style.display='none';
	}
	else {
		cur_display.style.display='block';
	}
	previous_element_id=element_id;
}
function show_hide_cls(element_id) {
	var cur_display=document.getElementById(element_id);
	if(previous_element_cls!=null && previous_element_cls!=element_id) {
		document.getElementById(previous_element_cls).style.display='none';
	}
	if (cur_display.style.display=='block' || cur_display.style.display=='') {
		cur_display.style.display='none';
	}
	else {
		cur_display.style.display='block';
	}
	//these lines are to work w/ the products navigator to reset the category prev id
	//since previous_element_cat is unused by all other insertions of main.js, this poses no problems on other uses.
	/*if (previous_element_cls!=null) {
		document.getElementById(previous_element_cls).style.display='none';
		previous_element_cls=null; 
	}*/
	previous_element_cls=element_id;
}
function show_hide_scls(element_id) {
	var cur_display=document.getElementById(element_id);
    //alert(cur_display.id);
	if(previous_element_scls!=null && previous_element_scls!=element_id) {
		document.getElementById(previous_element_scls).style.display='none';
	}
	if (cur_display.style.display=='block' || cur_display.style.display=='') {
		cur_display.style.display='none';
	}
	else {
		cur_display.style.display='block';
	}
	previous_element_scls=element_id;
	//these lines are to work w/ the products navigator to reset the category prev id
	//since previous_element_cat is unused by all other insertions of main.js, this poses no problems on other uses.
	/*if (previous_element_scls!=null) {
		document.getElementById(previous_element_scls).style.display='none';
		previous_element_scls=null; 
	}*/
}
function show_hide_cat(element_id) {
	var prev_display=document.getElementById(previous_element_cat);
	prev_display.style.display='none';
	if (previous_element_cat!=element_id) {
		var cur_display=document.getElementById(element_id);
		if (cur_display.style.display=='block' || cur_display.style.display=='') {
			cur_display.style.display='none';
		}
		else {
			var cls=element_id.split('_')[0];
			var cat=element_id.split('_')[1];
			if (cur_display.innerHTML=='') {
				var scat='';
				//alert('//c[@ci='+cat+']/s');
				var nodes=get_nodes('//c[@ci='+cat+']/s');
				for (var i=0; i<nodes.length; i++) {
					scat+=
						'<a href="products.asp?'+
						'cls='+cls+
						'&cat='+cat+
						'&scat='+nodes[i].getAttribute('si')+
						'&pg=1"'+
						'>'+nodes[i].getAttribute('sd')+'</a><br/>';
				}
				cur_display.innerHTML=scat;
			}
			cur_display.style.display='block';
		}
	}
	previous_element_cat=element_id;
}
function initialize_navigator() {

	//mozilla hiccups w/ the length property of List returned from selectNodes method.
	var nav='';
	var cur_cls, cur_cat, cur_scat;
	var cls, cls_id, cls_desc;
	var cat, cat_id, cat_desc;
	var scat, scat_id, scat_desc;
	
	if (location.search.length>0) {
		var qs=location.search;
		var qss=location.search.split('&');
		for (var i=0; i<qss.length; i++) {
			var field=qss[i].split('=');
			if (field[0].replace('?','')=='cls') {
				cur_cls=field[1];
			}
			else if (field[0].replace('?','')=='cat') {
				cur_cat=field[1];
			}
			else if (field[0].replace('?','')=='scat') {
				cur_scat=field[1];
			}
		}
	}

	cls=get_nodes('//p');
	alert(cls.length);
	for (var i=0; i<cls.length; i++) {
		cls_id=cls[i].getAttribute('pi');
		cls_desc=cls[i].getAttribute('pd');
		nav+=
			'<span id='+cls_id+'>'+
			'<b><a class="body" href="javascript:show_hide_cls(\'cls_'+cls_id+'\');">'+
			cls_desc+
			'</a></b></span><br>'+
			'<div class="navClass" id=cls_'+cls_id+' style="display:'+((cur_cls==cls_id)?'block':'none')+';"></div>';
		/*nav+=
			'<span id='+cls_id+'>'+
			'<b><a class="body" href="javascript:show_hide_cls(\'cls_'+cls_id+'\'">'+
			cls_desc+
			'</a></b></span><br>'+
			'<div class="navClass" id=cls_'+cls_id+' style="display:'+(cur_cls==cls_id)?'block':'none'+';"></div>';*/
		/*var cat=cls[i].get_nodes('child::c');
		for (var j=0; i<cat.length; i++) {
			var cat_id=cat[i].getAttribute('ci');
			var cat_desc=cat[i].getAttribute('cd');
			nav+='<a href="products.asp?cls='+cls_id+'&cat='+cat_id+'">'+cat_desc+'</a>'
			var scat=cat[i].get_nodes('child::s');
			for (var k=0; i<scat.length; i++) {
				
			}
		}*/
	}
	/*if (location.search.length>0) {
		cat=get_nodes('//p[@pi='+cur_cls+']/c');
		for (var i=0; i<cat.length; i++) {
			cat_id=cat[i].getAttribute('ci');
			cat_desc=cat[i].getAttribute('cd');
			nav+='<a href="products.asp?cls='+cls_id+'&cat='+cat_id+'">'+cat_desc+'</a><br>'

			var cat=cls[i].get_nodes('child::c');
			for (var j=0; i<cat.length; i++) {
				var cat_id=cat[i].getAttribute('ci');
				var cat_desc=cat[i].getAttribute('cd');
				nav+='<a href="products.asp?cls='+cls_id+'&cat='+cat_id+'">'+cat_desc+'</a>'
				var scat=cat[i].get_nodes('child::s');
				for (var k=0; i<scat.length; i++) {
					
				}
			}
		}
	}*/
	document.getElementById('prod_nav').innerHTML=nav;
}
function show_cat() {
	var cls, cat, scat, pg;
	if (location.search.length>0) {
		var qs=location.search;
		var qss=location.search.split('&');
		for (var i=0; i<qss.length; i++) {
			var field=qss[i].split('=');
			if (field[0].replace('?','')=='cls') {
				cls=field[1];
			}
			else if (field[0].replace('?','')=='cat') {
				cat=field[1];
			}
			/*if (field[0]=='cls') {
				cls=field[1];
			}
			else if (field[0]=='cat') {
				cat=field[1];
			}
			else if (field[0]=='scat') {
				scat=field[1];
			}
			else if (field[0]=='pg') {
				pg=field[1];
			}*/
		}
		show_hide_cat(cls+'_'+cat);
	}
}
function show_hide_alternate(element_id) {
	var cur_display=document.getElementById(element_id);
	if (cur_display.style.display=='none') {
		cur_display.style.display='block';
	}
	else {
		cur_display.style.display='none';
	}
	previous_element_id=element_id;
}
function show_hide_stocklist() {
	var listarea=document.getElementById('stocklist');
	var stocklist=document.getElementById('stocklist');
	var specials=document.getElementById('specials');
	if (listarea.style.display=='none') {
		listarea.style.display='block';
		if (!stocklist_loaded) {
			specials.innerHTML='<div class="loadMsg">Please wait while the specials & stocklist load...</div>';
			load_xml('get_specials.asp', 'specials');
			stocklist_loaded=true;
		}
	}
	else {
		listarea.style.display='none';
	}
}
function show_hide_by_prefix(form, prefix) {
	var cur_display;
	for(var i=0; i<form.elements.length; i++)
	{
		if (form.elements[i].id.substr(0,2)==prefix) {
			cur_display=form.elements[i].parentNode;
			if (cur_display.style.display=='block') {
				cur_display.style.display='none';
			}
			else {
				cur_display.style.display='block';
			}
		}
	}
}
function resize_overflow(previous_page) {
	/*if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}*/

	//var toolkit=java.awt.Toolkit.getDefaultToolkit(); //performance takes a hit when loading a java class.
	//var screensize=toolkit.getScreenSize();
	//alert(screensize.height);
	var previous_area;
	var auxIE=0;
	var auxMZ=0;
	//alert(previous_page);
	if (previous_page=='add_frequent' || previous_page=='add_promo') {
		previous_area=document.getElementById(previous_page+'_area');
	}
	else if (previous_page=='shipping') {
		previous_area=document.getElementById('shipping_materials');
	}
	else {
		previous_area=document.getElementById('order_'+previous_page+'_area');
	}
	
	var purOrder=document.getElementById('purOrder');
	
	if (purOrder) {
		//var shellTable=document.getElementById('shellTable');
		//shellTable.style.height="100%";
		
		//var winH = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
		//var winH = (window.innerHeight) ? window.innerHeight : screen.availHeight;
		//alert(screen.availHeight);
		//alert(winH);
		//alert(shellTable.height);
		
		if (window.innerHeight) {
			//works for mozilla; note that mozilla sizes new window in terms of innerwidth and height, whereas IE frame size.
			var winH = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
			//if (previous_area!=null) previous_area.style.height=winH-135-13;
			if (previous_area!=null) previous_area.style.height=winH-135-17-auxMZ;
			//purOrder.style.height=winH-138-17;
			//purOrder.style.height=winH-138-14-auxMZ;
			purOrder.style.height=winH-152-auxMZ;
		}
		else {
			//IE code;
			var winH = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
			if (previous_area!=null) previous_area.style.height=winH-143-auxIE;
			purOrder.style.height=winH-143-auxIE;
			//purOrder.style.height=winH-100-auxIE;
		}
	}
}
function nav_rollover(obj, norm, rover) {
	var objSrc=''+obj.src;
	//alert(objSrc);
	if (objSrc.indexOf(norm)>0) {
		obj.src='static/navigation/'+rover;
	}
	else {
		obj.src='static/navigation/'+norm;
	}
}
function returnValue(value) {
    return(value);
}
