/* Javascript used by Content Management System */

<!--   hide this script from non-javascript-enabled browsers
// function that displays status bar message
var showMsg = navigator.userAgent != "Mozilla/4.0 (compatible; MSIE 4.0; Mac_PowerPC)";
function dmim(msgStr) {
  document.returnValue = false;
  if (showMsg) { 
    window.status = msgStr;
    document.returnValue = true;
  }
}

// open window
function openWin( windowURL, windowName, windowFeatures ) { 
	return window.open( windowURL, windowName, windowFeatures ) ; 
} 

// image preview	
function previewImg( windowURL, windowName, windowFeatures, textfield ) { 
	var image =  eval("document.editform." + textfield + ".value");
	var openURL = windowURL + "?Image=" + image;
	return window.open( openURL, windowName, windowFeatures ) ; 
} 

// stop hiding -->

// Qforms stuff 
/*  Must also include: <script src="includes/qforms/lib/qforms.js" type="text/javascript"></script> */
<!--//
	// set the path to the qForms directory
	qFormAPI.setLibraryPath("includes/qforms/lib/");
	// this loads all the default libraries
	qFormAPI.include("*");

//Test float fields to make sure they are proper floats (allows negative numbers)
function __IsNumericfloat()
{
// For foreign currencies, change the decimal to a comma on the next line:
var ValidChars = "01213456789.-";
var IsNumber = true;
var Char ;
var sText = this.value;
var numDecimals = 0;

for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
//Checks for minus sign
if (Char == '-' && i > 0)
{
IsNumber = false;
}
//Checks to make sure there is only 1 decimal point in the number
// For foreign currencies, change the decimal to a comma on the next line:
if (Char == '.')
{
numDecimals = numDecimals + 1;
}
}

if (numDecimals > 1 || IsNumber == false)
{
this.error = "The field " +
this.description + " does not contain a valid number";
}
}

_addValidator("IsNumericfloat",__IsNumericfloat);

//-->


// Quicklist Cookies 
/*  add ID to quicklist */
<!--
	function includeInCookie(listname,value) {
		var name = "QuickList" + listname;
		var d = new Date();
		d.setTime( d.getTime() + (30*24*60*60*1000));
		var expires = '; expires=' + d.toGMTString();
		var QuickList = readCookie(name);
		if (!QuickList) QuickList = value;
		else {
			if (QuickList.indexOf(value) == -1) {
				QuickList = QuickList + "," + value;
			}
		}
		document.cookie = name + '=' + escape(QuickList)+ expires +'; path=/';
		// alert ("This item was added to your Quick List\n\nYou can view your Quick List by clicking the 'View Quick List' link.");
		// window.location.reload();
		var newhtml = '<a href="javascript:removeFromCookie(';
		newhtml = newhtml + "'" + listname + "',";
		newhtml = newhtml + "'" + value + "'";
		newhtml = newhtml + ')"><img src="images/icons/quicklist_on.gif" alt="Remove from List" border="0" align="left"></a>';
		
		document.getElementById(listname + value).innerHTML = newhtml;
	}
	
	function readCookie(name) {
		var eq = name + "=";
		var ca = document.cookie.split(';');
		if (!ca.length) return null;
		for(var i=0;i<ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(eq) == 0) return unescape(c.substring(eq.length,c.length));
		}
		return null;
	}


	function removeFromCookie(listname,item_id) {
					
		var name = "QuickList"+ listname;
		var d = new Date();
		d.setTime( d.getTime() + (30*24*60*60*1000));
		var expires = '; expires=' + d.toGMTString();
					
		if (item_id == "all") {
				var QuickList = "";
				document.cookie = name + '=' + escape(QuickList)+ expires +'; path=/';
				window.location.reload();
		}
		else {
			var QuickList = readCookie("QuickList" + listname);
			if (QuickList.length > 0) {
				if (QuickList.indexOf(item_id) > -1) {
					finalvar = QuickList.indexOf(item_id) + item_id.length + 1;
					var aux = "";
					aux = QuickList.substr(0, QuickList.indexOf(item_id));
					aux += QuickList.substr(finalvar);
					QuickList = aux;
				}
			}
	
			len = QuickList.length;
			len--;
			
			if (QuickList.lastIndexOf(",") == len) {
				QuickList = QuickList.substr(0, len);
			}
			
			document.cookie = name + '=' + escape(QuickList)+ expires +'; path=/';
			// alert ("This item was removed from your Quick List");
			
			var newhtml = '<a href="javascript:includeInCookie(';
			newhtml = newhtml + "'" + listname + "',";
			newhtml = newhtml + "'" + item_id + "'";
			newhtml = newhtml + ')"><img src="images/icons/quicklist_off.gif" alt="" title="Add to List" border="0" align="left"></a>';
			document.getElementById(listname + item_id).innerHTML = newhtml;
		}
			// window.location.reload();

	}
					
// END - Cookie's functions ----
//-->