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);
}

function IsValidEmail(sEmail){	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(sEmail)) return true;
}

// convert the content of the form into a GET string
// only text, checkbox, radio, select, textarea, hidden, password are processed.
function parseForm(formObj) {
	
	var getstr = "";

	for (i = 0; i < formObj.elements.length; i++) {
		var ele = formObj.elements[i];
		if (ele.tagName == "INPUT") {
			if (ele.type == "text" || ele.type == "hidden" || ele.type == "password") {
				getstr += ele.name + "=" + encodeURI(ele.value) + "&";
			}
			if (ele.type == "checkbox") {
				if (ele.checked) {
						getstr += ele.name + "=" + encodeURI(ele.value) + "&";
				} else {
						getstr += ele.name + "=&";
				}
			}
			if (ele.type == "radio") {
				if (ele.checked) {
						getstr += ele.name + "=" + encodeURI(ele.value) + "&";
				}
			}
		}
		if (ele.tagName == "SELECT") {
			var sel = ele;
			if (sel.multiple) {
				for (optionIndex = 0; optionIndex < sel.options.length; optionIndex++) {
					var opt = sel.options[optionIndex];
					if (opt.selected) {
						getstr += sel.name + "=" + encodeURI(opt.value) + "&";
					}
				}
			} else {
				if (sel.selectedIndex >= 0) {
					getstr += sel.name + "=" + encodeURI(sel.options[sel.selectedIndex].value) + "&";
				} //following the convention of a normal form submit, if nothing selected, do not include this select item
			}
		}
		if (ele.tagName == "TEXTAREA") {
			getstr += ele.name + "=" + encodeURI(ele.value) + "&";
		}
	}

	return getstr;
}


function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else 
  		countfield.value =  field.value.length;
//		countfield.value = maxlimit - field.value.length;}
}

function PopupDisplayProperty(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=Yes,location=0,statusbar=0,menubar=0,resizable=0,width=750,height=600,left=232,top=160');");
}

function popUpPreview(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=Yes,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=670,left=232,top=160');");
}

function CheckAll(FormName, CheckboxName, val) {
	dml=document.FormName;
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (dml.elements[i].name==CheckboxName) {
			dml.elements[i].checked=val;
		}
	}
}
function SearchRedirect(id) {
	switch (id) {
	// toddlers
	case 1: location.replace('searchresult.asp'); break;
	// twins
	case 2: location.replace('searchresult.asp'); break;
	// crawlers
	case 3: location.replace('searchresult.asp'); break;
	// babies
	case 4: location.replace('searchresult.asp'); break;
	// pre-school
	case 5: location.replace('searchresult.asp'); break;
	
	default: location.replace('searchresult.asp');
	}		
}
