var fieldvalue = {"search":"Product Search",
                  "work_phone":"555-555-5555",
				  "email":"email address",
						"zip":"#####"};

var addthis_config = {
		   services_exclude: 'print,email'
		}

var addthis_disable_flash = true;
var dbody = $(document.body);
var address_id = 'default_address';
var cookie_name = 'madisonhealthcare_local';
var calender_popup = {};

var address_list = {
	default_address: {
		name:     "Madison Health Care",
		address:  "7777 Center Avenue, Suite 400",
		address2: "",
		city:     "Huntington Beach",
		state:    "CA",
	    zip:      "92647",
		phone:    "800.603.3311",
	    fax:      "714.799.5500",
	    country:  "United States",
		lat:      "33.733667",
		lon:      "-117.99484"
	}
}

function openVideoDiv(gallery) {

	if($('header_flash'))
	{	
		Cookie.init({expires:15, name: 'madison_video', path: '/',refresh_cookie: false});
		
		if(Cookie.getData("play_flash")!=undefined)
			var playback = "?pause_vid="+Cookie.getData("play_flash");
		else
			var playback ="";	
		
		$('header_flash').innerHTML = AC_FL_PreloadContent( 
				                          'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
				                          'width','664',
				                          'height','263',
				                          'movie','flash/madison-health-care'+playback,
				                          'quality','high',
				                          'allowfullscreen','true',
				                          'wmode','transparent' );
		
		Cookie.setData("play_flash","pause")
	}
	if($('weSave'))
	{	
		$('weSave').innerHTML = AC_FL_PreloadContent( 
				                          'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
				                          'width','232',
				                          'height','135',
				                          'movie','flash/wesave',
				                          'quality','high',
				                          'allowfullscreen','true',
				                          'wmode','transparent' );
	}
	if($('landingSidebarFlash'))
	{	
		$('landingSidebarFlash').innerHTML = AC_FL_PreloadContent( 
				                          'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
				                          'width','232',
				                          'height','565',
				                          'movie','flash/we-save-large',
				                          'quality','high',
				                          'allowfullscreen','true',
				                          'wmode','transparent' );
	}

}

function bookmarksite(title, url)
{
    if (document.all) window.external.AddFavorite(url, title);
    else if (window.sidebar) window.sidebar.addPanel(title, url, "");
}

function get_document_window_height()
{
   if (document.body && document.body.clientHeight &&
       (document.body.clientHeight > 1)) return document.body.clientHeight;
   else if (window && window.innerHeight) return window.innerHeight;
   else if (document.documentElement && document.documentElement.offsetHeight)
      return document.documentElement.offsetHeight;
   else if (document.body && document.body.offsetHeight)
      return document.body.offsetHeight;
   return 0;
}

function get_document_window_width()
{
   if (document.body && document.body.clientWidth)
      return document.body.clientWidth;
   else if (window && window.innerWidth) return window.innerWidth;
   else if (document.documentElement && document.documentElement.offsetWidth)
      return document.documentElement.offsetWidth;
   else if (document.body && document.body.offsetWidth)
      return document.body.offsetWidth;
   return 0;
}

function convert_width(width,window_width)
{
   if (width == null) width = page_width + 52;
   else if (typeof(width) == 'string') {
      var percent_pos = width.indexOf('%');
      if (percent_pos != -1)
         width = window_width * (width.substr(0,percent_pos) / 100);
   }
   if (! document.all) {
      if (width > (window_width - 25)) width = window_width - 25;
   }
   else if (width > (window_width - 10)) width = window_width - 10;
   return width;
}

function convert_height(height,window_height)
{
   if (height == null) height = window_height;
   else if (typeof(height) == 'string') {
      var percent_pos = height.indexOf('%');
      if (percent_pos != -1)
         height = window_height * (height.substr(0,percent_pos) / 100);
   }
//   else height += header_offset;
   if (height > (window_height - 40)) height = window_height - 40;
   return height;
}

function calculate_left(width,window_width)
{
   var left = (window_width - width) / 2;
   if (! document.all) left += 10;
   if (left < 0) left = 0;
   return left;
}

function calculate_top(height,window_height)
{
   var top = ((window_height - height) / 2) - 3;
   if (top < 0) top = 0;
   return top;
}

function goto_url(val)
{
	if(val!="")
	location.href=val;
}

var ppi_opts = {
                draggable:   true,
                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
                }
}

var active_popup_imgs = new Array();
var ppcnt = 0;

function show_pop_content(id,title) {
         var img_pop = new DivDialogs(ppi_opts);

         if(arguments[2] != undefined)
         var w = arguments[2];
         else var w = 400
         img_pop.padding = 60;
         img_pop.create("&nbsp;",{"width":w,"height":0});
         img_pop.element.obj.style.position = "fixed";
         img_pop.element.data.style.background = "#f2f2f2";
         img_pop.add_overlay = true;
         img_pop.element.data.addClassName("pop_content");
         img_pop.init();

     img_pop.element.data.update($("popimg_cont"+id).innerHTML);

     img_pop.show_element();

}

function removeHTMLTags(htmlString){
    if(htmlString){
      var mydiv = document.createElement("div");
       mydiv.innerHTML = htmlString;

        if (document.all) // IE Stuff
        {
            return mydiv.innerText;
           
        }   
        else // Mozilla does not work with innerText
        {
            return mydiv.textContent;
        }                           
  }
} 

var address;

function get_address(id,use_cookies)
{
	address_id = id;
	
	if(use_cookies && Cookie.getData("cururl") != undefined )
    {
	    address_id = Cookie.getData("cururl");
    }
	else if(address_id == "")
		address_id = 'default_address';
    
	if(address_list[address_id].lat != "")
	    address = address_list[address_id].lat + "," + address_list[address_id].lon;
	else
	    address = address_list[address_id].address + " " + address_list[address_id].city + " " + address_list[address_id].state + " " + address_list[address_id].zip + " " + address_list[address_id].country;
}
//local_cookie = check_url();

window.onunload = function(){
	if($('map'))
	{
	   GUnload()
	}
};

function get_iframe(id)
{
	var iframe = document.frames ? document.frames[id] : document.getElementById(id);
	var ifWin = iframe.contentWindow || iframe;
	return ifWin;
	
} 

function print_iframe(id)
{
	var ifWin = get_iframe(id);
	ifWin.focus()
	ifWin.print();
	
	return false;
} 

var debug_container = new Element('div', {id:'debug_cont',style:"width:700px;color:#666;background:#fff;overflow:auto;height:200px;"});

var debug_table = new Element('table', {cellpadding:2,cellspacing:1,style:'width:100%;'});
var debug_tbody = new Element('tbody');
var debug_tr    = new Element('tr', {id:'debug_header'});
var function_td = new Element('th',{style:"width:150px;line-height:19px;color:#fff;background:#666;",valign:'top'});
var message_td  = new Element('th',{style:"line-height:19px;color:#fff;background:#666;",valign:'top'});


function show_debug() {	
    		
	function_td.insert("FUNCTION");
	message_td.insert("MESSAGE");

	debug_tr.insert(this.function_td); 
	debug_tr.insert(this.message_td); 
	debug_tbody.insert(this.debug_tr); 
	debug_table.insert(this.debug_tbody); 	
	debug_container.insert(this.debug_table);
	
	dbody.insert(this.debug_container); 
	debug_container.absolutize();
    divDialogs.create_dialog('draggable', 'debug_cont', 'debug_header', null);
}

function add_debug(funct,mess) {
	if(!$('debug_cont'))
		show_debug();
	
	temp_debug_tr    = new Element('tr');
	temp_function_td = new Element('td',{style:"width:100px;line-height:19px;color:#000;background:#ccc;",valign:'top'});
	temp_message_td  = new Element('td',{style:"line-height:19px;color:#000;background:#ccc;",valign:'top'});	
    		
	temp_function_td.insert(funct);
	temp_message_td.innerHTML = mess;

	temp_debug_tr.insert(temp_function_td); 
	temp_debug_tr.insert(temp_message_td); 
	debug_tbody.insert(temp_debug_tr); 
}

var swfu;

window.onload = function() {
	//cssMenu.init('header_menu');
	openVideoDiv(false);
	
	//alert(show_thankyou)
	if(show_thankyou)
	{
	    
		//alert('Display Thank You')
		var msg = '<h1 style="text-align: center;"><em><span style="font-family: Times New Roman;">Thank You</span></em></h1><p style="text-align: center;">Thank you for your interest in Madison Healthcare Insurance Services. <br>Your&nbsp;request has been submitted.</p>';
		if($('thnx')){
		   msg = $('thnx').innerHTML;
		}
		display_form_thank_you(msg)
	}
	

	
	if($('map'))
	{
		if($('directions'))
		{
			gmLocator.loader.initialize();
			gmLocator.options.map_draggable = true;
			gmLocator.options.largemapcontrol3d = true;
			gmLocator.options.maptypecontrol = true;
			gmLocator.options.marker_clickable = false;
			get_address('',false);
	        cont_size = new GSize(725,495);
			gmLocator.map.setup('map',cont_size);
			gmLocator.vars.zoom = 14;
			gmLocator.directions.directions_panel = $('directions');
			gmLocator.populate();
			
			if($('stadd'))
			{
			  gmLocator.directions.addresses = [$('stadd').value, address];
			  gmLocator.directions.make_path();
			  gmLocator.directions.create();
			  gmLocator.directions.load_directions();
			}

		}
		else
		{
			gmLocator.loader.initialize();
			gmLocator.directions.initialize();
			gmLocator.options.marker_clickable = true;
			get_address("default_address",false);
	        cont_size = new GSize(265,265);
			gmLocator.map.setup('map',cont_size);
			gmLocator.vars.zoom = 14;
			gmLocator.populate();
		    divDialogs.create_dialog('draggable', 'gdirectionsContainer', 'gdHeader', null);
		}
		
	}
}

var is_IE = (document.all)?true:false;
function set_width_for_view(id){
  if(!is_IE){return true;}
  var me = document.getElementById(id);
  me.style.width = me.autoWidth+'px';
}
function test_width_for_view(id,width){
  if(!width) var width = 154;
  if(!is_IE){return true;}
  var me = document.getElementById(id);
  //me.style.minWidth = '154px';
  me.style.width = 'auto';
  //*
  me.autoWidth = me.clientWidth;
  //alert(me.style.width + ' ' +me.autoWidth);
  if(me.autoWidth < width){
    me.autoWidth = width;
  }//*/
  me.style.width = width+'px';
}
function set_width_to_standard(id,width){
  if(!is_IE){return true;}
  //alert(me.orriginal_width);
  me = $(id);
  //me.style.width = me.orriginal_width+'px';
  if(!width)var width = 154;
  me.style.width = width + 'px';
}


