var specialToNonSpecialLetterMap = new Array(
    /* 192 -> */ 'A','A','A','A','A','A','A','C',
    /* 200 -> */ 'E','E','E','E','I','I','I','I','D','N',
    /* 210 -> */ 'O','O','O','O','O','x','O','U','U','U',
    /* 220 -> */ 'U','Y','o','S','a','a','a','a','a','a',
    /* 230 -> */ 'a','c','e','e','e','e','i','i','i','i',
    /* 240 -> */ 'o','n','o','o','o','o','o','-','o','u', 
    /* 250 -> */ 'u','u','u','y','t','y','A','a','A','a', 
    /* 260 -> */ 'A','a','C','c','C','c','C','c','C','c', 
    /* 270 -> */ 'D','d','D','d','E','e','E','e','E','e', 
    /* 280 -> */ 'E','e','E','e','G','g','G','g','G','g', 
    /* 290 -> */ 'G','g','H','h','H','h','I','i','I','i', 
    /* 300 -> */ 'I','i','I','i','I','i','J','j','J','j', 
    /* 310 -> */ 'K','K','k','L','l','L','l','L','l','L', 
    /* 320 -> */ 'l','L','l','N','n','N','n','N','n','n', 
    /* 330 -> */ 'N','n','O','o','O','o','O','o','O','o', 
    /* 340 -> */ 'R','r','R','r','R','r','S','s','S','s', 
    /* 350 -> */ 'S','s','S','s','T','t','T','t','T','t', 
    /* 360 -> */ 'U','u','U','u','U','u','U','u','U','u', 
    /* 370 -> */ 'U','u','W','w','Y','y','Y','Z','z','Z', 
    /* 380 -> */ 'z','Z','z','S','?','?','?','?','?','?',
    /* 390 -> */ '?','?','?','?','?','?','?','?','?','S',
    /* 400 -> */ '?','?','f','?','?','?','?','?','?','?',
    /* 410 -> */ '?','?','?','?','?','O','o','?','?','?',
    /* 420 -> */ '?','?','?','?','?','?','?','?','?','?',
    /* 430 -> */ '?','U','u','?','?','?','?','?','?','?',
    /* 440 -> */ '?','?','?','?','?','?','?','?','?','?',
    /* 450 -> */ '?','?','?','?','?','?','?','?','?','?',
    /* 460 -> */ 'u','A','a','I','i','O','o','U','u','U',
    /* 470 -> */ 'u','U','u','U','u','U','u','?','?','?',
    /* 480 -> */ '?','?','?','?','?','?','?','?','?','?',
    /* 490 -> */ '?','?','?','?','?','?','?','?','?','?',
    /* 500 -> */ '?','?','?','?','?','?','A','a','A','a',
    /* 510 -> */ 'O','o'
);


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

// Check that a string contains only letters
function isAlphabetic(string, ignoreWhiteSpace) {
   if (string.search) {
      if ((ignoreWhiteSpace && string.search(/[^a-zA-Z\s]/) != -1) || (!ignoreWhiteSpace && string.search(/[^a-zA-Z]/) != -1)) return false;
   }
   return true;
}

// Check that a string contains only numbers
function isNumeric(string, ignoreWhiteSpace) {
   if (string.search) {
      if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
   }
   return true;
}

function getElementDimensions(el){
	for (var lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop) {
		if(el.offsetParent) el=el.offsetParent;
		else break;
	}
	return {x:lx,y:ly,w:el.offsetWidth,h:el.offsetHeight}
}

function replaceSpecialChars(str) {

	for(var countChar=0; countChar < str.length; countChar++) {
	
		var charCode = str.charCodeAt(countChar);
		
        if(charCode >= 192 && charCode < 192+specialToNonSpecialLetterMap.length) {

			str = str.substring(0, countChar) + specialToNonSpecialLetterMap[charCode-192] + str.substring(countChar+1);
		}
	}

	return str;
}

function escapeSpecialChars(str) {

	for(var countChar=0; countChar < str.length; countChar++) {
	
		var charCode = str.charCodeAt(countChar);
		
        if(charCode >= 192 && charCode < 192+specialToNonSpecialLetterMap.length) {

			str = str.substring(0, countChar) + '&#'+charCode+';' + str.substring(countChar+1);
		}
	}

	return str;
}

function decodeSpecialChars(str) {

	var indexOfEncodedChr = str.indexOf('&#');
	
	while(indexOfEncodedChr != -1) {
		
		var indexOfColon = str.indexOf(';', indexOfEncodedChr);
		
		if(indexOfColon == -1) return str;
		
		var charCode = str.substring(indexOfEncodedChr+2, indexOfColon);
		
		str = str.substring(0, indexOfEncodedChr) + String.fromCharCode(charCode) + str.substring(indexOfColon+1);
		
		indexOfEncodedChr = str.indexOf('&#');
	}
	
	return str;
}

function findChildrenByTagName (ele, tnm, foundChildren) {

	if(!foundChildren)
		foundChildren = new Array();

	if(ele) {
		if(ele.tagName == tnm) foundChildren[foundChildren.length] = ele;
		
		for(var countEle=0; countEle < ele.childNodes.length; countEle++) {

			findChildrenByTagName(ele.childNodes[countEle], tnm, foundChildren);
		}
	}
	
	return foundChildren;
}

function progressCursor() {
    if(document.all && document.designMode) {
	    document.all.waitCursorDiv.style.display = 'block';
	    document.all.waitCursorDiv.style.cursor = 'progress';
    }
}

function normalCursor() {
    if(document.all && document.designMode) {
	    document.all.waitCursorDiv.style.cursor = 'default';
	    document.all.waitCursorDiv.style.display = 'none';
    }
}

function trim(str) {
	return str.replace(/^\s*|\s*$/g,"")
}



