function swapInnerHTML(myLayer, myData){
	el = document.getElementById(myLayer);
	el.innerHTML = myData;
}

function swapInput(myInput, myString){
	el = document.getElementById(myInput);
	el.value = myString;
}

var myWidth = 0, myHeight = 0;

//Non-IE
if( typeof( window.innerWidth ) == 'number' ) {
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
//IE 6+ in 'standards compliant mode'
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
//IE 4 compatible
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
}

// load content based on list box selection
function selectItem(item_id){
	//var elm = document.getElementById(faq_id); 
	//elm.className = 'selected_item'; 
	var url = 'content.php?id='+item_id;
	javaTechLoader(url, 'contentLyr', item_id);
}

function goToAnchor(pageAnchor){
	window.location.hash = '#'+pageAnchor;
}

// move cursor to specific form field
function putFocus(formInst, elementInst) {
	if (document.forms.length > 0) {
		document.forms[formInst].elements[elementInst].focus();
	}
}

// detect enter button press inside form text input fields, to prevent posting form!
function submitEnter(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13){
		// add product to cart
		add_product_to_cart();
		return false;
	}
	else
		return true;
}

// only allow integers 0-9 in form input fields!
function isNumericKey(e){
	var k = document.all ? e.keyCode : e.which;
	return ((k > 47 && k < 58) || k == 8 || k == 0);
}

function extractNumeric(str){
	return str.replace(/\D/g,"");
}

function limitInteger(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode < 46 || keycode > 57 || keycode == 191 || keycode == 190) {
		window.event.keyCode = 0;
		return true;
	}
	else
		return true;
}

// dynamic content loader
function javaLoader(url,id) {
	// show loading message
	initLoading_msg();
		if (document.getElementById) {
			var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		}
		if (x) {
			x.onreadystatechange = function() {
				if (x.readyState == 4 && x.status == 200) {
					el = document.getElementById(id);
					el.innerHTML = x.responseText;
					// hide loading message
					setTimeout('hideLoading_msg()', 800);
				}
		}
		x.open("GET", url, true);
		x.send(null);
	}
}

// toggle between two div layers
var currLayerId = "Layer1"; 

function togLayer(id) { 
	if(currLayerId){
		setDisplay(currLayerId, "none");
	}
	if(id){
		setDisplay(id, "block");
	}
	currLayerId = id; 
} 

function setDisplay(id,value) { 
	var elm = document.getElementById(id); 
	elm.style.display = value; 
}

// toggle any div layer between hidden & visable
function toggleObj(id){
	var elm = document.getElementById(id); 
	if(elm.style.display = 'none'){
		setDisplay(id, 'block');
	} else if(elm.style.display = 'block'){
		setDisplay(id, 'none');
	}
}

// show div layer
function showObj(myObject){
	setDisplay(myObject,"block");
}

// hide div layer
function hideObj(myObject){
	setDisplay(myObject,"none");
}

// popup window
function popUp(URL, pageWidth, pageHeight) {
	//day = new Date();
	//id = day.getTime();
	//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=" + pageWidth + ", height=" + pageHeight + ", left = 50, top = 50');");
	window.open(URL, 'popUpWindow', 'width=' + pageWidth + ', height=' + pageHeight + ', scrollbars=no');
}

function showLogin(){
	dd.elements.loginForm.show();
	javaXLoader('/forms/login_lite.php','loginForm');
	winX = (document.body.offsetWidth / 2) - 80;
	obj = dd.elements['loginForm'];
	obj.moveTo(winX,300);
}

function showChart(){
	obj = dd.elements['popupLayer'];
	winX = document.body.offsetWidth / 2;
	//winY = (document.body.offsetHeight / 2) - 60;
	dd.elements.popupLayer.show();
	obj.moveTo(winX,200);
}

function showhide(layerID, mode){
		var currentRef = document.getElementById(layerID).style
		//Display modes 1 for on 0 for off
		modes = new Array
		modes[0] = 'none'
		modes[1] = 'block'
	if(isNaN(mode))
		currentRef.display = (currentRef.display == 'none') ? 'block' : 'none'
	else
		currentRef.display = modes[mode]
}

function initLoading_msg(){
	showObj('maskLayer');
	obj = dd.elements['loading_msg'];
	winX = (document.body.offsetWidth / 2) - 50;
	winY = (document.body.offsetHeight / 2) - 25;
	dd.elements.loading_msg.show();
	obj.moveTo(winX,winY);
}

function hideLoading_msg(){
	hideObj('maskLayer');
	dd.elements.loading_msg.hide();
}

function expandDiv(myObject) {
	var elm = document.getElementById(myObject);
	elm.style.height = "600px";
	showObj('layer2');
	hideObj('layer1');
}

function collapseDiv(myObject) {
	var elm = document.getElementById(myObject);
	elm.style.height = "190px";
	showObj('layer1');
	hideObj('layer2');
}