function old$() {
	var element = arguments[0];
	if(element) {
		if (document.getElementById && document.getElementById(arguments[0])) {
			return document.getElementById(arguments[0]);
		}
		if(document.getElementsByName && document.getElementsByName(arguments[0])) {
			return document.getElementsByName(arguments[0]);
		}
		if (document.all && document.all[arguments[0]]) {
			return document.all[arguments[0]];
		}
		
		if (document.layers && document.layers[arguments[0]]) {
			return document.layers[arguments[0]];
		}
	}
	return null;
}

/*
function $() {
	var element = arguments[0];
	if(element) {
		if (document.getElementById && document.getElementById(arguments[0])) {
			return document.getElementById(arguments[0]);
		}
		if(document.getElementsByName && document.getElementsByName(arguments[0])) {
			return document.getElementsByName(arguments[0]);
		}
		if (document.all && document.all[arguments[0]]) {
			return document.all[arguments[0]];
		}
		
		if (document.layers && document.layers[arguments[0]]) {
			return document.layers[arguments[0]];
		}
	}
	return null;
}



*/
function getInputByName(form, name) {
    var inputs = form.getElementsByTagName('input');

    if (!name)
      return null;

    var matchingInputs = new Array();
    for (var i = 0; i < inputs.length; i++) {
      var input = inputs[i];
      if (name && input.name != name)
        continue;
      return input;
    }

    return null;
  }



function PostSecure(addr) {
	document.index.action = addr;
	return true;
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	//this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	//this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	//this.style = document.layers[name];
  }
}

function ShowWindow(path, windowOptions) {
	window.open(path, '', windowOptions);
	return false;
}

function ShowWindow2(path, windowOptions) {
	window.open(path, '', windowOptions);
}

function AddToCart(path,prodid,ref,action) {
	var newPath = (path + '/upc=' + prodid + '/ref=' + ref + '/');
	if(action != "undefined" && action != null && action.length > 0) {
		newPath += ("action=" + action);
	}
	if(prodid == "undefined" || prodid == null || prodid == 0) {
		alert("Choose an option for this product.");
		return false;
	}
	document.location = newPath;
}

function openWhatIsThis() {
	var path = arguments[0];
	var width = "300";
	var height = "200";
	if(arguments[1]) {
		width = arguments[1];
	}
	if(arguments[2]) {
		height = arguments[2];
	}
	/*
	var ns = false;
	var screenX;
	var screenY;
	if(navigator.appName == "Microsoft Internet Explorer") {
		screenX = window.screen.availWidth;
		screenY = document.body.offsetHeight;
	} else {
		screenX = window.screenY;
		screenY = window.screenX;
	}
	if(ns) {
		position = (",screenX=" + (document.screenX + 100) + ",screenY=" + (document.screenY + 100));
	} else {
		position = (",left=" + (document.left + 100) + ",top=" + (document.top + 100));
	}
	*/
	window.open(path,'','height=' + height + ',width=' + width + ',scrollbars=1,resizable=1');
	return false;
}

function selectCompactItems(itemarray, allarray) {
	var i; var item;
	if(allarray != "undefined" && allarray != null) {
		for(i = 0; i < allarray.length; i++) {
			eval("item = document.index." + allarray[i]);
			if(item != "undefined" && item != null) {
				item.checked = false
			}
		}
	}
	
	if(itemarray != "undefined" && itemarray != null) {
		for(i = 0; i < itemarray.length; i++) {
			eval("item = document.index." + itemarray[i]);
			if(item != "undefined" && item != null) {
				item.checked = true
			}
		}
	}
	return false;
}

function postCompactView(itemCount,path) {
	var selected = document.index.compact_list;
	if(selected) {
		for(i = 0; i < itemCount; i++) {
			var item = new getObj('check_' + i);
			if(item.obj) {
				if(item.obj.checked) {
					selected.value += (item.obj.value + ",");
				}
			}
		}
		var theForm = document.forms[0];
		if(theForm) {
			theForm.method = 'post';
			theForm.action = path;
			theForm.submit();
		}
	}
	return false;
}

function toggle(divID,obj) {
	var div = old$(divID);
	if(!div) {
		return;
	}
	if(div.style.display == "none") {
		//obj.innerText = "-";
		div.style.display = "";
	} else {
		//obj.innerText = "+";
		div.style.display = "none";
	}
	
	return false;
}
