<!--
var detect = navigator.userAgent.toLowerCase();
var OS,browser,total,thestring;
var version = 0;

if (checkIt('konqueror'))
{
   browser = "Konqueror";
   OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (checkIt('firefox')) browser = "Firefox"
else if (checkIt('netscape')) browser = "Netscape Navigator"
else if (!checkIt('compatible'))
{
   browser = "Mozilla"
   version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
   if (checkIt('linux')) OS = "Linux";
   else if (checkIt('x11')) OS = "Unix";
   else if (checkIt('mac')) OS = "Mac"
   else if (checkIt('win')) OS = "Windows"
   else OS = "an unknown operating system";
}

function checkIt(string)
{
   place = detect.indexOf(string) + 1;
   thestring = string;
   return place;
}
// Esta es la funcion que va a abrir la ventana, solamente recibe como parametro el nombre del html
// Hay que cambiar el ancho de la ventana dependiendo el tipo de navegador
// 763,749,767,766,765,770,766,766
function LB_open(theURL,scr,alto,saf,iem,iew,nnm,nnw,fir,moz,oth) {
   var nav = browser + ' ' + OS;
   switch (nav)
   {
      case 'Safari Mac':
        var anc = saf;
         break
      case 'Internet Explorer Mac':
        var anc = iem;
         break
      case 'Internet Explorer Windows':
        var anc = iew;
         break
      case 'Netscape Navigator Mac':
        var anc = nnm;
         break
      case 'Netscape Navigator Windows':
        var anc = nnw;
         break
      case 'Firefox Windows':
        var anc = fir;
         break
      case 'Mozilla Windows':
        var anc = moz;
         break
      default:
        var anc = oth;
         break
   }
   var winName = "popdown";
   var features = "scrollbars="+ scr + ",width=" + anc + ",height=" +alto;
   return window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i] && a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


/**
*  Switch to a different lightbox.
*/
function lightboxChange() 
{
   if (document.formu.lightbox.value == "A") 
   {
      //LB_open('pop_addnewlbjs.php','no',150,398,400,400,400,400,400,400,400);
      LB_open('pop_addnewlb.php','yes',250,398,400,400,400,400,400,400,400);
   }
   
   if (document.formu.lightbox.value == "F") 
   {
      //LB_open('pop_addnewlbjs.php','no',150,398,400,400,400,400,400,400,400);
      LB_open('pop_addnewlb.php?feedbox=1','yes',250,398,400,400,400,400,400,400,400);
   }

   if (document.formu.lightbox.value == "s") 
   {
      document.formu.lightbox.options[0].selected = true;
   }

   if (document.formu.lightbox.value != "s" && document.formu.lightbox.value != "A") 
   {
      document.formu.accion.value ="changeLightbox";

      if (document.formu.page1)
      {
         var page1 = document.formu.page1.value;

         document.formu.action = document.formu.action + "?page=" + page1; 
      }
      document.formu.submit();
   }
}

function searchboxChange() {

  if (document.formu.searchbox.value == "s") {
    document.formu.searchbox.options[0].selected = true;
  }
  if (document.formu.searchbox.value != "s" && document.formu.searchbox.value != "A") {
    document.formu.accion.value ="changeSearchbox";
    document.formu.submit();
  }
}

function compareSels() {
  document.formu.action = "compareimagesLB.php";
  document.formu.submit();
}

function manageLB() {
  document.formu.action = "managelb.php";
  document.formu.submit();
}

function delLightbox(id) {
  if (checkSelected())
  {
    document.formu.accion.value = "delLightbox";
    window.open('pop_confirmdel.php?lightbox=' + id,
      '_blank',
      'scrollbars=yes,height=300,width=450');
  }
}

function delLightboxOne(id, confirm) {
  document.formu.accion.value = "delLightboxOne";
  document.formu.id.value = id;
  if(confirm != false)
  {
     LB_open('pop_confirm.php?id='+escape('You will delete this image from this Lightbox. Are you sure?'),'no',150,398,400,400,400,400,400,400,400);
  }
  else
  {
     document.formu.submit();
  }
}

function delEntireLightbox(id)
{
   document.getElementById('accion').value = "delete";
   document.getElementById('deleteId').value = id;
   LB_open('pop_confirm.php?id='+escape('You are about to delete this Lightbox. Are you sure?'),'no',150,398,400,400,400,400,400,400,400);
}

function clearLB(id) {
  document.formu.accion.value = "clearLB";
  document.formu.id.value = id;
  LB_open('pop_confirm.php?id='+escape('You will delete all images on Lightbox Are you sure?'),'no',150,398,400,400,400,400,400,400,400);
}

function saveToLB(id) {
  if (checkSelected())
  {
    LB_open('pop_copymoveLB.php?id='+id,'yes',360,398,400,400,400,400,400,400,400);
  }
}

function saveToLBV2(id, projectId) 
{
  if (checkSelected())
  {
    var url = 'pop_copymoveLB.php?id='+id+'&projectId=' + projectId;
    LB_open(url,'yes',360,398,400,400,400,400,400,400,400);
  }
}

function viewSels() {
  if (checkSelected())
  {
    document.formu.action = "lightbox.php";
    document.formu.accion.value = "";
    document.formu.flagOpt.value = "selected";
    document.formu.submit();
  }
}

function viewSelsT() {
  if (checkSelected())
  {
    document.formu.action = "setup.php";
    document.formu.accion.value = "";
    document.formu.flagOpt.value = "selected";
    document.formu.submit();
  }
}

function compareSels(isDpl) {
  if (checkSelected())
  {
    if(isDpl)
      document.formu.action = "dplCompareImagesLB.php";
    else
      document.formu.action = "compareimagesLB.php";
    
    document.formu.submit();
  }
}

function compareSelsT(isDpl) {
  if (checkSelected())
  {
    if(isDpl)
      document.formu.action = "dplCompareImages.php";
    else
      document.formu.action = "compareimages.php";
    document.formu.submit();
  }
}

function manageLB() {
  document.formu.action = "managelb.php";
  document.formu.submit();
}

function removeOne(id, isReferencedByOrder) {
  document.formu.accion.value = "removeOne";
  document.formu.id.value = id;
  if (isReferencedByOrder == 1)
    LB_open('pop_confirm.php?id='+escape('Deleting this image will remove it forever. This image is also included in one or more orders. Do you want to continue?'),'no',150,398,400,400,400,400,400,400,400);
  else
    LB_open('pop_confirm.php?id='+escape('Deleting this image will remove it forever. Do you want to continue?'),'no',150,398,400,400,400,400,400,400,400);
}

function addLightbox() {
  document.formu.accion.value = "addLightbox";
  document.formu.submit();
}

function addLightboxOne(id) {
  document.formu.accion.value = "addLightboxOne";
  document.formu.id.value = id;
  document.formu.submit();
}
function addToLightbox(fileId, lightboxId)
{
  document.formu.accion.value = "addToLightbox";
  document.formu.id.value = fileId + "_" + lightboxId;
  document.formu.submit();
}
function removeFromLightbox(fileId, lightboxId)
{
  document.formu.accion.value = "removeFromLightbox";
  document.formu.id.value = fileId + "_" + lightboxId;
  document.formu.submit();
}
function delLB(lb) {
  document.formu.accion.value = "deleteLightbox";
  document.formu.id.value = lb;
  LB_open('pop_confirm.php?id='+escape("Click SUBMIT to continue with deletion."),'no',150,398,400,400,400,400,400,400,400);
}

function makeFirst(fileId, lightboxId)
{
  document.formu.accion.value = "makeFirst";
  document.formu.id.value = fileId;
  document.formu.submit();
}

function goTo(dest,acc) {
  document.formu.action = dest;
  document.formu.accion.value = acc;
  document.formu.submit();
}

function goToID(dest,acc,id) {
  document.formu.action = dest;
  document.formu.accion.value = acc;
  document.formu.id.value = id;
  document.formu.submit();
}

function goToIDS(dest,acc,ids) {
  document.formu.action = dest;
  document.formu.accion.value = acc;
  document.formu.ids.value = ids;
  document.formu.submit();
}

function download(position, container, ids) {
  var counter = 0;
  var idsString = '';
  // selecteds
  if (ids == 'sels')
  {
    counter = countSelected();
    idsString = 'sels';
  }
  else if (ids == 'all')
  {
    counter = 1;
    idsString = 'all';
  }
  else
  {
    idsString = 'ck' + ids  + '|';
    counter = 1;
  }

  if (counter > 0)
  {
    uri = '/pop_downloadimg.php?position=' + position + '&container=' + container + '&ids=' + idsString;
    MM_openBrWindow(uri,'','scrollbars=yes,width=756,height=580,top=0,left=0')
  }

  if (counter <= 0)
  {
    if (arguments.length == 5 && arguments[3] == 'java')
    {
      var defaultHeight = 340;   
      var appletWidth = 570;
      
      var nav = browser + ' ' + OS;
   	  switch (nav)
      {
        case 'Safari Mac':
          var appletHeight = defaultHeight;
          break
        case 'Internet Explorer Mac':
          var appletHeight = defaultHeight;
          break
        case 'Internet Explorer Windows':
          var appletHeight = 410;
          break
        case 'Netscape Navigator Mac':
          var appletHeight = defaultHeight;
          break
        case 'Netscape Navigator Windows':
          var appletHeight = defaultHeight;
          break
        case 'Firefox Windows':
          var appletHeight = defaultHeight;
          break
        case 'Mozilla Windows':
          var appletHeight = defaultHeight;
          break
        default:
          var appletHeight = defaultHeight;
          break
      }
   
      var winName = "popdown";
      var features = "scrollbars=no,width=" + appletWidth + ",height=" + appletHeight;
      return window.open('download/startDownload2.php?path_prefix='+arguments[4],winName,features);
    }
    else
    {
      LB_open('pop_alert.php?id='+escape('Please select an image to download'),'no',150,398,400,400,400,400,400,400,400);
    }
  }
}

function selectAll() {
  tot = document.formu.elements.length;
  for (i = 0; i < tot; i++) {
    if(document.formu.elements[i].type == 'checkbox' &&
     'ck' == document.formu.elements[i].name.substring(0, 2))
    {
      document.formu.elements[i].checked = true;
    }
  }
}

function deselectAll() {
  tot = document.formu.elements.length;
  for (i = 0; i < tot; i++) {
    if(document.formu.elements[i].type == 'checkbox' &&
     'ck' == document.formu.elements[i].name.substring(0, 2))
    {
      document.formu.elements[i].checked = false;
    }
  }
}

function allChanged() {
  if (document.formu.allCheck.checked == false) {
    deselectAll();
  }
  else {
    selectAll();
  }
  return true;
}

function viewFullScreen(position, container, id) {
 uri = 'pop_fullsize.php?position=' + position + '&container=' + container + '&id=' + id;
 MM_openBrWindow(uri,'','scrollbars=yes,top=0,left=0,resizable=yes');
}

function rtrim(strMyString) {
    return strMyString.replace(/^\s*/,"");
}

function ltrim(strMyString) {
    return strMyString.replace(/\s*$/, "");
}

function trim(strMyString) {
    return ltrim(rtrim(strMyString));
}

function onSend(position, container, ids)
{
  var counter = 0;
  var idsString = '';
  // selecteds
  if (ids == 'sels') {
    counter = countSelected();
    idsString = 'sels';
  }
  else {
    idsString = 'ck' + ids  + '|';
    counter = 1;
  }
  if (counter > 0)
    MM_openBrWindow('pop_send.php?position='+position+'&container='+container+'&ids='+idsString,'_send','scrollbars=yes,resizable=yes,width=800,height=690');
  else
    LB_open('pop_alert.php?id='+escape('Please select an image to send'),'no',150,398,400,400,400,400,400,400,400);
}

function onRetouch(position, container, ids, readonly)
{
  var idsString = '';
  // selecteds
  if (ids == 'sels') {
    alert('You cannot view Retouch Notes for more than one image at a time.');
  }
  else {
    idsString = 'ck' + ids  + '|';
  }
  
  MM_openBrWindow('pop_retouchz.php?position='+position+'&container='+container+'&ids='+idsString+'&readonly='+readonly,
   '_send','scrollbars=yes,resizable=yes,width=800,height=860');
}

function onLiveEdit(position, container, ids, readonly)
{
  var idsString = '';
  // selecteds
  if (ids == 'sels') {
    alert('You cannot perform Live Edit for more than one image at a time.');
  }
  else {
    idsString = 'ck' + ids  + '|';
  }
  MM_openBrWindow('pop_liveedit.php?position='+position+'&container='+container+'&ids='+idsString+'&readonly='+readonly,
   '_send','scrollbars=yes,resizable=yes,width=800,height=860');
}

function slideshow(setupId)
{
  window.open('slideshow.php?setup=' + setupId, '_blank',
    'width=750,height=650,scrollbars=yes,resizable=yes,location=no,menubar=no,toolbar=no,status=yes');
}

function onMetadata(position, container, id, isDpl)
{
  uri = (isDpl == null ? 'metadata.php' : 'dplMetadata.php') + '?position=' + position + '&container=' + container + '&i=' + id;
  window.location.href = uri;
}

function changeBgColor(elem, isSelected, isKilled)
{
  if (elem)
    elem.bgColor = isSelected? '#C9C9C9': (isKilled? '#EFEFCB': '');
}

function changeSelected(elem, isSelected, isKilled)
{
   if (elem)
   {
      if(isSelected)
         elem.style.borderTop = '3px solid #019DE7';
      else
         elem.style.borderTopWidth = '0px';
   }
}

function checkSelected( cancelErrorPopup )
{
  var selects = countSelected();
  if (0 == selects && cancelErrorPopup != 'true')
  {
    LB_open('pop_alert.php?id=' + escape('There are no files selected'),'no',150,398,400,400,400,400,400,400,400);
  }
  else if (0 == selects && cancelErrorPopup == 'true')
  {
     return 0;
  }

  return selects > 0;
}

//function singleSelectedFileName()
//{
//   if (countSelected() == 1)
//   {
//      var elementValue = null;
//      var tot = document.formu.elements.length;
//      for (var i = 0; i < tot; ++i)
//      {
//         if(document.formu.elements[i].type == 'checkbox' &&
//            'ck' == document.formu.elements[i].name.substring(0, 2))
//         {
//            if (document.formu.elements[i].checked == true)
//            {
//               elementValue = document.formu.elements[i].name;
//            }
//         }
//      }
//      for (var i = 0; i < tot; ++i)
//      {
//         if(elementValue != null &&
//            document.formu.elements[i].type == 'hidden' &&
//            elementValue == document.formu.elements[i].value)
//         {
//            var filename = document.formu.elements[i].name;
//            return filename;
//         }
//      }
//   }
//
//   return "";
//}

function renameImage()
{
   document.formu.accion.value ="renameSingleImage";
   document.formu.submit();
}

var allSelects = 0;  // count of selections
var idSelect = '';   // if exactly one is selected, this is the id
var nameSelect = ''; // if exactly one is selected, this is the name

function countSelected()
{
  var pageSelects = 0;

  var tot = document.formu.elements.length;
  for (var i = 0; i < tot; ++i)
  {
    if(document.formu.elements[i].type == 'checkbox' &&
      'ck' == document.formu.elements[i].name.substring(0, 2))
    {
      if (document.formu.elements[i].checked == true)
      {
        ++pageSelects;
      }
    }
  }

  // even if the async select fails to return a value, we should get at least a count
  //  of selects on the current page
  return Math.max(pageSelects, allSelects);
}

// update the count from the async callback
function setSelectCount(ct)
{
   allSelects = ct;
}

// update the single select from the async callback
function setSelection(id, name)
{
   idSelect = id;
   nameSelect = name;
}

function getSelectId()
{
   return idSelect;
}

function getSelectName(stripExtension)
{
   if (stripExtension && nameSelect.lastIndexOf('.') != -1)
   {
      return nameSelect.substring(0, nameSelect.lastIndexOf('.'));
   }
   return nameSelect;
}

function getKey(e)
{
   if (navigator.appName=="Netscape" || navigator.appName=="Mozilla")
      return e.which;
   else
      return e.keyCode;
}

function onOrderPrint(position, container, ids, product)
{
  var idsString = '';
  // selecteds
  if (ids == 'sels') {
    alert('You cannot order a print for more than one image at a time.');
  }
  else {
    idsString = 'ck' + ids  + '|';
  }
  MM_openBrWindow('pop_printorder.php?position='+position+'&container='+container+'&ids='+idsString
   +'&product='+product,'_print','scrollbars=yes,resizable=yes,width=1050,height=860');
}

function onOrderProofsheet(position, container, product)
{
   if (checkSelected())
   {
      MM_openBrWindow('pop_prooforder.php?position='+position+'&container='+container
       +'&ids=sels&product='+product,'_print','scrollbars=yes,resizable=yes,width=880,height=740');
   }
}

function onShowEdits(container)
{
	count = countSelected();
	if(count > 0)
	{
		tb_show('','pop_dplEdits.php?container=' + escape(container) + '&count='+ escape(count)+'&TB_iframe=true&modal=true&KeepThis=true&width=250&height=300');		
	}
	else
	{
		tb_show('', 'pop_dplEdits.php?error=nofiles&modal=true&TB_iframe=true&KeepThis=true&width=250&height=300');
	}
}

function numberFormat(num, decimalPlaces)
{
   var n = new Number(num);
   return addCommas(n.toFixed(decimalPlaces));
}

function addCommas(nStr)
{
   nStr += '';
   x = nStr.split('.');
   x1 = x[0];
   x2 = x.length > 1 ? '.' + x[1] : '';
   var rgx = /(\d+)(\d{3})/;
   while (rgx.test(x1)) {
      x1 = x1.replace(rgx, '$1' + ',' + '$2');
   }
   return x1 + x2;
}

function NextZoom (page)
{
   var newHref = location.href;
   var pageCheck = /page=+\d/;
   if (pageCheck.test(newHref))
   {
      newHref = newHref.replace(/page=+\d/, "page=" + page);
      
   }
   
   else
   {
      newHref += '&page=' + page;
      
   }
   
   location.href = newHref;
}

function isDate(obj, clearInvalid) {
    if (obj.value.length > 0)
	{
		if (obj.value.search(/^([0]?[1-9]|[1-9][0-2])(-|\\|-|\/|\.)?([0]?[1-9]|[1-2][0-9]|[3][0-1])(-|\\|-|\/|\.)?(\d{2}|\d{4})$/) == -1)
		{
			alert('This is not a valid date.  Please try again.');
			if(clearInvalid == true)
			{
				obj.value = '';
			}
			return false;
		}
		else
		{
			//Auto Format
			var p=/(\d{1,2})(-|\\|-|\/|\.)?(\d{1,2})(-|\\|-|\/|\.)?(\d{2,4})/.exec(obj.value);
			obj.value = '';
			if(p[1].length == 1)
				obj.value = '0';
			obj.value += p[1] + '/';

			if(p[3].length == 1)
				obj.value += '0';
			obj.value += p[3] + '/';
		
			if(p[5].length == 2)
			{
			  var today = new Date();
			  obj.value += '20';
			}
			obj.value += p[5];
		}
	}
	return true;
}

function isMoney(obj, clearInvalid) {
    if (obj.value.length > 0)
		{
		if (obj.value.search(/^\$?\d+((,\d{3})+)?(\.\d+)?$/) == -1)
		{
			alert('This is not a valid number.  Please try again.');
			if(clearInvalid == true)
			{
				obj.value = '';
			}
			return false;
		}
	}
	return true;
}

// Closes a thickbox or a popup
function closeMe(doReload)
{
   if(null == doReload)
      doReload = false;
   else if("false" == doReload)
      doReload = false;
   else if("true" == doReload)
      doReload = true;
   
   if(opener == null && self.parent != null && (typeof self.parent.tb_remove == 'function'))
   {
      // thickbox mode
      self.parent.tb_remove();
      if(doReload)
         self.parent.location.reload();
   }
   else
   {
      window.close();
        if(doReload)
      opener.location.reload();
   }
}

//-->
