function moneyFormat(textObj, dolSign) {
   var newValue = textObj.value;
   var decAmount = "";
   var dolAmount = "";
   var decFlag = false;
   var aChar = "";
   var dolSign = dolSign?'$':'';
   
   // ignore all but digits and decimal points.
   for(i=0; i < newValue.length; i++) {
      aChar = newValue.substring(i,i+1);
      if(aChar >= "0" && aChar <= "9") {
         if(decFlag) {
            decAmount = "" + decAmount + aChar;
         }
         else {
            dolAmount = "" + dolAmount + aChar;
         }
      }
      if(aChar == ".") {
         if(decFlag) {
            dolAmount = "";
            break;
         }
         decFlag=true;
      }
   }
   
   // Ensure that at least a zero appears for the dollar amount.

   if(dolAmount == "") {
      dolAmount = "0";
   }
   // Strip leading zeros.
   if(dolAmount.length > 1) {
      while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
         dolAmount = dolAmount.substring(1,dolAmount.length);
      }
   }
   
   // Round the decimal amount.
   if(decAmount.length > 2) {
      if(decAmount.substring(2,3) > "4") {
         decAmount = parseInt(decAmount.substring(0,2)) + 1;
         if(decAmount < 10) {
            decAmount = "0" + decAmount;
         }
         else {
            decAmount = "" + decAmount;
         }
      }
      else {
         decAmount = decAmount.substring(0,2);
      }
      if (decAmount == 100) {
         decAmount = "00";
         dolAmount = parseInt(dolAmount) + 1;
      }
   }
   
   // Pad right side of decAmount
   if(decAmount.length == 1) {
      decAmount = decAmount + "0";
   }
   if(decAmount.length == 0) {
      decAmount = decAmount + "00";
   }
   
   if(dolAmount)
   {
   	dolAmount = CommaFormatted(dolAmount);
   }
   // Check for negative values and reset textObj
   if(newValue.substring(0,1) != '-' ||
         (dolAmount == "0" && decAmount == "00")) {
      textObj.value = dolSign + dolAmount + "." + decAmount;

   }
   else{
      textObj.value = '-' + dolSign + dolAmount + "." + decAmount;
   }
}


function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	//var a = amount.split('.',2)
	//var d = a[1];d
	var d = [];
	var a = [];
	while(amount.length > 3)
	{
		var nn = amount.substr(amount.length-3);
		a.unshift(nn);
		amount = amount.substr(0,amount.length-3);
	}
	if(amount.length > 0) { a.unshift(amount); }
	n = a.join(delimiter);
	//if(d.length < 1) { amount = n; }
	//else { amount = n + '.' + d; }
	//amount = minus + amount;
	return n;
}



function checkEmpty(obj)
{
	trim_value = trim(obj.value);
	if(!trim_value)
	{	
		
		alert('This field should not be empty!');
		
		obj.style.border="1px solid #F52105";
		obj.focus();
		
	}	
}

function restore_border(obj)
{
	obj.style.border='1px solid #545353';
	document.getElementById('error_div').style.display='none';
}

function check_submit()
{
	$output = true;
	$email = getHtmlById('email');
	// required
	$array = new Array('full_name','phone','email','subject','message');
	for(i=0; i<$array.length; i++)
	{
		if(!trim(getHtmlById($array[i])))
		{
			document.getElementById($array[i]).style.border="1px solid #F52105";
			$output = false;
		}
	}
	
	 
	
	if($email && $output)
	{
		$invalid_email = false;
		if(!validateEmail($email))
		{
			document.getElementById('email').style.border="1px solid #F52105";
			alert('Invalid email format!');
			$invalid_email = true;
			$output = false;
			
		}

	}
	if(!$output) document.getElementById('error_div').style.display='';
	return $output;
}


function isNumeric(field)
 {
	  var check = true;
	  var value = field.value; //get characters
	  //check that all characters are digits, ., -, or ""
	  for(var i=0;i < field.value.length; ++i)
	  {
		   var new_key = value.charAt(i); //cycle through characters
		   if(((new_key < "0") || (new_key > "9")) && 
				!(new_key == ""))
		   {
				check = false;
				break;
		   }
	  }
	  return check;

 }
 
function validateEmail(id)
{
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
	return emailPattern.test(id);

} 
