var xmlHttp

function getSearchResults()
{
/*	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		} 

	var txtSearch = "name=" + encodeURI(document.getElementById('txtSearch').value)
	offState('dynContainer')

	var url = "include/searchresults.inc.asp?"



xmlHttp.onreadystatechange=function(){stateChanged('maincontent');}
/*stateChanged();
xmlHttp.open('POST',url+txtSearch,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", txtSearch.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(txtSearch);*/
}

function stateChanged(strElementName) 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById(strElementName).innerHTML=xmlHttp.responseText.toString();
onState()
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


var stateNode;

function offState(rootCell) {
 
	var tallyLeft = document.getElementById(rootCell).offsetLeft;
	var tallyTop = document.getElementById(rootCell).offsetTop;
	if (document.getElementById(rootCell).offsetParent) {
		var rootNodeFound = false;
		var offsetStart = document.getElementById(rootCell).offsetParent;
		while (!rootNodeFound) {
			tallyLeft += offsetStart.offsetLeft;
			tallyTop += offsetStart.offsetTop;
			if (offsetStart.offsetParent)
				offsetStart = offsetStart.offsetParent;
			else
				rootNodeFound = true;
		}
	}

	 var myWidth = 630, myHeight = 460;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }



	var shadow = document.createElement('div');
	shadow.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=90)';
	shadow.style.MozOpacity = 0.85;
	shadow.setAttribute('id', 'shadow_' + rootCell);
	shadow.style.position = 'absolute';
	shadow.style.left = '0px';
	shadow.style.top = '0px';
	shadow.style.width = myWidth.toString() + 'px';
	shadow.style.height = myHeight.toString() + 'px';
	shadow.style.background = '#FFFFFF';
	document.body.appendChild(shadow);

	var shadowMessage = document.createElement('div');
	shadowMessage.setAttribute('id', 'shadowMessage');
	shadowMessage.style.position = 'absolute';
	shadowMessage.innerHTML =
		'<table>' +
			'<tr>' +
				'<td valign=middle style="color:#006699;font-family: Arial;">' +
					'PLEASE WAIT' +
				'</td>' +
				'<td valign=middle>' +
					'<object type="application/x-shockwave-flash" data="throbber-bars1.swf" width="40" height="40">' +
						'<param name="movie" value="throbber-bars1.swf" />' +
						'<param name="BGCOLOR" value="#ffffff" />' +
						'<param name="wmode" value="transparent" />' +
					'</object>' +
				'</td>' +
			'</tr>' +
		'</table>';
	shadow.appendChild(shadowMessage);
	shadowMessage.style.left = ((shadowMessage.offsetParent.offsetWidth / 2) - (shadowMessage.offsetWidth / 2)).toString() + 'px';
	shadowMessage.style.top = ((shadowMessage.offsetParent.offsetHeight / 2) - (shadowMessage.offsetHeight / 2)).toString() + 'px';

	stateNode = 'shadow_' + rootCell;

}

function onState () {
	document.getElementById(stateNode).parentNode.removeChild(document.getElementById(stateNode));
}
var searchReq;
function searchSuggest(){

	if(document.getElementById('txtSearch').value.length >= 3)
	{
		searchReq = GetXmlHttpObject();
		if (searchReq.readyState == 4 || searchReq.readyState == 0) {		
			var str = escape(document.getElementById('txtSearch').value);		
			searchReq.open("GET", 'searchresults.inc.asp?search=' + str + '&searchSuggest=1', true);		
			searchReq.onreadystatechange = handleSearchSuggest; 		
			searchReq.send(null);	
		}	
	}
	else
	{
		document.getElementById('search_suggest').style.display = 'none';
	}
}

//Called when the AJAX response is returned.
function handleSearchSuggest() {	
	if (searchReq.readyState == 4)
	{		
		var ss = document.getElementById('search_suggest')		
		ss.innerHTML = '';		
		var str = searchReq.responseText.split("\n");		
		//for(i=0; i < str.length - 1; i++) 
		//	{			
			//Build our element string.  This is cleaner using the DOM, but			//IE doesn't support dynamically added attributes.			
		//	var suggest = '<div onmouseover="javascript:suggestOver(this);" ';			
		//	suggest += 'onmouseout="javascript:suggestOut(this);" ';			
		//	suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';			
		//	suggest += 'class="suggest_link">' + searchReq.responseText.toString() + '</div>';			
			ss.innerHTML += searchReq.responseText.toString();		
		//	}	
		if ( searchReq.responseText.toString() != '')
		{
			document.getElementById('search_suggest').style.display = '';
		}
	}
}

//Mouse over function
function suggestOver(div_value) 
{	
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) 
{	
	div_value.className = 'suggest_link';
}

//Click function
function setSearch(value) 
{	
	document.getElementById('txtSearch').value = value;	
	document.getElementById('search_suggest').innerHTML = '';
	document.getElementById('search_suggest').style.display = 'none';
}

function  updateQuantity()
{
		var len = document.getElementById('itemcount').value;
		var aQTYOrdered = new Array();
		for (var i=1; i <= len ; ++i)
		{
			aQTYOrdered[aQTYOrdered.length] = document.getElementById('QTYOrdered'+i).value
		}

		document.getElementById('qtysordered').value = aQTYOrdered.join(',');

		var aDrugIDs = new Array();
		for (i=1; i <= len ; ++i)
		{
			aDrugIDs[aDrugIDs.length] = document.getElementById('drugid'+i).value
		}

		document.getElementById('drugids').value = aDrugIDs.join(',');
		return true;
}


function SetEnabled( element, enabled )
{
	if (typeof(element) =='undefined')
		return;

	if (enabled == true)
	{
		element.disabled = false;
		element.style.backgroundColor = "white";
	}
	else
	{
		element.disabled = true;
		if (element.type == 'checkbox' || element.type == 'radio')
		{
			element.checked = false; //element.defaultChecked;
		}
		else
		{
			element.value = '';//element.defaultValue;
			element.style.backgroundColor = "#DDDDDD";
		}
	}
}

// Selects all the text in the textbox
function textSelectAll( textbox )
{
	if (textbox.setSelectionRange)
	{
		textbox.setSelectionRange(0,textbox.value.length);
	}
	else if (textbox.createTextRange)
	{
		var range = textbox.createTextRange();
		range.collapse(true);
		range.moveEnd('character', textbox.value.length);
		range.moveStart('character', 0);
		range.select();
	}
}

function StripWhitespace( str )
{
	str = str.replace(/^\s*/,"");	// Trim left
	str = str.replace(/\s*$/,"");	// Trim right
	return str;
}

function CreateAccount_ValidateLogin( oForm )
{
	var username	= StripWhitespace(oForm.elements['createaccount_username'].value);
	var pass		= StripWhitespace(oForm.elements['createaccount_password'].value);
	var passconfirm = StripWhitespace(oForm.elements['createaccount_password_confirm'].value);

	if (username == '')
	{
		alert('You must provide a username.');
		return false;
	}
	
	if (pass == '')
	{
		alert('You must provide a password.');
		return false;
	}
	
	if (pass != passconfirm)
	{
		alert('Passwords do not match.');
		return false;
	}
	
	return true;
}

function ChangePassword_ValidateForm( oForm )
{
	var oldpass		= StripWhitespace(oForm.elements['old_password'].value);
	var pass		= StripWhitespace(oForm.elements['new_password'].value);
	var passconfirm = StripWhitespace(oForm.elements['new_password_confirm'].value);

	if (oldpass == '')
	{
		alert('You must provide your existing password.');
		return false;
	}
	
	if (pass == '')
	{
		alert('You must provide a new password.');
		return false;
	}

	if (oldpass == pass)
	{
		alert('New password cannot be the same as your existing password.');
		return false;
	}
	
	if (pass != passconfirm)
	{
		alert('New passwords do not match.');
		return false;
	}
	
	return true;
}

function CreateAccount_ValidateClientAgreement( oForm )
{
	var bIAgree = oForm.elements['agree'].checked;

	if (bIAgree == false)
	{
		alert('You must agree to the Client Agreement to create an account.');
		return false;
	}
	
	return true;
}

function ValidatePatientProfile( theForm )
{
	var arMandatoryFields = new Array(
		'first_name',
		'last_name',
		'birthdate',
		'patient_sex',
		'phone_number1',
		'physician_name',
		'physician_phone'
	);
	
	var arMissingFields = new Array();
	
	// Ignore these fields
	var numfields = arMandatoryFields.length;
	for (var idx=0; idx < numfields; ++idx)
	{
		if (theForm.elements[arMandatoryFields[idx]])
		{
			var strFieldName = theForm.elements[arMandatoryFields[idx]].title;
			var strFieldValue = theForm.elements[arMandatoryFields[idx]].value;
			strFieldValue = StripWhitespace(strFieldValue);


			// If a mandatory field is empty
			if (strFieldValue == '')
			{
				// Add the field name to the list of missing fields
				arMissingFields[arMissingFields.length] = strFieldName;
			}
		}
	}

	if (arMissingFields.length > 0)
	{
		var strFieldList = arMissingFields.join('\n');
	
		alert('The following fields cannot be left blank:\n' + strFieldList);
		return false;
	}
	
	
	return true;
}

function ValidatePaymentInfo( theForm )
{
	var arMandatoryFields = new Array(
		'ship_address',
		'ship_city',
		'ship_state',
		'ship_country',
		'ship_postalcode',
		'payment_address',
		'payment_city',
		'payment_state',
		'payment_country',
		'payment_postalcode',
		'payment_method',
		'question_prescription_send_method'
		);

 
	// If a credit card is chosen, the other fields are required
	if (theForm.elements['payment_method'] && 
	    theForm.elements['payment_method'].value != 'MO' &&
	    theForm.elements['payment_method'].value != 'AGENTACCT' &&
	    theForm.elements['payment_method'].value != '')
	{
		if (theForm.elements['payment_method'].value != 'ONFILE' &&
	        theForm.elements['payment_method'].value != '')
		{

			arMandatoryFields[arMandatoryFields.length] = 'payment_name_on_card';
			arMandatoryFields[arMandatoryFields.length] = 'payment_card_num';
			arMandatoryFields[arMandatoryFields.length] = 'payment_expiry_month';
			arMandatoryFields[arMandatoryFields.length] = 'payment_expiry_year';
			
			if(theForm.elements['payment_name_on_card'].value.length < 5 )
			{
				alert ('Name on card must be atleast 5 characters long.');
				return false;
			}

		   var now         = new Date();
		   var monthnumber = now.getMonth() + 1;
		   var year        = now.getFullYear()
		   if((theForm.elements['payment_expiry_month'].value < monthnumber) && (theForm.elements['payment_expiry_year'].value <= year ))
			{
					alert('Invalid expiration date.')
					return false;
			}

		}
	}
/*	if (theForm.elements['rxrefill'].value == '')
	{
		arMandatoryFields[arMandatoryFields.length] = 'rxrefill';
	}
	if (theForm.elements['rxrefill'].value == 'Yes')
	{
		arMandatoryFields[arMandatoryFields.length] = 'rxrefilldays';
		arMandatoryFields[arMandatoryFields.length] = 'refillemail';

		var x = theForm.elements['refillemail'].value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,4})+$/;
		if (filter.test(x)){
		}
		else{
			alert('Please enter a valid email address.')
		 return false
		}

	}
*/	
	var arMissingFields = new Array();
	
	// Ignore these fields
	var numfields = arMandatoryFields.length;
	for (var idx=0; idx < numfields; ++idx)
	{
		if (theForm.elements[arMandatoryFields[idx]])
		{
			var strFieldName = theForm.elements[arMandatoryFields[idx]].title;
			var strFieldValue = theForm.elements[arMandatoryFields[idx]].value;
			strFieldValue = StripWhitespace(strFieldValue);


			// If a mandatory field is empty
			if (strFieldValue == '')
			{
				// Add the field name to the list of missing fields
				arMissingFields[arMissingFields.length] = strFieldName;
			}
		}
	}

	if (arMissingFields.length > 0)
	{
		var strFieldList = arMissingFields.join('\n');
	
		alert('The following fields cannot be left blank:\n' + strFieldList);
		return false;
	}


	if ( theForm.elements['payment_method'] && 
	     theForm.elements['payment_card_num'] &&
	     theForm.elements['payment_method'].value != 'MO' &&
	     theForm.elements['payment_method'].value != 'ONFILE' &&
	     theForm.elements['payment_method'].value != 'AGENTACCT' )
	{
		if (!ValidateCreditCard( theForm.elements['payment_method'].value, theForm.elements['payment_card_num'].value ))
		{
			return false;
		}
	}



	return true;
}


// Validate credit cards according to their type
function ValidateCreditCard( strCardType, strCardNum )
{
	switch(strCardType)
	{
		case 'VISA':
			return checkCard('V', strCardNum);
		case 'MC':
			return checkCard('M', strCardNum);
		case 'AMEX':
			return checkCard('A', strCardNum);
		case 'DISCOVER':
			return checkCard('D', strCardNum);
		case 'JCB':								
			return checkCard('J', strCardNum);	
	}
	alert('Invalid credit card type.');
	return false;
}

function checkCardNumWithMod10(cardNum) 
{
	var i;
	var cc = new Array(16);
	var checksum = 0;
	var validcc;

	// assign each digit of the card number to a space in the array	
	for (i = 0; i < cardNum.length; i++) {
		cc[i] = Math.floor(cardNum.substring(i, i+1));
	}

	// walk through every other digit doing our magic
	// if the card number is sixteen digits then start at the
	// first digit (position 0), otherwise start from the
	// second (position 1)
	for (i = (cardNum.length % 2); i < cardNum.length; i+=2) {
		var a = cc[i] * 2;
		if (a >= 10) {
			var aStr = a.toString();
			var b = aStr.substring(0,1);
			var c = aStr.substring(1,2);
			cc[i] = Math.floor(b) + Math.floor(c);
		} else {
			cc[i] = a;
		}
	}

	// add up all of the digits in the array
	for (i = 0; i < cardNum.length; i++) {
		checksum += Math.floor(cc[i]);
	}

	// if the checksum is evenly divisble by 10
	// then this is a valid card number
	validcc = ((checksum % 10) == 0);

	return validcc;
}

function cleanCardNum(cardNum) 
{
	var i;
	var ch;
	var newCard = "";

	// walk through the string character by character to build
	// a new string with numbers only
	i = 0;
	while (i < cardNum.length) {
		// get the current character
		ch = cardNum.substring(i, i+1);
		if ((ch >= "0") && (ch <= "9")) {
			// if the current character is a digit then add it
			// to the numbers-only string we're building
			newCard += ch;
		} else {
			// not a digit, so check if its a dash or a space
			if ((ch != " ") && (ch != "-")) {
				// not a dash or a space so fail
				alert("The Credit Card Number contains invalid characters.");
				return "";
			}
		}
		i++;
	}

	// we got here if we didn't fail, so return what we built
	return newCard;
}

function checkCard(cardType, cardNum) 
{
	var validCard;
	var cardLength;
	var cardLengthOK;
	var cardStart;
	var cardStartOK;
	
	// check if the card type is valid
	//if ((cardType != "V") && (cardType != "M") && (cardType != "A") && (cardType != "D")) {
	if ((cardType != "V") && (cardType != "M") && (cardType != "A") && (cardType != "D") && (cardType != "J")) {    
		alert("Please select a card type.");
		return false;
	}

	// clean up any spaces or dashes in the card number
	validCard = cleanCardNum(cardNum);
	if (validCard != "") {
		// check the first digit to see if it matches the card type
		cardStart = validCard.substring(0,1);

		var cardStartJCB;																							
		cardStartJCB = validCard.substring(0,4);																	
		
		cardStartOK = ( ((cardType == "V") && (cardStart == "4")) ||
				((cardType == "M") && (cardStart == "5")) ||
				((cardType == "A") && (cardStart == "3")) || 
				((cardType == "J") && ((cardStart == "3") || (cardStartJCB == "2131")  || (cardStartJCB == "1800"))) || 
				((cardType == "D") && (cardStart == "6")) );
		if (!(cardStartOK)) {
			// card number's first digit doesn't match card type
			alert("The Credit Card Number you've entered doesn't match the Card Type you selected.");
			return false;
		}

		// the card number is good now, so check to make sure
		// it's a the right length
		cardLength = validCard.length;		
		cardLengthOK = ( ((cardType == "V") && ((cardLength == 13) || (cardLength == 16))) ||
				 ((cardType == "M") && (cardLength == 16)) ||
				 ((cardType == "A") && (cardLength == 15)) ||
				 ((cardType == "J") && (((cardLength == 15) && ((cardStartJCB=="2131") || (cardStartJCB=="1800")))  || ((cardLength == 16) && (cardStart=="3")))) ||
				 ((cardType == "D") && (cardLength == 16)) );
		if (!(cardLengthOK)) {
			// not the right length
			alert("Invalid Credit Card Number.  Please make sure you've entered the Credit Card Number correctly.");
			return false;
		}

		// card number seems OK so do the Mod10
		if (checkCardNumWithMod10(validCard)) {
			return true;
		} else {
			alert("Invalid Credit Card Number.  Please make sure you've entered the Credit Card Number correctly.");
			return false;
		}
	} else {
		return false;
	}
}




function SetVisible( element, enabled )
{
	if (typeof(element) =='undefined')
		return;
		
	if (enabled == true)
	{
		element.style.display = 'inline';
	}
	else
	{
		element.style.display = 'none';
	}
}

function country_onchange( theForm, theControl )
{
	var country = theForm.elements['country'].value;
	var bEnableOtherField = (country == 'OTHER');
	
	if (bEnableOtherField)
	{
		SetVisible(theForm.elements['country_other'], 	true);
		SetVisible(theForm.elements['state_other'], 	true);
		SetVisible(theForm.elements['state'], 			false);
		theForm.elements['state'].value = '';
	}
	else
	{
		SetVisible(theForm.elements['country_other'], 	false);
		SetVisible(theForm.elements['state_other'], 	false);
		SetVisible(theForm.elements['state'], 			true);
		theForm.elements['country_other'].value = '';
		theForm.elements['state_other'].value = '';
	}
}

function patient_shipcountry_onchange( theForm, theControl )
{
	var country = theForm.elements['patient_shipcountry'].value;
	var bEnableOtherField = (country == 'OTHER');
	
	if (bEnableOtherField)
	{
		SetVisible(theForm.elements['patient_shipcountry_other'], 	true);
		SetVisible(theForm.elements['patient_shipstate_other'], 	true);
		SetVisible(theForm.elements['patient_shipstate'], 			false);
		theForm.elements['patient_shipstate'].value = '';
	}
	else
	{
		SetVisible(theForm.elements['patient_shipcountry_other'], 	false);
		SetVisible(theForm.elements['patient_shipstate_other'], 	false);
		SetVisible(theForm.elements['patient_shipstate'], 			true);
		theForm.elements['patient_shipcountry_other'].value = '';
		theForm.elements['patient_shipstate_other'].value = '';
	}
}

function ValidateAddressInfo( theForm )
{
	var arMandatoryFields = new Array(
		'address',
		'city',
		'country',
		'zip'
	);
	
	if (theForm.elements['country'] &&
		theForm.elements['country'].value == 'OTHER')
	{
		arMandatoryFields[arMandatoryFields.length] = 'state_other';
		arMandatoryFields[arMandatoryFields.length] = 'country_other';
	}
	else
	{
		arMandatoryFields[arMandatoryFields.length] = 'state';
	}
	
	var arMissingFields = new Array();
	
	// Ignore these fields
	var numfields = arMandatoryFields.length;
	for (var idx=0; idx < numfields; ++idx)
	{
		if (theForm.elements[arMandatoryFields[idx]])
		{
			var strFieldName = theForm.elements[arMandatoryFields[idx]].title;
			var strFieldValue = theForm.elements[arMandatoryFields[idx]].value;
			strFieldValue = StripWhitespace(strFieldValue);


			// If a mandatory field is empty
			if (strFieldValue == '')
			{
				// Add the field name to the list of missing fields
				arMissingFields[arMissingFields.length] = strFieldName;
			}
		}
	}

	if (arMissingFields.length > 0)
	{
		var strFieldList = arMissingFields.join('\n');
	
		alert('The following fields cannot be left blank:\n' + strFieldList);
		return false;
	}

/*
	if ( theForm.elements['payment_method'] && 
	     theForm.elements['payment_card_num'] &&
	     theForm.elements['payment_method'].value != 'MO' &&
	     theForm.elements['payment_method'].value != 'ONFILE' )
	{
		if (!ValidateCreditCard( theForm.elements['payment_method'].value, theForm.elements['payment_card_num'].value ))
		{
			return false;
		}
	}
*/
	return true;
}

function payment_method_onchange( theForm, theControl )
{
	var paymentmethod = theForm.elements['payment_method'].value;
	var bEnableCCFields = (paymentmethod != '' && 
			       paymentmethod != 'MO' &&
			       paymentmethod != 'ONFILE' &&
			       paymentmethod != 'AGENTACCT');
	
	SetEnabled(theForm.elements['payment_name_on_card'], 	bEnableCCFields);
	SetEnabled(theForm.elements['payment_card_num'], 	    bEnableCCFields);
	SetEnabled(theForm.elements['payment_expiry_month'], 	bEnableCCFields);
	SetEnabled(theForm.elements['payment_expiry_year'], 	bEnableCCFields);
	SetEnabled(theForm.elements['payment_card_cvv2'],  	    bEnableCCFields);
 
    if (paymentmethod =='AMEX' || paymentmethod =='DISCOVER')
    {
		document.getElementById("CVVBOXSHOW").style.display='none';
	    document.getElementById("CVVBOX").style.display='none';
    }
    else
		{
		document.getElementById("CVVBOXSHOW").style.display='';
	    document.getElementById("CVVBOX").style.display='';
    }

}

function ValidateAffiliateForm( theForm )
{
	var arMandatoryFields = new Array(
		'name',
		'phone',
		'strCAPTCHA'
	);
	
    var arMissingFields = new Array();
	var numfields = arMandatoryFields.length;
	for (var idx=0; idx < numfields; ++idx)
	{
		if (theForm.elements[arMandatoryFields[idx]])
		{
			var strFieldName = theForm.elements[arMandatoryFields[idx]].title;
			var strFieldValue = theForm.elements[arMandatoryFields[idx]].value;
			strFieldValue = StripWhitespace(strFieldValue);


			// If a mandatory field is empty
			if (strFieldValue == '')
			{
				// Add the field name to the list of missing fields
				arMissingFields[arMissingFields.length] = strFieldName;
			}
		}
	}

	if (arMissingFields.length > 0)
	{
		var strFieldList = arMissingFields.join('\n');
	
		alert('The following fields cannot be left blank:\n' + strFieldList);
		return false;
	}
	
	return true;
}
 
function ValidatePharmacyForm( theForm )
{
	var arMandatoryFields = new Array(
		'name',
		'email',
		'subject',
		'questions_comments'
	);
	
    var arMissingFields = new Array();
	var numfields = arMandatoryFields.length;
	for (var idx=0; idx < numfields; ++idx)
	{
		if (theForm.elements[arMandatoryFields[idx]])
		{
			var strFieldName = theForm.elements[arMandatoryFields[idx]].title;
			var strFieldValue = theForm.elements[arMandatoryFields[idx]].value;
			strFieldValue = StripWhitespace(strFieldValue);


			// If a mandatory field is empty
			if (strFieldValue == '')
			{
				// Add the field name to the list of missing fields
				arMissingFields[arMissingFields.length] = strFieldName;
			}
		}
	}

	if (arMissingFields.length > 0)
	{
		var strFieldList = arMissingFields.join('\n');
	
		alert('The following fields cannot be left blank:\n' + strFieldList);
		return false;
	}
	
	return true;
} 

function checkRXSend(){
	var sendrx = document.getElementById("question_prescription_send_method").value;
	if(sendrx=='CALLDR'){
		document.getElementById('doctornamerow').style.visibility = "visible";
		document.getElementById('doctorfaxrow').style.visibility = "visible";
		document.getElementById('doctortelrow').style.visibility = "visible";
		document.getElementById('faxinstructions').style.visibility = "visible";
	}
	else{
		document.getElementById('doctornamerow').style.visibility = "hidden";
		document.getElementById('doctorfaxrow').style.visibility = "hidden";
		document.getElementById('doctortelrow').style.visibility = "hidden";
		document.getElementById('faxinstructions').style.visibility = "hidden";
	}
}

function validateFax(){
	var sendrx = document.getElementById("question_prescription_send_method").value;
	var doctor = document.getElementById("doctorname").value;
	var fax1 = document.getElementById("doctorfax1").value;
	var tel1 = document.getElementById("doctortel1").value;
	var fax2 = document.getElementById("doctorfax2").value;
	var tel2 = document.getElementById("doctortel2").value;
	var fax3 = document.getElementById("doctorfax3").value;
	var tel3 = document.getElementById("doctortel3").value;


	
	
	if(sendrx=='CALLDR'){
	document.getElementById("doctorname").style.backgroundColor = "#ffffff";
	document.getElementById("doctortel1").style.backgroundColor = "#ffffff";
	document.getElementById("doctortel2").style.backgroundColor = "#ffffff";
	document.getElementById("doctortel3").style.backgroundColor = "#ffffff";
	document.getElementById("doctorfax1").style.backgroundColor = "#ffffff";
	document.getElementById("doctorfax2").style.backgroundColor = "#ffffff";
	document.getElementById("doctorfax3").style.backgroundColor = "#ffffff";	
	if(doctor.length == 0){
			alert('Please enter the doctors name.')
			document.getElementById("doctorname").style.backgroundColor = "#fff000"
			document.getElementById("doctorname").focus()
			return false;			
		}
		if (tel1.length != 3 || !IsNumeric(tel1)){
			alert('Please enter a valid telephone number.')
			document.getElementById("doctortel1").style.backgroundColor = "#fff000"
			document.getElementById("doctortel1").focus()
			return false;
		}
		if (tel2.length != 3 || !IsNumeric(tel2)){
			alert('Please enter a valid telephone number.')
			document.getElementById("doctortel2").style.backgroundColor = "#fff000"
			document.getElementById("doctortel2").focus()
			return false;
		}
		if (tel3.length != 4 || !IsNumeric(tel3)){
			alert('Please enter a valid telephone number.')
			document.getElementById("doctortel3").style.backgroundColor = "#fff000"
			document.getElementById("doctortel3").focus()
			return false;
		}		
		if (fax1.length != 3 || !IsNumeric(fax1)){
			alert('Please enter a valid fax number.')
			document.getElementById("doctorfax1").style.backgroundColor = "#fff000"
			document.getElementById("doctorfax1").focus()			
			return false;
		}
		if (fax2.length != 3 || !IsNumeric(fax2)){
			alert('Please enter a valid fax number.')
			document.getElementById("doctorfax2").style.backgroundColor = "#fff000"
			document.getElementById("doctorfax2").focus()			
			return false;
		}
		if (fax3.length != 4 || !IsNumeric(fax3)){
			alert('Please enter a valid fax number.')
			document.getElementById("doctorfax3").style.backgroundColor = "#fff000"
			document.getElementById("doctorfax3").focus()			
			return false;
		}		
	}
	
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function changefocus(txtbox, length, changeto)
{
	if (txtbox.value.length == length){
		document.getElementById(changeto).focus()
	}
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='/search.asp?index="+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
}


