function noVLPopup() {
if ( typeof( window[ 'qeTidyLinks' ] ) != "undefined" ) {
disablePopUp();
}
}

function lTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
			s = s.substring(j, i);
	}
	return s;
}


function rTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		i--;
		s = s.substring(0, i+1);
	}
		return s;
	}

	
function trim(str) {
	return rTrim(lTrim(str));
}

function infoBox(words,infoDiv) {

noVLPopup();


if (document.quote_engine.poptype.value != "popup" && document.quote_engine.poptype.value != "AUSpopup") {
document.getElementById(infoDiv).innerHTML = words;
}
else {
newwin=window.open("","infohelp","height=400,width=550,scrollbars=yes,resizable");
newwin.document.open("text/html","replace");
if (document.quote_engine.poptype.value != "AUSpopup") {
newwin.document.write("<html><head><title>Help</title></head><body><div style='color:#666666; font-family:arial,verdana; font-size:12px;'>");
}
else {
newwin.document.write(document.quote_engine.AUSpopupHeader.value);
}
newwin.document.write(words);
if (document.quote_engine.poptype.value != "AUSpopup") {
newwin.document.write("</div></body></html>");
}
else {
newwin.document.write(document.quote_engine.AUSpopupFooter.value);
}
newwin.document.close();
newwin.focus();
}
//document.all[infoDiv].innerHTML = words;
return true;

}

function isNumberString (InString)  {
	if (InString.length==0) return (false);
	var RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  return (false);
	}
	return (true);
}


function isDecimalString (InString)  {
	if(InString.length==0) return (false);
	
	var iCount=0;
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (TempChar == ".") {
			iCount++;
		}
	}

	if (iCount>1) {
		return (false);
	}

	var RefString="1234567890.";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
		return (false);
	}

	return (true);
}

function checkValidCardNumber(cardNumber) {
cardLength=cardNumber.length;

if (cardNumber=="4111111111111111" || cardNumber=="4111111111111112") {
return true;
}


if (cardLength<1) {
return false;
}

var card = new Array(cardLength-1);

for (counter=0;counter<cardLength;counter++) {
card[counter]=cardNumber.charAt(counter);
}

for (countdown=cardLength-2;countdown > -1;countdown-=2) {
card[countdown]=(card[countdown]-0)*2;
}

for (counter2=0;counter2<cardLength;counter2++) {
tempNum = card[counter2]
if (tempNum > 9) {
tempNum=tempNum-9;
card[counter2]=tempNum;
}
}

modulus = 0;

for (counter3=0;counter3<cardLength;counter3++) {
modulus+=(card[counter3]-0);
}


if (modulus%10 != 0) {
return false;
}
return true;
}

function containsSpaces (str) {
	if (str.indexOf(" ") == -1) {
		return false;
	}
	else {
		return true;
	}
}


function isDateXEX(dateStr, dateName) {
	
	if (trim(dateStr) == "") {
		alert(dateName + " " +rightDateFormatMSG);
		return false;
	}
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2,4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null) {
		alert(dateName + " " +rightDateFormatMSG);
		return false;
	}
	
	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[5];
	

//ADDED AT CAROLYNS REQUEST SO DOB HAVE TO BE IN RIGHT FORMAT
	if (year.length < 4) {
		alert(dateName + " " +rightDateFormatMSG);
		return false;
	}


	if (month < 1 || month > 12) { // check month range
		alert(monthFor+" " + dateName + " "+mustBeBetween+" 1 & 12.");
		return false;
	}
	
	if (day < 1 || day > 31) {
		alert(dayFor+" " + dateName + " "+mustBeBetween+" 1 & 31.");
		return false;
	}
	
	if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
		alert(monthFor+" " + dateName + " " + dateStr + doesNotHave+" 31 "+days)
		return false;
	}
	
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day == 29 && !isleap)) {
			alert(monthFor+" " + dateName + " " + dateStr + " "+doesNotHave+" " + day + " " + days);
			return false;
		}
	}
	return true; // date is valid
}


function getDatePart(dateStr, partName) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2,4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null) {
		return false;
	}
	
	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[5];


	if (year.length == 2) {
		if (year.substring(0, 1) == '0') {
			year = '20' + year;
		}
		else {
			year = '20' + year;
		}
	}
	
	if (partName == "d") {
		return day;
	}
	else if (partName == "m") {
		return month;
	}
	else if (partName == "y") {
		return year;
	}
	else {
		return false;
	}
}

//function getFullYear////////////////////////////////////////////
// fixes a Netscape 2 and 3 bug and IE it appears
function getFullYear(d) { // d is a date object
	yr = d.getYear();
	if (yr < 1000)
		yr += 1900;
	return yr;
}//end function getFullYear()///////////////////////////////////////


function getAge(dob) {
	var birthDate = new Date(getDatePart(dob, "y"), getDatePart(dob, "m") - 1, getDatePart(dob, "d")); 
	var today = new Date(todayYear, todayMonth - 1, todayDay);//todays date - values from server;
	

	var age = getFullYear(today) - getFullYear(birthDate);
	
	if (getFullYear(birthDate) >= getFullYear(today)&&birthDate.getMonth() >= today.getMonth() && birthDate.getDate() > today.getDate()) {
		return -1;
	}
	
	if (birthDate.getMonth() < today.getMonth()) {
	}
	else if (birthDate.getMonth() > today.getMonth()) {
		age -= 1;
	}
	else if (birthDate.getMonth() == today.getMonth()) {
		if (birthDate.getDate() <= today.getDate()) {
		}
		else {
			age -= 1;
		}
	}
	else {
		alert("error");
		return age;
	}
	
	return age;
}

function popup(file,width,height) {
newwin=window.open(""+file+"","myWindow","width="+width+",height="+height+"");
newwin.focus();
}//end if popup

function myRound(fltValue, intDecimal) {
var total = Math.round(fltValue * Math.pow(10, intDecimal)) / Math.pow(10, intDecimal);
if (total.toFixed) {//if browser supports toFixed() method
total.toFixed(intDecimal);
}
return total;
}

var first_word;


var littleWords = new Array("to", "in", "the", "of", "from", "a", "as", "an", "for", "and", "but", "with", "vs.", "or", "by", "if", "on", "v", "at");

var allCaps = new Array("aba", "pdf", "html", "xml", "fcc", "nchica", "hipaa", "glb", "erisa", "ftc", "eeo", "edgar", "osha", "cobra", "eeoc", "irs", "lp", "sec", "u.s.", "uk", "ec", "cmbs", "epa");

function uCase(textarea) {
textarea.value=textarea.value.toUpperCase()
}

function lCase(textarea) {
textarea.value=textarea.value.toLowerCase()
}

function changeCase(textarea) {
	first_word = true;
	var s = replaceSubstring(textarea.value,"-","- ");

	var str = s.toLowerCase();
	var str_temp = new Array();
	str_temp = str.split(" ");
	
	for (var i = 0; i < str_temp.length; ++i) {
		var pattern = /(^[\'\"]?)(\w)([\w]*)([\.\',:;]?)(.*)/;
		var word = str_temp[i];
		var result = pattern.exec(word);
		if (result != null) {
			str_temp[i] = toTitleCase(result, littleWords, allCaps);
		}
		first_word = getFirstWord(str_temp[i]);
	}

	var currLength = 0;
	for (var i = 0; i < str_temp.length; i++) {
		currLength += str_temp[i].length;
	}
	currLength += str_temp.length - 1;
	
	s = str_temp.join(" ");
	textarea.value = replaceSubstring(s,"- ","-");
}

function getFirstWord(word) {
	var ret = ( word.charAt(word.length-1) == ":");
	return ret;
}

function isInGroup(word, groupOfWords) {
//	word = word.replace(/:/, "");
	for (var i = 0; i < groupOfWords.length; ++i) {
		if (groupOfWords[i] == word)
			return true;
	}
	return false;
}

function getCase(word, littleWords, allCaps) {
	if (isInGroup(word, littleWords)) {
		return 1;	//return 1 if it is a little word;
	}
	if (isInGroup(word, allCaps)) {
		return 2;	//return 2 if this is an allcaps word;
	}
	return 3;		//return 3 for all other words;
}

function toTitleCase(result, littleWords, allCaps) {
	var word_temp, word_result;
//	result[0] contains the entire match
//	result[1] contains the (leading) ["'] (if any)
//	result[2] contains the first letter
//	result[3] contains the rest of the letters
//	result[4] contains the trailing punctuation (if any)
//	result[5] conains the trailing stuff and junk (if any)

	word_temp = result[2] + result[3];
	var word_case = getCase(word_temp, littleWords, allCaps);

	switch (word_case) {
		case 1:
			if (first_word) {
				first_word = false;
				word_result = result[2].toUpperCase() + result[3];
			} else {
				word_result = word_temp;
			}
			break;
		case 2:
			word_result = word_temp.toUpperCase();
			break;
		case 3:
			word_result = result[2].toUpperCase() + result[3];
			break;
	}

	word_result = result[1] + word_result;
	for (var i = 4; i < result.length; i++) {
		word_result += result[i];
	}

	
	return word_result;
}

function toSpace(textarea) {
	var s = textarea.value;
	s = s.replace(/_/g, " ");
	textarea.value = s;
}


function toUnderScore(textarea) {
	var s = textarea.value;
	s = s.replace(/\s/g, "_");
	textarea.value = s;
}

function clearArea(textarea) {
	textarea.value = "";
}

function getLengthText(TextArea) {
	var len = TextArea.value.length;
	alert("Length in chars\n" + len);
}

function selectTextArea(textarea) {
//	if (textarea.value == "") return;
//	var clip = textarea.createTextRange();
//	clip.execCommand("Cut");
	textarea.select();
}

function copyToClipboard(textarea) {
	if (textarea.value == "") return;
	var clip = textarea.createTextRange();
	clip.execCommand("Copy");
}

function pasteFromClipboard(textarea) {
	textarea.value = "";
	var clip = textarea.createTextRange();
	clip.execCommand("Paste");
}

   // Original JavaScript code by Duncan Crombie: dcrombie@chirp.com.au
   // Please acknowledge use of this code by including this header.

   // CONSTANTS
  var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

  function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null;  // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

 // patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      // patch suggested by Tom Denn 25/4/2001
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

  function strip(input, chars) {  // strip all characters in 'chars' from input
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) {  // format input using 'separator' to mark 000's
    input = "" + input;
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
  }

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

