/******* Begin Miscellaneous Functions *******/

function getAbsPath(site) {
	if (window.location.host == 'webq1.insidehli.com' || window.location.host == 'dev.insidehli.com' || window.location.host == '10.9.41.166') {
		//now we have to check to see if we're on the dev or test site (dev is our default db connection)
		if (window.location.pathname.match(/_test/g)) {
			//we're on testing site
			return 'http://' + window.location.host + '/' + site + '_test/';
		} else {
			//we're on dev (or we're defaulting to dev)
			return 'http://' + window.location.host + '/' + site + '_dev/';
		}//if (window.location.pathname.match(/_test/g))
	} else if (window.location.host == "qa.insidehli.com") {
		//we're on qa site
		return 'http://qa.hubbelllighting.com/alliance/';
	} else {
		//we're on production site
		return 'http://www.hubbelllighting.com/alliance/';
	}
}//function getAbsPath()

function validateForm(theForm) {
	theForm = $(theForm);
	var formAction = '';

	//default, all fields are required
	for (i = 0; i < theForm.length; i++) {
		//set our form action
		if (theForm[i].id == 'form_action') {formAction = theForm[i].value;}
		if (theForm[i].id != '' && theForm[i].type != 'hidden') {
			if (theForm[i].type == 'select-one') {
				if ($(theForm[i].id).readAttribute('required') === 'required' && !theForm[i].selectedIndex > 0) {
					//alert(theForm[i].id + ' is required.');
					alert($('lbl_' + theForm[i].id).innerHTML + ' is required.');
					theForm[i].focus();
					return false;
				}
			} else {
				if ($(theForm[i].id).readAttribute('required') == 'required') {
					if ($(theForm[i].id).readAttribute('datatype') == 'numeric') {
						if (theForm[i].value.strip() == '' || !isInteger($F(theForm[i].id))) {
							//alert(theForm[i].id + ' must be a numeric value.');
							alert($('lbl_' + theForm[i].id).innerHTML + ' must be a numeric value.');
							theForm[i].focus();
							return false;
						}
					} else if ($(theForm[i].id).readAttribute('datatype') == 'email') {
						if (theForm[i].value.strip() == '' || !checkEmail($F(theForm[i].id))) {
							alert('Please enter a valid email address.');
							theForm[i].focus();
							return false;
						}
					} else {
						if (theForm[i].value.strip() == '') {
							//alert(theForm[i].id + ' is required.');
							alert($('lbl_' + theForm[i].id).innerHTML + ' is required.');
							theForm[i].focus();
							return false;
						}
					}//if ($(theForm[i].id).readAttribute('datatype') == 'numeric')
				}//if ($(theForm[i].id).readAttribute('required') == 'TRUE')
			}//if (theForm[i].type == 'select-one')
		}//if (theForm[i].id != '')
	}//for (i = 0; i < theForm.length; i++)


	if (formAction == 'define_plan') {
		return validatePlanForm();
	}
	return true;
}

function validateContactForm(theForm) {
	//set some variables...
	var name = $F('name').strip(),company = $F('company').strip(),email = $F('email').strip(),phone = $F('phone').strip(),subject = $F('subject').strip(),questions_comments = $F('questions_comments').strip();

	//perform some validation...
	if (!validateRequired(name)) {
		alert('Name is required.');
		$('name').focus();
		return false;
	}

	if (!validateRequired(company)) {
		alert('Company is required.');
		$('company').focus();
		return false;
	}

	if (email == '' || !validateEmail(email)) {
		alert('Valid email address is required.');
		$('email').focus();
		return false;
	}

	if (phone == '' || !validatePhone(phone)) {
		alert('Valid phone number is required.');
		$('phone').focus();
		return false;
	}

	if (!validateRequired(subject)) {
		alert('Subject is required.');
		$('subject').focus();
		return false;
	}

	if (!validateRequired(questions_comments)) {
		alert('Question/Comment is required.');
		$('questions_comments').focus();
		return false;
	}

	return true;
}

function validatePasswordResetForm(theForm) {
	//let's make sure the user entered a password and that the password
	//is at least 5 characters in length
	if (theForm.password.value.length < 5) {
		alert("Password must be at least 5 characters.");
		theForm.password.value = '';
		theForm.confirm_password.value = '';
		theForm.password.focus();
		return false;

	}

	//check confirm password field
	if (theForm.confirm_password.value.length < 5) {
		alert("Please confirm the password entered.");
		theForm.confirm_password.value = '';
		theForm.confirm_password.focus();
		return false;
	}

	//check to ensure the two passwords are identical
	if (theForm.password.value != theForm.confirm_password.value) {
		alert("The two passwords you entered do not match. Please re-enter your password.");
		theForm.password.value = '';
		theForm.confirm_password.value = '';
		theForm.password.focus();
		return false;
	}

	return true;
}

/******* End Miscellaneous Functions *******/

/******* Begin Ajax Functions *******/

//We're appending a unique key/value at the end of our url to prevent caching in
//frickin Internet Exploiter (http://www.codestore.net/store.nsf/unid/BLOG-20071130)
function bogusQueryStringParam() {
	return '&_' + new Date().getTime();
}

function ajax(url,target,theFunction,theParams) {
	var completed = function(t) {
						$(target).innerHTML = (t.responseText != '' ? t.responseText : 'Data currently unavailable.');
					}

	url = getAbsPath('awe') + url;
	var pars = 'fnc=' + theFunction + '&params=' + escape(theParams) + bogusQueryStringParam();
	new Ajax.Request(url, {method: 'get',parameters: pars,onCreate: function() {showLoader(target);},onComplete:completed});
}//function ajax(url,target,theFunction,theParams)

function showLoader(target) {
		$(target).innerHTML = '<div id="' + target + '-loading-div">\n' +
							  '<table cellpadding="3" cellspacing="0"  border="0" id="no-border">\n' +
							  '<tr>\n' +
							  '<td class="last">&nbsp;Loading...</td>\n' +
							  '</tr>\n' +
							  '<tr>\n' +
							  '<td class="last"><img src="' + getAbsPath('awe') + 'images/loader.gif" /></td>\n' +
							  '</tr>\n' +
							  '</table>\n' +
							  '</div>';
}//function showLoader(target)

function ajaxDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200 || req.status == 304) {
            results = req.responseText;
            document.getElementById(target).innerHTML = results;
        } else {
            document.getElementById(target).innerHTML = "ajax error:\n" + req.statusText;
       }
   }
}

function hideLoader(target) {
		$(target).innerHTML = '';
}//function hideLoader(target)

/******* End Ajax Functions *******/

/****** Begin PO Form Functions *******/
function toggleComments() {
	if ($('comments-row').style.display == 'none' || $F('comments').strip() == '') {
		$('comments-row').toggle();
	}
}

function addPO() {
	var children = $('customer-po-table').getElementsByTagName('tr'), p = -1;
	for (i = 0; i < children.length; i++) {
		if (children[i].id.startsWith('po_')) {
			p++;
		}
	}

	//add our header if this is our first record
	if (p == -1) {
		$('po-header-row').toggle();
	}

	//increment p
	p += 1;

	var completed = function(t) {
						if (t.responseText != '') {
							Element.insert('add-po-buttons-row', {before:t.responseText});
						} else {
							alert('An unknown error occurred. Please try your request again, if you continue to receive this error, please contact the system administrator.');
						}
					}

	var url = getAbsPath('awe') + 'includes/ajax.php', pars = 'fnc=addPO&params=' + escape(p) + bogusQueryStringParam();
	new Ajax.Request(url, {method: 'get',parameters: pars,onComplete:completed});
}

function removePO(id) {
	var children = $('customer-po-table').getElementsByTagName('tr'), p = -1;

	for (i = 0; i < children.length; i++) {
		if (children[i].id.startsWith('po_')) {
			p++;
		}
	}

	if (p == 0) {
		//hide our header row
		$('po-header-row').toggle();
	}

	$(id).remove();
	return;
}

function validatePOForm() {
	//we need to validate our po entries, since they're grouped we'll
	//iterate through our table and validate each group
	var children = $('customer-po-table').getElementsByTagName('tr'),has_pos = false,product_lines = new Hash();

	for (i = 0; i < children.length; i++) {
			//valid group?
			if (children[i].id.startsWith('po_')) {
				//has pos, set variable
				has_pos = true;

				//set some variables...
				var group_id = children[i].id.gsub(/[^0-9\-\.]/, '');
				var product_line = $F('product_line_' + group_id);
				var po_number = $F('po_number_' + group_id).strip();
				var amount = $F('amount_' + group_id).strip();
				var entry_date = $F('entry_date_' + group_id).strip();

				//perform some validation...
				if (!validateRequired(product_line)) {
						alert('You must select a product line for each line item.');
						$('product_line_' + group_id).focus();
						return false;
				}

				//only initialize if it hasn't already been initialized
				if (product_lines.get(product_line) == undefined) {
					product_lines.set(product_line,0);
				}

				if (!validateRequired(po_number)) {
						alert('You must enter a po # for each line item.');
						$('po_number_' + group_id).focus();
						return false;
				}

				if (amount == '' || !validateNumeric(amount)) {
						alert('You must enter an amount for each line item.');
						$('amount_' + group_id).focus();
						return false;
				}

				if (entry_date == '' || !validateDate(entry_date)) {
						alert('Invalid date entered for line item. Date must be in format mm/dd/yyyy.');
						$('entry_date_' + group_id).focus();
						return false;
				}

				//update our amount for this product line
				amount = amount.replace(/[^0-9.]/g, '');
				product_lines.set(product_line, (parseFloat(product_lines.get(product_line)) + parseFloat(amount)));
			}//if (children[i].id.startsWith('po_'))
	}//for (i = 0; i < children.length; i++)

	//if user has entered at least one PO, we need to validate po amounts
	if (has_pos) {
		//here we're going to check our po amounts, if user submits for approval and the sum of pos for any given product
		//line is less than the entered plan amount for that product line, require user to enter a comment
		var submit_for_approval = isExisting(document.poform.submit_for_approval) ? $F('submit_for_approval') : null;

		if (submit_for_approval != null) {
			var comments = $F('comments').strip(),comments_required = false,hidden_fields = $('poform').getInputs('hidden');

			if (hidden_fields.length > 0) {
				for (var i = 0 ; i < hidden_fields.length; i++) {
					if (hidden_fields[i].id.startsWith('minimum_amount')) {
						product_line = hidden_fields[i].id.replace(/[^0-9]/g, '');
						if (parseFloat(product_lines.get(product_line) == undefined ? 0 : product_lines.get(product_line)) < parseFloat($F('minimum_amount_' + product_line))) {
							comments_required = true;
						}
					}//if (hidden_fields[i].id.startsWith('minimum_amount'))
				}//for (var i = 0 ; i < hidden_fields.length; i++)
			}//if (hidden_fields.length > 0)

			if (comments_required && comments == '') {
				alert('The sum of one or more of the POs entered do not meet the minimum amount for the plan selected. You must enter a comment before you can submit for approval.');
				$('comments').focus();
				new Effect.Highlight('comments-row', {startcolor: '#ffff99', endcolor: '#ffffff'});
				return false;
			}
		}
	}

	return true;
}

function validateApproveDeny(cb_element) {
	//only allowing one checkbox to be checked, but our fields aren't name the same so we're handling here
	var cb_array = $('poform').getInputs('checkbox');

	for (i = 0; i < cb_array.length; i++) {
		if (cb_array[i].checked && cb_array[i].id != cb_element.id) {
			cb_array[i].checked = false;
		}
	}

	return;
}

function toggleChainRow(row_id) {
	$('chain-locations-' + row_id).toggle();
}

/******* End PO Form Functions *******/

/******* Begin Plan Form Functions *******/

function prePopulatePlan(plan_name) {
	//remove all existing product lines
	removeProductLines();
	
	if (plan_name == '') {
		$('releases').value = '';
		$('fluorescent_discount').value = '';
		$('hloi_discount').value = '';
		$('life_safety_discount').value = '';
		$('recessed_track_discount').value = '';
		$('stock_return').value = '';
		$('stock_field_scrap').value = '';
		$('marketing_funds_cap').value = '';

		return;
	} else {
		//prepopulate our data
		
		//plan defaults
		var plan_data = {
						 'Red':{
							'releases':'2 (by 1/31/10)',
							'fluorescent_discount':'1.5%',
							'hloi_discount':'1.5%',
							'life_safety_discount':'1.5%',
							'recessed_track_discount':'1.5%',
							'stock_return':'2',
							'stock_field_scrap':'0.25% (0.5% fluorescent)',
							'marketing_funds_cap':'$2,000'
						 },
						 'White': {
							'releases':'3 (by 1/31/10)',
							'fluorescent_discount':'2.5%',
							'hloi_discount':'2.5%',
							'life_safety_discount':'2.5%',
							'recessed_track_discount':'2.5%',
							'stock_return':'3',
							'stock_field_scrap':'0.25% (0.5% fluorescent)',
							'marketing_funds_cap':'$3,500'
						 },
						 'Blue':{
							'releases':'3 (by 1/31/10) ',
							'fluorescent_discount':'4.0%',
							'hloi_discount':'4.0%',
							'life_safety_discount':'4.0%',
							'recessed_track_discount':'4.0%',
							'stock_return':'4',
							'stock_field_scrap':'0.25% (0.5% fluorescent)',
							'marketing_funds_cap':'$5,000'
						 }
						};

		//form fields
		for (key in plan_data[plan_name]) {
			$(key).value = plan_data[plan_name][key];
		}
		
		//product lines
		addProductLineDefaults();
	}
	
	return;
}

function addProductLineDefaults() {
	var completed = function(t) {
						if (t.responseText != ''){
							Element.insert('add-product-line-buttons-row', {before:t.responseText});
							$('tpl-header-row').show();
						} else {
							alert('An unknown error occurred. Please try your request again, if you continue to receive this error, please contact the system administrator.');
						}
					}

	var url = getAbsPath('awe') + 'includes/ajax.php', pars = 'fnc=addProductLineDefaults'  + bogusQueryStringParam();
	new Ajax.Request(url, {method: 'get', parameters: pars,onComplete:completed});
}

function addProductLine() {
	var children = $('plan-target-lines-table').getElementsByTagName('tr'), p = -1;

	var completed = function(t) {
						if (t.responseText != ''){
							Element.insert('add-product-line-buttons-row', {before:t.responseText});
						} else {
							alert('An unknown error occurred. Please try your request again, if you continue to receive this error, please contact the system administrator.');
						}
					}

	for (i = 0; i < children.length; i++) {
		if (children[i].id.startsWith('tpl_')) {
			p++;
		}
	}

	//add our header if this is our first record
	if (p == -1) {
		$('tpl-header-row').toggle();
	}

	//increment p
	p += 1;

	var url = getAbsPath('awe') + 'includes/ajax.php', pars = 'fnc=addProductLine&params=' + escape(p) + bogusQueryStringParam();
	new Ajax.Request(url, {method: 'get', parameters: pars,onComplete:completed});
}

function removeProductLine(id) {
	var children = $('plan-target-lines-table').getElementsByTagName('tr'),p = -1;

	for (i = 0; i < children.length; i++) {
		if (children[i].id.startsWith('tpl_')) {
			p++;
		}
	}

	if (p == 0) {
		//hide our header row
		$('tpl-header-row').hide();
	}

	$(id).remove();
	return;
}

function removeProductLines() {
	var table = document.getElementById('plan-target-lines-table');
	var rowCount = table.rows.length;
	
	for (var i = 0; i < rowCount; i++) {
		var row = table.rows[i];
	
		if (row.id != 'tpl-header-row' && row.id != 'add-product-line-buttons-row') {
			table.deleteRow(i);
			rowCount--;
			i--;
		}
	}
	
	//hide our header row
	$('tpl-header-row').hide();	
}

function addPlan(agent, customer, region) {
	var theParams = '&agent=' + escape(agent )+ '&customer=' + escape(customer) + '&region=' + escape(region);
	ajax('includes/ajax.php','plan-form-div','showDefinePlanForm',theParams);
}

function validatePlanForm() {
	//we need to validate our po entries, since they're grouped we'll
	//iterate through our table and validate each group
	var children = $('plan-target-lines-table').getElementsByTagName('tr'),product_lines = new Hash(),has_product_lines = false,areDupes = false;

	for (i = 0; i < children.length; i++) {
			//valid group?
			if (children[i].id.startsWith('tpl_')) {
				//set some variables...
				var group_id = children[i].id.gsub(/[^0-9\-\.]/, ''),product_line = $F('product_line_' + group_id),amount = $F('amount_' + group_id).strip();

				//perform some validation...
				if (!validateRequired(product_line)) {
						alert('You must select a product line for each line item.');
						$('product_line_' + group_id).focus();
						return false;
				}

				if (amount == '' || !validateNumeric(amount)) {
						alert('You must enter an amount for each product line.');
						$('amount_' + group_id).focus();
						return false;
				}

				//only initialize if it hasn't already been initialized
				if (product_lines.get(product_line) == undefined) {
					product_lines.set(product_line,0);
				}

				//increment our product line count in our hash
				var pl_count = parseInt(product_lines.get(product_line));
				pl_count++;

				product_lines.set(product_line, pl_count);

				//set has_product_lines since we have valid group
				has_product_lines = true;
			}//if (children[i].id.startsWith('tpl_'))
	}//for (var i = 0; i < children.length; i++)

	//order dating, auto field scrap, and freight claim assistance are only required if user checks the box to show these fields
	if ($F('show_order_dating')) {
			if ($F('order_dating').strip() == '') {
				alert("You must enter a value for Order Dating");
				return false;
			}
	}

	if ($F('show_auto_field_scrap')) {
			if ($F('auto_field_scrap').strip() == '') {
				alert("You must enter a value for Auto Field Scrap");
				return false;
			}
	}

	if ($F('show_freight_claim_assistance')) {
			if ($F('freight_claim_assistance').strip() == '') {
				alert("You must enter a value for Freight Claim Assistance");
				return false;
			}
	}

	//checking here being that these are below our form fields
	if (!has_product_lines) {
		alert('No product lines have been defined.');
		return false;
	}

	//let's validate our product lines to only allow one to be added
	product_lines.each(function(pair) {
					   	if (parseInt(pair.value) > 1) {
							areDupes = true;
						}
	});

	if (areDupes) {
		alert('Duplicate product lines have been entered for this plan. Please correct and resubmit.');
		return false;
	}

	return true;
}

/******* End Plan Form Functions *******/

/******* Begin Enrollment Functions *******/

function submitCustomerSearch(agent) {
	var id = $F('company.customer.id'),name = $F('company.customer.name'),buy_group_id = $F('company.customer.buy_group_id'),chain_id = $F('company.customer.chain_id'),city = $F('company.location.city'),state = $F('company.location.state_id'),zip = $F('company.location.zip');

	if (id == '' && name == '' && buy_group_id == '' && chain_id == '' && city == '' && state == '' && zip == '') {
		alert('At least one search criteria is required');
		$('company.customer.id').focus();
		$('search-results-row').hide();
		return;
	} else {
		ajax('includes/ajax.php', 'search-results', 'showCustomerSearchResults', escape('&agent=' + escape(agent) + '&company.customer.id=' + escape(id) + '&company.customer.name=' + escape(name) + '&company.customer.buy_group_id=' + escape(buy_group_id) + '&company.customer.chain_id=' + escape(chain_id) + '&company.location.city=' + escape(city) + '&company.location.state_id=' + escape(state) + '&company.location.zip=' + escape(zip)));
	}

	$('search-results-row').show();

	return;
}

function validateCustomerAgentAssignment(row_id) {
	var agent = $F('agent_' + row_id);

	if (agent == '') {
		alert('Please select an agent to associate with this customer.');
		new Effect.Highlight('customer_row_' + row_id, {startcolor: '#ffff99', endcolor: '#ffffff'});
		$('agent_' + row_id).focus();
		return false;
	}

	//set our row to process, not going to loop through all fields
	$('which_row').value = row_id;
	return true;
}

function validateTargetEnrollmentForm(user_type) {
	if (user_type == 'admin') {
		var period = $F('period_id');

		if (period == '') {
			alert('You must select a period for this enrollment.');
			$('period_id').focus();
			return false;
		}
	} else {
		return false;
	}

	return true;
}

function validateEnrollmentForm(admin) {
	var plans = $('enrollform').getInputs('radio'),plan_count = plans.length,checked_plan = false;

	for (var i = 0; i < plan_count; i++) {
		if (plans[i].checked) {
			checked_plan = true;
			break;
		}
	}

	//only check our customer contact fields if this isn't an admin
	if (admin != '1') {
		var contact_name = $F('contact_name').strip(),address = $F('address').strip(),city = $F('city').strip(),state = $F('state_id'),zip = $F('zip').strip(),email = $F('email').strip();

		if (!validateRequired(contact_name)) {
			alert('Contact name is required.');
			$('contact_name').focus();
			return false;
		}

		if (!validateRequired(address)) {
			alert('Address is required.');
			$('address').focus();
			return false;
		}

		if (!validateRequired(city)) {
			alert('City is required.');
			$('city').focus();
			return false;
		}

		if (!validateRequired(state)) {
			alert('State is required.');
			$('state_id').focus();
			return false;
		}

		if (!validateZip(zip)) {
			alert('Valid zip code is required.');
			$('zip').focus();
			return false;
		}

		if (!validateEmail(email)) {
			alert('Valid email address is required.');
			$('email').focus();
			return false;
		}
	}

	return true;
}

function deleteEnrollment(enroll_id) {
	var target = 'rightcolumn';
	var completed = function(t) {
						$(target).innerHTML = (t.responseText != '' ? t.responseText : 'An unknown error occurred. If you continue to receive this message, please contact your system administrator.');
					}

	var pars = 'fnc=deleteEnrollment&params=' + escape(enroll_id) + bogusQueryStringParam();
	new Ajax.Request(getAbsPath('awe') + 'includes/ajax.php', {
		method: 'post',
		parameters: pars,
		onCreate: function() {showLoader(target);},
		onComplete:completed
	});
}
/******* End Enrollment Functions *******/

/******* Begin Helper Functions *******/

function validateRequired(sVal) {
	//if it is rquired and blank then it is an error and continues to be required
	return (sVal != "" ? true : false);
}

function validateDate(sVal) {
	// our date regular expression (http://www.regexlib.com)
	var regex=/((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(11|0?[469])([/])(30|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(2[0-8]|1[0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(29)([/])([2468][048]00)$)|(^(0?2)([/])(29)([/])([3579][26]00)$)|(^(0?2)([/])(29)([/])([1][89][0][48])$)|(^(0?2)([/])(29)([/])([2-9][0-9][0][48])$)|(^(0?2)([/])(29)([/])([1][89][2468][048])$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048])$)|(^(0?2)([/])(29)([/])([1][89][13579][26])$)|(^(0?2)([/])(29)([/])([2-9][0-9][13579][26])$))/;
	return (regex.test(sVal) ? true : false);
}

function validateEmail(sVal) {
	//our email regular expression (http://www.regexlib.com)
	var regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return (regex.test(sVal) ? true : false);
}

function validatePhone(sVal) {
	//our regular expression to match phone numbers
	//Written by Liu Wei.(http://www.regexlib.com)
	var regex=/((\(\d{3,4}\)|\d{3,4}-)\d{4,9}(-\d{1,5}|\d{0}))|(\d{4,12})/;
	return (regex.test(sVal) ? true : false);
}

function validateZip(sVal) {
	// our email regular expression
	//Javascript matches US zipcodes not allowing all zeros in first 5 or +4 (http://www.regexlib.com)
	// Matches:  00501, 84118-3423, n3a 3B7
	var regex=/^((\d{5}-\d{4})|(\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d))$/;
	return (regex.test(sVal) ? true : false);
}

function validateNumeric(sVal) {
	//This expression will validate for US Currency with a wide range of input
	//Matches: 	[$1.99], [1.99], [.99] (http://www.regexlib.com)
	var regex =/^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.\d{1,2}?)$/;
	return (regex.test(sVal) ? true : false);
}

function explodeArray(item,delimiter) {
	var tempArray=new Array(1),Count=0,tempString=new String(item);

	while (tempString.indexOf(delimiter)>0) {
		tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
		tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
		Count=Count+1
	}//while (tempString.indexOf(delimiter)>0)

	tempArray[Count]=tempString;
	return tempArray;
}//function explodeArray(item,delimiter)

function isExisting(obj) {
  return typeof(obj) != 'undefined';
}//function isExisting(obj)

/******* End Helper Functions *******/