// rollover code
roll = new csRoll();
function csRoll(overSuffix, outSuffix){
	this.overSuffix = "_over";
	this.outSuffix = "_out";
	this.images = new Object()
	this.initialized = false;
}
csRoll.prototype.over = function csRollOver(imgName) { if (this.initialized) this.images[imgName].over(); }
csRoll.prototype.out = function csRollOut(imgName) { if (this.initialized) this.images[imgName].out(); }
csRoll.prototype.init = csRollInit;
function csRollInit(){
	var imgs = document.getElementsByTagName("img");
	for(var i = 0; i < imgs.length; i++) this.mapImage(imgs[i]);
	this.initialized = true;
}
csRoll.prototype.mapImage = csRollMapImage;
function csRollMapImage(img){
	if(img.name.indexOf("_ROLL") != -1)
		this.images[img.name.substr(0,img.name.lastIndexOf("_"))] = new csRollImage(img, this.overSuffix, this.outSuffix);
}
function csRollImage(img, overSuffix, outSuffix){
	this.img = img;
	this.baseSuffix = this.img.src.substr(this.img.src.lastIndexOf("."));
	var baseSrc = this.img.src.substr(0,this.img.src.lastIndexOf("_"));
	this.overSrc = baseSrc + overSuffix + this.baseSuffix;
	this.outSrc = baseSrc + outSuffix + this.baseSuffix;
	this.preloadOver = new Image(); 
	this.preloadOver.src = this.overSrc; 
	this.preloadOut = new Image();
	this.preloadOut.src = this.outSrc;
}
csRollImage.prototype.over = function csRollImageOver() { this.img.src = this.preloadOver.src; }
csRollImage.prototype.out = function csRollImageOut() {	this.img.src = this.preloadOut.src; }

//popup
function popLargeImage(sImage) {
	wLargeImage = new csWin("pop_image.asp?img=" + sImage, "Cipherlab", 550, 450);
}
function popAccessory(sCaption, sImage, sCopy) {
	wAccessory = new csWin("pop_accessory.asp?copy=" + sCopy + "&image=" + sImage + "&caption=" + sCaption, "Cipherlab", 270, 450, 1);
}
function popDetails(sID) {
	wDetails = new csWin("document.asp?id=" + sID, "Cipherlab", 650, 300, 1);
}
function popDownload(sID) {
	wDetails = new csWin("document.asp?id=" + sID, "Cipherlab", 650, 320, 1);
}
function replace(s, find, replacement) {
	return(s.replace(find, replacement));
}

function csWin(popUrl,popName,w,h,scrollbars,x,y,toolbar,menubar,resizable,status,directories){
	this.popUrl = popUrl;
	this.popName = popName;
	this.w = w ? w : screen.width;
	this.h = h ? h : screen.height;
	this.scrollbars = scrollbars ? scrollbars : 0;
	this.toolbar = toolbar ? toolbar : 0;
	this.menubar = menubar ? menubar : 0;
	this.resizable = resizable ? resizable : 0;
	this.status = status ? status : 0;
	this.directories = directories ? directories : 0;
	var winl = x ? x : ((screen.width - this.w) / 2);
	var wint = y ? y : ((screen.height - this.h) / 2);
	if (wint < 0) wint = 1;
	if (winl < 0) winl = 0;
	this.popWin = window.open(
		this.popUrl,
		this.popName,
		"top=" + wint + "," +
		"left=" + winl + "," +
		"toolbar=" + this.toolbar.toString() + "," +
		"directories=" + this.directories.toString() + "," +
		"status=" + this.status.toString() + "," +
		"menubar=" + this.menubar.toString() + "," +
		"scrollbars=" + this.scrollbars.toString() + "," +
		"resizable=" + this.resizable.toString() + "," +
		"width=" + this.w.toString() + "," +
		"height=" + this.h.toString()
	);
}
// form validation
function validateAccountInformation() {
	var bFormOK = true;
	if (checkString("First Name", "firstname", bFormOK)) bFormOK = false;
	if (checkString("Last Name", "lastname", bFormOK)) bFormOK = false;
	if (checkString("Company", "company", bFormOK)) bFormOK = false;
	if (bFormOK) document.frmThis.submit();
}
function validateForm() {
	var bFormOK = true;
	if (checkString("Name", "fldName", bFormOK)) bFormOK = false;
	if (checkString("Email", "fldEmail", bFormOK, true)) bFormOK = false;
	if (checkString("Phone", "fldPhone", bFormOK)) bFormOK = false;
	if (checkString("Evening Phone", "fldEvePhone", bFormOK, true)) bFormOK = false;
	if (checkString("Fax", "fldFax", bFormOK, true)) bFormOK = false;
	if (checkString("Address 1", "fldAddress1", bFormOK)) bFormOK = false;
	if (checkString("Address 2", "fldAddress2", bFormOK, true)) bFormOK = false;
	if (checkString("City", "fldCity", bFormOK)) bFormOK = false;
	if (checkString("State", "fldState", bFormOK)) bFormOK = false;
	if (checkString("Zip", "fldZip", bFormOK)) bFormOK = false;
	if (checkString("Country", "fldCountry", bFormOK, true)) bFormOK = false;
	if (checkString("Message", "fldMessage", bFormOK, true)) bFormOK = false;
	if (document.frmThis.fldBestTime.value == "0" && bFormOK) {
		alert("Please select best time to call");
		bFormOK = false;
	}
	if (bFormOK)
		document.frmThis.submit();
}
// form validation functions
function checkString(sFieldText, sFieldName, bFormOK, bBlankOK) {
	if (bFormOK) {
		if (hasScript(eval("document.frmThis." + sFieldName).value)) {
			alert(sFieldText + " contains illegal script text\nthat can cause problems with your information");
			eval("document.frmThis." + sFieldName).focus();
			return true;
		} else {
			if (!bBlankOK && isWhitespace(eval("document.frmThis." + sFieldName).value)) {
				alert(sFieldText + " is required");
				eval("document.frmThis." + sFieldName).focus();
				return true;
			} else {
				return false;
			}
		}
	}
	return false;
}
var sWhitespace = " \t\n\r";

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (sWhitespace.indexOf(c) == -1) return false;
	}
	return true;
}
function hasScript (inString) {
	var tmpString = stripWhitespace(inString).toUpperCase();
	if (tmpString.indexOf("<" + "SCRIPT") != -1) return true;
	if (tmpString.indexOf("<" + "/" + "SCRIPT") != -1) return true;
	if (tmpString.indexOf("<" + "%") != -1) return true;
	if (tmpString.indexOf("%" + ">") != -1) return true;
	if (tmpString.indexOf("<" + "?") != -1) return true;
	if (tmpString.indexOf("php" + ">") != -1) return true;
	if (tmpString.indexOf("language=") != -1) return true;
	return false;
}
function stripWhitespace (s) {
	return stripCharsInBag (s, sWhitespace);
}
function stripCharsInBag (s, bag){
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}
function isInteger (s){
	var i;
	if (isEmpty(s))
		if (isInteger.arguments.length == 1) return defaultEmptyOK;
		else return (isInteger.arguments[1] == true);
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	return true;
}
function isDigit (c){
	return (((c >= "0") && (c <= "9")) || c == ".");
}

// used on product page only
function init() {
  if (document.body.clientWidth < 1000) {
    document.body.style.width = "1000px";
  }
  if (document.body.clientWidth > 1100) {
    document.body.style.width = "auto";
  }
}

function toggleSearchResults(div) {
	if (document.getElementById(div)) {
		div = document.getElementById(div);
		if (div.style.display != 'none') {
			div.style.display = 'none';
		}
		else {
			div.style.display = 'block';
		}
	}
}