function BrowserInfo() {
	var agent = window.navigator.userAgent;
	if (agent.indexOf("MSIE") != -1) {
			var start = agent.indexOf("MSIE");
			this.name = "MSIE";
			this.version = parseFloat(agent.substring(start + 5, agent.indexOf(";", start)));
	} else if (agent.indexOf("Firefox") != -1) {
			var start = agent.indexOf("Firefox");
			this.name = "Firefox";
			this.version = agent.substring(start + 8, agent.length);
			var firstDec = this.version.indexOf(".") + 1;
			while (this.version.indexOf(".", firstDec) != -1)
				this.version = this.version.substring(0, firstDec) + this.version.substring(firstDec).replace(".", "");
			this.version = parseFloat(this.version);
	} else {
			this.name = "Unknown";
			this.version = 0;
	}
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function changephone() {
	phonetop = document.getElementById('phonetop');
	sidephone = document.getElementById('sidephone');
 	phonenum = readCookie('Prefs');
 	
 	if(phonenum != null) {
		phonetop.innerHTML = phonenum.replace('contactPhone=',"1-");
		sidephone.innerHTML = phonenum.replace('contactPhone=',"Toll Free: 1-");
	}
}
// JavaScript Validation


function disableFields(form) {
	for(i=0;i<form.length;i++) {
		form[i].disabled = true;
	}
}

function validate_email(field, alerttxt) {

    with (field) {

        apos = value.indexOf("@");

        dotpos = value.lastIndexOf(".");

        if (apos < 1 || dotpos - apos < 2)

        { alert(alerttxt); return false; }

        else { return true; }

    }

}

function validate_required(field, alerttxt, defaultvalue) {
    with (field) {
        if (value == null || value == "" || value == defaultvalue) {
            alert(alerttxt); return false;
        }
        else {
            return true;
        }
    }
}

function validate_form(thisform,frm) {
/*    with (thisform) {
        if (validate_required(thisform.lname, "First Name is Required", "") == false)
        { thisform.lname.focus(); return false; }
		
        if (validate_required(thisform.fname, "Last Name is Required", "") == false)
        { thisform.fname.focus(); return false; }

        if (validate_required(thisform.email, "Email is Required", "") == false)
        { thisform.email.focus(); return false; }

        if (validate_email(thisform.email, "Not a valid e-mail address!") == false)
        { thisform.email.focus(); return false; }

        if(thisform.address)
        if (validate_required(thisform.address, "Address is Required", "") == false)
        { thisform.address.focus(); return false; }

        if(thisform.city)
        if (validate_required(thisform.city, "City is Required", "") == false)
        { thisform.city.focus(); return false; }

        if(thisform.state)
        if (validate_required(thisform.state, "State is Required", "") == false)
        { thisform.state.focus(); return false; }

        if(thisform.zip)
        if (validate_required(thisform.zip, "Zip is Required", "") == false)
        { thisform.zip.focus(); return false; }

        if(thisform.phone)
            if (validate_required(thisform.phone, "Phone Number is Required", "") == false)
            { thisform.phone.focus(); return false; }
    }    
*/
    datastring = jQuery(thisform).serialize();

    jQuery.ajax({
    	type:"POST",
    	url:"include/ajax.php",
    	data:datastring,
    	success: function(data) 
		{
			eval(data);
    	}
    });
    return false;
}



function submit_form(thisform,frm) {
	datastring = jQuery(thisform).serialize();
    thisform = thisform;

    jQuery.ajax({
    	type:"POST",
    	url:"include/ajax.php?frm="+frm,
    	data:datastring,
    	success: function() {
    		alert("Thank you for your request");
    		thisform.reset();
    	}
    });

    return false;
}

var info = new BrowserInfo();
var userAgent = window.navigator.userAgent
var isIE = (window.navigator.userAgent.indexOf("MSIE") != -1);
var isIE6 = (info.name == "MSIE" && info.version < 7);
var isSafari = (window.navigator.userAgent.indexOf("Safari") != -1);
var isMac = navigator.appVersion.indexOf("Mac")!=-1;
var isFireFox = (window.navigator.userAgent.indexOf("Firefox") != -1);
var isFireFox3 = ((window.navigator.userAgent.indexOf("Firefox") != -1) && info.version >= 3);
var isMacFireFox = isMac && isFireFox;
var isMacFireFox3 = isMac && isFireFox3;
var is_iPod = navigator.appVersion.indexOf("iPod")!=-1;
var is_iPhone = navigator.appVersion.indexOf("iPhone")!=-1;

if (isIE)
	document.writeln('<link href="stylesIE.css" rel="stylesheet" type="text/css" />');

if (info.name == "MSIE" && info.version < 7)
	document.writeln('<link href="stylesIE6.css" rel="stylesheet" type="text/css" />');
else
	document.writeln('<link href="stylesDynamic.css" rel="stylesheet" type="text/css" />');

function writePngImage(url, width, height, alt) {
	if (!isIE6)
		document.write("<img alt=\"" + alt + "\" src=\"" + url + "\" style=\"width: " + width + "px; height: " + height + "px;\">");
	else
		document.write("<img src=\"spacer.png\" style=\"width: " + width + "px; height: " + height + 
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}

function writePngClass(url, width, height, alt, className) {
	if (!isIE6)
		document.write("<img alt=\"" + alt + "\" class=\"" + className + "\" src=\"" + url + "\" style=\"width: " + width + "px; height: " + height + "px;\">");
	else
		document.write("<img alt=\"" + alt + "\" class=\"" + className + "\"  src=\"spacer.png\" style=\"width: " + width + "px; height: " + height + 
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}

function renderFlash(src, width, height, features) {
	document.writeln('<embed src="' + src + '" quality="high" width="' + width + 
					 '" height="' + height + '" align="middle" allowscriptaccess="sameDomain" ' +
					 'type="application/x-shockwave-flash" ' + features + 
  					 'pluginspage="http://www.macromedia.com/go/getflashplayer" />');
}

function expandFeaturedMenu(id, open_top, closed_top) {
	if (eval('window.timer_' + id) != undefined) {
		clearTimeout(eval('window.timer_' + id));
		eval("window.timer_" + id + "=undefined");
	}
	
	var obj = document.getElementById(id);
	if (obj.className == "menu_closed") {
		obj.className = "menu_opened";
	
		var anim = CSNGAnim.create({
			objectId: id,
			property: "top",
			speed: 10,
			steps: 35,
			start: closed_top,
			stop: open_top
		});
		anim.start();
	}
}

function hideFeaturedMenu(id, open_top, closed_top) {
	if (eval('window.timer_' + id) == undefined) {
		eval('window.timer_' + id + '=' + setTimeout("hideFeaturedMenuEx('" + id + "'," + open_top + "," + closed_top + ")", 500));
	}
}

function hideFeaturedMenuEx(id, open_top, closed_top) {
	eval("window.timer_" + id + "=undefined");
	var obj = document.getElementById(id);
	
	var anim = CSNGAnim.create({
		objectId: id,
		property: "top",
		speed: 10,
		steps: 35,
		start: open_top,
		stop: closed_top,
		onComplete: function() { obj.className = "menu_closed"; }
	});
	anim.start();
}



function getCookie( name ) {
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
    return null;
  }
  if ( start == -1 ) return null;
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires_date.toGMTString() : "") + 
		((path) ? "; path=" + path : "") + 
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure" : "");
}

function deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

if (getCookie("FontSize") == null)
	setCookie("FontSize", "font_normal");

function loadFont() {
	var size = getCookie("FontSize");
	document.getElementsByTagName("body")[0].className = size;
	var btnTxtPlus = document.getElementById("btnTxtPlus");
	var btnTxtMinus = document.getElementById("btnTxtMinus");

	if (getCookie("FontSize") == "font_small") {
		btnTxtMinus.className = "btn_txt btn_txt_minus_static";
		btnTxtPlus.className = "btn_txt btn_txt_plus";
	}

	if (getCookie("FontSize") == "font_large") {
		btnTxtMinus.className = "btn_txt btn_txt_minus";
		btnTxtPlus.className = "btn_txt btn_txt_plus_static";
	}
}

function smallerFont() {
	var bodyTag = document.getElementsByTagName("body")[0];
	var btnTxtPlus = document.getElementById("btnTxtPlus");
	var btnTxtMinus = document.getElementById("btnTxtMinus");
		
	if (getCookie("FontSize") == "font_normal") {
		setCookie("FontSize", "font_small");
		bodyTag.className = "font_small";
		btnTxtMinus.className = "btn_txt btn_txt_minus_static";
	} else if (getCookie("FontSize") == "font_large") {
		setCookie("FontSize", "font_normal");
		bodyTag.className = "font_normal";
		btnTxtMinus.className = "btn_txt btn_txt_minus";
		btnTxtPlus.className = "btn_txt btn_txt_plus";
	}
	return false;
}

function largerFont() {
	var bodyTag = document.getElementsByTagName("body")[0];
	var btnTxtPlus = document.getElementById("btnTxtPlus");
	var btnTxtMinus = document.getElementById("btnTxtMinus");
		
	if (getCookie("FontSize") == "font_small") {
		setCookie("FontSize", "font_normal");
		bodyTag.className = "font_normal";
		btnTxtMinus.className = "btn_txt btn_txt_minus";
		btnTxtPlus.className = "btn_txt btn_txt_plus";
	} else if (getCookie("FontSize") == "font_normal") {
		setCookie("FontSize", "font_large");
		bodyTag.className = "font_large";
		btnTxtPlus.className = "btn_txt btn_txt_plus_static";
	}
	return false;
}
