function blank(s){//returns true if the element is blank
	for(var i=0; i<s.length; i++){
		var c=s.charAt(i);
		if((c!=' ') && (c!='') && (c!='\n')) return false;
	}
	return true;
}
function allblank(f){
	for (var i = 0; i<f.elements.length; i++){
		if(f.elements[i].type=="text" || f.elements[i].type=="textarea"){
			if(!blank(f.elements[i].value)){
				return true;
			}
		}
	}
	return false;
}
function alert_array(arr){
	var m="";
	for(var i=0;i<arr.length;i++){
		m+=arr[i]+"\n";
	}
	alert(m);
}
function get_element(elm){
	if(document.all){
		if(document.all[elm]) var el=document.all[elm];
		else return false;
	}	
	else if(document.getElementById){
		if(document.getElementById(elm)) var el=document.getElementById(elm);
		else return false;
	}
	return el;
}
function preload(url){
	var im = new Image();
	im.src=url;
}
function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}
///////////////   SELECT BOXES   ////////////////
function sb_open(el){
	var sb=get_element("dd_"+el);
	sb.style.display="block";
}
function sb_close(el){
	var sb=get_element("dd_"+el);
	sb.style.display="none";
}

function set_sel_text(el,val,change){
	var sel=get_element(el);
	sel.value=val;
	sb_close(el);
	if(change) set_dd_list();
}
function str_replace(str_normal,str_find,str_replace){
	var rv="";
	var ix=str_normal.toLowerCase().indexOf(str_find);
	while(ix>-1){
		rv+=str_normal.substring(0,ix)+str_replace;
		str_normal=str_normal.substring(ix+str_find.length);
		ix=str_normal.toLowerCase().indexOf(str_find);
	}
	return(rv+str_normal);
}
function set_dd_list(){
	var cat_sel=get_element("category");
	var sub_sel=get_element("sub_category");
	var s=new String(cat_sel.value);
	if(s.length){
		s=str_replace(s," ","_");
		s=str_replace(s,")","_");
		s=str_replace(s,"(","_");
		s=str_replace(s,"-","_");
		s=str_replace(s,".","_");
		s=str_replace(s,"'","_");
		s=str_replace(s,'"',"_");
		s=str_replace(s,'/',"_");
		s=str_replace(s,',',"_");
		s=str_replace(s,'&',"_");
		var cat=eval(s);

		for(var i=0;i<cat.length;i++){
			sub_sel.options[i] = new Option(cat[i],cat[i]);
		}
	}
}
/////////////////////////////////////////////////
var head_speed=100;
var ims_head=new Array(doc_root+"images/head_images/1.jpg",doc_root+"images/head_images/2.jpg",doc_root+"images/head_images/3.jpg",doc_root+"images/head_images/4.jpg",doc_root+"images/head_images/5.jpg",doc_root+"images/head_images/6.jpg",doc_root+"images/head_images/7.jpg");
var head_current=1;
var head_step=0;
function header_fade(){
	if(head_current<2){
		setTimeout("fade_in_head()",4000);
		setTimeout("fade_out_head()",8000);
		setTimeout("header_fade()",8000);		
	}
	else{
		setTimeout("fade_in_head()",8000);
		setTimeout("fade_out_head()",16000);
		setTimeout("header_fade()",16000);
	}
}
function fade_in_head(){
	head_step++;
	if(head_step>25){
		head_step=25;
		var im1=get_element("head_bottom");
		head_current++;
		if(head_current==ims_head.length) head_current=0;
		im1.src=ims_head[head_current];
	}
	else{
		var im2=get_element("head_top");
		im2.className="fade_"+head_step;
		setTimeout("fade_in_head()",head_speed);
	}
}
function fade_out_head(){
	head_step--;
	if(head_step<0){
		head_step=0;
		var im1=get_element("head_top");
		head_current++;
		if(head_current==ims_head.length) head_current=0;
		im1.src=ims_head[head_current];
	}
	else{
		var im2=get_element("head_top");
		im2.className="fade_"+head_step;
		setTimeout("fade_out_head()",head_speed);
	}
}

var ailment_step=25;
var ailment_height;
var original_ailheight=0;
var tout_ailment;
var ail_never_done=true;
function open_ailments(){
	var el=get_element("ailments");
	el.style.display='block';
	show_ailment();
}
function show_ailment(){
	var el=get_element("ailments");
	if(ailment_height<original_ailheight){
		ailment_height+=ailment_step;;
		el.style.height=ailment_height+"px";
		setTimeout("show_ailment()",1);
	}
}
function close_ailments(){
	var el=get_element("ailments");
	if(el && el.style.display=='block'){
		ailment_height=el.offsetHeight;
		if(ail_never_done){
			original_ailheight=ailment_height;
			ail_never_done=false;
		}
		close_ailment();
	}
}
function close_ailment(){
	var el=get_element("ailments");
	if(ailment_height<ailment_step){
		el.style.display='none';
	}
	else{
		ailment_height-=ailment_step;;
		el.style.height=ailment_height+"px";
		setTimeout("close_ailment()",1);
	}
}

function empty_input_if(el,text){
	var the_el=get_element(el);
	if(the_el.value==text){
		the_el.value="";
	}	
}