function parse_phone(_phone)
{
//this parse requires an areacode.
	oldphone = new String(_phone);
	newphone = new String();

	re = new RegExp("[.]","g");
	oldphone =  oldphone.replace(re,"");
	re = new RegExp("[ ]","g");
	oldphone =  oldphone.replace(re,"");
	re = new RegExp("[-]","g");
	oldphone =  oldphone.replace(re,"");
	re = new RegExp("[(]","g");
	oldphone =  oldphone.replace(re,"");
	re = new RegExp("[)]","g");
	oldphone =  oldphone.replace(re,"");


if(oldphone.length == 10)
	{
	newphone = "(" + oldphone.slice(0,3) + ")" + " " + oldphone.slice(3,6) + "-" + oldphone.slice(6,10);
	return newphone;
//	alert(oldphone + "\n" + newphone);
	}
if(oldphone.length == 7)
	{
	newphone = oldphone.slice(0,3) + "-" + oldphone.slice(3,7);
	return newphone;
//	alert(oldphone + "\n" + newphone);
	}

return oldphone;
}
function valid_phone(_phone)
{

// this valid phone requires an area code

	oldphone = new String(_phone);
	newphone = new String();
	if(oldphone.length > 8)
	{
	if(isNaN(oldphone.slice(1,4)) || isNaN(oldphone.slice(6,9)) || isNaN(oldphone.slice(10,14)))
		{
		return false;
		}
	}else{
	if(isNaN(oldphone.slice(0,3)) || isNaN(oldphone.slice(4,9)))
		{
		return false;
		}

	}
	return true;
}
function clean_dollar(_dollar)
	{
	
	
	olddollar = new String(_dollar);
	newdollar = new String();
	
	re = new RegExp("[ ]","g");
	olddollar =  olddollar.replace(re,"");
	re = new RegExp("[-]","g");
	olddollar =  olddollar.replace(re,"");
	re = new RegExp("[,]","g");
	olddollar =  olddollar.replace(re,"");
	re = new RegExp("[$]","g");
	olddollar =  olddollar.replace(re,"");
	re = new RegExp("[+]","g");
	olddollar =  olddollar.replace(re,"");
	re = new RegExp("[(]","g");
	olddollar =  olddollar.replace(re,"");
	re = new RegExp("[)]","g");
	olddollar =  olddollar.replace(re,"");
	
	newdollar = olddollar;
	return newdollar;
	}
function parse_dollar(_dollar)
	{
	var comma = 3
	var commaKount = 0
	
	olddollar = new String(_dollar);
	newdollar = new String();
	
	re = new RegExp("[.]","g");
	
	var dot = olddollar.search(re);
	
	if(dot == olddollar.length - 1)
		{
		olddollar = olddollar + "00";
		}
	if(dot == olddollar.length - 2)
		{
		olddollar = olddollar + "0";
		}
	if(dot == -1)
		{
		olddollar = olddollar + ".00";
		}
		
	while(olddollar.length - 3 - comma - commaKount > 0)
	{
	olddollar = olddollar.slice(0,olddollar.length - 3 - comma - commaKount) + "," + olddollar.slice(olddollar.length - 3 - comma - commaKount,olddollar.length);
	commaKount++;
	comma = comma + 3;
	if(commaKount > 3)
		break;
	}

	newdollar = "$" + olddollar;
	return newdollar;
	}
//
//	setdollar(_dollar)
//	_dollar is the javascript input element location (e.g. document.myform.myinputfield)
//	
//
//
function setdollar(_dollar)
	{
	if(_dollar.value != "")
		{
		cleanvalue = clean_dollar(_dollar.value);
		_dollar.value = parse_dollar(cleanvalue);
		}
	}
function ZoomIt(ZLocation)
{
winname = window.open(ZLocation,"detwin","toolbar=no,location=no,status=yes,scrollbars,resizable,dependent,width=660,height=485");
winname.focus();
winname.moveTo(25,25);
}
function ZoomIt2(ZLocation,winname2,myx,myy)
{
if(myx =="")
	myx = 660;
if(myy == "")
	myy = 485;
winname = window.open(ZLocation,winname2,"menubar=yes,toolbar=NO,location=NO,status=yes,scrollbars,resizable,dependent,width=" + myx + ",height=" + myy);
winname.focus();
winname.moveTo(25,25);
}


//////////////////////////////////////
//									//
//			US Phone Check			//
//									//
//////////////////////////////////////
function USphoneCheck(_name)
{	
	var frmValue = _name.value;
	var phoneregex = /^\(?(\d{3})\)?[\s\.\-\/]?(\d{3})[\s\.\-\/]?(\d{4})$/;
				  
	validPhone = phoneregex.exec(_name.value);
	
	if(validPhone)
    {
	 _name.value="(" + validPhone[1] +") " + validPhone[2] + "-" + validPhone[3];
	}
	else
	{
		if (_name.value != "")
		{
		 // Use CONFIRM or ALERT to warn user
			var agree=confirm("' " + frmValue + " '" + " is not a valid phone number\n\nFinal Format:\n(123) 123-1234\n\nAccepted Data Entry Formats:\n123.123.1234\n123-123-1234\n1231231234\n(123) 123-1234\n\nAccepted Formats will be re-formatted to Final Format\n\nForm Submission will NOT be allowed\nunless the field is blank or in the Final Format\n\nPress 'OK' to edit the number, 'CANCEL' to continue.");
			if (agree) 
			{
				_name.focus();
				_name.select();
			}
			else
			{
				return true;
			}
		 // alert ("' " + frmValue + " '" + " is not a valid phone number\n\nFinal Format:\n(123)123-1234\n\nAccepted Data Entry Formats:\n123.123.1234\n123-123-1234\n1231231234\n\nAccepted Formats will be re-formatted to Final Format\n\nForm Submission will not be allowed\nunless the field is blank or in the Final Format");
		}
	}
	return false;
}
function Format_Phone(_name)
{	
	var frmValue = _name.value;
	var phoneregex = /^\(?(\d{3})\)?[\s\.\-\/]?(\d{3})[\s\.\-\/]?(\d{4})$/;
				  
	validPhone = phoneregex.exec(_name.value);
	
	if(validPhone)
    {
	 _name.value="(" + validPhone[1] +") " + validPhone[2] + "-" + validPhone[3];
	}
	
	return _name.value;
}
