function disablesubmit (theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
		if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
		tempobj.disabled = true;
		}
	return true;
	}
	else {
		return false;
	}
}

function imgswp(name, newsrc)	{
	eval("document." + name + ".src = 'images/nav/" + newsrc + ".gif'");
	return false;
}

function imgswp2(name, newsrc)	{
	eval("document." + name + ".src = 'images/" + newsrc + "'");
	return false;
}

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
   
   //alert(temp);
   
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

function replaceSubstring2(argvalue, x, y) {
	alert('here!');
  if ((x == y) || (parseInt(y.indexOf(x)) > -1)) {
    errmessage = "replace function error: \n";
    errmessage += "Second argument and third argument could be the same ";
    errmessage += "or third argument contains second argument.\n";
    errmessage += "This will create an infinite loop as it's replaced globally.";
    alert(errmessage);
    return false;
  }
    
  while (argvalue.indexOf(x) != -1) {
    var leading = argvalue.substring(0, argvalue.indexOf(x));
    var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
	argvalue.length);
    argvalue = leading + y + trailing;
  }

//alert(argvalue);
  return argvalue;

}


function toggleVisibility(elementID) {
	foo=document.getElementById(elementID);
	if ((foo.style.display=='block') || ((foo.style.display==''))) {
		foo.style.display='none';
		}
	else	{
		foo.style.display='block';
		}
	return false;
}	

function unhideElement(elementID) {
	foo=document.getElementById(elementID);
	foo.style.display='block';
}

function hideElement(elementID) {
	foo=document.getElementById(elementID);
	foo.style.display='none';
}


function getXmlHttpObject() {
	try {
	  // Firefox, Opera 8.0+, Safari
	  return new XMLHttpRequest();
	  }
	catch (e) {
	  // Internet Explorer
	  try {
	    return new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e) {
	    try {
	      return new ActiveXObject("Microsoft.XMLHTTP");
	      }
	    catch (e) {
	      return false;
	      }
	    }
	 }
}


function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


//AJAX pings the page; doesn't wait for reply (none is needed)
function bannerClick(bannerGUID) {
	var xmlReq;
	var someURL;

	xmlReq=getXmlHttpObject();
  if (xmlReq) {
  	if ((document.domain=='192.168.1.163') || (document.domain=='talim'))
  		someURL='http://' + document.domain + ':45678/ob_bclick.asp?guid=' + bannerGUID;
  	else
  		someURL='http://' + document.domain + '/ob_bclick.asp?guid=' + bannerGUID;
  	
  	//alert(someURL);
		xmlReq.open("POST", someURL, true);
		xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		xmlReq.send("hello");
		//alert('bannerClick6: Request sent to ' + someURL);
		}
	else {
		//alert("bannerClick4: couldn't create XML req object");
	}
	//alert("bannerClick4: here 666");
	return true;
}


function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}