var detect = navigator.userAgent.toLowerCase();
if (checkIt('msie') && !checkIt('opera')) { var strDisplay = "block"; } else { var strDisplay = "table-row"; }
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function ShowHideRows(RowID,Img) {
	var step1 = RowID.split(",");
	for (var i = 0; i < step1.length; i++) {
		if (document.getElementById(step1[i]).style.display == "" || document.getElementById(step1[i]).style.display == strDisplay || document.getElementById(step1[i]).style.display == null) {
			document.getElementById(step1[i]).style.display = "none";
			document.getElementById(Img).src = "../imagenes/hs-show.gif";
			DoCookie(hsPage,step1[i]+";");
		} else if (document.getElementById(step1[i]).style.display == "none") {
			document.getElementById(step1[i]).style.display = strDisplay;
			document.getElementById(Img).src = "../imagenes/hs-hide.gif";
			ClearCookie(hsPage,step1[i]+";");
		}
	}
}
function ShowHideAllRows(Action) {
	var rows = document.getElementsByTagName("TR");
	for (i = 0; i < rows.length; i++) {
		if (rows[i].id.indexOf('hs') == 0) {
			var step2 = rows[i].id.split("-");
			var step3 = step2[0].substring(2, step2[0].length);
			if (Action) {
					document.getElementById(rows[i].id).style.display = strDisplay;
					document.getElementById('hs-img'+step3).src = "../imagenes/hs-hide.gif";
					ClearCookie(hsPage,rows[i].id+";");
			} else {
					document.getElementById(rows[i].id).style.display = "none";
					document.getElementById('hs-img'+step3).src = "../imagenes/hs-show.gif";
					DoCookie(hsPage,rows[i].id+";");
			}
		}
	}
}
function ShowHideInics(Action) {
	var rows = document.getElementsByTagName("TR");
	for (c = 3; c < rows.length; c++) {
		if (rows[c].id.indexOf('hs') == 0) {
			var step2 = rows[c].id.split("-");
			var step3 = step2[0].substring(2, step2[0].length);
			if (Action) {
					document.getElementById(rows[c].id).style.display = strDisplay;
					document.getElementById('hs-img'+step3).src = "../imagenes/hs-hide.gif";
					ClearCookie(hsPage,rows[c].id+";");
			} else {
					document.getElementById(rows[c].id).style.display = "none";
					document.getElementById('hs-img'+step3).src = "../imagenes/hs-show.gif";
					DoCookie(hsPage,rows[c].id+";");
			}
		}
	}
}

function IsInCookie(Name,Value) {
	var cookie = GetCookie(Name);
	if (cookie != null) {
		if (cookie.indexOf(Value)) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
function DoCookie(Name,Value) {
	var cookie = GetCookie(Name);
	if (cookie != null) {
		if (!IsInCookie(Name,Value)) {
			SetCookie(Name,Value,exp);
		} else {
			SetCookie(Name,cookie + Value,exp);
		}
	} else {
		SetCookie(Name,Value,exp);
	}
}
function ClearCookie(Name,Value) {
	var cookie2 = GetCookie(Name);
	if (cookie2 != null) {
		var strCookie = replaceSubstring(cookie2,Value,"")
		SetCookie(Name,strCookie,exp);
	}
}

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

