function locatorCheck(form,site,flag) {
/*	if (!form.policy.checked) {
		alert("You must agree to the privacy statement to use this tool.");
		return;
	}
*/	
	// Submit with a valid Zip
	if (form.zipCode.value != "") {
                if (flag.toLowerCase() == 'yes' && site.toLowerCase() == 'power_over_your_pain') {
                   recordIt('', '', 'lead', 'drlocator');
                }
		form.submit();
		return;
	}
	
	// Submit with a valid City and State
	if (form.city.value != "" && form.state.value != "") {
                if (flag.toLowerCase() == 'yes' && site.toLowerCase() == 'power_over_your_pain') {
                   recordIt('', '', 'lead', 'drlocator');
                }
		form.submit();
		return;
	}
	
	// Submit with a valid State
	if (form.state.value != "") {
                if (flag.toLowerCase() == 'yes' && site.toLowerCase() == 'power_over_your_pain') {
                   recordIt('', '', 'lead', 'drlocator');
                }
		form.submit();
		return;
	}
	
	alert("You must enter a Zip Code, City and State or State");
}

function locatorQuickCheck(theForm,site,flag){
	if (theForm.fullAddress.value != "") {
                if (flag.toLowerCase() == 'yes' && site.toLowerCase() == 'power_over_your_pain') {
                   recordIt('', '', 'lead', 'drlocator');
                }
		theForm.submit();
		return;
	}

	alert("You must enter a Zip Code, City and State or State");
}

function locatorCheckSpanish(form) {
	// Submit with a valid Zip
	if (form.zipCode.value != "") {
		form.submit();
		return;
	}
	
	// Submit with a valid City and State
	if (form.city.value != "" && form.state.value != "") {
		form.submit();
		return;
	}
	
	// Submit with a valid State
	if (form.state.value != "") {
		form.submit();
		return;
	}
	
	alert("Incluir c\u00F3digo postal, ciudad y estado");
}


function ansLeaveSite(site) {
	leaveSite(site,false);
}
function ansLeaveSite(site,newWindow) {
	var notice = "This website may provide links to other websites not affiliated with St. Jude Medical. St. Jude Medical is not responsible for the content of other sites.";
	if (confirm(notice)) {
		if (newWindow) window.open(site,"_blank");
		else location = site;
	}
}
function sjmLeaveSite(site,newWindow) {
	var notice = "Diese Webseite beinhaltet Links zu anderen externen Webseiten anderer Firmen oder sonstiger Dritter. SJM hat grunds\u00EFtzlich keinen Einflu\u00DF auf die Gestaltung oder den Inhalt externer Seiten, und \u00FCbernimmt f\u00FCr deren Inhalte keine Verantwortung";
	if (confirm(notice)) {
		if (newWindow) window.open(site,"_blank");
		else location = site;
	}
}

// Shows and hides the appropriate elements.
// theEle - <a> tag which has the call to this method.  Can usually use
//          The word "this" in the call
// which - element to hide/show.  Usually document.getElementById(val)
function toggleInfo(which, src) {
	
	document.getElementById("personal_info").style.display = "none";
	document.getElementById("physician").style.backgroundColor = "#fe5";
	
	document.getElementById("phys_clinics").style.display = "none";
	document.getElementById("clinic_add").style.display = "none";
	document.getElementById("clinic").style.backgroundColor = "#fe5";
	
	document.getElementById("phys_staff").style.display = "none";
	document.getElementById("staff").style.backgroundColor = "#fe5";
	
	document.getElementById("phys_docs").style.display = "none";
	document.getElementById("docs").style.backgroundColor = "#fe5";
	
	which.style.display = "";
	src.style.backgroundColor = "#fc0";
	
}

// Shows or hides the add clinic form
function toggleAddClinic(which) {
	if(which.style.display == "") {
		which.style.display = "none";
	} else {
		which.style.display = "";
	}

}

// Delete Physician Info
// Requires a form element called delete which will be set true
function deletePhysEle(theForm) {
	if (confirm("Are you sure you want to delete this item?")) {
		theForm.deleteEle.value="true";
		theForm.submit();
	} else {
		return false;
	}
}

function saveArea(theForm, label, area) {
	// If there are changes on another form, prompt the user
	if (findChanges(area)) {
		if (! confirm("You are saving information for " + area + ".  Any other changes will be lost")) {
			return;
		}	
	}
	
	// Submit
	if (area == "Physician") {
		savePhysician(theForm, label);
	} else {
		submitElement(theForm, label);
	}

}

// Looks for changes in the other forms and returns the form name if another
// form is updated
function findChanges(theName) {
	var forms = document.forms;
	changedForm = false;
	for (i=0; i < forms.length; i++) {
		innerForm = forms[i];
		
		// Don't check the current form
		if (theName == innerForm.name) {
			continue;
		}
		
		// Loop each of the elements in the form and look for changes
		for (x=0; x<innerForm.length; x++) {
			var ele = innerForm[x];
			if (ele.type.indexOf("checkbox") > -1) {
				if (ele.checked != ele.defaultChecked) {
					changedForm = true;
				}
			} else if (ele.type.indexOf("select") > -1) {
				for (y=0; y < ele.options.length; y++) {
					if (ele.options[y].selected) {
						if (! ele.options[y].defaultSelected) {
							changedForm = true;
						}
					}
				}
			} else {
				if (ele.value != ele.defaultValue) {
					changedForm = true;
				}
			}
		



		}
	}
	
	return changedForm;
}

// Performs a logic check for physician and passes it to the update element	
function savePhysician(theForm, val) {
	var locator = parseInt(theForm.statusId.value);
	var type = parseInt(theForm.surgeonTypeId.value);
	var success = false;
	if (locator == 1) {
		if (type == 0) {
			success = true;
		}
	} else {
		success = true;
	}
	
	// If success isfalse, prompt the user
	if (success) {
		submitElement(theForm, val);
		return;
	} else {
		alert("Only Customers are allowed on the locator.  Please change the Physician Type");
		return false;
	}
}
	
// Checks the total implants and selects the proper class then submits
function savePlan(theForm) {
	var total = parseInt(theForm.totalImplants.value);
	var chk = false;
	var len = theForm.implantClass.length;
	var chkVal = "";
	for(i = 0; i < len; i++) {
		if (theForm.implantClass[i].checked == true) {
			chk = true;
			chkVal = theForm.implantClass[i].value;
		}
	}
	
	// Make sure the total implants matches the Implant Class
	if(!chk && total > 0) {
		if (total < 13) {
			theForm.implantClass[2].checked = true;
		} else if (total < 25) {
			theForm.implantClass[1].checked = true;
		} else {
			theForm.implantClass[0].checked = true;
		}
	} else if (chk && total > 0) {
		var isSame = true;
		if (total > 12 && chkVal == "C") {
			isSame = false;
		} else if ((total < 13 || total > 24) && chkVal == "B") {
			isSame = false;
		} else if (total< 25 && chkVal == "A") {
			isSame = false;
		}
		
		if (! isSame) {
			alert("The total annual usage does not match the class selection"); 
			return;
		}
	}
	
		submitElement(theForm, 'Your submission requires the');
}

// Autmatically selects the implant class based upon the total selected
function setProjected(theForm) {
	var val = parseInt(theForm.totalImplants.value);
	for(i=0; i < theForm.implantClass.length; i++) {
		if (i == 0 && val > 24) {
			theForm.implantClass[0].checked =true;
		} else if (i == 1 && val > 12 && val < 25) {
			theForm.implantClass[1].checked =true;
		} else if (i == 2 && val > 0 && val < 13) {
			theForm.implantClass[2].checked =true;
		} else {
			theForm.implantClass[i].checked =false;
		}
	}
}

// Totals the Business Plan rojected usage info
function calcTotal(theForm) {
	var tq1 = checkNumeric("trialQ1", theForm)
	var tq2 = checkNumeric("trialQ2", theForm)
	var tq3 = checkNumeric("trialQ3", theForm)
	var tq4 = checkNumeric("trialQ4", theForm)
	var total = tq1 + tq2 + tq3 + tq4;
	theForm.trialTotal.value = total;
	
	var pq1 = checkNumeric("permQ1", theForm);
	var pq2 = checkNumeric("permQ2", theForm);
	var pq3 = checkNumeric("permQ3", theForm);
	var pq4 = checkNumeric("permQ4", theForm);
	var ptotal = pq1 + pq2 + pq3 + pq4;
	theForm.permTotal.value = ptotal;
	
	function checkNumeric(field, theForm) {
	//alert(field);
	var val = parseInt(theForm.elements[field].value);
	if (isNaN(val)) {
		
		if (theForm.elements[field].value.length > 0) {
			alert("The entered value must be a number");
			theForm.elements[field].focus();
		}
		
		theForm.elements[field].value = 0;
		val = 0;
	}
	return val;
}
}

// Checks the form elements for the quick newsletter sign-up form.
function checkSignUpVals(theForm, message) {
	for (i=0; i < theForm.elements.length; i++) {
		node = theForm.elements[i];
		
		// Display a message to the user that required elements are not filled out			
		if (node.value == null || node.value == "" || node.value == "your email address" || node.value == "first name" || node.value == "last name") {
			alert(message + " \"" + node.id.replace("_", " ") + "\"");
			node.focus();
			return false;
		}
		
		if (node.id == "email_address") {
			if (!checkEmail(node.value)) {
				alert(message + " a valid email address.");
				node.focus();
				return false;
			}
		}
	}
	
	theForm.submit();
}

//Supports metrics for PaintYourPain tool.
function trackImage(url) {
	var http;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        http = new XMLHttpRequest();
    }
	http.open("GET", url);
	http.onreadystatechange = function() {};
	http.send(null);
}

//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}


//v1.1
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AX_RunContent(){
  var ret = AC_AX_GetArgs(arguments);
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_AX_GetArgs(args){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "pluginspage":
      case "type":
      case "src":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "data":
      case "codebase":
      case "classid":
      case "id":
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":

      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  return ret;
}

// Script from http://htmldog.com/articles/suckerfish/dropdowns/
// Authors: Patrick Griffiths and Dan Webb
// Supports the POYP site language pull-down list.
			// listHover = function() {
			//var sfEls = document.getElementById("lang-nav").getElementsByTagName("li");
			//for (var i=0; i<sfEls.length; i++) {
			//	sfEls[i].onmouseover=function() {
			//		this.className+=" listHover";
			//	}
			//	sfEls[i].onmouseout=function() {
					//this.className=this.className.replace(new RegExp(" listHover\\b"), "");
//				}
//			}
//		}
//		if (window.attachEvent) {
//			window.attachEvent("onload", listHover);
//		}

//Cool MPC toggle April 2007
	
function toggleDisplay(obj)
{
        //var me = document.getElementById(obj);
          me = document.getElementById(obj);
		if (me.style.display=="block")
		{
			me.style.display="none";
		}
		else 
		{
			if (me.style.display=="block")
			{
				me.style.display="none";
				window.setTimeout("obj.style.display='block';",3000,"JavaScript");
			}
			else 
			{
				me.style.display="block";
			}
		}
}


function toggle_off_all(section,num){
			var MAX = eval(num);
			for (var i=0; i<MAX; i++) {
				var iobj=section + i ;
		 
			//	alert( num + " ?? " + iobj );
				
				me = document.getElementById(iobj);
			        me.style.display="none";
						
						
		}
				
	
		
}
		
		
function toggle_on_all(section,num){

	var MAX = eval(num);
	for (var i=0; i<MAX; i++) {
		var iobj=section + i ;
		 
	//	alert( obj + " " + iobj );
				
		var me = document.getElementById(iobj);
		me.style.display="block";
						
						
	}
				
	
		
}

//Clears Success Story form fields and re-submits form.
function clearSuccessForm(theForm) {
	clearForm(theForm);
	theForm.submit();
}

/* Rotating images */
var _timeout_length = 6000;
var timeout_id;
var _stopRotation = false;
var _pauseState=0;
var _userControlling = false;
var frames;
frames=0;
var imageCount;
imageCount=4;
images=new Array(4);
links=new Array(4);

images[0]=new Image();
images[0].src='/binary/org/ANS-MEDICAL/images/poyp2/1192x304-1.jpg';
images[0].alt='Image 1 of 4';
links[0]=new String();
links[0].value='/sb/next/featured/kim';

images[1]=new Image();
images[1].src='/binary/org/ANS-MEDICAL/images/poyp2/1192x304-2.jpg';
images[1].alt='Image 2 of 4';
links[1]=new String();
links[1].value='/sb/next/featured/charles';

images[2]=new Image();
images[2].src='/binary/org/ANS-MEDICAL/images/poyp2/1192x304-3.jpg';
images[2].alt='Image 3 of 4';
links[2]=new String();
links[2].value='/sb/next/featured/beth';

images[3]=new Image();
images[3].src='/binary/org/ANS-MEDICAL/images/poyp2/1192x304-4.jpg';
images[3].alt='Image 4 of 4';
links[3]=new String();
links[3].value='/sb/next/featured/adam';

function animateImages() {
	setImage(frames);
	if (_stopRotation == true) {
	       pausePlay();
	       _userControlling = false;
	    }    else    {
	            timeout_id = setTimeout('animateImages()',_timeout_length);
		}
	if (_userControlling == true) {
		frames =(frames+1)%imageCount;
	} else {
		frames = frames+1;
		if (frames >= imageCount) {
			frames = 0;
			_stopRotation = true;
		}
	}
}

function setImage(frameValue) {
	frames = frameValue;
	var Img = document.getElementById('imageWrapperId');

	if (Img) {
		Img.style.backgroundImage = 'url('+images[frames].src+')';
	}
	//} else {
	//	alert('An image was not found.');
	//}
	
	var imageLink = document.getElementById('image_link');
	if (imageLink)   {
		var imageLinkUrl = links[frames].value;
		imageLink.setAttribute('href',imageLinkUrl);
	}
	
	var Btn;
	var x = 0;
	while (x != imageCount) {
		Btn = document.getElementById('Btn'+x);
		Btn.className='';
		x = x + 1;
	}
	
	Btn = document.getElementById('Btn'+frames);
	Btn.className='current';
}

function pausePlay_setNextState(parmState) {
	var Btn = document.getElementById('controlButtonPausePlay');
	if (Btn) {
		Btn.style.backgroundImage = "url('/binary/themes/ANS_THEME_US2/images/btn_"+parmState+".gif')";
		Btn.blur();
	}
	var Btn;
	var x = 0;
	while (x != imageCount) {
		Btn = document.getElementById('Btn'+x);
		Btn.className=''; x = x + 1;
	}
	Btn = document.getElementById('Btn'+frames);
	Btn.className='current';
}

function pausePlay() {
	_userControlling = true;
	_stopRotation = false;
	
	if (_pauseState == 0) {
		_pauseState =(_pauseState+1)%2;
		pausePlay_setNextState('play');
		clearTimeout(timeout_id);
	} else {
	_pauseState =(_pauseState+1)%2;
	pausePlay_setNextState('pause');
	animateImages();
	}
}
/* END of rotating image JS */