
function refreshMain() {

   if (window.opener) {
      window.opener.location.reload();
   }
}

var newWind;

function popUp(URL,WIDTH,HEIGHT) {

   newWind = window.open(URL,"POPUP","HEIGHT="+HEIGHT+",WIDTH="+WIDTH+",scrollbars=yes,resizable=yes,alwaysraised=yes");

//   if (newWind.opener=null) {
      newWind.opener = window;
//   }

   newWind.moveTo(200,200);

}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

var LOGINWINVAR;
var EDITWINVAR;
var WINS = new Array();

function getLogin(DBNAME) {
   var cookie=getCookie(DBNAME);
   if (cookie) {
      title="Account Information & Settings";
      width=600;
      height=400;
   } else {
      title="Please Login:";
      width=300;
      height=200;
   }
   //alert("starting login win with dbname=" + DBNAME);
   LOGINWINVAR = dhtmlmodal.open('LOGINWIN','iframe','/cgi-bin/login.pl?DBNAME='+DBNAME,title,'width='+width+'px,height='+height+'px,center=1,resize=0,scrolling=0','recal');
   //LOGINWINVAR.moveTo('middle','middle');
   LOGINWINVAR.onclose=function() {location.reload();return true;}

}

function editWin(URL) {
   //alert("starting login win with dbname=" + DBNAME);
   EDITWINVAR = dhtmlwindow.open('EDITWIN','iframe',URL,'WMS Editor:','width=800px,height=600px,center=1,resize=0,scrolling=0','recal');
   EDITWINVAR.moveTo('middle','middle');
   EDITWINVAR.onclose=function() {location.reload();return true;}

}

function showHide(URL,ID) {
   //alert("Showing " + URL + "in element "+ID);
   if (document.getElementById(ID).innerHTML == "") {
      document.getElementById(ID).style.display = "block";
      makeRequest(URL,ID)
   } else {
      document.getElementById(ID).innerHTML="";
      document.getElementById(ID).style.display = "none";
   }
}

function getPicID(DBNAME,ID) {
   //alert("DBNAME " + DBNAME + " and ID" + ID);

   var imgid = dhtmlmodal.open('GetPIC','iframe','/wms/wmsimgid&COND=customer.schema='+DBNAME,'Select Image:','width=640px,height=480px,center=1,resize=1,scrolling=1','recal');
   imgid.moveTo('middle','middle');
   imgid.onclose=function(){
      var imagePath;
      imagePath=this.contentDoc.getElementById('returnHTML').innerHTML;
      //alert("picid = "+ imagePath);
      id(ID).value = imagePath; 
      id(ID+"_pic").src = "/PIC-SIZE/"+imagePath+"-90.jpg"; 
      return true;
   };
}

function openWin(URL,ID,NAME,SIZE,RELOAD) {
   //var WINS = new Array();
   
   if (SIZE > 0 && SIZE <= 100) {
      var Width = document.body.clientWidth* SIZE /100;
      var Height = document.body.clientHeight * SIZE / 100;
   } else {
      var sizes = SIZE.split("x");
      //alert("WIDTH="+sizes[0]+" HEIGHT="+sizes[1]);
      var Width = sizes[0];
      var Height = sizes[1];
   }
   //alert("Opening " + URL + "ID("+ID+") Name:"+ NAME + "Size: " + SIZE + "DIM:" + Width + "x" + Height);

   if (RELOAD == "reload") {
      WINS[ID] = dhtmlwindow.open('TOOL'+ID,'iframe',URL,NAME,'width='+Width+'px,height='+Height+'px,center=1,resize=1,scrolling=1','recal');
      WINS[ID].moveTo('middle','middle');
      WINS[ID].onclose=function(){
         //alert ("closing " + WINS[ID]);
         document.location.reload();
         return true;
      };
   } else {
      WINS[ID] = dhtmlwindow.open('TOOL'+ID,'iframe',URL,NAME,'width='+Width+'px,height='+Height+'px,center=1,resize=1,scrolling=1','recal');
      WINS[ID].moveTo('middle','middle');
   }
}

function id (id) {
   return document.getElementById(id);
}

function $ (id) {
   return document.getElementById(id);
}
/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
*/

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};



// Read a page's GET URL variables and return them as an associative array.
function getUrlVars() {
   var vars = [], hash;
   var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

   for(var i = 0; i < hashes.length; i++) {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
     
   }
   return vars;
}


