
function CheckCoupon(CouponCode) {
		if(CouponCode.length == 6 || CouponCode.length == 7) { 
			//return true;
			document.getElementById('lblCouponStatus').innerHTML = "<strong><font color=\"black\">Checking Coupon...</font></strong>"
			var oXMLHttp = zXmlHttp.createRequest();
			var url = "CheckCoupon.asp?CouponCode=" + CouponCode
			//			alert(url)
			oXMLHttp.open("GET", url + '&rnd=' + Math.random(), true);
			oXMLHttp.onreadystatechange = function() {
				if(oXMLHttp.readyState == 4) {
					if(oXMLHttp.status == 200){
						var Response = oXMLHttp.responseText;
						HandleCounponResponse(Response)
					} else alert("There was an error while processing this screen.  The document was not ready to process. (Code: CC-" + oXMLHttp.status + ")  Please try again.");
				}
			};
			oXMLHttp.send(null);
		} else {
			document.getElementById('lblCouponStatus').innerHTML = "<strong><font color=\"red\">Coupon Not Valid.</font></strong>";
			document.getElementById('bCoupon').value = 0;
			//	document.getElementById('couponcode').focus()
			return false;
		}
}

function HandleCounponResponse(sRes) {
	if(sRes == 0) {
		document.getElementById('lblCouponStatus').innerHTML = "<strong><font color=\"red\">Coupon Not Valid.</font></strong>";
		document.getElementById('bCoupon').value = 0;
		// document.getElementById('couponcode').focus()
		return false;
	}	else {
		document.getElementById('lblCouponStatus').innerHTML = "<strong><font color=\"green\">Coupon Valid</font></strong>";
		document.getElementById('bCoupon').value = 1;
		return true;
	}
}

function CheckPassword(Password){
	if(Password.length < 6) { 
		document.getElementById('lblPasswordStatus').innerHTML = "<strong><font color=\"red\">Too Short - Min Len 6 Chars</font></strong>"	
	} else {
		document.getElementById('lblPasswordStatus').innerHTML = ' '	
	}
}		

function CheckUserName(UserName){
	// SAVE THE ROUND TRIP IF THE NAME IS BLANK
	if(UserName != '') {
		if(UserName.length < 6) { 
			document.getElementById('lblUserNameStatus').innerHTML = "<strong><font color=\"red\">Too Short - Min Len 6 Chars</font></strong>"	
		} else {
			document.getElementById('lblUserNameStatus').innerHTML = "<strong><font color=\"black\">Checking Username Availability...</font></strong>"
			var oXMLHttp = zXmlHttp.createRequest();
			var url = "CheckUserName.asp?UserName=" + UserName
			//			alert(url)
			oXMLHttp.open("GET", url + '&rnd=' + Math.random(), true);
			oXMLHttp.onreadystatechange = function() {
				if(oXMLHttp.readyState == 4) {
					if(oXMLHttp.status == 200){
						var Response = oXMLHttp.responseText;
						HandleResponse(Response)
					} else alert("There was an error while processing this screen.  The document was not ready to process. (Code: CUN-" + oXMLHttp.status + ")  Please try again.");
				}
			};
			oXMLHttp.send(null);
		}
	}
}

function HandleResponse(sRes) {
	if(sRes == 0) {
		document.getElementById('lblUserNameStatus').innerHTML = "<strong><font color=\"red\">Username Taken, Please Try Another One.</font></strong>"
		document.getElementById('UserName').focus()
	}	else {
		document.getElementById('lblUserNameStatus').innerHTML = "<strong><font color=\"green\">Username Available</font></strong>"
	}
}





function CheckAddress(){

	if(((document.getElementById("City").value != '' && document.getElementById("StateCode").value != '') || document.getElementById("ZipCode").value != '')) {
		sAddress = document.getElementById("Street1").value + ', ' + document.getElementById("City").value + ', ' + document.getElementById("StateCode").value + ', ' + document.getElementById("ZipCode").value;
		document.getElementById("divResults").innerHTML = '<strong>Verifying Address...</strong>';
		GetLonLat(sAddress);
	}
}

function GetLonLat(searchid) { 
	geocode.getLocations(searchid, addpoint); 
}

function addpoint(results){
	var place;
	var errcode;
	
	if(results.Status.code == 200) {
		/*
		http://www.google.com/apis/maps/documentation/reference.html#GGeoStatusCode
		G_GEO_SUCCESS (200) 	 No errors occurred; the address was successfully parsed and its geocode has been returned. (Since 2.55)
		G_GEO_SERVER_ERROR (500) 	A geocoding request could not be successfully processed, yet the exact reason for the failure is not known. (Since 2.55)
		G_GEO_MISSING_ADDRESS (601) 	The HTTP q parameter was either missing or had no value. (Since 2.55)
		G_GEO_UNKNOWN_ADDRESS (602) 	No corresponding geographic location could be found for the specified address. This may be due to the fact that the address is relatively new, or it may be incorrect. (Since 2.55)
		G_UNAVAILABLE_ADDRESS (603) 	The geocode for the given address cannot be returned due to legal or contractual reasons. (Since 2.55)
		G_GEO_BAD_KEY (610) 	The given key is either invalid or does not match the domain for which it was given. (Since 2.55)
		*/

		place = results.Placemark[0];
		sLongitude = place.Point.coordinates[0];
		sLatitude = place.Point.coordinates[1];
		
		//document.getElementById("divResults").innerHTML = document.getElementById("divResults").innerHTML + '<br>Long: ' + sLongitude + '<br>Lat: ' + sLatitude;
		document.getElementById("Latitude").value = sLatitude
		document.getElementById("Longitude").value = sLongitude
		document.getElementById("divProcessStatus").innerHTML = document.getElementById("divProcessStatus").innerHTML + 'Latitude: ' + sLatitude + ' <br>\n Longitude: ' + sLongitude + ' <br>\n <u> Accuracy: ' + results.Placemark[0].AddressDetails.Accuracy + '</u><br>';
		//document.getElementById("divResults").innerHTML
		
		//alert(place.AddressDetails.Accuracy)
		document.getElementById("divResults").innerHTML = document.getElementById("divResults").innerHTML + place.address
		/*
		http://www.google.com/apis/maps/documentation/reference.html#GGeoAddressAccuracy
		4 	 Town (city, village) level accuracy. (Since 2.59)
		5 	Post code (zip code) level accuracy. (Since 2.59)
		6 	Street level accuracy. (Since 2.59)
		7 	Intersection level accuracy. (Since 2.59)
		8 	Address level accuracy. (Since 2.59)
		*/

		
		if(results.Placemark[0].AddressDetails.Accuracy > 5){
			document.getElementById("divResults").innerHTML = '<strong><font color=\"green\">Address Verified</font></strong>';
			document.getElementById("accuracy").value = results.Placemark[0].AddressDetails.Accuracy;
		} else {
			document.getElementById("divResults").innerHTML = '<strong><font color=\"yellow\" style=\"background-color: #cccccc;\">Address Verified (' + results.Placemark[0].AddressDetails.Accuracy + ')</font></strong>';
			document.getElementById("accuracy").value = results.Placemark[0].AddressDetails.Accuracy;
			//alert(document.getElementById("accuracy").value);
		}
	} else {
			if(sAddress.length > 5){
				
				//alert(document.getElementById("ZipCode").value);
				GetLonLat(document.getElementById("ZipCode").value)
			}else{
				document.getElementById("divResults").innerHTML = '<strong><font color=\"red\">Your Address May Be Invalid.  Please Verify Your Address.</font></strong>';			
			}

		//errcode = results.Status.code;
		//alert('Invalid Address.  Please Verify Your Address Is Entered Correctly. \n Error Code:' + errcode + '\n If your address is correct please call us for assistance.  877-444-6339')
		//document.getElementById("Street1").focus();
	}

}




//  This function will select an item from a drop down list.
//  DropDownId - The id of the drop down box we are looking through.
//  ValToSet - This is the value from the drop down we are looking to match.
//  #### NOTES
//  This function must be called after the page has loaded... aka in the page onload.  Otherwise the drop down box
//  might not be printed to the site yet.
//  Created By:  AjW
function SelectFromDropDown(DropDownId, ValToSel) {
	VID = document.getElementById(DropDownId)
	for (var i=0;i<VID.length;i++) {
		if(VID.options[i].value == ValToSel) { 
			VID.options[i].selected = true;
			break;
		}
	}
}

function RemoveBad(strTemp) {
    strTemp = strTemp.replace(/\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-/g,"");
    return strTemp;
}

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);
}




/* **********************************************************************************
//   SINCE THERE ARE MANY NEEDS FOR STATE Related Function We've Create A State Object
//  Properties -  	States[Array].Code
					States[Array].Name
					
	Methods - 		StateNameByCode("2 Letter State Code") - returns state name
					StateCodeByName("State Name") - returns 2 letter state code
					GetStatesDD() - returns prefilled <OPTIONS> to use inside a drop down.
************************************************************************************/
function GetStateObject() {
	
	var objStates = new Object();
	
	var objStates = {
		States : [
				{ Code: "AL", Name: "Alabama" },
				{ Code: "AK", Name: "Alaska" },
				{ Code: "AZ", Name: "Arizona" },
				{ Code: "AR", Name: "Arkansas" },
				{ Code: "CA", Name: "California" },
				{ Code: "CO", Name: "Colorado" },
				{ Code: "CT", Name: "Connecticut" },
				{ Code: "DE", Name: "Delaware" },
				{ Code: "FL", Name: "Florida" },
				{ Code: "GA", Name: "Georgia" },
				{ Code: "HI", Name: "Hawaii" },
				{ Code: "ID", Name: "Idaho" },
				{ Code: "IL", Name: "Illinois" },
				{ Code: "IN", Name: "Indiana" },
				{ Code: "IA", Name: "Iowa" },
				{ Code: "KS", Name: "Kansas" },
				{ Code: "KY", Name: "Kentucky" },
				{ Code: "LA", Name: "Louisiana" },
				{ Code: "ME", Name: "Maine" },
				{ Code: "MD", Name: "Maryland" },
				{ Code: "MA", Name: "Massachusetts" },
				{ Code: "MI", Name: "Michigan" },
				{ Code: "MN", Name: "Minnesota" },
				{ Code: "MS", Name: "Mississippi" },
				{ Code: "MO", Name: "Missouri" },
				{ Code: "MT", Name: "Montana" },
				{ Code: "NE", Name: "Nebraska" },
				{ Code: "NV", Name: "Nevada" },
				{ Code: "NH", Name: "New Hampshire" },
				{ Code: "NJ", Name: "New Jersey" },
				{ Code: "NM", Name: "New Mexico" },
				{ Code: "NY", Name: "New York" },
				{ Code: "NC", Name: "North Carolina" },
				{ Code: "ND", Name: "North Dakota" },
				{ Code: "OH", Name: "Ohio" },
				{ Code: "OK", Name: "Oklahoma" },
				{ Code: "OR", Name: "Oregon" },
				{ Code: "PA", Name: "Pennsylvania" },
				{ Code: "RI", Name: "Rhode Island" },
				{ Code: "SC", Name: "South Carolina" },
				{ Code: "SD", Name: "South Dakota" },
				{ Code: "TN", Name: "Tennessee" },
				{ Code: "TX", Name: "Texas" },
				{ Code: "UT", Name: "Utah" },
				{ Code: "VT", Name: "Vermont" },
				{ Code: "VA", Name: "Virginia" },
				{ Code: "WA", Name: "Washington" },
				{ Code: "DC", Name: "Washington DC" },
				{ Code: "WV", Name: "West Virginia" },
				{ Code: "WI", Name: "Wisconsin" },
				{ Code: "WY", Name: "Wyoming" }
			],
		StateNameByCode:function(StateCode) {
				for (i=0;i<this.States.length;i++) {
					if (this.States[i].Code == StateCode) {
						return this.States[i].Name;
						break;
					}
				}
			},
		StateCodeByName:function(StateName) {
				for (i=0;i<this.States.length;i++) {
					if (this.States[i].Name == StateName) {
						return this.States[i].Code;
						break;
					}
				}
			},				
		GetStatesDD:function() {
				var sDD = "";
				for (i=0;i<this.States.length;i++) {
					sDD += "<OPTION value=\"" + this.States[i].Code + "\">" + this.States[i].Name + "</OPTION>";
				}
				return sDD;
				}	
		}	
	return objStates;
}	


function ToggleVisible(divID) {
	var divEl = document.getElementById(divID)
	var isVisible = (divEl.style.visibility == 'hidden') ? true : false;
	
	divEl.style.visibility = isVisible ? "visible" : "hidden";
	divEl.style.display = isVisible ? "inline" : "none";
}