// 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); };
}
// -------------------------------------------------------
// comment management stuff
function show_busy_comment_row(id) {
	if($('show_comments_'+id)) { Element.hide('show_comments_'+id); };
	if($('hide_comments_'+id)) { Element.hide('hide_comments_'+id); };
	if($('comments_busy_'+id)) { Element.show('comments_busy_'+id); };
}
function hide_comments(id) {
	var e = 'tr_post_comments_'+id;
	if($(e)) { $(e).innerHTML = ''; }; //Element.hide(e); };
	if($('hide_comments_'+id)) { Element.hide('hide_comments_'+id); };
	if($('show_comments_'+id)) { Element.show('show_comments_'+id); };
} 
// -------------------------------------------------------
// validation methods
function validate_date(element,which_date) {
	var date_str = $F(element);
	if(date_str.length==0) { return true; }
	var pieces = date_str.split('/');
	var mon = -1;
	var day = -1;
	var year = -1;
	if(pieces.length == 3) {
		mon = Number(pieces[0]);
		day = Number(pieces[1]);
		year = Number(pieces[2]);
	} else {
		pieces = date_str.split('-');
		if(pieces.length == 3) {
			if(pieces[0]>'1900') {
				mon = Number(pieces[1]);
				day = Number(pieces[2]);
				year = Number(pieces[0]);
			} else {
				mon = Number(pieces[0]);
				day = Number(pieces[1]);
				year = Number(pieces[2]);
			}
		}
	}
	if((mon>=1&&mon<=12)&&(day>=1&&day<=31)&&(year>=1900)) {
		return true;
	}
	alert(which_date+' is invalid. Please enter date in MM/DD/YYYY format.');
	return false;
}

//-----------------------------------------------------------
// method to get staff profile from drop-down selection
function select_staff_profile() {
	var shortname = $F('staff_name');
	window.location='/staff/' + shortname;
}
// method to get medium from drop-down selection
function select_medium() {
	if($F('medium_name')!='') {
		var med_id = $F('medium_name');
		window.location='/portfolio/medium/' + med_id;
	}
}
//function to make Google Map==================================
function do_map() {
	var map = new GMap2(document.getElementById("google_map"));
	map.setCenter(new GLatLng(33.933850, -83.435107), 15);
	map.addControl(new GSmallMapControl());
	var point = new GLatLng(33.933850, -83.435107);
	map.addOverlay(new GMarker(point));
}// end do_map()

//functions for quotes admin pages==================================
function show_add_quote_form() {
	Element.hide( 'add-quote-link' );
	Element.show( 'add-quote-form' );
} // end show_add_quote_form()
function hide_add_quote_form() {
	Element.hide( 'add-quote-form' );
	Element.show( 'add-quote-link' );
} // end hide_add_quote_form()
function show_add_quote_busy() {
	Element.show( 'add-quote-busy' );
	Element.hide( 'add-quote-form' );
} // end show_add_quote_busy()

//function to validate form input==================================
function validate_required(field, alerttxt) {
	with (field) {
  	if (value==null || value=="") {
  		alert(alerttxt);
			return false;
  	}
  	else {
  		return true;
  	}
	}
}

// ==============================================
// Functions for swapping images on profile index
// ==============================================
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr;
	for(i=0; a&&i<a.length&&(x=a[i])&&x.oSrc; i++){
		x.src=x.oSrc;
	}
}

function MM_swapImage() { //v3.0
  MM_swapImgRestore();
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
