// methods to show/hide "AJAX" form divs. assumes you have _form, _busy, and _link divs
function show_busy_div(name) {
	if($(name+'_form')) { Element.hide(name+'_form'); };
	if($(name+'_link')) { Element.hide(name+'_link'); };
	if($(name+'_busy')) { Element.show(name+'_busy'); };
}
function show_form_div(name) {
	if($(name+'_link')) { Element.hide(name+'_link'); };
	if($(name+'_busy')) { Element.hide(name+'_busy'); };
	if($(name+'_form')) { Element.show(name+'_form'); };
}
function show_link_div(name) {
	if($(name+'_busy')) { Element.hide(name+'_busy'); };
	if($(name+'_form')) { Element.hide(name+'_form'); };
	if($(name+'_link')) { Element.show(name+'_link'); };
}
function clear_form_div(name) {
	if($(name+'_form')) { $(name+'_form').innerHTML = ''; }
	if($(name+'_form')) { Element.hide(name+'_form'); };
	if($(name+'_busy')) { Element.hide(name+'_busy'); };
	if($(name+'_link')) { Element.show(name+'_link'); };
}
// methods to show/hide "AJAX" form spans in table rows.
function show_busy_row(name,id) {
	if($('tr_'+name+'_link_'+id)) { Element.hide('tr_'+name+'_link_'+id); };
	if($('tr_'+name+'_busy_'+id)) { Element.show('tr_'+name+'_busy_'+id); };
}
function show_link_row(name,id) {
	if($('tr_'+name+'_busy_'+id)) { Element.hide('tr_'+name+'_busy_'+id); };
	if($('tr_'+name+'_link_'+id)) { Element.show('tr_'+name+'_link_'+id); };
}
// methods to show/hide busy widgets
function show_busy_widget(name) {
	if($(name)) { Element.show(name); };
} 
function hide_busy_widget(name) {
	if($(name)) { Element.hide(name); };
}

// method for showing/removing the default value for an input
// USAGE: $('input_id').defaultValueActsAsHint();
(function(){
  var methods = {
    defaultValueActsAsHint: function(element){
      element = $(element);
      element._default = element.value;
      
      return element.observe('focus', function(){
        if(element._default != element.value) return;
        element.removeClassName('hint').value = '';
      }).observe('blur', function(){
        if(element.value.strip() != '') return;
        element.addClassName('hint').value = element._default;
      }).addClassName('hint');
    }
  };
   
  $w('input textarea').each(function(tag){ Element.addMethods(tag, methods) });
})();

// -------------------------------------------------------
// Methods specific to photo galleries
// -------------------------------------------------------
function flash_talk(parms){

	new Ajax.Request('/admin/galleries/upload_complete?upload_session_id=' + parms, {asynchronous:true, evalScripts:true}); return false;
}




function showImage(){

	var theImages = new Array() 
	theImages[0] = '/images/rot1.jpg'
	theImages[1] = '/images/rot2.jpg'
	theImages[2] = '/images/rot3.jpg'
	theImages[3] = '/images/rot4.jpg'
	theImages[4] = '/images/rot5.jpg'

	var j = 0
	var p = theImages.length;
	var preBuffer = new Array()
	for (i = 0; i < p; i++){
	   preBuffer[i] = new Image()
	   preBuffer[i].src = theImages[i]
	}
	var whichImage = Math.round(Math.random()*(p-1));

document.write('<img src="'+theImages[whichImage]+'">');

}

function process_filter() {
    
    
    
    Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
    
    Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
    
    if (!Prototype.Browser.IE7 && !Prototype.Browser.IE6) {
		Element.show('process_nav'); 
	    Element.hide('process_nav_off');
	}
}

function products_filter() {

    Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
    
    Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
    
    if (!Prototype.Browser.IE7 && !Prototype.Browser.IE6) {
		Element.show('products_nav'); 
		Element.hide('products_nav_off');
	}
}



function apply_tags(){
	var tags = $F('batch_tags');
	var form_inputs = Form.getInputs('batch_form');
	
	for(var i=0; i<form_inputs.length; i++){
		if(form_inputs[i].name.match("tags")){
			if( form_inputs[i].value.length > 0 ){ form_inputs[i].value = form_inputs[i].value + ", " + tags; }
			else { form_inputs[i].value = tags; }
		}
	}
	
	// clear out the field
	Field.clear('batch_tags');
}