
///////////////////////////////////////////////////////////////////////////////////
//The functions
//////////////////////////////////////////////////////////////////////////////////
//isEmpty(s)   	    		Returns True if s is empty
//isWhitespace(s)  	 		Returns True if string s is empty or whitespace characters only
//isEmail(s [,canBeEmpty])	Returns True if valid Email
//getNameValue(thestring)  Retruns a array with edit object name and value
//fillTheForm()   			This function fills two drop down boxes
//updateForm()   				This function fills two drop down boxes
//CCU(the_object,max) This function displays the amount of characters left in the status bar
//										CCU == Count Characters Used   :)
//getProperties(obj,sep)  Get all the properties of a object and seperate them using the sep value
//getRadioValue(radioObject) Get the selected value of a group of radion buttons

///////////////////////////////////////////////////////////////////////////////
//Global vars
//////////////////////////////////////////////////////////////////////////////

// whitespace characters
var whitespace = " \t\n\r";
//All the ilegal characters in a email adress i think!

var ilegal = "!\"#$%&'()*+,/:;<=>?[\\]^`{|}~€?‚ƒ„… †‡ˆ‰Š‹Œ?Ž??‘’“”•–—˜™š›œ?žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕ"//×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ "
//																																																																		|
//var ilegal = "!\"#$%&'()*+,/:;<=>?[\\]^`{|}~€?‚ƒ„… †‡ˆ‰Š‹Œ?Ž??‘’“”•–—˜™š›œ?žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ "
var g_strFromDB = "";
// Check whether string s is empty.
var swapCodes   = new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230); // dec codes from char at
var swapStrings = new Array("--", "--", "'",  "'",  '"',  '"',  "*",  "...");

function cleanWordClipboard(input) {
    // debug for new codes
    // for (i = 0; i < input.length; i++)  alert("'" + input.charAt(i) + "': " + input.charCodeAt(i));

    var output = input;
    for (i = 0; i < swapCodes.length; i++) {
        var swapper = new RegExp("\\u" + swapCodes[i].toString(16), "g"); // hex codes
        output = output.replace(swapper, swapStrings[i]);
    }
    return output;
}

function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or
// whitespace characters only.
function isWhitespace (s)
{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmail (s,canBeEmpty)
{   if (isEmpty(s))
       if (!canBeEmpty) return false;
       else return true;

    // is s whitespace?
    if (isWhitespace(s)) return false;

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
   while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    //look for a dubble @
   if (s.indexOf("@") != -1)
   {
    if (s.indexOf("@",s.indexOf("@")+1) != -1)
    {
      return false;
    }
   }
   // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function test_path()
{
alert("it works!");
}

// checks for ilegal chars
function isLegal (s)
{   var i;

  //Well if the string is not a valid email adress then  add the @ sign
  if (isEmail(s)){ilegal1 = ilegal}else{ilegal1 = ilegal + "@"}
    // Search through string's characters one by one
    // until we find a ilegal character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (ilegal1.indexOf(c) != -1) return false;
    }

    // All characters are whitespace.
   return true;
}

function getNameValue(thestring)
{
/*
This function returns a array where the number and text is stored in
ex: The result will be 888
var myString = "888||My category" ;
alert(getNameValue(myString)[0]);
*/
var intPipeAt = 0
var returnValue = new Array("","")
  if (thestring != null)
  {
    intPipeAt = thestring.indexOf("||")
    returnValue[0] = thestring.substring(0,intPipeAt)
    returnValue[1] = thestring.substring(intPipeAt+2,thestring.length)
  }
  return returnValue
}


function updateForm()
{
/*
This function needs to have 2 objects called
  obj_sectionlist	:A drop down list
  obj_catlist			:A drop down list
and a array that holds the sections and categories (see catsec.js)
call this function when your section drop down box changes
*/
  if ((obj_sectionlist)&&(obj_catlist))
  {
    var intCurrentSection =  obj_sectionlist.selectedIndex;
    var intI
    var newCategorie = new Option("Not Selected");
    var maxlenght = new Array(obj_sectionlist.length,obj_catlist.length)

//		alert(intCurrentSection);
    if (intCurrentSection < 0)
    {
    intCurrentSection = 1;
//		alert(intCurrentSection < 0);
    }
      //empty the categorie selection box
      for(intI=0; intI<maxlenght[1]; intI++)
      {
        obj_catlist.options[0]=null;
      }

      obj_catlist.options[0]=newCategorie
      obj_catlist.options[0].value = "*"

       //if the user selected the Not Selected then we just do nothing!
      if (obj_sectionlist.selectedIndex == 0) return;

      //fill our categorie selection list!
      if (arrayCat[intCurrentSection-1].length > 1)
      {
        for (intI=1;intI<arrayCat[intCurrentSection-1].length;intI++)
        {
          if (getNameValue(arrayCat[intCurrentSection-1][intI])[1] != "")
          {
            var newCategorie = new Option(getNameValue(arrayCat[intCurrentSection-1][intI])[1]);
            obj_catlist.options[intI]=newCategorie;
            obj_catlist.options[intI].value = getNameValue(arrayCat[intCurrentSection-1][intI])[0];
          }//if (get
        }//for
        obj_catlist.selectedIndex = 0;
      }//if (array
  }
  else
  {
    alert("updateForm();\n Error!\n Please contact Job Mail website support to report this error.");
    return false;
  }
}

function fillTheForm()
{
/*
This function needs to have 2 objects called
  obj_sectionlist	:A drop down list
  obj_catlist			:A drop down list
and a array that holds the sections and categories (see catsec.js)
call this function on your onload!
*/
  if ((obj_sectionlist)&&(obj_catlist))
  {
    var intI = 0
    var intJ = 0
    var intOldValues = new Array(obj_sectionlist.selectedIndex,obj_catlist.selectedIndex)
    var maxlenght = new Array(obj_sectionlist.length,obj_catlist.length)

      //If the global var with the name g_strFromDB has been created
      //g_strFromDB you must create and give some value!
      if (g_strFromDB != "")
      {
        /*
        Why this code?
        Ok, you see the guy comes in with categorie id that is stored
        with his data and I try to find that categorie in our array list
        if so change the a array called intOldValues witch I use to
        restore his previos selected section and categorie
        */
        for (intI=0;intI<arrayCat.length;intI++)
        {
          if (arrayCat[intI][0] != "")
          {
            for (intJ=0;intJ<arrayCat[intI].length;intJ++)
            {
              if (arrayCat[intI][intJ] != "")
              {
                if (getNameValue(arrayCat[intI][intJ])[0] == g_strFromDB)
                {
                  intOldValues[0] = intI+1;
                  intOldValues[1] = intJ;
                }
              }
            }
          }
        }
      }

      //clean the section and categories selection boxes!
      for(intI=0; intI<maxlenght[0]; intI++)
      {
        obj_sectionlist.options[0]=null;
      }

      for(intI=0; intI<maxlenght[1]; intI++)
      {
        obj_catlist.options[0]=null;
      }

      //Add the fisrt item the selection boxes
      var newSection = new Option("Not Selected");
      obj_sectionlist.options[0]=newSection
      obj_sectionlist.options[0].value = "*"
      var newCategorie = new Option("Not Selected");
      obj_catlist.options[0]=newCategorie
      obj_catlist.options[0].value = "*"

      //Add all the sections!
      for (intI=0;intI<arrayCat.length;intI++)
      {
        if (arrayCat[intI][0] != "")
        {
          var newSection = new Option(getNameValue(arrayCat[intI][0])[1]);
          obj_sectionlist.options[intI+1]=newSection;
          obj_sectionlist.options[intI+1].value=getNameValue(arrayCat[intI][0])[0]
        }
      }

      //Looking at this you might think i am "(_. () |)"  or something! :)
      //I have solved the IE BUG !!!
      if (intOldValues[0] != 0){obj_sectionlist.selectedIndex = intOldValues[0]}else{obj_sectionlist.selectedIndex = 0}
      updateForm();
      if (intOldValues[1] != 0){obj_catlist.selectedIndex = intOldValues[1]}else{obj_catlist.selectedIndex = 0}
  }
  else
  {
    alert("fillTheForm();\n Error!\n Please contact Job Mail website support to report this error.");
    return false;
  }

}

//CCU = Count Characters Used   :)
function CCU(the_object,max)
{
var intUsed = 0
  if (the_object != null)
  {
    intUsed = max - the_object.value.length
    if (intUsed > -1)
    {
      window.status = intUsed + ' character(s) left'
    }
    else
    {
      window.status = 'Exceeding maximum length with '+  Math.abs(intUsed) + ' character(s)'
    }
  }
}

function getProperties(obj,sep) {
    var properties = "";
    for (var propName in obj) {
   properties +=propName+"="+obj[propName]+sep;
    }
    return properties;
}

function getPropertiesContainName(obj,sep,propname)
{
    var properties = "";
  for (var propName in obj)
  {
    if (propName.toLowerCase().indexOf(propname)>-1)
    {
      properties +=propName+"="+obj[propName]+sep;
    }
  }
    return properties;
}

function getRadioValue(radioObject)
{
  var value = null
  for (var i=0;i < radioObject.length; i++)
  {
    if (radioObject[i].checked)
    {
      value = radioObject[i].value;
      break;
    }
  }
  return value;
}

function ShowErrorFixError(aObject,aMessage)
{
   alert(aMessage);
   aObject.value = '0';
   aObject.focus();
}

function ello() {
  alert('we');
}
//calculator functions----------------------------------------------------
function calculate(cWhichCalc) {
  with (document.testamentForm) {
    if ( cWhichCalc == '0' ) {
      //validate all fields
      varCalc = true;
      if ((aHouse.value == "")||(isNaN(aHouse.value))) {
        ShowErrorFixError(aHouse,"Please enter a valid price!")
        varCalc = false;
      } else if ((aOtherProperty.value == "")||(isNaN(aOtherProperty.value))) {
        ShowErrorFixError(aOtherProperty,"Please enter a valid deposit!")
        varCalc = false;
      } else if ((aInvestments.value == "")||(isNaN(aInvestments.value))) {
        ShowErrorFixError(aInvestments,"Please enter a valid interest rate!")
        varCalc = false;
      } else if ((aVehicles.value == "")||(isNaN(aVehicles.value))) {
        ShowErrorFixError(aVehicles,"Please enter a valid number of payments!")
        varCalc = false;
      } else if ((aPolicies.value == "")||(isNaN(aPolicies.value))) {
        ShowErrorFixError(aPolicies,"Please enter a valid number of payments!")
        varCalc = false;
      } else if ((aFurniture.value == "")||(isNaN(aFurniture.value))) {
        ShowErrorFixError(aFurniture,"Please enter a valid number of payments!")
        varCalc = false;
      } else if ((aOther.value == "")||(isNaN(aOther.value))) {
        ShowErrorFixError(aOther,"Please enter a valid number of payments!")
        varCalc = false;
      }
      var tempMonthly;
      if (varCalc == true) {
        //all values are set, do calculations
        tempMonthly = (parseInt(aHouse.value) + parseInt(aOtherProperty.value) + parseInt(aInvestments.value) + parseInt(aVehicles.value) + parseInt(aPolicies.value) + parseInt(aFurniture.value) + parseInt(aOther.value));
        aTotal.value = tempMonthly;
      }
    }
    if ( cWhichCalc == '1' ) {
      //validate all fields
      varCalc = true;
      if ((lBonds.value == "")||(isNaN(lBonds.value))) {
        ShowErrorFixError(lBonds,"Please enter a valid price!")
        varCalc = false;
      } else if ((lCA.value == "")||(isNaN(lCA.value))) {
        ShowErrorFixError(lCA,"Please enter a valid deposit!")
        varCalc = false;
      } else if ((lBA.value == "")||(isNaN(lBA.value))) {
        ShowErrorFixError(lBA,"Please enter a valid interest rate!")
        varCalc = false;
      } else if ((lOther.value == "")||(isNaN(lOther.value))) {
        ShowErrorFixError(lOther,"Please enter a valid number of payments!")
        varCalc = false;
      }
      var tempMonthly;
      if (varCalc == true) {
        //all values are set, do calculations
        tempMonthly = (parseInt(lBonds.value) + parseInt(lCA.value) + parseInt(lBA.value) + parseInt(lOther.value));
        lTotal.value = tempMonthly;
      }
    }
  }
}

var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;

//preload rollover images
function preloadFunc(tempPath, varString) {
  imgArray = new Array();
  arrayOfString = new Array();
  arrayOfStrings = varString.split(',');
  for (i=0; i<arrayOfStrings.length; i++) {
    imgArray[i] = new Image();
    imgArray[i].src = tempPath + arrayOfStrings[i];
  }
}

function out(obj,color){obj.bgColor = color;}

function over(obj,color)
{
  obj.bgColor = color;cursor(obj);
  obj.style.color = "red";
}
function cursor(obj){obj.style.cursor = 'pointer'; }

function clicked(obj){if (obj.cells[1].childNodes[0]){if (obj.cells[1].childNodes[0].tagName == "A"){location.href = obj.cells[1].childNodes[0].href;}}}
function clicked2(obj){if (obj.cells[0].childNodes[0]){if (obj.cells[0].childNodes[0].tagName == "A"){location.href = obj.cells[0].childNodes[0].href;}}}

function populateBrands(formName, BrandID, DealershipName) {
  with (eval("document." + formName)) {

    varBrandID = eval(BrandID);
    tempNum = varBrandID.selectedIndex;

    //empty out dealers box
    varBrandName = eval(DealershipName);
    for (i=0;i<varBrandName.length;i++) {
      varBrandName.options[i]=null
    }
    varBrandName.options.length = 0;

    //create new options
    varBrandArray = new Array();
    varBrandArray = BrandArray;

    //populate
    for (j=0;j<varBrandArray[tempNum].length;j++) {
      brandString = varBrandArray[tempNum][j];
      var tempOption = new Option(brandString, brandString);
      varBrandName.options[j] = tempOption;
    }
  }
}

function MM_preloadImages() {
  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 mOver(obj) {
  strName = obj.name;
  obj.src = '../images/nav/mainLinks/'+strName+'_over.gif';
}
function mOut(obj) {
  strName = obj.name;
  obj.src = '../images/nav/mainLinks/'+strName+'.gif';
}
function changeDisplay(str) {
  document.display.displayName.value = str;
}

// My frame name keeps changing and that gets incremented.
function frameSlooth() {
  tmpStr = parent.frames.length+'\n';
  for (i=0;i<parent.frames.length;i++) {
    tmpStr=tmpStr + parent.frames[i].name+'\n';
  }
  alert(tmpStr);
}

function changeIt(obj) {
  if(mOver == 0) {
    if(obj == imageDiv){mOver=1}
    if(holder.innerHTML != obj.innerHTML) {
      holder.innerHTML = obj.innerHTML;
    }
  }
  if(obj == flashDiv) {
    mOver = 0;
    holder.innerHTML = obj.innerHTML;
  }
}



//Strips a numeric value of all illegal chars. Gunther Kruger.
function cleanNumericField(iVal) {
  var re = /\s|\W|\D/g;
  if ( iVal != '' ) {
    var tmpStr = iVal;
    tmpStr = tmpStr.replace(re, '');
    if ( tmpStr != '' ) {
      return parseInt(tmpStr);
    } else {
      return parseInt(0);
    }
  } else {
    return parseInt(0);
  }
}

//Retrieve all the obj properties. Coenie Richards.
function getProperties(obj,sep) {
    var properties = "";
    for (var propName in obj) {
   properties +=propName+"="+obj[propName]+sep;
    }
    return properties;
}

function getPropertiesContainName(obj,sep,propname)
{
    var properties = "";
  for (var propName in obj)
  {
    if (propName.toLowerCase().indexOf(propname)>-1)
    {
      properties +=propName+"="+obj[propName]+sep;
    }
  }
    return properties;
}

function viewImage(obj,size) {

  if (size == 'large') {URL='../ProductImage.cfm?imageName='+obj+'&size='+size+'&noEnlarge=1'}
  else {URL='../ProductImage.cfm?imageName='+obj+'&size='+size}
  window.open(URL,'imageWin','width=180,height=180,scrollbars=no,toolbars=no');
}

function openWin(url,w,h) {
  window.open(url,'pop','width='+w+',height='+h+',scrollbars=yes,toolbars=no');
}
function viewDocument(obj,size) {


  URL='../cfm/showDocument.cfm?imageName='+obj+'&size='+size+'&noEnlarge=1'

  window.open(URL,'imageWin','width=380,height=280,scrollbars=no,toolbars=no');
}

function valEmail(sEmail)
{
  var sPattern=/^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)$/gi;
  //var re=new RegExp(sPattern);
  sEmail=trim(sEmail);
  ret=sEmail.match(sPattern);
  if (ret==null)
  {
    return false;
  }
  else
  {
    return true;
  }
}

/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

