var AkamaiFlag="false";
var pthName = "/Images/";
var pthBrandName_MO = "MO_branding";
var pthBrandName_CC = "CC_branding";
var loc1 = "http://a323.g.akamai.net/7/323/1582/";
var loc2 = "https://a248.e.akamai.net/7/248/1582/";
var loc3 = "/www.getsmart.com";
var versionLen = 10;
var MO_brandLen = 11;

	function getImageName() {
		var prtcl = location.protocol;

		for (i = 0;i < document.images.length; i++) {
			imgName = document.images[i].name;
			if ((imgName == null) || (imgName.length == 0)) {
				continue;
			}

			/* 	
				Get the first 11 characters and check if it is brand name. 
				If so, eliminate the version number and add the path to brand name.
			*/

			BrandPath = imgName.substring(0,MO_brandLen);
			if ((BrandPath == pthBrandName_MO) || (BrandPath == pthBrandName_CC)) {
				datetimeVar = imgName.substring(MO_brandLen, versionLen + MO_brandLen);
				finalImgName = imgName.substring(versionLen + MO_brandLen)
				imgSrc = pthName + BrandPath + "/" + finalImgName;
			} else {
				datetimeVar = imgName.substring(0,versionLen);
				finalImgName = imgName.substring(versionLen)
				imgSrc = pthName + finalImgName;
			}

			locationName = ChangeHttpNames(datetimeVar);

			document.images[i].src = locationName + imgSrc;
		}
	}

	function ChangeHttpNames(version) {
		var prtcl = location.protocol;
		if (AkamaiFlag == "true") {	
			if (prtcl == "http:")
				PthBegin = loc1 + version + loc3;
			else
				PthBegin = loc2 + version + loc3;
		} else {
			PthBegin = "";
		}
		
		return PthBegin;
	}

	function replace(strvalue, strsearch, strreplace) {
		var strtemp;
		strtemp=strvalue.substring(0,strvalue.indexOf(strsearch))  + strreplace + strvalue.substring(strvalue.indexOf(strsearch)+ strsearch.length,strvalue.length);
		return strtemp;
	}

	function ChangePicAkamai(Name) {
		KeepVar = Name;
		versionName = Name.substring(0,versionLen);
		finalImgName = Name.substring(versionLen,Name.length);

		ChangeHttpNames(versionName);
		replacedName = replace(finalImgName, "-off.", "-on.");
		SwitchImg =  PthBegin + pthName + replacedName; 
		document.images[KeepVar].src=SwitchImg;
	} 

	function FixAkamai() {
		SwitchImg = PthBegin + pthName + finalImgName;
		document.images[KeepVar].src=SwitchImg;
	} 	
	
	window.onload = function(){getImageName();};


