//
//  *********************************************************************
//  ***   Copyright: NetSuccess - ANS Medical 2003				 	***
//  ***   Filename: "index.cfm"				          				***
//  ***   Author: Dan Blackman							   			***
//  ***   Project: ANS Medical	       				   				***
//  ***   File Type: Cold Fusion MX            		   				***
///  ***   Date Created:  3/12/2003		  							***
//  *********************************************************************

//Template Purpose:
//This page is the container for the for the Patient Index page...

//Application Modification Log:/
//DATE		BY				MODIFICATION
//--------------------------------------------------------------------------------
//3/12/2003	Dan Blackman	Created Template
//-------------------------------------------------------------------------------->

//Finds the first field on the page and sets focus to it.

		//--- This function sets focus to the first element on each form

	function newWindow(mypage,myname,w,h,features) {
		  if(screen.width){
		  var winl = (screen.width-w)/2;
		  var wint = (screen.height-h)/2;
		  }else{winl = 0;wint =0;}
		  if (winl < 0) winl = 0;
		  if (wint < 0) wint = 0;
		  var settings = 'height=' + h + ',';
		  settings += 'width=' + w + ',';
		  settings += 'top=' + wint + ',';
		  settings += 'left=' + winl + ',';
		  settings += features;
		  win = window.open(mypage,myname,settings);
		  win.window.focus();
	}	
		


			function doSelection(el) {
				var arAncors = document.all.tags("A");
				for (var i = 0; i < arAncors.length; i++) {
					if (arAncors[i].isSelected == 1) {
						arAncors[i].style.cssText = "color:white;background-color:666699;";
						arAncors[i].isSelected = 0;
					}
				}
				
				el.style.cssText = "color:666699;background-color:white;";
				el.isSelected = 1;
			}


			function treeClick(argTreeId) {
				var el = event.srcElement;
				thePath = el.src.toLowerCase();
				theParts = thePath.split("/");
				srcImage = theParts[theParts.length - 1];
					
				if (el.treeExpanded == "1") {
					if (srcImage == "minus.gif") {
						el.src = el.treeImagePath + "plus.png";
					}
					else {
						el.src = el.treeImagePath + "plusbottom.png";
					}
					el.treeExpanded = "0";
					collapseItem(argTreeId);
				}
				else {
					if (srcImage == "plus.gif") {
						el.src = el.treeImagePath + "minus.png";
					}
					else {
						el.src = el.treeImagePath + "minusbottom.png";
					}
					el.treeExpanded = "1";
					//collapseAll(argTreeId);
					expandItem(argTreeId);
				}
			}



			function expandItem(argTreeId) {
				var arTables = document.all.tags("TABLE");
				for (var i = 0; i < arTables.length; i++) {
					if (arTables[i].treeParent == argTreeId) {
						arTables[i].style.display = '';
					}
					if (arTables[i].treeId == argTreeId) {
						var arColumns = arTables[i].all.tags("TD");
						for (var j = 0; j < arColumns.length; j++) {
							if (arColumns[j].treeElType == "3") {
								if (arColumns[j].children.tags("A")[0] != null) {
									arColumns[j].children.tags("A")[0].children.tags("IMG")[0].src = arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeXIcon;
								}
								else {
									arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("IMG")[0].treeXIcon;
								}
							}
						}
					}
				}
			}


			function collapseItem(argTreeId) {
				var arTables = document.all.tags("TABLE");
				for (var i = 0; i < arTables.length; i++) {
					/// Loop over all the tables
					if(arTables[i].treeId == undefined || arTables[i].treeId == '0')
					{ 
						continue;
					}else
					{
						// Loop over the columns in a specific table
						var arColumns = arTables[i].all.tags("TD");
						var isCollapsing = 0;
						for (var j = 0; j < arColumns.length; j++) {
							if (arTables[i].treeId == argTreeId) {
								if (arColumns[j].treeElType == "3") {
									/// Change the tree Icon
									if (arColumns[j].children.tags("A")[0] != null) {
										arColumns[j].children.tags("A")[0].children.tags("IMG")[0].src = arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeIcon;
									}
									else {
										arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("IMG")[0].treeIcon;
									}
								}
								// Change Hyperlink Text
								if (arColumns[j].treeElType == "4") {
									if (arColumns[j].children.tags("A")[0] != null) {
										arColumns[j].children.tags("A")[0].isSelected = 1;
										arColumns[j].children.tags("A")[0].style.cssText = "color:666699;background-color:white;";
									}
								}
							}
							else {
								// Hide the cild tables for this node
								if (arColumns[j].treeId == argTreeId) {
									isCollapsing = 1;
									arTables[i].style.display = 'none';
								}
								if (isCollapsing == 1) {
									/// Change the Minus sign to a Plus Sign
									if (arColumns[j].treeElType == "2") {
										arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + "plus.png";
										arColumns[j].children.tags("IMG")[0].treeExpanded = "0";
									}
									if (arColumns[j].treeElType == "5") {
										arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + "plusbottom.png";
										arColumns[j].children.tags("IMG")[0].treeExpanded = "0";
									}
									if (arColumns[j].treeElType == "3") {
										if (arColumns[j].children.tags("A")[0] != null) {
											arColumns[j].children.tags("A")[0].children.tags("IMG")[0].src = arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeIcon;
										}
										else {
											arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("IMG")[0].treeIcon;
										}
									}
									if (arColumns[j].treeElType == "4") {
										if (arColumns[j].children.tags("A")[0] != null) {
											if (arColumns[j].children.tags("A")[0].isSelected == 1) {
												arColumns[j].children.tags("A")[0].isSelected = 0;
												arColumns[j].children.tags("A")[0].style.cssText = "color:white;background-color:666699;";
											}
										}
									}
								}
							}				
						}
					}
				}
			}

			function collapseAll() {
				var arTables = document.all.tags("TABLE");
				for (var i = 0; i < arTables.length; i++) {
					/// Loop over all the tables
					if(arTables[i].treeId == undefined || arTables[i].treeId == '0')
					{ 
						continue;
					}else
					{
						// Loop over the columns in a specific table
						var arColumns = arTables[i].all.tags("TD");
						var isCollapsing = 0;
						for (var j = 0; j < arColumns.length; j++) {
							if (arTables[i].treeParent == 0) {
								if (arColumns[j].treeElType == "3") {
									/// Change the tree Icon
									if (arColumns[j].children.tags("A")[0] != null) {
										arColumns[j].children.tags("A")[0].children.tags("IMG")[0].src = arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeIcon;
									}
									else {
										arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("IMG")[0].treeIcon;
									}
								}
								// Change Hyperlink Text
								if (arColumns[j].treeElType == "4") {
									if (arColumns[j].children.tags("A")[0] != null) {
										arColumns[j].children.tags("A")[0].isSelected = 1;
										arColumns[j].children.tags("A")[0].style.cssText = "color:666699;background-color:white;";
									}
								}
							}
							else {
								// Hide the cild tables for this node
								if (arColumns[j].parenttree != argTreeId) {
									isCollapsing = 1;
									arTables[i].style.display = 'none';
								}								
								if (isCollapsing == 1) {
									/// Change the Minus sign to a Plus Sign
									if (arColumns[j].treeElType == "2") {
										arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + "plus.png";
										arColumns[j].children.tags("IMG")[0].treeExpanded = "0";
									}
									if (arColumns[j].treeElType == "5") {
										arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + "plusbottom.png";
										arColumns[j].children.tags("IMG")[0].treeExpanded = "0";
									}
									if (arColumns[j].treeElType == "3") {
										if (arColumns[j].children.tags("A")[0] != null) {
											arColumns[j].children.tags("A")[0].children.tags("IMG")[0].src = arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("A")[0].children.tags("IMG")[0].treeIcon;
										}
										else {
											arColumns[j].children.tags("IMG")[0].src = arColumns[j].children.tags("IMG")[0].treeImagePath + arColumns[j].children.tags("IMG")[0].treeIcon;
										}
									}
									if (arColumns[j].treeElType == "4") {
										if (arColumns[j].children.tags("A")[0] != null) {
											if (arColumns[j].children.tags("A")[0].isSelected == 1) {
												arColumns[j].children.tags("A")[0].isSelected = 0;
												arColumns[j].children.tags("A")[0].style.cssText = "color:white;background-color:666699;";
											}
										}
									}
								}
							}
						}
					}
				}
			}




//passes the value of the file to a hidden field
		function submitRegister(theForm){
			var theSuffix;
			var l;
			var theURL;

			theURL = theForm.artifact.value;
			theForm.artifact_path.value = theURL;
			l = theURL.length;
	
			if (l < 4) {
				alert("Invalid File Name!" );
				return false;
			}
	
			l = l - 4;
			theSuffix = theURL.substring(l);
			theForm.suffix.value = theSuffix;
			theForm.submit();
			return true;
		}

//Finds the first field on the page and sets focus to it.

		//--- This function sets focus to the first element on each form

function setElementFocus()
{
    if (document.forms[0] != null)
    {

      for(i=0;i<document.forms[0].elements.length;i++)
      {
  
         if (document.forms[0].elements[i].type == 'text')
          {
            document.forms[0].elements[i].focus();
            break;
          } else
		  	{if (document.forms[0].elements[i].type == 'file')
				{
				document.forms[0].elements[i].focus();
            	break;
				}
			}
      }
    }
}
		

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_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];}}
}

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_swapImage() { //v3.0
  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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  { 
  	test=args[i+2]; val=MM_findObj(args[i]);
    if (val) 
	{ 
		nm=val.name; 
		if ((val=val.value)!="") 
		{
		  if (test.indexOf('isEmail')!=-1) 
		  { 
		  		p=val.indexOf('@');
			  if (p<1 || p==(val.length-1)) 
				errors+='- '+nm+' must contain an e-mail address.\n';
		  } else if (test!='R') 
			{
				if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
				if (test.indexOf('inRange') != -1) 
				{ 	
					p=test.indexOf(':');
					min=test.substring(8,p); max=test.substring(p+1);
					if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
				} 
	} 
  } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; 
}

  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

///Used in Iternational Pages
function ShowAnswer(id,targetonly) {
  var answer = document.getElementById("a"+id);
  if (answer.style.display == "none") {
    answer.style.display = "block";
  } else if (!targetonly) {
    answer.style.display = "none";
  }

  PositionQuote();
}

function PositionQuote() {
}


///Disable Right Click
function right(e) {
var msg = "Sorry, you don't have permission to save ANS images. Please contact Advanced Neuromodulation Systems at 1-800-727-7846 for assistance.";
if (navigator.appName == 'Netscape' && e.which == 3) {
alert(msg);
return false;
}
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
alert(msg);
return false;
}
else return true;
}

function trap() 
  {
  if(document.images)
    {
    for(i=0;i<document.images.length;i++)
      {
      document.images[i].onmousedown = right;
      document.images[i].onmouseup = right;
      }
    }
  }

