// Main JS page for RhomboidMail
// PH (06/03/03) = Do We need this JS function?
//function lib_bwcheck(){ //Browsercheck (needed)
//  this.ver=navigator.appVersion
//  this.agent=navigator.userAgent
//  this.dom=document.getElementById?1:0
//  this.opera5=this.agent.indexOf("Opera 5")>-1
//  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
//  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
//  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
//  this.ie=this.ie4||this.ie5||this.ie6
//  this.mac=this.agent.indexOf("Mac")>-1
//  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
//  this.ns4=(document.layers && !this.dom)?1:0;
//  this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
//  return this
//}
// var bw=new lib_bwcheck();

// 9Apr09: TB created new functions openWindowFixed and openWindowFree to make redundant
// the old openWindow and OpenWindow.
// And tidied up.

// TB's open new window with no tools and no resizing
function openWindowFixed(strURL, URLToken)
  {
    W = window.open(strURL +"&" + URLToken, "NewWindow", "top=50, left=100, height=600, width=500, menubar=no, scrollbars=no, status=no, toolbar=no, resizable=no");
    W.focus();
  }

// TB's open new window with all the tools and resizing
function openWindowFree(myPage, myName, w, h, scroll) 
  {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    alert('my alert js 1');
    winProps = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';
    alert('my alert js 2');
    winModal = window.open(myPage, myName, winProps);
    alert('my alert js 3');
    winModal.focus();
  }

// Do the MouseOver Image Functions 
function newImage(arg) 
  {
    if (document.images) 
      {
        rslt = new Image();
        rslt.src = arg;
        return rslt;      
      }
  }
  
function changeImages() 
  {

    if (document.images && (preloadFlag == true)) 
      {
        for (var i=0; i<changeImages.arguments.length; i+=2) 
          {
            document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
          }
      }
  }
  
var preloadFlag = false;

function preloadImages() 
 {
    if (document.images) 
      {
        SubmitbtnOver = newImage("images/Submit_btnOver.gif");
      UpbtnOver = newImage("images/Up_btnOver.gif");
      DownbtnOver = newImage("images/Down_btnOver.gif");
         preloadFlag = true;
      }
  }  

// Do the Open New Window Function
// Whenever we see the following called in code, change it to openWindowFixed.
function OpenWindow(strURL, URLToken)
  {
    W = window.open(strURL +"&" + URLToken, "NewWindow", "top=50,left=100,height=600,width=500,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no");
    W.focus();
  }  

// Do the Open New Window Function   
function OpenPicWindow(strURL, URLToken)
  {
    W = window.open(strURL +"&" + URLToken, "PicWindow", "top=50,left=100,height=0,width=0,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no");
    W.focus();
  }  
  
// Do the Open New Window Function   
function OpenEmailPreviewWindow(EmailID, URLToken)
  {
    W = window.open("index.cfm?FuseAction=Emails.Preview&EmailID=" + EmailID + "&" + URLToken, "EmailPreviewWindow", "top=50,left=100,height=480,width=640,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes");
    W.focus();
  }  
  
function SelObjs(Objs, CtrlObj)
  {
    for (var i=0; i < Objs.length; i++)
      Objs[i].checked = CtrlObj.checked;
  }
  
 // Submit the form
 function SubmitForm(FormObj, ActionValue,Target)       
 {
   // Check the length of Target is greater than 0 set the forms target
   if (Target.length > 0)
   {
     FormObj.target = Target;
   }
   // Submit the form
   FormObj.action = ActionValue;
   FormObj.submit();
 }
 
  // General Validation Functions

 // Checks to see if the item contains any values
 function ContainsAnyText(textvalue)
  {
    // Check to see if there are values apart from spaces
    textvalue=textvalue.split(" ").join("");
    if (textvalue.length>0 )
    {
         return true;
    }
    
    // Otherwise return false
    return false;
  } 
  
  function ValueExists(obj)
    {
      var obj_type = obj.type;
      if (obj_type == "text" || obj_type == "password" || obj_type == "hidden" || obj_type == "textarea" || obj_type == "file")
      {
        if (obj.value.length == 0) 
          return false;
        else 
          return true;
      }
      else if (obj_type == "select-one")
           {                           
              for (i=0; i < obj.length; i++)
              {
                // BE: Changed it so we ca have 0 in the selection box
                //if ((obj.options[i].selected) && (obj.options[i].value != 0))
                if ((obj.options[i].selected) && (obj.options[i].value.length > 0))
                {
                  return true;
                }
              }
           }
      return false;  
    }   
  
  // Check that the e-mail address supplied is valid
  function isEmail(emailAddress) 
  {
    // are regular expressions supported?
    var supported = 0;
    if (window.RegExp) 
    {
      var tempStr = "a";
      var tempReg = new RegExp(tempStr);
      if (tempReg.test(tempStr)) supported = 1;
    }

    // If regular expressions are not supported do the following  
    if (!supported) 
      return (emailAddress.indexOf(".") > 2) && (emailAddress.indexOf("@") > 0);
  
    // If regular expressions are supported do the following
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(emailAddress) && r2.test(emailAddress));
  }

   
// Whenever we see the following called in code, change it to openWindowFree.
   function openWindow(mypage, myname, w, h, scroll) 
    {
      var winl = (screen.width - w) / 2;
      var wint = (screen.height - h) / 2;
      winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
      winModal = window.open(mypage, myname, winprops);
      winModal.focus();
    }
    
  // this will remove all the contents of the Select object passed in 
  function removeAll(formelement)
    { 
      var selectLength = formelement.length; 
      for (var i = 0; selectLength > i; i++) 
        { 
          removelast(formelement); 
        } 
    } 
  
  // will remove the LAST entry in a Select box 
  function removelast(formelement)
    { 
      var thelength = formelement.length; 
      formelement.options[thelength - 1].value = ""; 
      formelement.options[thelength - 1].text = ""; 
      formelement.length = thelength - 1; 
    } 
  
  // Function to hide or unhide items
  function divVisibility(id,vis)
  {
    var dddd;
    if(document.all)
    {
      dddd=document.all[id].style;
      dddd.visibility = vis ? "visible" : "hidden";
    }
    if(document.layers)
    {
      dddd=document.layers[id];
      dddd.visibility = vis ? "show" : "hide";
    }
  }  
