//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}










function loadLanguageStyleSheet(){
    currentStartPosition = window.location.href.indexOf("language=");
    currentEndPosition = window.location.href.length;
  
    if(currentStartPosition > -1){
      part1 = window.location.href.substring(currentStartPosition + 9, currentEndPosition);
      //alert("part1: " + part1);
    }else{
      part1 = "US-EN"
    }
    
    //alert(part1);
    
    if(part1 == "US-ES"){
      document.write("<link REL='stylesheet' HREF='/css/lifemax_mila/spanish_lifemax_mila.css' TYPE='text/css'>");
      document.write("<script src='/js/lifemax_mila/content_nav_spanish.js' type='text/javascript' charset='utf-8'></script>");
      //alert("1");
    }else if(part1 == "CA"){
        document.write("<link REL='stylesheet' HREF='/css/lifemax_mila/canada_lifemax_mila.css' TYPE='text/css'>");
        document.write("<script src='/js/lifemax_mila/content_nav_canada.js' type='text/javascript' charset='utf-8'></script>");
    }else if(part1 == "PH"){
        document.write("<link REL='stylesheet' HREF='/css/lifemax_mila/philippines_lifemax_mila.css' TYPE='text/css'>");
        document.write("<script src='/js/lifemax_mila/content_nav_philippines.js' type='text/javascript' charset='utf-8'></script>");
    }else if(part1 == "JP"){
        document.write("<link REL='stylesheet' HREF='/css/lifemax_mila/japanese_lifemax_mila.css' TYPE='text/css'>");
        document.write("<script src='/js/lifemax_mila/content_nav_japanese.js' type='text/javascript' charset='utf-8'></script>");
    }else{
      document.write("<link REL='stylesheet' HREF='/css/lifemax_mila/lifemax_mila.css' TYPE='text/css'>");
      document.write("<script src='/js/lifemax_mila/content_nav.js' type='text/javascript' charset='utf-8'></script>");
      //alert("2");
    }
}







function setLanguage(action, language){
    //alert("Aw Yeah!");

    var pageUrl = window.location.href;
    var currentStartPosition = 0;
    var currentEndPosition = 0;
    var part1 = "";
    var part2 = "";
    var part3 = "";

    if(action == 'update'){
      
      if(pageUrl.indexOf("language=") > -1){ //Query language value alread there
      
        currentStartPosition = pageUrl.indexOf("language=");
        currentEndPosition = pageUrl.length;
      
        //part1 = pageUrl.i
      
        part1 = pageUrl.substring(0, currentStartPosition + 9);
        part2 = document.getElementById("oLanguage").value;
        
        //alert(part1);
        //alert(part2);
        
        
        //window.location.reload();
        
        
        //alert(pageUrl.substring(currentStartPosition + 10, currentEndPosition));
      }else{ //Querystring there
        
        if(pageUrl.indexOf("?") > -1){ //Querystring there
            part1 = pageUrl;
            part2 = "&language=" + document.getElementById("oLanguage").value;
        }else{ // Querystring not there
            part1 = pageUrl;
            part2 = "?language=" + document.getElementById("oLanguage").value;
        }
        
      }
      
      
      
      //alert(pageUrl);
      //alert("part1: " + part1);
      //alert("part2: " + part2);
      
      
      //alert("Fart");
      
      
      
      
  
      
      
      
      
      
      
      //alert(document.getElementById("main-nav-US-EN").style.background);
      //document.getElementById("main-nav-US-EN").style.background = "url('/images/lifemax_mila/es/nav_bg.png') no-repeat";
      //document.getElementById("main-nav-US-EN").style.height = "20px";
 
      
      //alert(pageUrl);
      
    }

    if(action == "update"){ // If the dropdown value changed then update the currentLanguage with the new language.
       currentLanguage = document.getElementById("oLanguage").value;
       window.location = part1 + part2; // Reload the page with the new querystring.
        return;
    }else{ // Otherwise set put the querystring value in.
       currentLanguage = getQueryStringValue("language");
    }

    //alert(currentLanguage);

    if(!currentLanguage){ // If there is no language value set still then set it equal to the current dropdown box value (this happens upon initial page load).
      //alert("No language");
      currentLanguage = document.getElementById("oLanguage").value;
    }else{ // Otherwise set the dropdown box equal to the language set above.
        document.getElementById("oLanguage").value = currentLanguage;
    }

    // Change the menu and content appropriate to each language.
    modifyContent(document.getElementById("main-nav").innerHTML, currentLanguage);


}









function getQueryStringValue(passedInValue){
    queryString = window.location.search.substring(1);
    arrQueryStringValues = queryString.split("&");
    //alert(arrQueryStringValues);

    for(i=0; i < arrQueryStringValues.length; i++){
      currentValue = arrQueryStringValues[i].split("=");
      //alert(currentValue);
      if(currentValue[0] == passedInValue){
        return currentValue[1];
      }
    }
}

function modifyContent(menuString, currentLanguage){

    //alert(currentLanguage);

    //alert(menuString);
    //alert(menuString.indexOf("menu"));
    
    var currentFoundPosition = menuString.indexOf("menu-"); // Start off with first occurence for if check below.
    var currentFoundEndPosition = 0;
    var lastFoundPosition = 0;
    var currentMenuItem = "";
    var currentMenuHTML = "";
    var aspPosition = 0;
    var htmlPosition = 0;
    var usedPosition = 0;
    
    var pathPart1 = "";
    var pathPart2 = "";
    var pathPart3 = "";
    var pathPart2Temp1 = "";
    var pathPart2Temp2 = ""
    var modifiedPath = "";
   
    if(currentFoundPosition > 0){ // We have something so now lets parse it.
 
        while(currentFoundPosition > 0){ // Loop through the menu string as long as we are still finding menu items.
            
            currentFoundPosition = menuString.indexOf("menu-", lastFoundPosition);
            
            if(lastFoundPosition > currentFoundPosition){ // If there are no more to find then we're done.
                //alert("Break");
                break;
            }else{ // Otherwise, keep searching
                currentFoundEndPosition = menuString.indexOf('\"', currentFoundPosition); // Find the menu item end (where the dq is)
        
                //alert(currentFoundPosition);
                //alert(currentFoundEndPosition);
                //alert(menuString);
                currentMenuItem = menuString.substring(currentFoundPosition, currentFoundEndPosition);
                //alert(currentMenuItem);
                currentMenuHTML = document.getElementById(currentMenuItem).innerHTML;
                //break;
                //alert(currentMenuItem);
                //alert("error: " + currentMenuHTML);
                
                // Manipulate the url and add the language value
                if(currentMenuHTML.indexOf("?") < 1){ // If there isn't a querystring value then add the question mark
                    //alert("No querystring values.");
                    //alert("lastFoundPosition: " + lastFoundPosition + " " + "currentFoundPosition: " + currentFoundPosition);
                    //currentMenuHTML
                    
                    aspPosition = currentMenuHTML.indexOf(".asp");
                    htmlPosition = currentMenuHTML.indexOf(".html");
                    
                    if(aspPosition > -1){ // Local testing
                    
                        // This will never be the case because there will always be the filename= querystring value when testing locally.
                        
                    }else if(htmlPosition > -1){ // Server testing
                        //alert(currentMenuHTML);
                        
                        pathPart1 = currentMenuHTML.substring(0, htmlPosition + 5);
                        //alert(pathPart1);
                        pathPart2 = "?language=" + currentLanguage; // Part to add quertystring value to.
                        //alert(pathPart2);
                        pathPart3 = currentMenuHTML.substring(currentMenuHTML.indexOf('\"', htmlPosition), currentMenuHTML.length);
                        //alert(pathPart3);
                        
                        modifiedPath = pathPart1 + pathPart2 + pathPart3;
                        document.getElementById(currentMenuItem).innerHTML = modifiedPath;
                        //alert(document.getElementById(currentMenuItem).innerHTML);
                        //break;
                    }
                    
                    
                }else{ // Otherwise add the ampersand
                
                    aspPosition = currentMenuHTML.indexOf(".asp");
                    htmlPosition = currentMenuHTML.indexOf(".html");
                
                    if(currentMenuHTML.indexOf("language") > -1){
                        // Modify the language value that's already there
                        
                        if(aspPosition > -1){ // Local testing
                        
                            pathPart1 = currentMenuHTML.substring(0, aspPosition + 4);
                            //alert(pathPart1);
                            pathPart2 = currentMenuHTML.substring(aspPosition + 4, currentMenuHTML.indexOf('\"', aspPosition)); // Part to add quertystring value to.
                            //pathPart2 = pathPart2 + "&language=" + currentLanguage;
                            
                            ///////
                            // Need to parse out language part form pathPart2 above and replace it with the new language
                            //alert(pathPart2);
                            pathPart2Temp1 = pathPart2.substring(0, pathPart2.indexOf("language=") + 9)
                            //alert(pathPart2Temp1);
                            //pathPart2Temp2 = pathPart2.substring(pathPart2.indexOf("language=") + 9, pathPart2.length)
                            pathPart2Temp2 = currentLanguage;
                            //alert(pathPart2Temp2); 
                            pathPart2 = pathPart2Temp1 + pathPart2Temp2;
                            ////////
                            
                            
                            pathPart3 = currentMenuHTML.substring(currentMenuHTML.indexOf('\"', aspPosition), currentMenuHTML.length);
                            //alert(pathPart3);
                            
                            modifiedPath = pathPart1 + pathPart2 + pathPart3;
                            //alert(modifiedPath);
                            document.getElementById(currentMenuItem).innerHTML = modifiedPath;
                            //alert(document.getElementById(currentMenuItem).innerHTML);
                            //break;
                            
                        }else if(htmlPosition > -1){ // Server testing
                        
                            pathPart1 = currentMenuHTML.substring(0, htmlPosition + 5);
                            //alert(pathPart1);
                            pathPart2 = currentMenuHTML.substring(htmlPosition + 5, currentMenuHTML.indexOf('\"', htmlPosition)); // Part to add quertystring value to.
                            //pathPart2 = pathPart2 + "&language=" + currentLanguage;
                            
                            ///////
                            // Need to parse out language part form pathPart2 above and replace it with the new language
                            //alert(pathPart2);
                            pathPart2Temp1 = pathPart2.substring(0, pathPart2.indexOf("language=") + 9)
                            //alert(pathPart2Temp1);
                            //pathPart2Temp2 = pathPart2.substring(pathPart2.indexOf("language=") + 9, pathPart2.length)
                            pathPart2Temp2 = currentLanguage;
                            //alert(pathPart2Temp2); 
                            pathPart2 = pathPart2Temp1 + pathPart2Temp2;
                            ////////
                            
                            
                            pathPart3 = currentMenuHTML.substring(currentMenuHTML.indexOf('\"', htmlPosition), currentMenuHTML.length);
                            //alert(pathPart3);
                            
                            modifiedPath = pathPart1 + pathPart2 + pathPart3;
                            //alert(modifiedPath);
                            document.getElementById(currentMenuItem).innerHTML = modifiedPath;
                            //alert(document.getElementById(currentMenuItem).innerHTML);
                            //break;
                        }
                        
                    }else{ // Add the language value
                        
                        
                        if(aspPosition > -1){ // Local testing
                        
                            pathPart1 = currentMenuHTML.substring(0, aspPosition + 4);
                            //alert(pathPart1);
                            pathPart2 = currentMenuHTML.substring(aspPosition + 4, currentMenuHTML.indexOf('\"', aspPosition)); // Part to add quertystring value to.
                            pathPart2 = pathPart2 + "&language=" + currentLanguage;
                            //alert(pathPart2);
                            pathPart3 = currentMenuHTML.substring(currentMenuHTML.indexOf('\"', aspPosition), currentMenuHTML.length);
                            //alert(pathPart3);
                            
                            modifiedPath = pathPart1 + pathPart2 + pathPart3;
                            document.getElementById(currentMenuItem).innerHTML = modifiedPath;
                            //alert(document.getElementById(currentMenuItem).innerHTML);
                            //break;
                            
                        }else if(htmlPosition > -1){ // Server testing
                            alert("HIT");
                        }
                    }
                }
                //
                
                lastFoundPosition = currentFoundEndPosition + 1;
                //alert(lastFoundPosition);
            }
        }  
    }
    
    // Change the displaying text and images to match the language selected.
    changeHomeSWF(); // This should probably only be called if your on the home page but due to time constraints I'm going to leave this here.
    changeSubMenus(currentLanguage);
    changeBodyContent();
    changeImages(currentLanguage);
}

function changeHomeSWF(){
    
    var filePath = "";
    var gatewayURL = "";

      if(currentLanguage == "US-EN"){
        filePath = "/site-media/swf/en/Lifemax.en.swf";
        gatewayURL = "http://www.lifemax.net/en/gateway/";
      }else if(currentLanguage == "US-ES"){
        filePath = "/site-media/swf/es/Lifemax.es.swf";
        gatewayURL = "http://www.lifemax.net/es/gateway/";
      }else if(currentLanguage == "PH"){
        filePath = "/site-media/swf/ph/Lifemax.ph.swf";
        gatewayURL = "http://www.lifemax.net/en/gateway/";
      }else if(currentLanguage == "CA"){
        filePath = "/site-media/swf/ca/Lifemax.ca.swf";
        gatewayURL = "http://www.lifemax.net/en/gateway/";
      }else if(currentLanguage == "JP"){
        filePath = "/site-media/swf/en/Lifemax.en.swf";
        gatewayURL = "http://www.lifemax.net/en/gateway/";
      }

      //alert(filePath);


      var flashvars = {
        gateway_url: gatewayURL,
        BASE_DIRECTORY: "",
        SWF_LOCATION: ""
      };
      
      var params = {
        allowscriptaccess: "always",
        wmode: "transparent"
      };
      
      var attributes = {};
      swfobject.embedSWF(filePath, "flash-content", "950", "556", "9.0.115.0", "/site-media/swf/expressInstall.swf", flashvars, params, attributes);
}



function replaceAll(txt, replace, with_this) {
  return txt.replace(new RegExp(replace, 'g'),with_this);
}


function changeSubMenus(currentLanguage){

    var subMenuString = document.getElementById("main-nav").innerHTML;
    // Replace any capitalized source HTML tags with lowercased tags so that IE will work.
    subMenuString = replaceAll(subMenuString, "<A href", "<a href");
    subMenuString = replaceAll(subMenuString, "</A>", "</a>");
    subMenuString = replaceAll(subMenuString, "<DIV", "<div");
    subMenuString = replaceAll(subMenuString, "</DIV", "</div");
    subMenuString = replaceAll(subMenuString, "<LI>", "<li>");
    subMenuString = replaceAll(subMenuString, "</LI>", "</li>");
    
    //alert(subMenuString);
    
    
    var currentFoundPosition = subMenuString.indexOf("<a href"); // Start off with first occurence for if check below.        
    var lastFoundPosition = 0;
    var currentFoundEndPosition = 0;
    var currentSubMenuItem = "";
    var currentSubMenuHTML = "";
    var part1 = "";
    var part2 = "";
    var part3 = "";
    var newSubMenuHTML = "";
    
    //subMenuString = subMenuString.toLowerCase();
    //alert(subMenuString.indexOf('<div id=\"menu-mila video mila video'));

    // Remove mila vide and testimonials if Canada
    if(currentLanguage == "CA"){
        var milaVideoStartPosition = subMenuString.indexOf('<div id=\"menu-mila video mila video'); 
        var endDivPosition = 0;
        var divToRemove = "";
        
        if(milaVideoStartPosition > 0){
            milaVideoStartPosition = subMenuString.indexOf("<li>", milaVideoStartPosition - 10);
            
            endDivPosition = subMenuString.indexOf("</li>", milaVideoStartPosition); 
 
            part1 = subMenuString.substring(0, milaVideoStartPosition);
            part2 = subMenuString.substring(endDivPosition + 5, subMenuString.length);
            subMenuString = part1 + part2;
            //alert(subMenuString);
            //alert(part1);
            //alert(part2);
            
            
        }
        
       // return;
        
        var testimonialsStartPosition = subMenuString.indexOf('<div id=\"menu-testimonials testimonials');
        
        if(testimonialsStartPosition > 0){
            testimonialsStartPosition = subMenuString.indexOf("<li>", testimonialsStartPosition - 10);
            
            endDivPosition = subMenuString.indexOf("</li>", testimonialsStartPosition);
            //alert("start: " + milaVideoStartPosition + " end: " + endDivPosition);
            
            part1 = subMenuString.substring(0, testimonialsStartPosition);
            part2 = subMenuString.substring(endDivPosition + 5, subMenuString.length);
            subMenuString = part1 + part2;
            //alert(part1);
            //alert(part2);
            
            //alert(subMenuString);
        }
    }
    
    //return;
    
    //alert(subMenuString.indexOf('<DIV id=\"menu-mila video mila video'));
    
    //alert('<DIV id=\"menu-mila video mila video');
    
    //alert(currentFoundPosition);
    
    
    if(currentFoundPosition > 0){ // We have something so now lets parse it.
 
        while(currentFoundPosition > 0){ // Loop through the menu string as long as we are still finding menu items.
            
            currentFoundPosition = subMenuString.indexOf("<a href", lastFoundPosition);
            
            if(lastFoundPosition > currentFoundPosition){ // If there are no more to find then we're done.
        
                newSubMenuHTML = newSubMenuHTML + subMenuString.substring(lastFoundPosition - 1, subMenuString.length);
                document.getElementById("main-nav").innerHTML = newSubMenuHTML;
                //alert(newSubMenuHTML);
                
                break;
            }else{ // Otherwise, keep searching
                //alert(currentFoundPosition);
                
                currentFoundPosition = subMenuString.indexOf(">", currentFoundPosition); // Find the menu item end (where the dq is)
                newSubMenuHTML = newSubMenuHTML + subMenuString.substring(lastFoundPosition - 1, currentFoundPosition + 1);
                currentFoundEndPosition = subMenuString.indexOf("<", currentFoundPosition);
                currentSubMenuItem = subMenuString.substring(currentFoundPosition + 1, currentFoundEndPosition);
                
                
                
                // Check for spanish and replace the sub menu items
                if(currentLanguage == "US-ES"){
                   if(currentSubMenuItem == "mila video"){
                      currentSubMenuItem = "video de mila";
                   }else if(currentSubMenuItem == "testimonials"){
                      currentSubMenuItem = "testimonios"; 
                   }else if(currentSubMenuItem == "news"){
                      currentSubMenuItem = "notica";
                   }else if(currentSubMenuItem == "our mission"){
                      currentSubMenuItem = "nuestra misi&oacute;n";
                   }else if(currentSubMenuItem == "our story"){
                      currentSubMenuItem = "nuestra historia";
                   }else if(currentSubMenuItem == "world vision"){
                      currentSubMenuItem = "visi&oacute;n global";
                   }else if(currentSubMenuItem == "company bios"){
                      currentSubMenuItem = "biograf&iacute;as";
                   }else if(currentSubMenuItem == "contact us"){
                      currentSubMenuItem = "contactenos";
                   }else if(currentSubMenuItem == "my story"){
                      currentSubMenuItem = "mi historia";
                   }else if(currentSubMenuItem == "contact me"){
                      currentSubMenuItem = "contacto";
                   }else if(currentSubMenuItem == "overview"){
                      currentSubMenuItem = "visi&oacute;n general";
                   }else if(currentSubMenuItem == "compensation plan"){
                      currentSubMenuItem = "plan de compensaci&oacute;n";
                   }else if(currentSubMenuItem == "opportunity video"){
                      currentSubMenuItem = "video de oportunidad";
                   }else if(currentSubMenuItem == "events"){
                      currentSubMenuItem = "eventos";
                   }else if(currentSubMenuItem == "webinars"){
                      currentSubMenuItem = "seminarios en web";
                   }
                }else if(currentLanguage == "JP"){
                   if(currentSubMenuItem == "mila video"){
                      currentSubMenuItem = "mila video";
                   }else if(currentSubMenuItem == "testimonials"){
                      currentSubMenuItem = "testimonials"; 
                   }else if(currentSubMenuItem == "news"){
                      currentSubMenuItem = "news";
                   }else if(currentSubMenuItem == "our mission"){
                      currentSubMenuItem = "our mission";
                   }else if(currentSubMenuItem == "our story"){
                      currentSubMenuItem = "our story";
                   }else if(currentSubMenuItem == "world vision"){
                      currentSubMenuItem = "world vision";
                   }else if(currentSubMenuItem == "company bios"){
                      currentSubMenuItem = "company bios";
                   }else if(currentSubMenuItem == "contact us"){
                      currentSubMenuItem = "contact us";
                   }else if(currentSubMenuItem == "my story"){
                      currentSubMenuItem = "my story";
                   }else if(currentSubMenuItem == "contact me"){
                      currentSubMenuItem = "contact me";
                   }else if(currentSubMenuItem == "overview"){
                      currentSubMenuItem = "overview";
                   }else if(currentSubMenuItem == "compensation plan"){
                      currentSubMenuItem = "compensation plan";
                   }else if(currentSubMenuItem == "opportunity video"){
                      currentSubMenuItem = "opportunity video";
                   }else if(currentSubMenuItem == "events"){
                      currentSubMenuItem = "events";
                   }else if(currentSubMenuItem == "webinars"){
                      currentSubMenuItem = "webinars";
                   }
                }
                
                newSubMenuHTML = newSubMenuHTML + currentSubMenuItem;
                lastFoundPosition = currentFoundEndPosition + 1;   
                
                             
            }
        }
    }
}

function changeImages(currentLanguage){
    
    var pageContent = document.getElementById("wrap").innerHTML;
    var currentFoundPosition = pageContent.indexOf("main-nav=" + currentLanguage); // Start off with first occurence for if check below.
    var currentFoundEndPosition = 0;
    var lastFoundPosition = 0;
    var currentItem = "";
    var currentMenuHTML = "";
    var aspPosition = 0;
    var htmlPosition = 0;
    var usedPosition = 0;
    
    var part1 = "";
    var part2 = "";
    var part3 = "";
    var pathPart2Temp1 = "";
    var pathPart2Temp2 = ""
    var modifiedPath = "";
   
    if(currentFoundPosition > 0){ // We have something so now lets parse it.
 
        //alert(currentFoundPosition);
        currentFoundEndPosition = pageContent.indexOf('\"', currentFoundPosition); // Find the menu item end (where the dq is)
        //alert(currentFoundEndPosition);
        currentItem = pageContent.substring(currentFoundPosition, currentFoundEndPosition);
        //alert(currentMenuItem);
        
        part1 = pageContent.substring(0, currentFoundPosition);
        part2 = currentItem + "-" + currentLanguage;
        part3 = pageContent.substring(currentFoundEndPosition, pageContent.length);
        //alert(part1);
        //alert(part2);
        //alert(part3);
        
        document.getElementById("wrap").innerHTML = part1 + part2 + part3;
        
        //currentMenuHTML = document.getElementById(currentMenuItem).innerHTML;
       
    }
    
}

function changeBodyContent(){
    
     // Build a list of all availabe languages in the dropdown box.
    var languageList = document.getElementById("oLanguage");
    var currentLanguageCode = "";
    
    for(var i = 0; i < languageList.options.length; i++){
      //alert(languageList.options[i].value); 
      currentLanguageCode = languageList.options[i].value;
      
      if(currentLanguage != currentLanguageCode){ // Hide the other language content blocks because they're not the one selected.
        hideShowLanguageContent("none", currentLanguageCode);
      }else{ // Show
        hideShowLanguageContent("block", currentLanguageCode);        
      }
    }
}

function hideShowLanguageContent(action, currentLanguageCode){
    
    //alert("action: " + action + " " + "currentLanguageCode: " + currentLanguageCode);
    
    var pageContent = document.getElementById("languageContent").innerHTML;
    var currentFoundPosition = 0;
    var currentFoundEndPosition = 0;
    var lastFoundPosition = 0;
    var currentDiv = "";
    var currentDivHTML = ""
    
    //document.getElementById(currentLanguageCode + "-1").style.display = "none";
    currentFoundPosition = pageContent.indexOf('id=\"' + currentLanguageCode); // Start off with first occurence for if check below.
    
    //alert("currentFoundPosition: " + currentFoundPosition);
    //alert('id=\"' + currentLanguageCode);
    //alert(pageContent);
    
    if(currentFoundPosition > 0){ // We have something so now lets parse it.

        while(currentFoundPosition > 0){ // Loop through the page content string as long as we are still finding matching items.
            
            
            currentFoundPosition = pageContent.indexOf('id=\"' + currentLanguageCode, lastFoundPosition);
            
            if(lastFoundPosition > currentFoundPosition){ // If there are no more to find then we're done.
                //alert("Break");
                break;
            }else{ // Otherwise, keep searching
            
                //alert("Yo");
                currentFoundEndPosition = pageContent.indexOf('\"', currentFoundPosition + 4); // Find the menu item end (where the dq is)
                //alert("Hey");
                currentDiv = pageContent.substring(currentFoundPosition + 4, currentFoundEndPosition);
                //alert("currentDiv: " + currentDiv);
                
                //alert(document.getElementById(currentDiv));
                document.getElementById(currentDiv).style.display = action;
            }
            
            lastFoundPosition = currentFoundEndPosition + 1;
            //alert("lastFoundPosition: " + lastFoundPosition);
            //break;       
        }
    }
}