function getElem(id) { return document.getElementById(id); }


//Link Description script- ?? Dynamic Drive (www.dynamicdrive.com)
//For full source code and TOS, visit http://www.dynamicdrive.com

//change link descriptions to your own. Extend as needed
var linktext=new Array()
		linktext[0]="Return to the WYSIweb home page&nbsp;"
		linktext[1]="WYSIweb Editor features and versions&nbsp;"
		linktext[2]="Try our demo and edit a web page in your browser!&nbsp;"
		linktext[3]="Edit your profile&nbsp;"
		linktext[4]="Special opportunities for Web Developers, ISPs and Software Vendors&nbsp;"
		linktext[5]="Contact us for Customer Support&nbsp;"

function show_text(thetext, whichdiv){
if (ie) eval("document.all."+whichdiv).innerHTML=linktext[thetext]
else if (ns6) getElem(whichdiv).innerHTML=linktext[thetext]
}

function reset(whichdiv){
	if (ie) { 
		eval("document.all."+whichdiv).innerHTML='&nbsp;'; 
	} else if (ns6) { 
		getElem(whichdiv).innerHTML='&nbsp;'; 
	}
}

function Start(page) {
OpenWin = window.open(page, "CtrlWindow", "width=562,height=430,menubar,directories,location,scrollbars,status,resizable,left=0,top=0,screenX=0,screenY=0");
}

function CheckWindows() {
	if (navigator.userAgent.indexOf("Windows") == -1 && navigator.userAgent.indexOf("Mac OS X") == -1) {
		document.write(' <span class="red">You do not appear to be using Windows or Mac OS X.</span>');
	}
}

function CheckCookies() {
	if (!navigator.cookieEnabled) {
		document.write(' <span class="red">Cookies appear to be disabled in your browser.</span>');
	}

}

function CheckIE() {
	ua = navigator.userAgent;
	ieOffset = ua.indexOf("MSIE ");
	version = parseFloat(ua.substring(ieOffset + 5, ua.indexOf(";", ieOffset)));
	if (ieOffset != -1) {
		var html = (version >= 6) ? '<span style="color:green;">' : '<span class="red">';
		document.write(html + ' You appear to be using IE version ' + version + '.</span> ');
	} else if (ua.indexOf("Gecko/20") != -1) {
		document.write(' <span style="color:green;">You appear to be using a Mozilla-based browser.</span>');
	} else {
		document.write(' <strong class="red">You do not appear to be using a supported browser.</strong>');
	}
}

function goBack(url,dontClose) {
	if (window.opener && opener != null && !opener.closed) {
		opener.location = url;
		opener.focus();
		if(!dontClose) self.close();
	} else {
		self.location = url;
	}
}

function changeFont(size) {
	ds = document.styleSheets[0];
	cssProperty = (ns6) ? "cssRules" : "rules";
	for (i=0; i<7; i++) {
		eval("oldsize = parseFloat(ds." + cssProperty + "[i].style.fontSize)");
		newsize = oldsize + size;
		if (newsize>0.1 && newsize<4) {
			eval("ds." + cssProperty + "[i].style.fontSize = '" + newsize + "em'");
		}
	}
		
}

function previewTemplate(direction, thumbs) {
	if (!template) return; //defined in jsp
	//storing abbr in option class
	var abbrev = template.options[template.selectedIndex].className;
	var max = tmpl[abbrev].length - 1;
	if (!tmpl[abbrev][max]) max--; //IE makes last value null instead of ignoring it (because of extra comma)
	colorIndex += direction;
	if (colorIndex < 0) colorIndex = max;
	if (colorIndex > max) colorIndex = 0;
	var next = colorIndex + 1;
	getElem("styleNo").innerHTML = next; 
	if (thumbs) {
		getFormElem("siteSettings.templateColor.id").value = tmpl[abbrev][colorIndex]; // start at 1 not zero
	} 
	var suffix = thumbs ? "_tn.jpg" : ".jpg";
	getElem("templateImage").src = "/templates/" + abbrev + "_" + tmpl[abbrev][colorIndex] + suffix;
	getElem("yourName").className = (abbrev=="pbg" || abbrev=="public03") ? "" : "hidden";
  	getElem("desc").innerHTML = template.options[template.selectedIndex].title + ".";
  	//precache next img
	if (next <= max) {
		var preload = new Image();
		preload.src = "/templates/" + abbrev + "_" + tmpl[abbrev][next] + suffix;
	}
}

function hasClass(object, className) {
	if (!object.className) return false;
	if (object.className == className) return true;
	return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
}

function getElementsWithClassName(el, cls, tag) {
	var allElements = el.getElementsByTagName(tag || "*") || document.all;
	var elemColl = new Array();
	for (var i = 0; i< allElements.length; i++) {
		if (hasClass(allElements[i], cls)) {
			elemColl[elemColl.length] = allElements[i];
		}
	}
	return elemColl;
}

var rxCurrencyFormat = /([0-9]+)([0-9]{3})/;

function formatCurr(num) {
  var str = "" + Math.abs(Math.round(num * 100));
  while (str.length < 3) { // need at least 3 chars, so add leading zeros
		str = "0" + str;
  }
  var decPoint = str.length - 2;
  str = (str.substring(0,decPoint) + "." + str.substring(decPoint,str.length));
  while(rxCurrencyFormat.test(str)) {
	str = str.replace(rxCurrencyFormat, '$1,$2');
  }
  return str;
}

var rxNotNumber = /[^\d]+/g;

function key(txt) {
	txt.value = txt.value.replace(rxNotNumber, "");
	if (window.event && event.keyCode == 9) { //IE only - for tabbing	
		setTimeout( function() { txt.select(); txt.focus(); }, 100 );
	} else {
		calc();
	}
}

function calc() {
	var f = getElem("calculator");
	var totalUsers = 0, total = 0, grandTotal = 0;
	for (var i=3; --i > -1;) {
		var users = parseInt(f.elements["users"][i].value, 10);
		if (isNaN(users) || users == 0) {
			f.elements["users"][i].value = "";
			getElem("total" + i).innerHTML = "";
			continue;
		}
		totalUsers += users;
		total = users * parseInt(getElem("rate" + i).innerHTML, 10);
		getElem("total" + i).innerHTML = formatCurr(total);
		grandTotal += total;
	}
	getElem("totalUsers").innerHTML = totalUsers;
	getElem("total3").innerHTML = formatCurr(grandTotal);
	var percent = 50;
	if (totalUsers < 100) percent = 40;
	if (totalUsers < 50) percent = 30;
	if (totalUsers < 25) percent = 20;
	if (totalUsers < 10) percent = 10;
	if (totalUsers < 5) percent = 0;
	var cell = getElementsWithClassName(getElem("calculator"), "percent", "TD");
	for (i = cell.length; --i > -1;) {
		users = f.elements["users"][i];
		if (users) users = users.value;
		cell[i].innerHTML = (users == "") ? "" : percent + "%";
		total = parseInt(getElem("total" + i).innerHTML.replace(",", ""), 10);
		if (isNaN(total)) total = 0;
		getElem("net" + i).innerHTML = (users == "") ? "" : formatCurr( (percent * total) / 100 );
	}
	getElem("net3").innerHTML = "$" + getElem("net3").innerHTML;
}

function popImg(url,title,w,h) { // overrides IE6 auto image resizing (at least, it used to)	
	sizeStr = (w) ? (",width=" + w + ",height=" + h) : "";
	newWindow = window.open("","","titlebar,resizable,status"+sizeStr);
	if (newWindow != null) {
	    html = "<html><head><title>"+title+"</title></head><body style='margin:0'>";
		html += '<img src="'+url+'" alt="">';
		//html += '<p align="right" style="font:13px arial,sans-serif;"><a href="javascript:self.close()">Close window</a>&nbsp;</p>';
		html += '</body></html>';
		newWindow.document.write(html);
		newWindow.document.close();
		newWindow.focus();
	}
	return false;
}

if (typeof brSetup == "function") {
    var gMenuStyles = new Array;
    window.onload = function () {
	    gMenuXoffset = 0;
	    gMenuXoffsetMac = 6;
	    gMenuYoffset = 17;
	    gMenuYoffsetMac = 1;
	    gMenuYoffsetIe5 = 15;
        gMenuStyles[0] = new Array("backgroundColor","#039","");
        gMenuStyles[1] = new Array("color","white","#039");
        brSetup();
        brFindEmails();
    };
}