function checkForm(formID) { 
	formbox = eval("document." + formID); 
	if (isEmpty(formbox.elements['First Name'].value)) {
	formbox.elements['First Name'].style.backgroundColor='#fff0f5';
	formbox.elements['First Name'].style.fontWeight='bold';
	formbox.elements['First Name'].style.color='#660000';
		alert("Please enter a valid First Name");
		formbox.elements['First Name'].focus();
		return false;
	} else if (isEmpty(formbox.elements['Last Name'].value)) {
	formbox.elements['Last Name'].style.backgroundColor='#fff0f5';
	formbox.elements['Last Name'].style.fontWeight='bold';
	formbox.elements['Last Name'].style.color='#660000';
		alert("Please enter a valid Last Name");
		formbox.elements['Last Name'].focus();
		return false;
	} else if (!isValidEmail(formbox.elements['Email Address'].value)) {
	formbox.elements['Email Address'].style.backgroundColor='#fff0f5';
	formbox.elements['Email Address'].style.fontWeight='bold';
	formbox.elements['Email Address'].style.color='#660000';
		alert("Please enter a valid Email Address. (name@host.com)");
		formbox.elements['Email Address'].focus();
		return false;
	} else {
		return true;
	}
	
	
	
}


function toggleMe() {
var div2 = document.getElementById('div2');
var div1 = document.getElementById('div1');
	if ( div2.className == 'hide' ) {
		div2.className = 'show';
		div1.className = 'hide';
	} else {
		div2.className = 'hide';
		div1.className = 'show';
	}
}



var _T = "locked";
var _F = "unlocked";
function lockIt(_P)  {

	var _L = document.theForm.lck.value;
	
	if(_L==_P)return;
	document.theForm.city.disabled=(document.theForm.lck.value=(_L==_F)?_T:_F)==_T;
	document.theForm.zipcode.disabled=(document.theForm.lck.value=(_L==_F)?_T:_F)!=_T;
}


function lockIt_2(_P)  {

	var _L = document.theForm.lck_2.value;
	
	if(_L==_P)return;
	document.theForm.streetnumber1.disabled=(document.theForm.lck_2.value=(_L==_F)?_T:_F)!=_T;
	document.theForm.street_number_start.disabled=(document.theForm.lck_2.value=(_L==_F)?_T:_F)==_T;
	document.theForm.street_number_end.disabled=(document.theForm.lck_2.value=(_L==_F)?_T:_F)==_T;
	
}

function CheckAll() {
  for (var i = 0; i < document.thisForm.elements.length; i++) {
    if(document.thisForm.elements[i].type == 'checkbox'){
      document.thisForm.elements[i].checked =  false;
	}
  }
}


function compHomePopUp(url) {
	window.open(url,"MyPopup",'height=300,width=500');
} 


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1997;
var now = new Date();
var maxYear = now.getFullYear();
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		return false;
	}
return true
}

function ValidateForm(){
	var dt=document.theForm.sdate;
	var dt1=document.theForm.edate;
	var epur=document.theForm.epurchaseprice;
	var spur=document.theForm.spurchaseprice;
	
	
	if (!IsNumeric(spur.value))  { 
		alert('Please enter only numbers for the Purchase Price.') 
		spur.focus(); 
		return false; 
	}
	  
	if (!IsNumeric(epur.value)) { 
		alert('Please enter only numbers for the Purchase Price.') 
		epur.focus(); 
		return false; 
	} 
	
	if (spur.value.length != 0 && epur.value.length == 0) { 
		alert('Please enter an ending Purchase Price.') 
		epur.focus(); 
		return false; 
	} 
	
	if (parseInt(spur.value) > parseInt(epur.value)) { 
		alert('Your Ending Purchase Price needs to be higher than you Starting.') 
		epur.focus(); 
		return false; 
	} 
    return true;
 }

function IsNumeric(sText) {
	var ValidChars = "0123456789,";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)  { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1)  {
			IsNumber = false;
		}
	}
	return IsNumber;
}


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function roundNumber(number,decimals) {
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
			numString += ".";// give it one at the end
		}
		var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
		var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
		if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
			if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		newString = numString.substring(0,cutoff) + d1.toString();
	}
	if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i < decimals-decs;i++) newString += "0";
	return newString; // Output the result to the form field (change for your purposes)
}


