/************************************************************************** 
*************************************************************************** 
*  Program Name: $Id: common.js,v 1.10 2009-03-08 23:29:38 neo Exp $
*  Program Author:  Michael T. Schock
*  Creation Date: 05-15-2006
*  CVS Revision: $Revision: 1.10 $
*  Copyright (c) 2006
*************************************************************************** 
*************************************************************************** 
*  Program Summary:
*  Javascript functions common to all pages
*
*
*************************************************************************** 
**************************************************************************/

	
//  Add functions to window.onload.
/*  This functin will add a function to the onload event for the page.
	
	Input:  
		functionName:  Name of the function to add.
	Return:
		0:  Success
		1:  Failure
*/
function Add_Load_Event(functionName) 
{
	//  Variables
	var origLoad;
	 
	//  Set the original onload
	origLoad = window.onload;
	
	//  Set the onload
	if (typeof window.onload != 'function') 
	{
		window.onload = functionName;
	}
	else 
	{
		window.onload = function() 
		{
			origLoad();
			functionName();
		}
	}
	
	return(0);
}

//!  Convert Password for encryption
/**  Use the MD5 Hash Algorithm.  */
function Convert_Password(passName)
{
	//  Convert and restore the password
	document.getElementById(passName).value = calcMD5(document.getElementById(passName).value);
}

//!  Encrypt Password(s)
/**  Encrypt the passwords on the page.  */
function Validate_User(control1, control2)
{
	//  Variables
	var pass1;
	var pass2;
	
	//  Get pass var
	pass1 = Trim(document.getElementById(control1).value);
	pass2 = Trim(document.getElementById(control2).value);
	
	if(pass1 == '' || pass2 == '' || pass1 != pass2)
	{
		alert('Password mismatch.  Please correct.');
		document.getElementById(control1).value = '';
		document.getElementById(control2).value = '';
		return(1);
	}
		
	//  Encrypt the data in the password fields
	if(control1 != '')
		Convert_Password(control1);
		
	if(control2 != '')
		Convert_Password(control2);
		
	//  Submit the page
	Submit_Page('Add_User', 'Data_Form');
}

//!  IsNumeric function
/**  This function will accept a value and check that it is a number.  */
function Is_Numeric(passedValue)
{
	//  Variables
	var validChars = "0123456789.";
	var loop;
	var charValue;

	//  Loop through the passed value character and look for anything not a number.
	for(loop = 0; loop < passedValue.length; loop++)
	{
		//  Get the character
		charValue = passedValue.charAt(loop);

		//  Character is not a number
		if(validChars.indexOf(charValue) == -1)
		{
			//  Failure
			return(1);
		}
	}

	//  Success
	return(0);
}


//!  Is valid secure
/**  This function will check to see if the passed value is valid for a password.  */
function Is_Valid_Secure(passedValue)
{
	//  Variables
	var validChars;
	var validChars1 = " ";
	var validChars2 = "!\"#$%&'()*+`,./";
	var validChars3 = "0123456789";
	var validChars4 = ":;<=>?@";
	var validChars5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var validChars6 = "{\\]^_"
	var loop;
	var charValue;

	//  Set the data string
	validChars = validChars1 + validChars2 + validChars3 + validChars4 + validChars5 + validChars6;

	//  Loop through the passed value character and look for anything not a valid character.
	for(loop = 0; loop < passedValue.length; loop++)
	{
		//  Get the character
		charValue = passedValue.charAt(loop);

		//  Character is not a number
		if(validChars.indexOf(charValue) == -1)
		{
			//  Failure
			return(1);
		}
	}

	//  Success
	return(0);
}

//!  Is valid text
/**  This function will check to see if the passed value is valid for general text.  */
function Is_Valid_Text(passedValue)
{
	//  Variables
	var validChars;
	var validChars1 = "0123456789";
	var validChars2 = "abcdefghijklmnopqrstuvwxyz ";
	var validChars3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var loop;
	var charValue;

	//  Set the data string
	validChars = validChars1 + validChars2 + validChars3;

	//  Loop through the passed value character and look for anything not a valid character.
	for(loop = 0; loop < passedValue.length; loop++)
	{
		//  Get the character
		charValue = passedValue.charAt(loop);

		//  Character is not a number
		if(validChars.indexOf(charValue) == -1)
		{
			//  Failure
			return(1);
		}
	}

	//  Success
	return(0);
}

//!  String Pad
/**  This function will pad a variable.  */
function String_Pad(dataString, pad, size, orientation)
{
	//  Variables
	var loop;
	var padData = '';

	//  Negative check
	if(size < 0)
		size = 0;

	//  Size check
	if(String(dataString).length >= size)
		return(dataString);

	//  Loop through and create the pad
	for(loop = (String(dataString).length); loop < size; loop++)
	{
		if(padData == '')
			padData = String(pad);
		else
			padData = String(padData) + String(pad);
	}

	//  Append the string to the pad
	if(orientation == 'right')
		dataString = String(padData) + String(dataString);
	else
		dataString = String(dataString) + String(padData);

	//  Return the data
	return(dataString);
}

//!  Trim function
/**  This function will trim left and right spaces.  */
function Trim(dataString)
{
	//  Variables
	var start = 0;
	var stop = 0;
	var loop;
	var trimString = '';

	//  Check the length 
	if(dataString.length == 0)
		return(0);
		
	//  Get the start
	for(loop = 0; loop < dataString.length; loop++)
	{
		if(dataString.substring(loop, (loop + 1)) != ' ')
		{
			start = loop;
			break;
		}
	}

	//  Get the end
	for(loop = dataString.length - 1; loop >= 0; loop--)
	{
		if(dataString.substring(loop, loop + 1) != ' ')
		{
			stop = loop + 1;
			break;
		}
	}

	//  Error
	if(stop < start || stop == start || (stop == 0 && start == 0))
		return(trimString);

	//  Get the trimmed substring
	trimString = dataString.substring(start, stop);

	//  Return the trimmed string
	return(trimString);
}

//!  Right Trim function
/**  This function will trim the right.  */
function R_Trim(dataString)
{
	//  Variables
	var start = 0;
	var stop = 0;
	var loop;
	var trimString = '';

	//  Check the length 
	if(dataString.length == 0)
		return(0);
		
	//  Get the end
	for(loop = dataString.length - 1; loop >= 0; loop--)
	{
		if(dataString.substring(loop, loop + 1) != ' ')
		{
			stop = loop + 1;
			break;
		}
	}

	//  Error
	if(stop < start || stop == start || (stop == 0 && start == 0))
		return(trimString);

	//  Get the trimmed substring
	trimString = dataString.substring(start, stop);

	//  Return the trimmed string
	return(trimString);
}

//!  Left Trim function
/**  This function will trim the left.  */
function L_Trim(dataString)
{
	//  Variables
	var start = 0;
	var stop = dataString.length;
	var loop;
	var trimString = '';

	//  Check the length 
	if(dataString.length == 0)
		return(0);
		
	//  Get the start
	for(loop = 0; loop < dataString.length; loop++)
	{
		if(dataString.substring(loop, loop + 1) != ' ')
		{
			start = loop;
			break;
		}
	}

	//  Error
	if(stop < start || stop == start || (stop == 0 && start == 0))
		return(trimString);

	//  Get the trimmed substring
	trimString = dataString.substring(start, stop);

	//  Return the trimmed string
	return(trimString);
}


//!  Extract variable
/**  This function will extract a single or multiple variables from the table class hidden
	variables.  */
function Extract_Variable(hiddenVar)
{
	//  Variables
	var start;
	var stop;
	var extractedString;
	var varNumber = 0;
	var loop;

	//  Find the number of elements in the array
	for(loop = 0; loop < hiddenVar.length; loop++)
	{
		//  Count the number of commas
		if(hiddenVar.substring(loop, loop + 1) == ',')
			varNumber++;
	}
	
	arraySize = (varNumber + 1)/2;
	
	//  Create an array for the data
	var dataArray = new Array(Math.ceil(arraySize));
		
	//  Loop through the string and get the data
	for(loop = 0; loop < dataArray.length; loop++)
	{ 
		//  Skip over the table index
		if(loop == 0)
			start = 0;
		else
			start = stop + 1;

		stop = hiddenVar.indexOf(",", start);
		
		//  Get the data position
		start = stop + 1;
		stop = hiddenVar.indexOf(",", start);
		
		if(stop < start)
			stop = hiddenVar.length;
			
		//  Parse the data 
		dataArray[loop] = hiddenVar.substring(start, stop);
	}

	//  Return the data array
	return(dataArray);
}

//!  Print the page
/**  This function will open the print page function.  */
function Print_Page()
{
	// Print the page
	window.print();
}


//!  Delay function (milliseconds)
/**  This function will create a delay in milliseconds.  */
function Delay(timeInterval)
{
	//  Variables
	var then;
	var now;

	//  Get current time
	then = new Date().getTime();

	//  Set the current time to now
	now = then;

	//  Loop until gap is met
	while((now-then) < timeInterval)
	{
        	now = new Date().getTime();
	}
}

//!  Disable a page control
/**  This function will disable a control.  */
function Disable_Control(varObj)
{
	if(typeof(varObj) == 'string')
		varObj = document.getElementById(varObj);

	varObj.disabled = true;
}

//!  Enable a page control
/**  This function will enable a control.  */
function Enable_Control(varObj)
{
	if(typeof(varObj) == 'string')
		varObj = document.getElementById(varObj);

	varObj.disabled = false;
}

//!  Function to set a class for an object
/**  This function will set a class for a given object.  */
function Set_Class(objRef, classTitle)
{
	//  Variables
	var varObj;
	
	if(typeof(objRef) == 'string')
	{
		varObj = document.getElementById(objRef);
		varObj.className = classTitle;
	}
	else	
		objRef.className = classTitle;
}

//!  Page Submit
/**  This function will submit the page and set the page action.  */
function Submit_Page(pageAction, formId)
{
	//  Set the page action
	if(document.getElementById('Page_Action'))
	document.getElementById('Page_Action').value = pageAction;

	//  Submit the page
	document.getElementById(formId).submit();
}

//!  Form Submit
/**  This function will submit the page and set the page action.  */
function Submit_Form(actionName, pageAction, formId)
{
	//  Set the page action
	if(actionName != '')
		document.getElementById(actionName).value = pageAction;

	//  Submit the page
	document.getElementById(formId).submit();
}

//!  Table Submit
/**  This function will submit a page if a table item is selected.  */
function Table_Submit(tableNumber, selectType, pageAction, formId)
{
	//  Check the table selection
	if(Check_Table(tableNumber, selectType))
		return(1);

	//  Set the page action
	document.getElementById('Page_Action').value = pageAction;

	//  Submit the page
	document.getElementById(formId).submit();
}

//!  Table Data Submit
/**  This function will verify at a single or multiple selection in the table.  */
function Check_Table(tableNumber, selectType)
{
	//  Variables
	var dataObj;
	var dataValue;
	var dataFlag;
	var loop = 0;
	var count = 0;
	
	//  Verify table object exists
	if(!document.getElementById('Table_Control_Hidden_' + tableNumber + '_0'))
		return(0);
	
	//  Get the table object
	dataObj = document.getElementById('Table_Control_Hidden_' + tableNumber + '_0');
	dataValue = dataObj.value;
	
	//  If nothing is selected, exit
	if(dataValue.length == 0)
	{
		alert('Please select a table item(s)');
		return(1);
	}

	//  Count the number of selections (Count the comma's)
	for(loop = 0; loop < dataValue.length;loop++)
	{
		//  Search for the comma
		dataFlag = dataValue.indexOf(',', loop);
		if(dataFlag == -1)
			break;
			
		//  Increment the loop to the comma index
		loop = dataFlag;
		
		//  Keep track of the count
		count++;
	}
	
	if(selectType == 'Single')
	{
		if(count == 1)
		{
			return(0);
		}
		else
		{
			alert('Only a single item can be selected in the table');
			return(1);
		}
	}
	
	if(selectType == 'Multiple' && count > 1)
	{
		return(0);
	}
}

//!  Create Input Row
/**  Function to create a new row in a table with a label and and input element.  */
function Create_Input_Row(tableObj, elementName, labelHtml, rowIndex)
{
	//  Variables
	var newRow;
	var labelCell;
	var inputCell;
	var newLabel;
	var newInput;

	//  Add a new row to the table
	newRow = tableObj.insertRow(rowIndex);

	//  Add a label cell
	labelCell = newRow.insertCell(0);

	//  Add a input cell
	inputCell = newRow.insertCell(1);

	//  Add an input to the input cell
	newInput = document.createElement("input");

	//  Set the attributes for the input
	newInput.type = "text";
	newInput.id = elementName;
	newInput.name = elementName;

	//  Append the input to the cell
	inputCell.appendChild(newInput);

	//  Add a label to the label cell for the input
	newLabel = document.createElement("label");

	//  Set the attributes for the label
	newLabel.innerHTML = labelHtml;

	//  Append the label to the cell
	labelCell.appendChild(newLabel);
}

//!  Remove HTML
/**  This is a function to remove all html tags from the string.  */
function RemoveHTML( strText )
{
	//  This will remove all tags, but the data should not contain "<" or ">"
	var regEx = /<[^>]*>/g;
	return strText.replace(regEx, "");
}

//!  Show Update
/**  This function will show the provided popup and set the parameters.  
	tableSelect should be 'N', 'S<table number>', 'M<table number>'.  */
function Show_Popup(elementName, iframeName, objTop, objLeft, objWidth, objHeight, tableSelect)
{
	//  Variables
	var elementObj;
	var iframeObj;
	var tableData;
	var tableNumber;
	var tableAction;
	var count = 0;
	var loop = 0;
	
	//  Determine if a table element needs to be selected
	if(tableSelect != 'N')
	{
		tableNumber = tableSelect.substring(1, (tableSelect.length));
		tableData = document.getElementById('Table_Control_Hidden_' + tableNumber + '_0').value;
			
		//  Verify that only one item is selected
		for(loop = 0; loop < tableData.length; loop++)
		{
			if(tableData.substring(loop, loop + 1) == ',')
				count++;
		}
		
		//  Verify an item is selected
		if(count == 0)
		{
			alert('Please select an item from the appropriate table.');
			return(1);
		}
			
		//  Determine if it is a single or multi select
		if(tableSelect.substring(0, 1) == 'S')
		{
			if(count > 1)
			{
				alert('Please select only one row from the table.');
				return(1);
			}
		}
	}
	
	//  Set the popup to the desired location
	elementObj = document.getElementById(elementName);
	iframeObj = document.getElementById(iframeName);
	
	//  Position the div in the center of the screen
	elementObj.style.position = "absolute";
	elementObj.style.top = objTop;
	elementObj.style.left = objLeft;
	elementObj.style.width = objWidth;
	elementObj.style.height = objHeight;
	elementObj.style.zIndex = "1000";
	elementObj.style.display = 'block';
	
	//  Position the iframe under the div
	iframeObj.style.position = "absolute";
	iframeObj.style.top = objTop;
	iframeObj.style.left = objLeft;
	iframeObj.style.width = objWidth;
	iframeObj.style.height = objHeight;
	iframeObj.style.zIndex = "999";
	iframeObj.style.display = 'block';
	
	//  Show the blocks
	iframeObj.style.visibility = "visible";
	elementObj.style.visibility = "visible";
	
	//  Return success
	return(0);
}


//!  Hide Update
/**  This function will hide the update window.  */
function Hide_Popup(elementName, iframeName)
{
	//  Variables
	var elementObj;
	var iframeObj;
	
	//  Get the object references
	elementObj = document.getElementById(elementName);
	iframeObj = document.getElementById(iframeName);
	
	//  Drop the div down
	elementObj.style.zIndex = "0";
	
	//  Hide the iframe in the upper left corner
	iframeObj.style.position = "absolute";
	iframeObj.style.top = "0";
	iframeObj.style.left = "0";
	iframeObj.style.width = "0";
	iframeObj.style.height = "0";
	iframeObj.style.zIndex = "0";
	
	//  Hide the blocks
	iframeObj.style.block = "none";
	iframeObj.style.visibility = "hidden";
	elementObj.style.display = 'none';
	elementObj.style.visibility = "hidden";
	
	//  Return success
	return(0);
}

//!  Page Direct
/**  Redirect the form to the specified page.  */
function Page_Direct(dataForm, pageName)
{
        //  Reset the action
        document.getElementById(dataForm).action = pageName;

        //  Submit the page
        document.getElementById(dataForm).submit();
	//  Return success
	return(0);
}

//!  Page Redirect
/**  Redirect the form to the specified page.  */
function Page_Redirect(dataForm, pageName, actionData)
{
	//  Set the page action
	document.getElementById('Page_Action').value = actionData;
	
        //  Reset the action
        document.getElementById(dataForm).action = pageName;

        //  Submit the page
        document.getElementById(dataForm).submit();

	//  Return success
	return(0);
}

//!  Set select value
/**  Set the value of a select html element.  */
function Select_Set(elementName, selectValue)
{
	//  Variables
	var selectObj = null;
	var loop = 0;
	
	//  Set the object
	selectObj = document.getElementById(elementName);
	
	if(selectObj)
	{
		while(loop < selectObj.length)
		{
			if(selectObj.options[loop].value == selectValue)
				break;
			loop++;
		}
		selectObj.options[loop].selected = true;
	}
	//  Return success
	return(0);
}


//!  Create Select Control
/**  Create the select control utilizing input data.  */
function Create_Select_Data(elementName, selectData, selectValue, selectedData)
{
	//  Variables
	var selectObj;
	var selectLength;
	var loop;
	var optionDoc;
	
	//  Get the obj
	selectObj = document.getElementById(elementName);
	
	//  Get the length of the select
	selectLength = selectObj.options.length;
	
	//  Delete the options in the object
	for(loop = (selectLength - 1); loop >= 0; loop--)
	{
		//  Remove
		selectObj.options[loop] = null;
	}
	
	//  Add the blank select item
	optionDoc = new Option('', '');
	selectObj.options[0] = optionDoc;
	
	//  Add the remaining items
	for(loop = 0; loop < selectData.length; loop++)
	{
		//  Get Data and Value
		optionDoc = new Option(selectData[loop], selectValue[loop]);
		selectObj.options[(loop + 1)] = optionDoc;
		if(selectedData == selectValue[loop])
			selectObj.options[(loop + 1)].selected = true;
		else
			selectObj.options[(loop + 1)].selected = false;
	}
	
	//  Return success
	return(0);
}

//  Variables for Image_Uploader
var imageCounter = 0;

function Add_Image_Uploader()
{
	//  Variables
	var parentDiv = '';
	var newDiv = '';
	var newHtml = '';
	
	//  Increment the counter
	imageCounter++;
	
	//  Get the parent div
	parentDiv = document.getElementById('Image_Upload_Holder');
	
	//  Set the new HTML
	newHtml = "<input style=\"float:left; width:75%;\" type=\"file\" id=\"File_Name_" + imageCounter + "\" name=\"File_Name_" + imageCounter + "\"><div class=\"Site_Link\" style=\"float:right; margin-left:25px; font-weight:bold; font-size:10pt; cursor:pointer;\" onclick=\"Delete_Element('Image_Upload_Holder', 'File_Holder_" + imageCounter + "');\">Remove File</div><br style=\"clear:both;\" />";
	
	//  Create the new div
	newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'File_Holder_' + imageCounter);
	newdiv.setAttribute('style', 'margin-bottom:5px;');
	
	//  Set the inner html for the new div
	newdiv.innerHTML = newHtml;
	
	//  Append the child
	parentDiv.appendChild(newdiv);	
}

//  Variables for Video_Uploader
var videoCounter = 0;

function Add_Video_Uploader()
{
	//  Variables
	var parentDiv = '';
	var newDiv = '';
	var newHtml = '';
	
	//  Increment the counter
	videoCounter++;
	
	//  Get the parent div
	parentDiv = document.getElementById('Video_Upload_Holder');
	
	//  Set the new HTML
	newHtml = "<input style=\"float:left; width:75%;\" type=\"text\" id=\"Video_Name_" + videoCounter + "\" name=\"Video_Name_" + videoCounter + "\"><div class=\"Site_Link\" style=\"float:right; margin-left:25px; font-weight:bold; font-size:10pt; cursor:pointer;\" onclick=\"Delete_Element('Video_Upload_Holder', 'Video_Holder_" + videoCounter + "');\">Remove File</div><br style=\"clear:both;\" />";
	
	//  Create the new div
	newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'Video_Holder_' + videoCounter);
	newdiv.setAttribute('style', 'margin-bottom:5px;');
	
	//  Set the inner html for the new div
	newdiv.innerHTML = newHtml;
	
	//  Append the child
	parentDiv.appendChild(newdiv);	
}

//  Variables for Price Break
var priceBreakCounter = 0;

function Add_Price_Break(qty, price, indexSeq)
{
	//  Variables
	var parentDiv = '';
	var newDiv = '';
	var newHtml = '';
	
	//  Increment the counter
	priceBreakCounter++;
	
	//  Get the parent div
	parentDiv = document.getElementById('Price_Upload_Holder');
	
	//  Set initial values
	qty = qty != '' ? qty : '';
	price = price != '' ? price : '';
	indexSeq = indexSeq != '' ? indexSeq : '';
	
	//  Set the new HTML
	newHtml = "<div class=\"Site_Link\" style=\"float:left; font-weight:bold; font-size:10pt; cursor:pointer; margin-right:30px; background-color:#cccccc; color:black; border:outset 2px #cccccc;\" onclick=\"Admin_Delete_Pricebreak('" + indexSeq + "'); Delete_Element('Price_Upload_Holder', 'Price_Holder_" + priceBreakCounter + "');\">&nbsp;X&nbsp;</div><div style=\"float:left; font-size:12pt; font-weight:bold; margin-right:10px;\">Price Qty</div><input style=\"float:left; width:45px;\" type=\"text\" id=\"Price_Break_Qty_" + priceBreakCounter + "\" name=\"Price_Break_Qty_" + priceBreakCounter + "\" value=\"" + qty + "\"><div style=\"float:left; margin-left:20px; font-size:12pt; font-weight:bold; margin-right:10px;\">Price</div><input style=\"float:left; width:85px;\" type=\"text\" id=\"Price_Break_" + priceBreakCounter + "\" name=\"Price_Break_" + priceBreakCounter + "\" value=\"" + price + "\"><br style=\"clear:both;\" />";
	
	//  Create the new div
	newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'Price_Holder_' + priceBreakCounter);
	newdiv.setAttribute('style', 'margin-bottom:5px;');
	
	//  Set the inner html for the new div
	newdiv.innerHTML = newHtml;
	
	//  Append the child
	parentDiv.appendChild(newdiv);	
}

function Delete_Element(parentName, childName)
{
	//  Variables
	var parentObj = '';
	var childObj = '';
	
	//  Get the parent node
	parentObj = document.getElementById(parentName);
	childObj = document.getElementById(childName);
	
	//  Delete the node
	parentObj.removeChild(childObj);
}

//  Index image index
var leftIndex = 1;
var rightIndex = 1;

function Rotate_Images_Left()
{
	//  Variables
	var loop;
	var imgObj;
	var imageName = '';
	
	//  Get the image object
	imgObj = document.getElementById('Image_1');
	if(!imgObj)
		return(0);
		
	//  Set the image name
	imageName = 'Images/Display/l' + leftIndex + '.jpg';
	
	//  Set the image to the obj
	imgObj.src = imageName;
	
	//  Increment the index
	if(leftIndex >= 6 || leftIndex < 1)
		leftIndex = 1;
	else
		leftIndex++;
		
	//  Recall this function after 2 seconds
	setTimeout('Rotate_Images_Left()', 5000);
	
}

function Rotate_Images_Right()
{
	//  Variables
	var loop;
	var imgObj;
	var imageName = '';
	
	//  Get the image object
	imgObj = document.getElementById('Image_2');
	if(!imgObj)
		return(0);
		
	//  Set the image name
	imageName = 'Images/Display/r' + rightIndex + '.jpg';
	
	//  Set the image to the obj
	imgObj.src = imageName;
	
	//  Increment the index
	if(rightIndex >= 6 || rightIndex < 1)
		rightIndex = 1;
	else
		rightIndex++;
		
	//  Recall this function after 2 seconds
	setTimeout('Rotate_Images_Right()', 5000);
	
}

function Number_Format(number, precision)
{
	//  Variables
	var power = 0;
	var numData = 0;
	var mod = 0;
	
	//  Set the power (This will set how many decimals)
	power = Math.pow(10, precision || 0);
	
	//  Set the data
	numData = Math.round(number * power) / power;
	
	//  Check to see if it is an integer
	mod = numData % 1;
	numData = numData.toFixed(precision);
		
	return(numData);
}


function Submit_Review()
{
	//  Verify user data
	if(Trim(document.getElementById('Email_1').value) == '')
	{
		alert('The email must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Email_2').value) == '')
	{
		alert('The email must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Email_1').value) != Trim(document.getElementById('Email_2').value))
	{
		alert('Both email fields must match.  Please verify the email address and the retype address match.');
		return(0);
	}
	
	//  Billing Address
	if(Trim(document.getElementById('First_Name').value) == '')
	{
		alert('The name must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Last_Name').value) == '')
	{
		alert('The name must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Address_1').value) == '')
	{
		alert('The address must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('City').value) == '')
	{
		alert('The city must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('State').value) == '')
	{
		alert('The state must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Zipcode').value) == '')
	{
		alert('The zipcode must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Phone').value) == '')
	{
		alert('The phone number must be filled in for the user information.');
		return(0);
	}
	
	//  Shipping Address
	if(Trim(document.getElementById('Shipping_Address_1').value) == '')
	{
		alert('The Shipping address must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Shipping_City').value) == '')
	{
		alert('The Shipping city must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Shipping_State').value) == '')
	{
		alert('The Shipping state must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Shipping_Zipcode').value) == '')
	{
		alert('The Shipping zipcode must be filled in for the user information.');
		return(0);
	}
	
	if(Trim(document.getElementById('Shipping_Phone').value) == '')
	{
		alert('The Shipping phone number must be filled in for the user information.');
		return(0);
	}
	
	//  Check data
	if(Trim(document.getElementById('Card_Type').value) == '')
	{
		alert('The card type must be filled in.');
		return(0);
	}
	if(Trim(document.getElementById('Card_Name').value) == '')
	{
		alert('The card name must be filled in.');
		return(0);
	}
	if(Trim(document.getElementById('Card_Number').value) == '')
	{
		alert('The card number must be filled in.');
		return(0);
	}
	if(Trim(document.getElementById('Exp_Month').value) == '')
	{
		alert('The card month expiration must be filled in.');
		return(0);
	}
	if(Trim(document.getElementById('Exp_Year').value) == '')
	{
		alert('The card year expiration must be filled in.');
		return(0);
	}
	if(Trim(document.getElementById('Card_ID_Number').value) == '')
	{
		alert('The card ID number must be filled in.');
		return(0);
	}
	
	//  Submit the data
	document.getElementById('Next').disabled=true; 
	document.getElementById('Next').value='Submitted'; 
	Submit_Page('', 'Data_Form');
}

function Submit_Checkout()
{
	//  Submit the data
	document.getElementById('Submit_Order').disabled=true; 
	document.getElementById('Submit_Order').value='Submitted'; 
	Submit_Page('', 'Data_Form');
}

function Fill_Shipping()
{
	//  Check to see if the box is checked or not
	if(document.getElementById('Bill_Same').checked == true)
	{
		//  Set the values
		document.getElementById('Shipping_Address_1').value = document.getElementById('Address_1').value;
		document.getElementById('Shipping_Address_2').value = document.getElementById('Address_2').value;
		document.getElementById('Shipping_City').value = document.getElementById('City').value;
		document.getElementById('Shipping_State').selectedIndex = document.getElementById('State').selectedIndex;
		document.getElementById('Shipping_Zipcode').value = document.getElementById('Zipcode').value;
		document.getElementById('Shipping_Phone').value = document.getElementById('Phone').value;
	}
	else
	{
		//  Clear the values
		document.getElementById('Shipping_Address_1').value = '';
		document.getElementById('Shipping_Address_2').value = '';
		document.getElementById('Shipping_City').value = '';
		document.getElementById('Shipping_State').selectedIndex = 0;
		document.getElementById('Shipping_Zipcode').value = '';
		document.getElementById('Shipping_Phone').value = '';
	}
}


//!  Make sure data is only numeric
/**  Remove non-numeric fields in a string.  */
function Valid_Numeric(dataField)
{
	if(!/^d*$/.test(dataField.value))
		dataField.value = dataField.value.replace(/[^\d]/g, "");
}

//!  Make sure data is numeric and allows decimal point
/**  Remove non-numeric fields in a string.  */
function Valid_Float(dataField)
{
	if(!/^d*$/.test(dataField.value))
		dataField.value = dataField.value.replace(/[^\d.]/g, "");
}

//  Check comment length
function Check_Length(objRef, varLength)
{
	//  Check length
	if(objRef.value.length > varLength)
		objRef.value = objRef.value.substring(0, varLength);
}

//  Global Scroll Var
var moveObj = '';
var resetScroll = 0;
	
//  Scroll
function Marquee_Scroll()
{
	//  Variables
	var dataLength;
	var dataDuration;
	var marqueeObj;
	var stringObj;

	
	//  Get the length of the data
	dataLength = document.getElementById('Marquee_Data').offsetWidth;
	
	//  Get the Marquee Object and the string object
	marqueeObj = document.getElementById('Marquee_Scroller');
	stringObj = document.getElementById('Marquee_Data');
	
	//  Add the span to the marquee block
	if(!resetScroll)
		marqueeObj.appendChild(stringObj);
		
	//  Set the data	
	stringObj.style.visibility = 'visible';
	stringObj.style.height = 'auto';
	stringObj.style.position = 'relative';
	stringObj.style.left = '980px';

	//  Move the data from right to left
	moveObj = new Effect.Move('Marquee_Data', { x: -980, mode: 'absolute', duration: 20, afterFinish: Reset_Marquee });
	
}

function Reset_Marquee()
{
	//  Variables
	var marqueeObj;
	var stringObj;
	
	//  Get the String object
	stringObj = document.getElementById('Marquee_Data');
	
	// Reset the parameters
	stringObj.style.left = '980px';
	
	setTimeout(Marquee_Scroll, 500);
}

function Stop_Marquee()
{
	moveObj.cancel();
}

function Display_Cat_Popup(catNumber)
{
	var divOffset;
	var divWidth;
	var popTop;
	var popLeft;
	
	divOffset = $('Cat_Box_' + catNumber).cumulativeOffset();
	divWidth = $('Cat_Box_' + catNumber).getWidth() + 5;
	
	//  Set the top and left of the popup
	$('Cat_Box_Popup_' + catNumber).clonePosition($('Cat_Box_' + catNumber), {offsetLeft:divWidth, offsetTop:-10});
	$('Cat_Box_Popup_' + catNumber).setStyle({ position:'absolute', display:'block', height:'auto'});
}

function Hide_Cat_Popup(catNumber)
{
	$('Cat_Box_Popup_' + catNumber).setStyle({ display:'none' });
}

function Set_Prod_Image(indexSeq, imageName, catDisplay)
{
	//  Variables
	var prodDisplay;
	var strDisplay;
	var onclick;
	
	//  Set the onclick
	if(catDisplay != '')
		onclick = "window.location.href='product_detail.php?Category=" + catDisplay + "&amp;Page_Number=1&amp;Index_Seq=" + indexSeq + "&amp;Home_Page=';";
	else
		onclick = 'false;';
		
	//  Create the display data
	strDisplay = '<img width="200px" height="200px" style="cursor: pointer;" title="Click for product detail" onclick="' + onclick + '" alt="' + imageName + '" src="Images/Product/Resized/r_' + imageName + '" id="Prod_Image_' + indexSeq + '">';
	
	//  Set the data into the image display
	$('Prod_Display_' + indexSeq).update(strDisplay);
	
}

function Set_Prod_Video(indexSeq, videoStr)
{
	//  Set the data into the image display
	$('Prod_Display_' + indexSeq).update(videoStr);
	
}
