Subversion Repositories DevTools

Rev

Rev 3898 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 *    COMMON JAVASCRIPTS
 */

<!--
var clickedButton = false;
function check() {
   if (clickedButton) {
       clickedButton = false;
        return true;
    } else {
       return false;
   }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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,'left=20,top=20,'+features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.1
  if (selObj.options[selObj.selectedIndex].value) {
     eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
     if (restore) selObj.selectedIndex=0;
  }
}

function Cascaded_Menu(targ,url,selObj,restore){ //v3.1
  if (selObj.options[selObj.selectedIndex].value) {
     eval(targ+".location='"+url+selObj.options[selObj.selectedIndex].value+"'");
     if (restore) selObj.selectedIndex=0;
  }
}

//
//  Validate Forms
//  Arguments:
//    --Silent          - Optional. Supresses alert
//    Triplets          - Zero or more triplets.
//                        Eg: 'FRpkgName','Package Name','RisPackage'
//      FormObject      - Form Object ID
//      TextPrefix      - Error message Prefix
//      TestType        - Type of test to perfom.
//                        First letter may be R - Required.
//
function MM_validateForm() {
   var ii,p,pl,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
   var REresults;
   var pass,passc;
   var showAlert = true;

   // Other general validations
   var cleanStrRE = /^[0-9a-z_\.\(\)\-]+$/i;
   var pkgRE = /^[a-z][a-z0-9_-]*[a-z0-9]$/i;
   var versionRE = /^[0-9a-z_\.\(\)\-]+$/i;
   var re_patch_ver_format = /^\d+\.\d+\.\d+\.p\d+\.[a-zA-Z0-9]+$/;
   var urlRE = "^https?://[a-z1-9]";
   //character range disallowed
   var HTMLchr = /[\<\>\'\"]+/i;
   var alphanumRE = /^[a-z0-9]+$/i;

   // Options are first
   for (ii=0; ii<(args.length-2) && typeof(args[ii]) === 'string' && args[ii].indexOf('--') == 0; ii++) {
    switch(args[ii].toLowerCase()) {
      case "--silent" :
        showAlert = false;
        break;
    }
  }

  // Iterate over arguments
  // These are in triplets
  //    Name of form object - Value is extracted for user as 'val'
  //    Text Prefix for error - 'nm'
  //    Type of Test to Perform -'test'
   for (; ii<(args.length-2); ii+=3) {
      nm=args[ii+1];
      test=args[ii+2];
      if ( typeof(args[ii]) === 'string' ) {
        val=MM_findObj(args[ii]);
        if (val) {
           val=val.value;

           if (val!="") {
              if (test.indexOf('isEmail')!=-1) {
                 p=val.indexOf('@');
                 if (p<1 || p==(val.length-1) || test.charAt(0) == '@') errors+='- '+nm+' must contain an e-mail address.\n';
              }

              if (test.indexOf('isDate') != -1) {
                 if (val.indexOf("/") != -1) {
                    tmpARR = val.split("/");
                    if (tmpARR.length == 3) {
                       if (!(tmpARR[0]>0  && tmpARR[0]<32  && tmpARR[1]>0 && tmpARR[1]<13 && tmpARR[2]>1900 && tmpARR[2]<9999)) {
                          errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
                       }
                    } else {
                       errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
                    }
                 } else {
                    errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
                 }
              }

              if (test.indexOf('isPackage')!=-1) {
                 REresults = val.search(pkgRE);
                 if (REresults < 0) errors += val + ' - '+nm+' is not valid. Valid characters are A-Z a-z 0-9 - _\n'
                          + 'Names must start with a letter and cannot contain spaces or symbols other than - and _\n';
              }

              if (test.indexOf('isCleanStr')!=-1) {
                 REresults = val.search(cleanStrRE);
                 if (REresults < 0) errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
              }

              if (test.indexOf('isVersionStr')!=-1) {
                 REresults = val.search(versionRE);
                 if (REresults < 0) errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
              }

              if (test.indexOf('isPatchVersionStr')!=-1) {
                 if ( !re_patch_ver_format.test(val) ) {
                    errors += val + '- '+nm+' is not of form (integer).(integer).(integer).p(integer).(extension)\n';
                 }
              }

              if (test.indexOf('isCCPath')!=-1) {
                 var CCPathRE = /^\\|\/[a-z]+[0-9a-z_\.\-\\\/ ]+$/i;

                 REresults = val.search(/^(\\|\/)/);
                 if (REresults < 0) errors += val + '- '+nm+' must begin with \\ or /\n';
               
                 REresults = val.search(CCPathRE);
                 if (REresults < 0) errors += val + '- '+nm+' uses invalid character.\nAllowed characters are \\ / A-Z a-z 0-9 . - _ SPACE\n';
              }

              if (test.indexOf('isCCLabel')!=-1) {
                 var CCLabelRE = /^[0-9a-z_\.\-]+$/i;

                 REresults = val.search(CCLabelRE);
                 if (REresults < 0) errors += val + '- '+nm+' uses invalid character.\nAllowed characters are A-Z a-z 0-9 . - _\n';
              }

              if (test.indexOf('isSVNTag')!=-1) {
                  // Subversion Tag validation
                  var SVNTagValidPeg = /^@?\d+$/;
                  var SVNTagRE = /^[0-9a-z_\.\-]+$/i;
                
                 if ( val.search(SVNTagValidPeg) < 0) {

                      var stripped;
                      stripped = val.replace (/@\d+$/,"");
                      if (stripped.search(SVNTagRE) < 0)
                          errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
                 }
              }

              if (test.indexOf('isSVNPegTag')!=-1 && ! errors) {
                  // Subversion Tag has peg - Must have done valid check first
                  var SVNTagPegged = /@?\d+$/;

                  if ( val.search(SVNTagPegged) < 0) {
                      errors += val + '- '+nm+' Must be pegged for Manually Versioned Package. ie:tag@pegNumber\n';
                 }
              }
            
              if (test.indexOf('isSVNPath')!=-1) {
                 // Subversion Base Path validation
                 var SVNTagValidCharsRE = /^[0-9a-z_\.\-\/]+$/i;
                 var SVNTagInValidSlashAtBOL = /^\/.*$/i;
                 var SVNTagInValidSlashAtEOL = /\/$/i;
                 var SVNTagInValidSlash = /^.*\/\/.*$/i;
                 var SVNTagInValidTrunkAnywhereRE = /\/trunk\//i;
                 var SVNTagValidTagAnywhereRE = /^.*\/tags\/.*$/i;

                 if (val.search(SVNTagValidCharsRE) < 0)
                    errors += val + ' - '+nm+' uses invalid character. Allowed characters are / A-Z a-z 0-9 . - _\n';
                 else if (val.search(SVNTagInValidSlashAtBOL) >= 0)
                    errors += val + ' - '+nm+' begins with a /. This is not allowed.\n';
                 else if (val.search(SVNTagInValidSlashAtEOL) >= 0)
                    errors += val + ' - '+nm+' ends with a /. This is not allowed.\n';
                 else if (val.search(SVNTagInValidSlash) >= 0)
                    errors += val + ' - '+nm+' uses //. This is not allowed.\n';
                 else if (val.search(SVNTagValidTagAnywhereRE) >= 0)
                       errors += val + ' - '+nm+' contains /tags/. This is not allowed.\n';
                 else if (val.search(SVNTagInValidTrunkAnywhereRE) >= 0)
                       errors += val + ' - '+nm+' contains /trunk/. This is not allowed.\n';
                 else {
                          var bits = val.split("/");
                          if ( bits.length < 4 )
                              errors += val + ' - Must contain at least 4 path items.\n';
                        
                          var ttbcount = 0;
                          var i
                          for (i=0; i < bits.length; i++ )
                          {
                              var el = bits[i];
                              if ( el == 'tags') ttbcount++;
                              if ( el == 'trunk') ttbcount++;
                              if ( el == 'branches') ttbcount++;
                          }
                          if ( ttbcount != 1 )
                              errors += val + ' - '+nm+' must contain exactly one of tags, trunk or branches. It contains '+ttbcount+'.\n';
                          
                          if ( bits.pop() == 'branches' )    
                              errors += val + ' - '+nm+' must not end in branches.\n';
                        
                       }
              }

              // No longer used in this simple form
              if (test.indexOf('isVersionNumber')!=-1) {
                 REresults = -1;
                 if (REresults < 0) errors += val + ' - '+nm+' isVersionNumber is no longer supported in this form';
              }

              if (test.indexOf('isURL')!=-1) {
                 REresults = val.match(urlRE);
                 if (REresults == null) errors += '"'+val+'" is not a valid URL.\n';
              }

              if (test.indexOf('isAlphaNum')!=-1) {
                 REresults = val.match(alphanumRE);
                 if (REresults == null) errors += '"'+nm+'" must be an alphanumeric value.\n';
              }

              if (test.indexOf('isChangePassword')!=-1) {
                 pass=MM_findObj('FRpassword');
                 passc=MM_findObj('FRpasswordc');
                 if (pass.value!=passc.value) errors+='- Password confirmation does not match.\n';
              }

              if (test.indexOf('maxLength')!=-1) {
                 p=test.indexOf(':');
                 max=test.substring(p+1);
                 if (val.length>max) errors+='- '+nm+' can be maximum '+max+' characters long.\n';
              }

              if (test.indexOf('notHTML')!=-1) {
                 if (val.match(HTMLchr)) errors+='- '+nm+' has invalid characters like \'< > quotes\'\n';
              }

              if (test.charAt(0)=='R') {

                 if (test.indexOf('isNumber') != -1) {
                    if (isNaN(val)) errors+='- '+nm+' must be a number.\n';
                 }

                 if (test.indexOf('inRange') != -1) {
                    p=test.indexOf(':');
                    min=test.substring(8,p);
                    max=test.substring(p+1);
                    if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
                 }

                 if (test.indexOf('inLength')!=-1) {
                     pl=test.indexOf('inLength')
                    p=test.indexOf(':');
                        min=test.substring(pl+8,p);
                        if (val.length<min) errors+='- '+nm+' must be at least '+min+' characters long.\n';
                  }
              }
           } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';


           if (test.indexOf('isPassword')!=-1) {
              pass=MM_findObj('FRpassword');
              passc=MM_findObj('FRpasswordc');
              if (!MM_findObj('FRdomainauth').checked) {
                 if (test.indexOf('inLength')!=-1) {
                     pl=test.indexOf('inLength')
                    p=test.indexOf(':');
                        min=test.substring(pl+8,p);
                        if (val.length<min) errors+='- '+nm+' must be at least '+min+' characters long.\n';
                  }
                 if (pass.value!=passc.value) errors+='- Password confirmation does not match.\n';
              } else {
                 if (MM_findObj('FRdomain_name').value=="") errors += '- Domain Name is required.\n';
              }
           }

           if (test.indexOf('isDomainName')!=-1) {
              if (MM_findObj('FRdomainauth').checked) {
                 if (MM_findObj('FRdomain_name').value=="") errors += '- Domain Name is required.\n';
              }
           }
        }
      }
      else {
        // Alternate form. First item is an object
        // Contents are test specific
        var valp = args[ii];

          // Expects object with data to examine
        if (test.indexOf('isVersionNumber')!=-1) {
          var rv = MM_ValidateVersion(valp.vBase, valp.vExt, valp.isAuto || false, valp.isPatch || false);
          if ( rv )
            errors += '- ' +nm+rv;
        }
      }
   }

   if (errors) {
      if ( showAlert )
        alert('The following error(s) occurred:\n\n'+errors);
      clickedButton=false;
   } else {
      clickedButton=true;
   }
   document.MM_returnValue = (errors == '');
   document.MM_error = errors;

  if (document.MM_returnValue && showAlert)
    MM_showProgressBar();
}

function MM_showProgressBar() {
  var pb = MM_findObj('ProgressBar');
  if ( pb )
    pb.style.visibility='visible';
}

function MM_hideProgressBar() {
  var pb = MM_findObj('ProgressBar');
  if ( pb )
    pb.style.visibility='hidden';
}

function isChecked(boxName, buttonId) {
  var formButton = document.getElementById(buttonId);
  var boxes = document.getElementsByName(boxName);
  var btnChecked = false;
  if (formButton) {
    for (var i = 0; i < boxes.length; i++) {
      if (boxes[i].checked) {
        btnChecked = true;
      }
    }

    if (btnChecked) {
      formButton.disabled = false;
      formButton.style.color="";
    }
    else {
      formButton.disabled = true;
      formButton.style.color="silver";
    }
  }
}

function confirmDelete(m)
{
   var agree=confirm('Are you sure you want to delete '+m+'?');
   if (agree) {
      MM_showProgressBar();
      return true;
   } else {
      return false;
   }
}

function confirmAction(m)
{
   var agree=confirm(m);
   if (agree) {
      MM_showProgressBar();
      return true;
   } else {
      return false;
   }
}

function DisplaySPAN(show) {
   if (show) {
      MM_findObj("spanHideDetails").style.display = "block";
      MM_findObj("spanPkgInfo").style.display = "block";
      MM_findObj("spanShowDetails").style.display = "none";
   } else {
      MM_findObj("spanHideDetails").style.display = "none";
      MM_findObj("spanPkgInfo").style.display = "none";
      MM_findObj("spanShowDetails").style.display = "block";
   }
}

function ToggleDisplay () {
   var i, args, div_name, visibility
   args=ToggleDisplay.arguments;
   for (i=0; i<(args.length); i+=1) {
      div_name=args[i];
      if ( MM_findObj(div_name).style.display == 'block' ) {
         MM_findObj(div_name).style.display = 'none';
      } else {
         MM_findObj(div_name).style.display = 'block';
      }

   }
}

function Visible () {

   var i, args, div_name, visibility
   args=Visible.arguments;
   for (i=0; i<(args.length); i+=2) {
      div_name=args[i];
      visibility=args[i+1]
      MM_findObj(div_name).style.display = visibility;

   }
}

function DisplayObjects () {
   var i, args, div_name
   args=DisplayObjects.arguments;
   for (i=0; i<(args.length); i+=1) {
      div_name=args[i];
      MM_findObj(div_name).style.display = 'block';
   }
}

function GetCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) { endstr = document.cookie.length; }
   return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) return GetCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }

   return null;
}

function go_submit( formname, actionname )
{
   formname.action.value = actionname;
   formname.submit();
}

function ExpandAll()
{
   var elem

   if (document.all)
   {
      // Run this for IE
      elem = document.all;
   } else {
      // Run this for other browsers
      elem = document.getElementsByTagName('div');
   }

   for (i in elem)
   {
      if (elem[i].id)
      {
         if (elem[i].id.indexOf('SHORT_') == 0) elem[i].style.display = 'none';
         if (elem[i].id.indexOf('FULL_') == 0) elem[i].style.display = 'block';
      }
   }

}

function CollapseAll()
{
   var elem

   if (document.all)
   {
      // Run this for IE
      elem = document.all;
   } else {
      // Run this for other browsers
      elem = document.getElementsByTagName('div');
   }

   for (i in elem)
   {
      if (elem[i].id)
      {
         if (elem[i].id.indexOf('SHORT_') == 0) elem[i].style.display = 'block';
         if (elem[i].id.indexOf('FULL_') == 0) elem[i].style.display = 'none';
      }
   }

}


function height()
{
   if( typeof( window.innerWidth ) == 'number' )
   {
      h = window.innerHeight;
   }
   else if(document.documentElement&&(document.documentElement.clientHeight ))
   {
      h = document.documentElement.clientHeight;
   }
   else if( document.body &&   ( document.body.clientWidth || document.body.clientHeight ) )
   {
      h = document.body.clientHeight;
   }

   var e = document.getElementById("LayerDescription");

   if (navigator.userAgent.indexOf('Internet Explorer'))
   {
      e.style.height = h - 350 + "px";
      e.style.overflow = "auto";
   }
   else
   {
      // This line shouldn't be run by IE; it doesn't seem to work. It gets run in Firefox, etc.
      e.style.minHeight= h - 350 + "px";
      e.style.overflow = "auto";
   }
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//
// MM_ValidateVersion(versionBase, versionExt, isAutobuild isPatch)
// Should NOT be used externally. Use MM_validateForm to access this function
//
//    versionBase   eg 1.2.3
//    versionExt    eg .cr
//    isAutobuild   true or false
//    isPatch       true or false
//
// Returns a non-zero-length error string if version is NOT valid, else returns a zero-length string
//
//////////////////////////////////////////////////////////////////////////////////////////////////
function MM_ValidateVersion(versionBase, versionExt, isAutobuild, isPatch)
{
   var re_std_ver_format   = /^\d+\.\d+\.\d+$/;
   var re_patch_ver_format = /^\d+\.\d+\.\d+\.p\d+$/;
   var re_cots_ver_format  = /^[\w]+[\w\.\-]*$/;   // starts with letter or digit or underscore, subsequent chars can be letters or digits or _ or . or -
   var re_cots_ver_format_exc1 = /[-_.]+[-_.]+/;   // look for any two adjacent special characters
   var re_cots_ver_format_exc2 = /[0-9A-Za-z]+/;   // look for any alphanumeric char
   var isCots = versionExt == ".cots" || versionExt == ".tool";

   if (!isAutobuild) {
      if ( versionBase.length == 0 ) {
         return " is of zero length";
      } else if ( !isCots) {
         if ( isPatch ) {
            if ( !re_patch_ver_format.test(versionBase) ) {
               return " is not of form (integer).(integer).(integer).p(integer)";
            }
         } else {
            if ( !re_std_ver_format.test(versionBase) ) {
               return " is not of form (integer).(integer).(integer)";
            }
         }
      } else if (isCots) {
         var extName = versionExt.toUpperCase().substr(1);

         if ( !re_cots_ver_format.test(versionBase) ) {
            return " " + extName + " package must begin with letter/digit/underscore, cannot contain any whitespace, and only special characters underscore/dash/dot are allowed";
         }

         if ( re_cots_ver_format_exc1.test(versionBase) ) {
            return " " + extName + " package cannot contain two adjacent special characters (underscore/dash/dot)";
         }

         if ( !re_cots_ver_format_exc2.test(versionBase) ) {
            return " " + extName + " package must contain one or more alphanumeric characters";
         }
      }
   }

   // everything ok - no error
   return "";
}


// Manipulate the class list for a given element
function hasClass(ele, cls) {
    return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}

function addClass(ele, cls) {
    if (!this.hasClass(ele, cls)) ele.className += " " + cls;
}

function removeClass(ele, cls) {
    if (hasClass(ele, cls)) {
        var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        ele.className = ele.className.replace(reg, ' ');
    }
}

function toggleClass(ele, cls1, cls2){
    if(hasClass(ele, cls1)){
        replaceClass(ele, cls1, cls2);
    }else if(hasClass(ele, cls2)){
        replaceClass(ele, cls2, cls1);
    }else{
        addClass(ele, cls1);
    }
}

// Highlight combobox if selection is zero
// Returns true:  None-zero selection
// Returns false: Invalid element or item-0 selected
function checkSeletion(el)
{
   if (el ) {
     if ( el.selectedIndex == 0) {
        addClass(el, 'form_error');
     } else {
        removeClass(el, 'form_error');
        return true;
     }
   }
   return false;
}

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function setCookie(c_name,value,exdays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
  document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
  var c_value = document.cookie;
  var c_start = c_value.indexOf(" " + c_name + "=");
  if (c_start == -1)
  {
    c_start = c_value.indexOf(c_name + "=");
  }
  if (c_start == -1)
  {
    c_value = null;
  }
  else
  {
    c_start = c_value.indexOf("=", c_start) + 1;
    var c_end = c_value.indexOf(";", c_start);
    if (c_end == -1)
    {
      c_end = c_value.length;
    }
  c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}

//-->