
/* function to append a load event to the window */
/* added 6-16-08 by srobinson (stream creative) */
function add_load_event(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/* function to set the focus to a given field (if available & not hidden) */
/* added 6-16-08 by srobinson (stream creative) */
function set_focus(element_id){
	var elem=document.getElementById(element_id);
	if(elem && elem.type!="hidden"){
		elem.focus();
	}
}

/* function to set the opacity of a given object.  Used by the error*/
/* and add-to-cart popups to create the 50% gray mask behind the popups */
/* added 6-16-08 by srobinson (stream creative) */
function set_opacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

    function toggle(obj){
    obj = obj.parentNode;
    obj.className = (obj.className == 'open') ? 'closed' : 'open';
    return false;
    }
    
    function buttonHover(obj){
    obj.className = (obj.className == 'standardButtonOn') ? 'standardButton' : 'standardButtonOn';
    return false;
    }
    
    function specialButtonHover(obj){
    obj.className = (obj.className == 'specialButtonOn') ? 'specialButton' : 'specialButtonOn';
    return false;
    }

	function swapFullyPathedSecureUrl(form) {
	form.action = "https://www.chdist.com/secured/checkorderstatus.do";
	}

	function enlarge_text(val){
	var wrapper=document.getElementById('wrapper');
	if (wrapper.style.fontSize == "") {  
      wrapper.style.fontSize = "1.2em";  
	}
	if (parseFloat(wrapper.style.fontSize)+(val*0.2)>1.8 || parseFloat(wrapper.style.fontSize)+(val*0.2)<0.75){
		return;
	}
    wrapper.style.fontSize = parseFloat(wrapper.style.fontSize) + (val * 0.2) + "em";
	}
	
	var searchFieldPrompt;
	
	function search_focus(search_field){
		if(search_field.value.toUpperCase()=='SEARCH SITE'){
			searchFieldPrompt = search_field.value;
			search_field.value='';
		}
	}
	function search_blur(search_field){
		if(search_field.value.replace(/^\s+|\s+$/g, '')==''){
			search_field.value = searchFieldPrompt;
		}
	}
	
	function toggleStyle(){
		var style=document.getElementById('mainstyle');
		if(style.href.substring(style.href.lastIndexOf('/')+1)=='chdist.css'){
			style.href='/css/avenue.css';
		}else{
			style.href='/css/chdist.css';
		}
	}
	
//////////////////////
//  Calendar Stuff  //
//////////////////////

var format = '%m/%d/%Y';
var cal_obj=null;
var cal_target='';

// show calendar
function show_cal(field_id) {

	if (cal_obj){
		cal_obj.hide
	};

	cal_target = document.getElementById(field_id);
	

	cal_obj = new RichCalendar();
	cal_obj.start_week_day = 1;
	cal_obj.show_time = false;
	cal_obj.language = 'en';
	cal_obj.user_onchange_handler = cal_on_change;
	cal_obj.user_onclose_handler = cal_on_close;
	cal_obj.user_onautoclose_handler = cal_on_autoclose;

	cal_obj.parse_date(cal_target.value, format);

	cal_obj.show_at_element(cal_target, "adj_right-top");
}

// user defined onchange handler
function cal_on_change(cal, object_code) {
	if (object_code == 'day') {
		cal_target.value = cal.get_formatted_date(format);
		cal.hide();
		cal_obj = null;
	}
}

// user defined onclose handler (used in pop-up mode - when auto_close is true)
function cal_on_close(cal) {
	cal.hide();
	cal_obj = null;
}

// user defined onautoclose handler
function cal_on_autoclose(cal) {
	cal_obj = null;
}

function hide_cal(){
	cal_obj.hide();
}
