﻿function CheckCookies(){
	var CookiesOff;
	
	//if cookies are not enabled let user know that browser must be supporting cookies for this demo to run ok
	CookiesOff = CheckForCookiesOn();	
	
}
function CheckForCookiesOn(){
//checks to see if browser has cookie support enabled,
//	if not an alert box is displayed, letting user know we need cookies
//also returns true if cookies disabled, otherwise false is returned	
	var blnCookiesSupported = false;
	
	//set the cookie
	document.cookie = 'testit' + "=" + escape('hi') + ";"
	
	//now attempt to retrieve the cookie
	var aCookie = document.cookie.split(";");
	for (var i=0; i < aCookie.length; i++)
	{ 
		var aCrumb = aCookie[i].split("=");
		if ('testit' == aCrumb[0])
		{
			blnCookiesSupported=true; 
			return false; 
		}	
		if (blnCookiesSupported==false){
			alert('In order to obtain a Quick Quote your browser must be set up so that it utilizes cookies.');
			return true;
		}
	}
}
window.onload = CheckCookies;	

function format_phone(txtBox) {
	var no_funny_chars = txtBox.value.replace(/[^0-9]/g,'');
	
	if(no_funny_chars.length == 0) {
		txtBox.value = "";
		return;
	}

	var replacement = no_funny_chars.substr(0,1);
	
	if(replacement != '1') {
		no_funny_chars = '1' + no_funny_chars;
		replacement = '1';
	}
	
	if(no_funny_chars.length > 1) {
		replacement += "-" + no_funny_chars.substr(1,3);
	}
	if(no_funny_chars.length > 4) {
		replacement += "-" + no_funny_chars.substr(4,3);
	}
	if(no_funny_chars.length > 7) {
		replacement += "-" + no_funny_chars.substr(7,4);
	}
	if(no_funny_chars.length > 11) {
		replacement += " x " + no_funny_chars.substr(11,5);
	}
	txtBox.value = replacement;
}