/* 	File: 	 smdev.js
Authors: Various
Compiled by: Humberto Olarte Cupas
Company: sol media development
Description: smdev.js is a compilation of several javascript
funtions to provide a centralized environment with all the common
routines needed for website operation. It includes browser
detection, css loading, alternate text, popup windows,
email validation.

Some of the code included here was coded by other authors and
is so specified where needed.
*/
/****************************************************************/
//
// Browser detection Routines
//
/* ***********************************************************
** DETECT.JS - JS Browser/Version/Platform Detection Library
** =========================================================
** This library contains functions to detect/return the user's
** browser, version, and platform and to jump to a URL if
** the user is using a specified browser and/or version and/or
** platform. It's yours for free; please maintain this header!
**
** To load this library in an HTML doc, put the following
** line in the doc's HEAD (before any other SCRIPT tags):
**
** <SCRIPT SRC="detect.js" LANGUAGE="JavaScript"></SCRIPT>
**
** Author      Ver  Date    Comments
** ======      ===  ====    ========
** Rick Scott  1.0  1/1/00  First release
**
** Copyright 2000, Rick Scott, all rights reserved.
*********************************************************** */

/* ***********************************************************
** Functions
** =========
** getBrowser()
**   returns browser: "netscape", "ie", "other"
** getBrowserVer()
**   returns browser version number or "n/a"
** getPlatform()
**   returns browser OS: "mac", "win", "unix", "other"
** ifBVPjump(browser, version, platform, URL);
**   jumps to URL if user's browser, version, platform all
**   match the first three arguments
**   browser - "netscape", "ie", "other", "any"
**   version - "#.x", "#.#[#]", "any"
**             "#.x" matches any version #
**               ex: "4.x" matches 4.0, 4.05, 4.5, etc.
**             "#.#[#]" matches only version #.#[#]
**               ex: "4.05" matches 4.05, not 4.0, 4.5
**   platform - "mac", "win", "unix", "other", "any"
**   URL - relative or absolute URL
**   examples:
**     ifBVPjump("ie", "4.x", "win", "ie4winpage.html");
**       would jump to ie4winpage.html if the user's BVP
**       were IE, 4.x, Windows
**     ifBVPjump("IE", "4.x", "win", "ie4winpage.html");
**       wouldn't work because "ie" is case-sensitive
**    ifBVPjump("any", "any", "unix", "unixpage.html");
**       would jump to unixpage.html if user's P were UNIX
**     ifBVPjump("any", "any", "any", "index.html");
**       would jump to index.html regardless of user's BVP
** isNetscape()
**   returns true if Netscape, false if not
** isIE()
**   returns true if IE, false if not
** isVer3()
**   returns true if version is 3.x, false if not
** isVer4()
**   returns true if version is 4.x, false if not
** isVer4up()
**   returns true if version is 4.0+, false if not
**   this is a quick way to test for DHTML capability
** isVer5()
**   returns true if version is 5.x, false if not
** isMac()
**   returns true if OS is Mac, false if not
** isWin()
**   returns true if OS is Windows, false if not
** isUNIX()
**   returns true if OS is UNIX, false if not
*********************************************************** */

function getBrowser()  // get the browser program name
{
	if (navigator.appName == null || navigator.appName == "")
	return "other";
	else if (navigator.appName == "Netscape")
	return "netscape";
	else if (navigator.appName == "Microsoft Internet Explorer")
	return "ie";
	else
	return "other";
}

function isNetscape()  // is browser Netscape?
{
	if (getBrowser() == "netscape")
	return true;
	else
	return false;
}

function isIE()  // is browser IE?
{
	if (getBrowser() == "ie")
	return true;
	else
	return false;
}

function getBrowserVer()  // get the browser version
{
	if (navigator.appVersion == null || navigator.appVersion == "")
	return "n/a";
	// fix for IE 5.x appVersion bug, which returns 4.x instead of 5.x
	if (isIE() && navigator.userAgent.indexOf("5.") != -1)
	{
		var verNum = "";
		var str = navigator.userAgent;
		var pos = str.indexOf("IE ");  // real version num follows "IE "
		for (pos=pos+3; pos<str.length; pos++)  // build verNum string
		if (str.charAt(pos) == "." ||
		(str.charAt(pos) <= "9" && str.charAt(pos) >= "0"))
		verNum += str.charAt(pos);
		else
		break;
		return verNum;
	}
	var verArray = navigator.appVersion.split(" ");
	return verArray[0];
}

function isVer3()  // is browser version 3.x?
{
	if (getBrowserVer() >= 3.0 && getBrowserVer() < 4.0)
	return true;
	else
	return false;
}

function isVer4()  // is browser version 4.x?
{
	if (getBrowserVer() >= 4.0 && getBrowserVer() < 5.0)
	return true;
	else
	return false;
}

function isVer4up()  // is browser version 4.0+? (for DHTML coding)
{
	if (getBrowserVer() >= 4.0)
	return true;
	else
	return false;
}

function isVer5()  // is browser version 5.x?
{
	if (getBrowserVer() >= 5.0 && getBrowserVer() < 6.0)
	return true;
	else
	return false;
}

function getPlatform()  // get the browser platform (OS)
{
	if (navigator.platform == null || navigator.platform == "")
	return "other";
	else if (navigator.platform.indexOf("Mac") >= 0)
	return "mac";
	else if (navigator.platform.indexOf("Win") >= 0)
	return "win";
	else if (navigator.platform.indexOf("Unix") >= 0)
	return "unix";
	else
	return "other";
}

function isMac()  // is browser OS Mac?
{
	if (getPlatform() == "mac")
	return true;
	else
	return false;
}

function isWin()  // is browser OS Windows?
{
	if (getPlatform() == "win")
	return true;
	else
	return false;
}

function isUNIX()  // is browser OS UNIX?
{
	if (getPlatform() == "unix")
	return true;
	else
	return false;
}

function ifBVPjump(browser, version, platform, URL)
{
	// first make sure that version = user's browser version
	if (version.indexOf("x") != -1)  // version is in "#.x" format
	{
		if ((version.charAt(0) == "3") && (isVer3() == false))
		return;  // version's incorrect, return
		else if ((version.charAt(0) == "4") && (isVer4() == false))
		return;  // version's incorrect, return
		else if ((version.charAt(0) == "5") && (isVer5() == false))
		return;  // version's incorrect, return
	}
	else if (version.indexOf(".") != -1) // version is in #.#[#] format
	{
		if (version != getBrowserVer())
		return;  // version's incorrect, return to caller
	}
	// okay, version's correct, but what about browser/platform?
	if ( ((browser == getBrowser()) || (browser == "any"))
	&&
	((platform == getPlatform()) || (platform == "any")) )
	top.document.location.href = URL;  // BVP all correct, jump!
	else
	return;  // B and/or P incorrect, return
}

/***************************************************************************************/
//
/* CSS loading by Browser */
//
/***************************************************************
* This script loads a different CSS depending the platform and the browser
* It uses the detect.js v1.0 Library coded by Rick Scott (1/1/00)
*
* Feb 16, 2002
* Modified to redirect on old browsers (IE4, NS4 and worst)
*
* H. Olarte
* Nov 26, 2000
****************************************************************/
if (getPlatform() == "win") {
	if (isIE()) { document.write('<link rel="stylesheet" href="/main/styles/main_win.css" type="text/css">') }
	else if (isNetscape() && (getBrowserVer() <= 4.9)) { document.write('<link rel="stylesheet" href="/main/styles/main_nets4.css" type="text/css">')}
	else if (isNetscape() && (getBrowserVer() >= 5)) { document.write('<link rel="stylesheet" href="/main/styles/main_win.css" type="text/css">');
}
}
/*
if (getPlatform() == "mac") {
	if (isIE() && (getBrowserVer() <= 4.9)) { document.write('<link rel="stylesheet" href="/main/styles/main_mac.css" type="text/css">') }
	else if (isNetscape() && (getBrowserVer() <= 4.9)) { document.write('<link rel="stylesheet" href="/main/styles/nets4_mac.css" type="text/css">') }
	else if (isNetscape() && (getBrowserVer() >= 5)) { document.write('<link rel="stylesheet" href="/main/styles/main_mac.css" type="text/css">') }
}
*/
if (getPlatform() == "other") {document.write('<link rel="stylesheet" href="/main/styles/main_win.css" type="text/css">') }

/**********************************************************************************/
/***********************************************************************************/
//
// Popup Window script
//

//function NewWindow(mypage, myname, w, h, scroll) {
//	var winl = (screen.width - w) / 2;
//	var wint = (screen.height - h) / 2;
//	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
//	win = window.open(mypage, myname, winprops)
//	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
//}


function newWindow(url,name,features){
   var newWin = window.open(url,name,features);
}


/*********************************************************************************
Use Example for Popup script:
<a href="/about_us/nut_tables/nt_vanilla.html" onclick="NewWindow(this.href,'name','320','340','yes');return false;">
<img src="/main/images/facts_vanilla.jpg" width="160" height="140" border="0">
Vanilla</a>

**********************************************************************************/

//The following code converts TD to link:

function Arr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}
function Aba(src,clrIn) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}
function Cli(src) {
	if(event.srcElement.tagName=='TD'){
		src.children.tags('A')[0].click();
	}
}

//Ends TD convert

/*******************************************************************************
The following code creates and updated roman numeral for the copyright notice
********************************************************************************/
var date = new Date();
year = date.getYear();
year = year - 0;
if (year < 70) { year += 2000; }
if (year < 1000) { year +=1900; }

//var LMDate = new Date( document.lastModified );
//year = LMDate.getYear();
//year = year - 0;
//if (year < 70) { year += 2000; }
//if (year < 1000) { year +=1900; }

//function MyConvert(){
//temp  = document.romanguy.my_year.selectedIndex;
//temp2 = document.romanguy.my_year.options[temp].value;
//document.romanguy.yahoo.value = Roman(temp2);
//}

function Init() {
this.length = Init.arguments.length;
for ( var i = 0; i < this.length; i++ ) this[ i + 1 ] = Init.arguments[ i ];
}
function Roman(number) {
if (number < 1000) { alert(number+" is too small\nMinumum value is 1000"); number = 1; }
if (number > 5999) { alert(number+" it too big\nMaximum value is 5999"); number = 5999; }
var roman_unit = new Init("","I","II","III","IV","V","VI","VII","VIII","IX");
var roman_tens = new Init("","X","XX","XXX","XL","L","LX","LXX","LXXX","XC");
var roman_hund = new Init("","C","CC","CCC","CD","D","DC","DCC","DCCC","CM");
var roman_thou = new Init("","M","MM","MMM","MMMM","MMMMM");

var v = 0; var w = 0; var x = 0; var y = 0;
v = ((number - (number % 1000)) / 1000) + 1;
number = (number % 1000);
w = ((number - (number % 100)) / 100) + 1;
number = (number % 100);
x = ((number - (number % 10)) / 10) + 1;
y = (number % 10) + 1;
return (roman_thou[v] + roman_hund[w] + roman_tens[x] + roman_unit[y]);
}

/***********************************************************************************
The following goes wherever you need the roman year to appear:

<script language="JavaScript"><!-- document.write(Roman(year)) // --></script>

************************************************************************************/