if (window.event + "" == "undefined") event = null;

if (navigator.appVersion.substring(0,1) >= 3)
{
  bgen1   = new Image(); bgen1.src ="iconos/home.gif";
  bgen1p  = new Image(); bgen1p.src  ="iconos/homep.gif";
  bgen2   = new Image(); bgen2.src ="iconos/map_site.gif";
  bgen2p  = new Image(); bgen2p.src  ="iconos/map_sitep.gif";
  bgen3   = new Image(); bgen3.src ="iconos/contact_us.gif";
  bgen3p  = new Image(); bgen3p.src  ="iconos/contact_usp.gif";
  top1    = new Image(); top1.src  ="iconos/top.gif";
  top1p   = new Image(); top1p.src="iconos/topp.gif";
  back1   = new Image(); back1.src="iconos/back.gif";
  back1p  = new Image(); back1p.src="iconos/backp.gif";
}

function CambiaImg(imgid, imgnew)
{
  if (navigator.appVersion.substring(0,1) >= 3) {
    document.images[imgid].src = eval(imgnew + ".src");
  }
}

function OpenWin(pag,w,h)
{
  Ventana = window.open(pag, "maple", "width=" + w + ",height=" + h + ",resizable=0,noresize=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no");
}

function validateCheckSelectList(chkName) {
  var form  = document.forms[0];
  var total = 0;
  for (i=0; i<form.elements.length; i++) {
    var elemento = form.elements[i];
    if (elemento.type == "checkbox" && elemento.id.indexOf(chkName) > 0) {
      if (elemento.checked) total++;
    }
  }
  if (total > 0) return true;
  return false;
}

function validateOnlyOneChecked(chkName) {
  var form  = document.forms[0];
  var total = 0;
  for (i=0; i<form.elements.length; i++) {
    var elemento = form.elements[i];
    if (elemento.type == "checkbox" && elemento.id.indexOf(chkName) > 0) {
      if (elemento.checked) total++;
    }
  }
  if (total == 1) return true;
  return false;
}

function checkEditAction(chkName) {
  if (!validateCheckSelectList(chkName)) {
    alert("Please select at least one element");
    event.returnValue = false;
    return false;
  } else if (!validateOnlyOneChecked(chkName)) {
    alert("Please select only one element");
    event.returnValue = false;
    return false;
  }
  return true;
}

function checkDeleteAction(chkName) {
  if (!validateCheckSelectList(chkName)) {
    alert("Please select at least one element");
    event.returnValue = false;
    return false;    
  }
  return confirm("Are you sure to delete all selected records?");
}

function checkApproveAction(chkName) {
  if (!validateCheckSelectList(chkName)) {
    alert("Please select at least one element");
    event.returnValue = false;
    return false;    
  }
  return confirm("Are you sure to approve/disapprove all selected records?");
}

function checkPublishAction(chkName) {
  if (!validateCheckSelectList(chkName)) {
    alert("Please select at least one element");
    event.returnValue = false;
    return false;
  }
  return confirm("Are you sure to publish/unpublish all selected records?");
}

function addSubtitlePage() {
  var subTitlePreview = "(preview page)";
  if (window.name == 'mapleChildWin') {
    //alert(document.title);
    if (document.title.indexOf(subTitlePreview) < 0) {
      document.title += " " + subTitlePreview;
    }
  }
}

function addParamUrlPreviousPage() {
  var subTitlePreview = "(preview page)";
  if (window.name == 'mapleChildWin') {
    var urls = $("a");
    for (i=0; i<urls.length; i++) {
      var signo = "?";
      if (urls[i].href.indexOf(signo) >= 0) {
        signo = "&";
      }
      if (urls[i].href.indexOf('.aspx') >= 0 || urls[i].href.indexOf('.htm') >= 0) {
        if (urls[i].href.substr(urls[i].href.length - 1) != '#') {
          if (urls[i].href.indexOf('isInternalPreviousPage') < 0) {
            urls[i].href += signo + "isInternalPreviousPage=true";
            //alert(urls[i].href);
          }
        }
      }
    }
  }
}
