iens6=document.all||document.getElementById
ie=document.all
dom=document.getElementById
ns4=document.layers

vars = new Object();

function parseQueryString (str) {
  str = str ? str : location.search;
  var query = str.charAt(0) == '?' ? str.substring(1) : str;
  var args = new Object();
  if (query) {
    var fields = query.split('&');
    for (var f = 0; f < fields.length; f++) {
      var field = fields[f].split('=');
      args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
    }
  }
  return args;
}

function spawn(model) {
	var width = 640;
	var height = 480;
	var features = "menubar,resizable,width=" + width + ",height=" + height;
	var url = "/media/?model=" + model;
	var name = "photo";
	
	window.open(url, name, features);
	return false;
}

function getImgTag() {
	var query = parseQueryString();
	var model = query.model ? query.model : "default"
	return '<img src="/media/' + model + '">';
}


if (navigator.userAgent.indexOf("Opera")!=-1
    && document.getElementById) type="OP"; 
if (document.all) type="IE"; 
if (document.layers) type="NN"; 
if (!document.all && document.getElementById) type="MO";


function showHide(showID, category)
{
	if(vars[category] && vars[category]!=null)
	{
		if(showID==vars[category])
			return;
		
		if(category!=null)
		{
			var hide = getObject(vars[category]);
			hide.display = "none";
		}
	}
	
	if(showID)
	{
		var show = getObject(showID);
		show.display = "block";
		vars[category] = showID;
	} else
		delete vars[category];
}

function ChangeContent(id, str) {
  if (type=="IE") {
    document.all[id].innerHTML = str;
  }
  if (type=="NN") {
    document.layers[id].document.open();
    document.layers[id].document.write(str);
    document.layers[id].document.close();
  }
  if (type=="MO") {
    document.getElementById(id).innerHTML = str;
  }
}

function SwapContent(divFrom, divTo) {
  if (type=="IE") {
    swapString = document.all[divFrom].innerHTML;
  }
  if (type=="MO") {
    swapString = document.getElementById(id).innerHTML;
  }
  
  ChangeContent(divTo, swapString);
}

function getObject(lid, nostyle)
{
	if(dom)
		return (nostyle ? document.getElementById(lid) : document.getElementById(lid).style)
	else if(ie) 
		return document.all.lid;
	else
		return document.lid;
}

function showpic(theUrl, imgW, imgH)
{
	   w = screen.width;
	
	var leftPos = (w-imgW)/2;
	
	window.open(theUrl + '&w='+imgW+'&h='+imgH,'showpic','width=' + (imgW+20) + ',height=' + ((imgH<470 ? imgH : 500) - 20) + ',top=50,left=' + leftPos + ',scrollbars=no,location=no,directories=no,status=no,menubar=yes,toolbar=no,resizable=no');
}
