

function setReturn(whLocation){
	parent.parent.returnLoc = whLocation
	parent.parent.mainFrame.location = "manage_patients_fr.htm"
}

function clearFileName(){
	parent.parent.filename = ""
	parent.parent.loggedIn = true
}

function resetModifiedFlag(){
	parent.parent.topFrame.modifiedFlag = false
}

function setModifiedFlag(){
	parent.parent.topFrame.modifiedFlag = true
}
/*
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function updateContent(){
//alert("ok")
parent.content.location.reload(true)
}

function popUpWindowB(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr,'popUpWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
*/

var popUpWin=0;

function puWindow(URLStr, width, height) {
  
  if(popUpWin && !popUpWin.closed) {
	popUpWin.close();
  }
  
  var winl = (screen.width - width)/2;
  var wint = (screen.height - height)/2;
  
  //popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+winl+', top='+wint+',screenX='+winl+',screenY='+wint+'');
  popUpWin = (window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+winl+',top='+wint+',screenX='+winl+',screenY='+wint+''));
   
}

function closePopUpWarning() {
	var w = document.getElementById('warningDiv');
	w.style.visibility = 'hidden';
}



function updateMeds(myArray){
		whichMed = parent.parent.topFrame.medsLength
		parent.parent.topFrame.meds[whichMed]= new med(myArray,whichMed)
		parent.parent.topFrame.meds[whichMed].selected = true
		parent.parent.topFrame.medsLength ++
}

var hManyArray = new Array(" ","&frac14","&frac12","1","1&frac12","2","2&frac12","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","&nbsp;")

var translationArray = new Array(" ","","","1","1","2","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","","","","","","","","","","","&nbsp;")

function med(myArray,whichMed){
			if(myArray[25] == ""){
		//alert(myArray[25])
		myArray[25] = myArray[24]
		myArray[24] = myArray[23]
		myArray[23] = myArray[22]
		myArray[22] = myArray[21]
		myArray[21] = myArray[20]
		myArray[20] = myArray[19]
		myArray[19] = myArray[18]
		myArray[18] = myArray[17]
		myArray[17] = myArray[16]
		myArray[16] = myArray[15]
		myArray[15] = myArray[14]
		myArray[14] = myArray[13]
		myArray[13] = myArray[12]
		myArray[12] = myArray[11]
		myArray[11] = myArray[10]
		myArray[10] = myArray[9]
		myArray[9] = myArray[8]
		myArray[8] = myArray[7]
		myArray[7] = myArray[6]
		myArray[6] = myArray[5]
		myArray[5] = myArray[4]
		myArray[4] = myArray[3]
		myArray[3] = myArray[2]
		myArray[2] = myArray[1]
		myArray[1] = 1000
		
	}
		var shift = (myArray[3] == "Add a medication") ? 1 : 0;

	this.ID = myArray[0]
	this.sequence = myArray[1]
	this.mclass = myArray[2 + shift]
	this.purpose = myArray[3 + shift]
	this.pname = myArray[4 + shift]
	this.generic = myArray[5 + shift]
	this.manufacturer = myArray[6 + shift]
	this.form = myArray[7 + shift]
	this.dose = myArray[8 + shift]
	//this.image = myArray[7 + shift]
	this.image = myArray[9 + shift].replace(/\,\d*/, '');
	//this.times = new Array(24)
	this.times =  myArray[10 + shift].split(",") //!!!
	
	this.selected = myArray[12 + shift]
	this.instructions = myArray[13 + shift]
	this.prescriptionURL = myArray[14 + shift]
	this.useGeneric = myArray[15 + shift]
	this.medNum = myArray[16 + shift]
	this.daily = myArray[17 + shift]
	this.dailyData = myArray[18 + shift]
	this.baseName = this.pname
	this.baseDose = this.dose
if(this.daily == "" || this.daily == "true"){this.daily = true}
	if(this.useGeneric == "true"){this.useGeneric = true}
	this.purpose_sp = myArray[19 + shift]
	this.form_sp = myArray[20 + shift]
	this.instructions_sp = myArray[21 + shift]
	this.dailyData_sp = myArray[22 + shift]
	this.dose_sort = myArray[23 + shift]
	//alert(this.ID)
	//tTast =myArray[24]
	
	if((myArray[24 + shift] == "" || myArray[24 + shift] == undefined ) && this.image != "liquid_clear.jpg" && this.image != "ped_syringe.gif" ){		this.hmany = myArray[11 + shift].split(",")
		if(String(this.daily) == "false"){
			this.hmany[0] = "Non Daily"
			
			if(this.mclass == "Insulin"){
				this.hmany[0] = "Adjustments"
			}
			if(this.dailyData == "Take as needed"){
				this.hmany[0] = "PRN"
			}
		}else{
			if(this.mclass != "Insulin"){
				this.hmany = convertOldRegimens(myArray[11 + shift])
				
			}
		}
		this.hmanyFract = convertFractions2(myArray[11 + shift],this.mclass,this.image,this.pname,this.generic,this.daily)
		
	}else{
		this.hmany = myArray[11 + shift].split(",")
		this.hmanyFract = myArray[24 + shift].split(",")
	}
	this.routes = myArray[25 + shift]
	this.HVmedID = myArray[26 + shift]
	this.route = myArray[27 + shift]

	/////NEW_start///
	if(this.dose_sort == undefined || this.dose_sort == "undefined"){
		//this.dose_sort = findDose_sort(this.dose)
	}
	if(this.sequence == ""){
		this.sequence = 100000
	}
	for (i = 0;i < this.hmany.length; i++){
		if(String(this.hmany[i]) == "undefined"){
			this.hmany[i]=-1
		}
	}
	for (i = 0;i < this.hmanyFract.length; i++){
		if(String(this.hmanyFract[i]) == "undefined"){
			this.hmanyFract[i]=-1
		}
	}
	if(this.hmany[0] == "Adjustments"){
		parent.parent.topFrame.insulinAdjustment = true
	}
	//alert(this.hmany)
	//alert(this.hmanyFract)
	
}

function convertOldRegimens(tString){
	tArray =  tString.split(",")
	for(i=1;i<tArray.length;i++){
		if(tArray[i] > 0){ // not -1
			tArray[i] = translationArray[tArray[i]]
		}
	}
	return tArray
}

function convertFractions2(tString,tClass,tImage,tName,tGeneric,tDaily){
	var fArray = new Array(24); 
	for(y=0; y<24; y++){
		fArray[y] = -1
	}
	tArray =  tString.split(",")
	//alert(tImage)
	if(tClass != "Insulin" && tImage != "injection.gif"){
		for(m=0;m<24;m++){
			if(tArray[m] != -1 && tArray[m] != " " &&  tArray[m] != "undefined"){
				fArray[m] = String(eval("document.translateRegimen.opt" + parseInt(tArray[m]) + ".value"))
			}
		}
	}

	if(tImage == "injection.gif" && tDaily != "false"){
		if(tImage == "injection.gif"){alert("Please correct the Quantities and Times for \n\n" + tName  + "(" + tGeneric + ").")}
	}	
	return fArray
}


function setLoggedIn(){
	parent.parent.loggedIn = true
	//alert("true")
}

function goRefine(){
	if (parent.parent.checkInteractions == 1){
		parent.location.href ="refine_fr.htm"
	}else{
		//popUpWindow('interaction_warning.htm',300,200,400,300)
		puWindow('interaction_warning.htm',400,300)
		parent.parent.checkInteractions = 0
	}
}



		
