
function o(strid) {
	if(document.getElementById(strid)){return document.getElementById(strid);}else return false;
}


/* doctors page */
function sh_doctornav( intWhich ) {
	// clear all the classes and add current to intWhich
	// display/hide doctor info
	for(var i=1;i<7;i++) {
		o("dn"+i).className = "";
		o("dc"+i).style.display = "none";
		if(i==intWhich) {
			o("dn"+i).className = "current";
			o("dc"+i).style.display = "block";
		}
	}
}

var homeGalXML = '/img/gallery_models/gallery.xml';
var galPath = '';
var galTotal = 0;
var galCurr = 0;
var galSrcs = new Array();
var galTimeout = 5000;

$(document).ready(function() {
	if(o('main')) { /* home page onready */

		// load xml gallery data
		$.get(homeGalXML, function(xml) {

			json = $.xml2json(xml);

			// load the images, global vars, onload start the gallery

			galTotal = json.images.image.length;

			galPath = json.path;

			var strLoad = '';

			for(i=0;i<json.images.image.length;i++) {

				if(i==(json.images.image.length-1)) { // last one, add onload

					strLoad += '<img src="'+json.path+json.images.image[i].file+'" border="0" alt="">';

				} else {

					strLoad += '<img src="'+json.path+json.images.image[i].file+'" border="0" alt="">';

				}

				galSrcs[i] = json.images.image[i].file;

			}

			// write them into the page
			o("loadslide").innerHTML = strLoad;

		});



	}
}
);

$(document).ready(function() {

	if(o('main')) { /* home page onload */

		galleryStart();

	}
});

function galleryStart() {

	if(galPath != undefined) {

		// hide preloaded images
		o("loadslide").style.display = "none";

		setTimeout("galleryFadeOutCurrent();",galTimeout);

	} else setTimeout("galleryStart()",1000);

}

function galleryFadeInNext() {

	o("slide").src = galPath + galSrcs[galCurr];

	$("#slide").fadeIn("slow");

	setTimeout("galleryFadeOutCurrent();",galTimeout);

}

function galleryFadeOutCurrent() {

	$("#slide").fadeOut("slow");

	if(galCurr != (galTotal-1)) {
		galCurr++;
	}
	else galCurr = 0;

	setTimeout("galleryFadeInNext();",750);
}


/* topics */
var numQuestions = 0;
var curQuestion = null;

function initTopics() {
	questions = document.getElementsByTagName('h5');
	answers = getElementsByClassName('ans');
	numQuestions = questions.length;
	for(i=0;i<questions.length;i++) {

		// set question id
		questions[i].id="question"+i;

		// set an onclick event
		o('question'+i).onclick = function() {showTopic(this.id);}

		// set answer id
		answers[i].id="answer"+i;

		// add close link to answer
		o('answer'+i).innerHTML = o('answer'+i).innerHTML + '<p><a href="javascript:showTopic(\'question'+i+'\');">close topic</a> | <a href="/topics.php">all health topics</a> | <a href="/forms.php">all forms</a></p>'

		// hide answer
		o('answer'+i).style.display = "none";

		// add an anchor tag to the question
		arrQuest = o('question'+i).innerHTML.split(" ");
		firstWord = arrQuest[0];
		firstWord = firstWord.replace('"','');
		firstWord = firstWord.replace('\'','');

		questCtnt = o('question'+i).innerHTML;
		o('question'+i).innerHTML = '';
		o('question'+i).innerHTML = '<a name="'+firstWord+'"></a>' + questCtnt;

		// set a name for deep-linking
		o('question'+i).name = firstWord;

	}

	// check for URL var
	strUrl = location.href
	arrTemp = strUrl.split("#");
	if(arrTemp[1] != undefined) { // we're deep-linking

		strAnchor = arrTemp[1];
		for(i=0;i<questions.length;i++) {
			if(questions[i].name == strAnchor) {
				showTopic('question'+i);
			}
		}
	}
}
function showTopic(id) {
	ansId = id.substring(8);
	if(curQuestion != ansId) {
		curQuestion = ansId;

		// hide all answers
		for(i=0;i<numQuestions;i++) {
			o('answer'+i).style.display = "none";
			o('answer'+i).className = "ans";
			o('question'+i).className = '';
		}

		// show the one
		o('answer'+ansId).className = 'ans curanswer';
		o('question'+ansId).className = 'active';
		$('#answer'+ansId).slideDown("slow");

		// add an url value
		strAnchor = o('question'+ansId).name
		strUrl = location.href
		arrTemp = strUrl.split("#");
		if(arrTemp[1] != undefined) {
			location.replace(arrTemp[0] + '#' + strAnchor);
		} else {
			location.replace(location.href + '#' + strAnchor);
		}


	} else { // user clicked on currently open header
		$('#answer'+ansId).slideUp("slow");
		o('answer'+ansId).className = 'ans';
		o('question'+ansId).className = '';
		curQuestion = null;
	}

}


/* ie6 notice */

var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

if(isIE6) {
	$(document).ready(function() {
		o('ie6').innerHTML = '<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx"><b>Notice:</b> For a better browsing experinece, <u>upgrade your browser</u>.</a>';
	});
}


function checkRefillForm() {
	var str = '';
	if(o('txtPet').value == '')
	{
		str += "\n- Please enter a pet name";
	}
	if(o('txtLastName').value == '')
	{
		str += "\n- Please enter a last name";
	}
	if(o('txtFirstName').value == '')
	{
		str += "\n- Please enter a first name";
	}
	if(o('txtPhone').value == '')
	{
		str += "\n- Please enter a phone number";
	}
	if(o('txtMed').value == '')
	{
		str += "\n- Please enter a medication";
	}
	if(o('txtQuantity').value == '')
	{
		str += "\n- Please enter a quantity";
	}




	if(str == '')
	{
		return true;
	} else
	{
		alert(str);
		return false;
	}
}

function closeRefillError() {
	o('refillErrorBox').style.display="none";
}
