

//****************************************************
// IsMac
//****************************************************
function InsertQuickTimeMovie()
{
document.write("<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width='320' height='240' CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>\n");
document.write("<param name='src' value='http://www.minisage.com/nirh/videos/nirh_web_small.mov' />\n");
document.write("<param name='autoplay' value='true'>\n");
document.write("<param name='loop' value='false'>\n");
document.write("<param name='controller' value='true'>\n");
document.write("</object>\n");
}


//****************************************************
// IsMac
//****************************************************
function IsMac()
{
  if(navigator.appVersion.indexOf("Win") != -1)
  {
    return false;
  }
  else if(navigator.appVersion.indexOf("Mac") != -1)
  {
    return true;
  }
  else return false;
}
//****************************************************
// StripStringOfCommas 
// Removes commas from a string
//****************************************************
function StripStringOfCommas(sString)
{
	
	var s = sString.replace(/,/g,"");  	// remove commas from string

	return s;
}
//***********************************************
// FormatCurrency
//***********************************************
function FormatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	
	if (isNaN(num))
	{
		num = "0";
	}
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if (cents<10)
	{
		cents = "0" + cents;
	}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	}
	
	//return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + num + '.' + cents);
}

var popUpWin=0;
var popUpLinkWin=0;
//****************************************************
// popUpLinkWindow
// optional arguments: width,height,left,top
//****************************************************
function popUpLinkWindow(url)
{
  	if(popUpLinkWin)
  	{
    	if(!popUpLinkWin.closed) popUpLinkWin.close();
  	}
	
	var nWidth=600;
	var nHeight=400;
	var nLeft=10;
	var nTop=10;
	
	if (popUpLinkWindow.arguments.length > 1)
	{
		nWidth = parseInt(popUpLinkWindow.arguments[1])
	}
	if (popUpLinkWindow.arguments.length > 2)
	{
		nHeight = parseInt(popUpLinkWindow.arguments[2])
	}
	if (popUpLinkWindow.arguments.length > 3)
	{
		nLeft = parseInt(popUpLinkWindow.arguments[3])
	}
	if (popUpLinkWindow.arguments.length > 4)
	{
		nTop = parseInt(popUpLinkWindow.arguments[4])
	}
	
	popUpLinkWin = open(url, 'link', 'height=' + nHeight + ',width=' + nWidth + ',left=' + nLeft + ',top=' + nTop + ',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
	popUpLinkWin.focus();
}
//****************************************************
// ConvertHTML
// Converts the opening and closing HTML tags to parens
//****************************************************
function ConvertHTML(sInput)
{
	var sOutput = sInput;
    sOutput=sOutput.replace(/</g,"(");
    sOutput=sOutput.replace(/>/g,")");
	return sOutput;
}

//****************************************************
// StripStringOfVulnerableChars 
// Removes vulnerable chars from a string
//****************************************************
function StripStringOfVulnerableChars(sString,bStripSpaces)
{
	
	var s = sString.replace(/'/g,"");  	// remove tics from string
	s = s.replace(/;/g,"");  			// remove semicolons from string
	s = s.replace(/\(/g,"");  			// remove lefts paren from string
	s = s.replace(/\)/g,"");  			// remove right parens from string
	s = s.replace(/\*/g,"");  			// remove asterisk from string
	s = s.replace(/"/g,"");  			// remove double quotes from string
	s = s.replace(/--/g,"");  			// remove double dash from string
	s = s.replace(/=/g,"");  			// remove equal signs from string

	//s = s.replace(/#/g,"");  			// remove pound signs from string
	if (bStripSpaces)
	{
		s = s.replace(/ /g,"");  		// remove spaces from string
	}
	return s;
}

//****************************************************
// JSTrim
// Removes LEADING and TRAILING spaces ONLY from a string
// optional 3rd and 4th parms: BOOL BOOL
// 3rd parm: BOOL  - strip vulnerable chars
// 4th parm: BOOL  - strip spaces as part of strip
//****************************************************
function JSTrim (inputString, removeChar) 
{
	var returnString = inputString;
	if (removeChar.length)
	{
	  while(''+returnString.charAt(0)==removeChar)
		{
		  returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
	  {
	    returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	
	
	// check to see if additional parms were passed to tell us to 
	// strip out dangerous security risk chars
	var bCheckForVulnerabilities = (JSTrim.arguments.length > 2) ? JSTrim.arguments[2] : false;
	
	var bStripSpacesFromString = (JSTrim.arguments.length > 3) ? JSTrim.arguments[3] : false;
	
	// convert html? if no parm specified, will default to true
	var bConvertHTML = true;
	if (JSTrim.arguments.length > 4) 
	{
		if (JSTrim.arguments[4] == false)
		{
			bConvertHTML=false;	
		}
	}
	
	// convert any html chars
	var s = bConvertHTML ? ConvertHTML(returnString) : returnString;
	
	// if requested, strip also for vulnerabilities
	if (bCheckForVulnerabilities) 
	{
		s = StripStringOfVulnerableChars(s,bStripSpacesFromString);
	}
	else
	{
		// just clean of all spaces?
		if (bStripSpacesFromString)
		{
			s = s.replace(/ /g,"");  		// remove spaces from string
		}
	}
	
	return s;
}
//****************************************************
// JSTrimSpace
// Removes leading and trailing spaces from a string
//****************************************************
function JSTrimSpace(inputString)
{
	return JSTrim(inputString,' ');
}
//*******************************
// CleanCCNumber
//*******************************
function CleanCCNumber(s)
{
	// remove non-numerics
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) 
	{
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	
	return w;
}

//*******************************
// IsValidCCNumber
//*******************************
function IsValidCCNumber(s) {
	// remove non-numerics
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) {
	x = s.charAt(i);
	if (v.indexOf(x,0) != -1)
	w += x;
	}
	// validate number
	j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) return false;
	k = Math.floor(j);
	m = Math.ceil(j) - k;
	c = 0;
	for (i=0; i<k; i++) {
	a = w.charAt(i*2+m) * 2;
	c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	return (c%10 == 0);
}
//**********************************************
// isNumberFloat
//**********************************************
function isNumberFloat(inputString)
{
  return (!isNaN(parseFloat(inputString))) ? true : false;
}
//**********************************************
// isNumberInt
//**********************************************
function isNumberInt(inputString)
{
  return (!isNaN(parseInt(inputString))) ? true : false;
}
//**********************************************
// elem
//**********************************************
/*function elem() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var name = arguments[i];
		var val = name;
		if (typeof name == "string") {
			val = document.getElementById(name);
			if (! val) 
			{
				alert("Could not find element " + name);
				return false;
			}
		}
		if (arguments.length == 1) 
			return val;
		elements.push(val);
	}
	return elements;
}*/
//******************************
// toggle_nav
//******************************	
function toggle_nav(objimg,id) {
	//var e = elem("nav_" + id);

	var e = MM_findObj("nav_" + id);
	if (!e) 
	{
		alert("ERROR: No nav_"+ id);
		return;
	}
	
	// currently using right arrow?
	if (objimg.src.indexOf("arrowright.gif")>-1)
	{
		objimg.src = objimg.src.replace(/right.gif/g,"down.gif");  
	}
	else
	{
		objimg.src = objimg.src.replace(/down.gif/g,"right.gif");  
	}
	
	/*if (new RegExp("\\bnoshow\\b").test(e.className))
	{
		e.className = e.className.replace("noshow", " ");
	}
	else
	{
		e.className = e.className + " noshow ";
	}*/
	if (e.className.indexOf("noshow") > -1)
	{
		e.className = "navrows";
	}
	else
	{
		e.className="navrows noshow";
	}

}
//*******************************
// IsValueInStringList
//*******************************
function IsValueInStringList(sValue,sReturnList)
{
	var arrList = sReturnList.split(sReturnList,",");
	var nLen = arrList.length;
	for (var x = 0; x<nLen; x++)
	{
		sWrk = arrList[x];
		if (sWrk == sValue)
		{
			return true;
		}
	}
	
	return false;
}
//**********************************************
// ValidateNumericInput
// usage: from html input form: onkeydown="return ValidateNumericInput(event.keyCode)"
//**********************************************
function ValidateNumericInput(nKeyCode)
{
	
	var bAllowDecimals = (ValidateNumericInput.arguments.length > 1) ? ValidateNumericInput.arguments[1] : true;

	// allow 0 through 9 on regular keyboard
	if ((nKeyCode >= 48) && (nKeyCode <= 57)) return true;
	// allow 0 through 9 on keypad
	if ((nKeyCode >= 96) && (nKeyCode <= 105)) return true;
	
	// allow backspace
	if (nKeyCode == 8) return true;
	
	// allow delete key
	if (nKeyCode == 46) return true;
	
	// allow tab key
	if (nKeyCode == 9) return true;
	// allow shift key
	if (nKeyCode == 16) return true;
	
	// allow decimal point (period)
	if (bAllowDecimals)
	{
		if (nKeyCode == 190) return true;
	}
	
	return false;
}

//*******************************
// IsValidEmail
//*******************************
function IsValidEmail(sEmail)
{
	//var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	//return (filter.test(sEmail));
	
	return (sEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);

}
/*
	// clear out a listbox
	document.categoryform.itemlist.length=0;
	
	// dyanmically add the 'no items' back to the list
	var myEle = document.createElement("option");
	myEle.value = '';
	myEle.text = "--No Items--";
  	document.categoryform.itemlist.add(myEle)

	// alternate: to add a new item
	theSel.options[theSel.length] = new Option('yourText', 'yourValue');
	
	// to remove the last item
	theSel.options[theSel.length - 1] = null;


*/