// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//function detectBrowser(){
//	var browser=navigator.appName;
//	var b_version=navigator.appVersion;
//	var version=parseFloat(b_version);
//	if ((browser=="Microsoft Internet Explorer") && (version<7)){
	//	if(confirm("In order to view this site properly you must download Internet Explorer 7 or higher. To download the latest version, please click ok.")){
	//		window.location.href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx";	
	//	}
//	}
//}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
	var rv = -1; // Return value assumes failure.
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		rv = parseFloat( RegExp.$1 );
	}
	return rv;
}
function detectBrowser(){
	var ver = getInternetExplorerVersion();
	if(ver>-1 && ver<7.0){
		msg="In order to view this site properly you must download Internet Explorer 7 or higher. To download the latest version, please click ok.";
		if(alert(msg)) window.location.href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx";
	}
}
function resize(el){  
	if (window.innerHeight && window.scrollMaxY) {
		$(el).style.height=window.innerHeight+window.scrollMaxY+'px';
		}else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			$(el).style.height=document.body.offsetHeight+document.body.scrollHeight+'px';
		}else {
			$(el).style.height=document.body.clientHeight+'px';
		}
	
	/*
	var frame = document.getElementById("black");  
	var htmlheight = document.body.parentNode.scrollHeight;  
	var windowheight = window.innerHeight;  
	if ( htmlheight < windowheight ) { document.body.style.height = windowheight + "px"; frame.style.height = windowheight + "px"; }  
	else { document.body.style.height = htmlheight + "px"; frame.style.height = htmlheight + "px"; } */ 
}

var alert_win;
function tmh_alert(notice, options) {
  options = $H({title: 'Notice'}).merge(options).toObject();
  if (alert_win) { alert_win.close(); };
  alert_win = new Window({className: 'tmh',
                          title: options.title, 
                          width: 300, 
                          height: 150,
                          destroyOnClose: true,
                          minimizable: false,
                          maximizable: false,
                          showEffectOptions: {duration: 0.5}
                         });
  ok_btn = '<div style="margin-top: 20px; text-align: center;"><input type="button" onclick="alert_win.close();" value="OK" /></div>'
  alert_win.setHTMLContent('<div style="padding: 10px">'+notice+ok_btn+'</div>');
  alert_win.setZIndex(24000);
  alert_win.showCenter();       
}

var popup;
function tmh_popup(options) {
  options = $H({title: '', width: 400, height: 400, content: null, ajax_url: null, ajax_parameters: {}}).merge(options).toObject();
  if (popup) { popup.close(); };
  popup = new Window({className: 'tmh',
                      title: options.title,
                      width: options.width,
                      height: options.height,
                      destroyOnClose: true,
                      minimizable: false,
                      maximizable: false,
                      showEffectOptions: {duration: 0.5}
                     });
  if (options.content)  { popup.setHTMLContent('<div style="padding: 10px">'+options.content+'</div>'); }
  if (options.ajax_url) { popup.setAjaxContent(options.ajax_url,
                                               {parameters: options.ajax_parameters,
                                                asynchronous:true, evalScripts:true}); }
  popup.setZIndex(25000);
  popup.showCenter();
}


function toggle_sorters(selected_sorter,arr){
	for(i=0;i<arr.size();i++){
		$(arr[i]+"_desc_off").show();
		$(arr[i]+"_desc_on").hide();
		$(arr[i]+"_asc_off").show();
		$(arr[i]+"_asc_on").hide();
	}
	$(selected_sorter+"_on").show();
	$(selected_sorter+"_off").hide();


}
function check_group(exc_item,check_value){
	var opposite_check_value = check_value==true ? false : true
	var my_array = ["view_all","view_medical","view_farrier","view_supplements","view_events","view_general"]
	for(var i=0;i<my_array.length;i++){
		if(my_array[i]!=exc_item) $(my_array[i]).checked=opposite_check_value;
	}
}
function toggle_group(){
	var my_array = ["medical","farrier","supplements","events","general"]
	for(var j=0;j<my_array.length;j++){
		var my_arr = $('calendar_view').select('[id="'+my_array[j]+'"]');
		for(var i=0;i<my_arr.length;i++){
			if($('view_all').checked==true || $('view_'+my_array[j]).checked==true) {
				my_arr[i].show();
			}else{
				my_arr[i].hide();
			}
		}
	}

}
function toggle_group_month_view(){
	var my_array = ["medical","farrier","supplements","events","general"]
	for(var k=0;k<32;k++){
		if($('day_num_'+k)!=null){
			var my_count = 0;
			if($('num_events_'+k)!=null){
			var my_num_events = $('num_events_'+k);
		} else{
			my_num_events=null;
		}
			for(var j=0;j<my_array.length;j++){
				var my_arr = $('day_num_'+k).select('[id="'+my_array[j]+'"]');
				for(var i=0;i<my_arr.length;i++){
					if(($('view_all').checked==true || $('view_'+my_array[j]).checked==true) && my_count<3) {
						my_arr[i].show();
					}else{
						my_arr[i].hide();
					}
					if($('view_all').checked==true || $('view_'+my_array[j]).checked==true) {
						my_count=my_count+1;
					}

				}

			}
			if(my_num_events!=null){
				//	alert(my_count);
				if(my_count>3 && my_count-3!=0) {

					my_num_events.show();
					my_num_events.innerHTML="&#43;"+(my_count-3)+" Activities";
				}else{
					my_num_events.hide();
				}
			}
		//	alert(my_count);
		}
	}
}
function section_dd_toggle(section,in_select_value){
	$(section+'_container').toggle();
	$(section+'_link').toggle();
	if(in_select_value!=null && in_select_value!=''){
		window.location.href=in_select_value;
	}
}


	 
