var PopupParams = 
[
  {
  id:'show-animal',
  width:850, 
  height:900,
  winid:null
  },
  {
  id:'private-documents',
  width:850, // need to be at least 850 for filethingee
  height:900,
  winid:null
  },
  // default:
  {
  id:'',
  width:850, 
  height:600,
  winid:null
  }
];

function getPopupParamsIndex(id)
{
  var ix;
  var params = null;
  for (ix = 0; ix<PopupParams.length; ix++)
  {
    params = PopupParams[ix];
    if (id == params.id) return ix;
    if (!params.id) return ix; // default
  }
  return -1;
}

var WindowName = 'care-window';
var WindowId = null;

function popupWindowOpen(id,source,title,force_flag)
{
  var force = false;

  if (arguments.length > 3) 
  {
    force = force_flag; // popup can popup another window
  }

  if (PageIsWindow())
  {
    parent.popupWindowOpen(id,source,title,force);
	return;
  }
  
  var winid = WindowId;
  var winname = WindowName;
  var center = 1;
  if (force) 
  {
    winid = null; // force new window
	winname = title;
	center=0;
  }

  var ix = getPopupParamsIndex(id);
  if (ix < 0) return;
  var width= PopupParams[ix].width;
  var height =  PopupParams[ix].height;
  if (winid != null)
  {
    winid.style.display="none";
  }
  winid =
    dhtmlwindow.open(winname, 'iframe', source, title, 
      'width='+width+'px,height='+height+'px,center='+center+',resize=1,scrolling=1');
  if (!force) 
  {
    WindowId  = winid;
  }
}

function popupWindowClose(id)
{
  if (PAGE_ID.indexOf("top") != 0)
  {
    parent.popupWindowClose(id);
	return;
  }
  if (WindowId != null)
  {
//alert("close: " + WindowId);
    WindowId.style.display="none";
  }
}

function popupWindowResize(id,width,height)
{
  if (PAGE_ID.indexOf("top") != 0)
  {
    parent.popupWindowResize(id,width,height);
	return;
  }
  if (WindowId != null)
  {
//alert("resize 1: " + WindowId);
//alert("resize 2: " + WindowId.style.width);  
//alert("resize 3: " + WindowId.contentarea.style.height);  
//    WindowId.style.height=height+"px";
    WindowId.style.width=width+"px";
    WindowId.contentarea.style.height=height+"px";
//alert("resize 4: " + WindowId.style.height);  
  }
}

function popupShowAnimal(id,name)
{
  popupWindowOpen('show-animal', '/showanimal.php?Id='+id, name);
}

function closeShowAnimal()
{
  popupWindowClose('show-animal');
}

function popupShowDonate(id,name)
{
  popupWindowOpen('show-donate', '/showdonate.php?Id='+id, name);
}

function closeShowDonate()
{
  popupWindowClose('show-donate');
}

//function popupPrivateDocuments()
//{
////  popupWindowOpen('private-documents', '/private_docs.php', 'Manage Private Documents');
//  popupWindowOpen('private-documents', '/private/ft2.php', 'Manage Private Documents');
//}
//
//function closePrivateDocuments()
//{
//  popupWindowClose('private-documents');
//}

function popupViewImage(path)
{
  popupWindowOpen('view-image', '/view_image.php?Path='+escape(path), 'View Image');
}

function closeViewImage()
{
  popupWindowClose('view-image');
}

function popupAdoptionForm(shelterid,id,type,number)
{
  if (!id) var id=0;
  if (!type) var type='';
  if (!number) var number=0;
  popupWindowOpen('adoption-form', '/adoptform.php?Shelter='+escape(shelterid)+'&Id='+escape(id)+'&Type='+escape(type)+'&Number='+escape(number), 'Adoption Form');
}

function closeAdoptionForm()
{
  popupWindowClose('adoption-form');
}

function popupAdoptionAgree(shelterid,id,type,number)
{
  popupWindowOpen('adoption-agree', '/adoptformagree.php?Shelter='+escape(shelterid)+'&Id='+escape(id)+'&Type='+escape(type)+'&Number='+escape(number), 'Adoption Agreement');
}

function closeAdoptionAgree()
{
  popupWindowClose('adoption-agree');
}

//function popupEmailForm()
//{
//  popupWindowOpen('adoption-agree', '/adoptformagree.php?Shelter='+escape(shelterid)+'&Id='+escape(id)+'&Type='+escape(type)+'&Number='+escape(number), 'Adoption Agreement');
//}

function popupShowHappyEnding(id,title)
{
  popupWindowOpen('show-happyending', '/showhappyending.php?Id='+id, title);
}

function popupEditAnimal(key,operation,shelter,type)
{
  popupWindowOpen('edit-animal', '/editanimal.php?Key='+key+'&Operation='+operation+'&Shelter='+shelter+'&Type='+type, 'Edit Animal');
}

function popupEditLink(key,operation)
{
  popupWindowOpen('edit-link', '/editlink.php?Key='+key+'&Operation='+operation, 'Edit Link');
}

function popupEditHappyEnding(key,operation)
{
  popupWindowOpen('edit-happyending', '/edithappyending.php?Key='+key+'&Operation='+operation, 'Edit Happy Ending');
}

function popupEditDonate(key,operation)
{
  popupWindowOpen('edit-donate', '/editdonate.php?Key='+key+'&Operation='+operation, 'Edit Donation');
}

function popupEditEvent(key,operation)
{
  popupWindowOpen('edit-event', '/editevent.php?Key='+key+'&Operation='+operation, 'Edit Event');
}

function popupEditLocation(key,operation)
{
  popupWindowOpen('edit-location', '/editlocation.php?Key='+key+'&Operation='+operation, 'Edit Location');
}

function popupEditContact(key,operation)
{
  popupWindowOpen('edit-contact', '/editcontact.php?Key='+key+'&Operation='+operation, 'Edit Contact');
}

function popupEditFaq(key,operation)
{
  popupWindowOpen('edit-faq', '/editfaq.php?Key='+key+'&Operation='+operation, 'Edit FAQ');
}

function popupShowBackgrounds()
{
  popupWindowOpen('show-backgrounds', '/showbackgrounds.php', 'Show Backgrounds', true);
}

function popupImage(url,name)
{
  popupWindowOpen('image', url, name);
}

function closeImage()
{
  popupWindowClose('image');
}

function popupPrivateDocuments()
{
  popupWindowOpen('private-documents', '/private/ft2x.php', 'Private Documents');
}

function popupTextFile(url)
{
  popupWindowOpen('text-file', url, 'Text File');
}

function popupEditPassword()
{
  popupWindowOpen('edit-password', '/editpassword.php', 'Edit Password');
}


