// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// used to make external URL's open in a new window and also be XHTML valid
function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors .length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
      anchor.target = "_blank";
//      anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window)" : "opens in a new window";
      anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
    }
  }
}
window.onload = externalLinks;

function toggle_and_save(element) {
  element = $(element);
  element.toggle();
  document.cookie = element.id + '-open=' + element.visible() + '; path=/';
}

function widgets_checkall(frm) {
  all_checkboxes = $(frm).getInputs('checkbox');
  all_checkbox = all_checkboxes.first();
  elements = all_checkboxes.reject(function(n) { return n.getAttribute('id') == 'all_pages'})
  if (all_checkbox.checked) {
    elements.invoke('setAttribute', 'checked', true);
    $$('.placement').invoke('removeAttribute', 'disabled');
  }
  else {
    elements.invoke('removeAttribute', 'checked');
    $$('.placement').invoke('setAttribute', 'disabled', 'disabled');
  }
}
function mark_for_destroy(element, hide) {
    $(element).next('.should_destroy').value = 1;
    $(element).up('.' + hide).hide();
}
function toggle_disable(elem) {
  elem = $(elem);
  if (elem.getAttribute('disabled')) {
    elem.removeAttribute('disabled');
  }
  else {
    elem.setAttribute('disabled', true);
  }
}

function toggleDetailedDescriptionLink(ddId, ddIdToggle) {
   if (ddId.style.display == "none") {
       ddIdToggle.innerHTML = "Click here to view detailed information about this product";
   } else {
      ddIdToggle.innerHTML = "hide";
   }
}

function restore_default_value(id, default_value) {
	jQuery('#' + id).val(default_value);
}


function checkAvailability(date) {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} 
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}

			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
	    // show loader which things are happening
	    if(xmlHttp.readyState!=4) {
	        $('availability').innerHTML="<img src=\"/images/loader.gif\" alt=\"Loading\" />";
	    }
		if(xmlHttp.readyState==4) {
			$('availability').innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET","/conference_rooms/check_availability/"+conference_room_id+"?date="+date,true);
	xmlHttp.send(null);
}
