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;
  }
}
var address_list = {
    default_address: {
  name:     "",
  address:  "",
  address2: "",
  city:     "",
  state:    "",
    zip:      "",
  phone:    "",
    fax:      "",
    country:  "",
  lat:      "37",
  lon:      "-95"
}
}

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;
}
// JavaScript Validationfunction 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,
      statusCode:     {        200: function() {          alert("Thank you for your request");          thisform.reset();        },      404: function() {          alert("Thank you for your request");          thisform.reset();        }          } 
    });
    return false;
}
var img_mng;

var dd_opts = {
    draggable:   false,
    static_top:  false,
    add_overlay: false,
    overlay:     null,
    alt_cont:    false,
    hide_only:   false,
    anchored:    false,
    id:          null,
    corners:      {
        top_left:false,
        bottom_left:false,
        top_right:false,
        bottom_right:false
    },
    padding: true,
    
    element: {
      obj: null,
      handle: null,
      data: null
    }
}

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() {
  var phonetop = document.getElementById('phonetop');
  var sidephone = document.getElementById('sidephone');
   phonenum = readCookie('Prefs');
   
   if(phonenum != null) {
    phonetop.innerHTML = phonenum.replace('contactPhone=',"1-");
    sidephone.innerHTML = phonenum.replace('contactPhone=',"Toll Free: 1-");
  }
}function close_video(){
  start_rotator();  if(document.getElementById('video_div_home_catheter')){    document.getElementById('flashTotal').removeChild(document.getElementById('video_div_home_catheter'));  }}
function start_rotator(){
    if(document.getElementById('home_rotator2')){
      img_mng = new imageControls('#home_rotator2');
    }
    if(img_mng){
        img_mng.rotator = setTimeout("img_mng.rotate_image(1)",5000);
    }
} 
function kill_rotator(){
  if(img_mng.rotator){
    clearTimeout(img_mng.rotator);
  }
}
img_mng = false;
window.onload = function() {
  loadFont();
  if(document.getElementById('home_rotator')) {
    img_mng = new imageControls('#home_rotator');
      img_mng.rotator = setTimeout("img_mng.rotate_image(1)",5000);
  }
  
  if(document.getElementById('map')) {
    var dpanel;
    
    gmap = new gmLocator('map');
    if ($('directions')) {
      gmap.options.marker_clickable = false;
      gmap.options.marker_draggable = false;
      gmap.options.largemapcontrol3d = true;
      gmap.options.map_draggable = true;
      gmap.options.maptypecontrol = true;
      gmap.map_options.scaleControl = true;
      gmap.map_options.streetViewControl = true;
      gmap.map_options.zoom = 10;
    }
    else {
      gmap.options.marker_clickable = true;
      gmap.options.marker_draggable = false;
      gmap.options.smallzoomcontrol3d = true;
      gmap.options.maptypecontrol = true;
      gmap.options.map_draggable = false;
      gmap.map_options.zoom = 11;
      gmap.map_options.scrollwheel = false;
    }
    
    gmap.Markers = new Markers();
    gmap.get_address();
      
    gmap.Directions = new Directions(gmap.map,gmap.options);
    gmap.Directions.Markers = new Markers();
  }
}
