// JavaScript Document

function setDDBox(getFldName, getFldValue){
//Sets Combo box value to value	
	var fldName = eval(getFldName);
	var fldValue = getFldValue;
   	var i="";  
   	for (var i = 0; i < fldName.length; i++) {
         if (fldName.options[i].value == fldValue) {
		          fldName.options[i].selected=true;     	   
		 }
   	}
}


function getDDBoxValue(fldName){
//Gets 'Value' value from DD
	var Indx = fldName.selectedIndex;
	return fldName.options[Indx].value;
}



function getDDBoxText(fldName){
//Gets Displayed text from DD
	var Indx = fldName.selectedIndex;
	return fldName.options[Indx].text;
}



function addElement(list, text_in, value_in){
//Updates dd box for ddProvState

    var o = list.options;
    var nIdx;
	if (o.length < 0)// IE for Mac 4.5 sets length to -1 if list is empty
		nIdx = 0;
	else
		nIdx = o.length;

	o[nIdx] = new Option(text_in, value_in);
	list.disabled = false;
}




function setRadio(getFldName, getFldValue){
	var fldName = eval(getFldName);
	var fldValue = getFldValue;
	var i="";
	
	for (var i = 0; i < fldName.length; i++) {
		if (fldName[i].value == fldValue){
			fldName[i].checked = true;
		}
	}
}


function getRadio(getFldName){
	var fldName = eval(getFldName);
	var fldValue = null;
	
	for (var i = 0; i < fldName.length; i++) {
		if (fldName[i].checked == true){
			fldValue = fldName[i].value;
		}
	}
	return fldValue;
}


function setCheckBox(getFldName, getFldValue){
//If checkbox value and get value match, then checkbox is set to checked.
	var fldName = eval(getFldName);
	var fldValue = getFldValue;

	if (fldName.value == fldValue){
		fldName.checked = true;
	}
}



//===== SHOW HIDE =====
//Hide or show elements
function hideElement(getElem){
//Hides the font select area
 var ElemArea = document.getElementById(getElem);
 ElemArea.style.display = "none"
 
}

 
function showElement(getElem){
//Displays the font select area
 var ElemArea = document.getElementById(getElem); 
 ElemArea.style.display = "inline"
}

function showElementBlock(getElem){
//Displays the font select area
 var ElemArea = document.getElementById(getElem); 
 ElemArea.style.display = "block"
}


function elementClass(getElem, getClass){
//Sets a class for selected element (P, Table etc.)
 var ElemArea = document.getElementById(getElem); 
 ElemArea.className = getClass;
}

//----- end ------//



//======= Node Vals =======
function setParentNodeVal($getElement, $getValue){
//Sets a node/text area to value
	getNode = window.opener.document.getElementById($getElement);
	getNode.childNodes[0].nodeValue = $getValue;
}


function getParentNodeVal($getElement){
//Returns node/text area value
	getNode = window.opener.document.getElementById($getElement);
	return getNode.childNodes[0].nodeValue;
}




function setNodeVal(getElement, getValue){
//Sets a node/text area to value
	getNode = document.getElementById(getElement);
	getNode.childNodes[0].nodeValue = getValue;
}


function getNodeVal(getElement){
//Returns node/text area value
	getNode = document.getElementById(getElement);
	return getNode.childNodes[0].nodeValue;
}
//======= End of Node Vals =======




//===== ADVOCATE STUFF =====/
function PostClientLog(getCaseID, getUserType){
//Sets form to post to details
	document.frmClient.caseid.value = getCaseID;
	
	switch(getUserType){
		case 'advocate':
			document.frmClient.action = "/Home_Support/Advocate/Client/Client_Log.php";
			break;
			
		case 'agency':
			document.frmClient.action = "/Home_Support/Agency/Client/Client_Log.php";
			break;
			
	}
	
	document.frmClient.submit();
}


function PostClientProfile(getCaseID){
//Sets form to post to details
	document.frmClient.caseid.value = getCaseID;
	document.frmClient.action = "/Home_Support/Advocate/Client/Client_Profile.php";
	document.frmClient.submit();
}


// eof advocate



function openFeedback(nameFile){
//Opens the feed back form and populates it.
	var win = window.open("http://www.innfromthecoldkelowna.org/Feedback/FeedBack_Input.php?Comp=InnFromTheCold&Progm=web&Env="+navigator.appName+" "+navigator.appVersion+"&FormName="+nameFile, "feedback", "height=600, width=550, resizable=yes, scrollbars=no");
	win.focus();
}


function ContactAdvocate(){
	var ContactEmail = document.form1.email.value
	var UserName = document.form1.username.value
	var Password = document.form1.password.value
	var User = document.form1.fname.value
	
	var win = window.open("mailto:"+ContactEmail+"?subject=Your Log-In for Inn from the Cold&body="
			+User+" here is your password to log into the database. %0A"
			+"After every visit, please log in and type your report. You can start with logging the first introduction meeting. %0A"
			+"%0A"
			+"To Log-in, go to: http://www.innfromthecoldkelowna.org/Home_Support/index.php %0A"
			+"%0A"
			+"User Name: "+UserName+" %0A"
			+"Password: "+Password+" %0A"
			+"%0A"
			+"If for some reason it doesn't work, or you have any questions, please contact me. %0A"
			+"%0A"
			+"There is a 'Feedback' button on the log page, if there are database suggestions or bugs, please click, write and submit the Feedback to us. Our programmer can then work on it immediately. %0A"
			+"%0A"
			+"Thank you. %0A"
			+"%0A"
			+"Tara %0A",
			"emailwindow", "height=200, width=200, resizable=no, toolbar=no, scrollbars=no, menubar=no");	
}


function ContactAgency(){
	var ContactEmail = document.form1.worker1_email.value
	var UserName = document.form1.username.value
	var Password = document.form1.password.value
	var User = document.form1.worker1_first.value
	
	var win = window.open("mailto:"+ContactEmail+"?subject=Your Log-In for Inn from the Cold&body="
			+User+" here is your password to log into the database. %0A"
			+"After every visit, please log in and type your report. You can start with logging the first introduction meeting. %0A"
			+"%0A"
			+"To Log-in, go to: http://www.innfromthecoldkelowna.org/Home_Support/index.php %0A"
			+"%0A"
			+"User Name: "+UserName+" %0A"
			+"Password: "+Password+" %0A"
			+"%0A"
			+"If for some reason it doesn't work, or you have any questions, please contact me. %0A"
			+"%0A"
			+"There is a 'Feedback' button on the log page, if there are database suggestions or bugs, please click, write and submit the Feedback to us. Our programmer can then work on it immediately. %0A"
			+"%0A"
			+"Thank you. %0A"
			+"%0A"
			+"Tara%0A",
			"emailwindow", "height=200, width=200, resizable=no, toolbar=no, scrollbars=no, menubar=no");		
}




//----- First Aid ----- //
function FirstAid_Yes(){
//Shows appropriate div if first aid is yes
	showElementBlock('divFirstAid_Yes')
	hideElement('divFirstAid_No')
}


function FirstAid_No(){
//Shows appropriate div if first aid is yes
	showElementBlock('divFirstAid_No')
	hideElement('divFirstAid_Yes')
}



//----- Food Safe ----- //
function FoodSafe_Yes(){
//Shows appropriate div if first aid is yes
	showElementBlock('divFoodSafe_Yes')
	hideElement('divFoodSafe_No')
}


function FoodSafe_No(){
//Shows appropriate div if first aid is yes
	showElementBlock('divFoodSafe_No')
	hideElement('divFoodSafe_Yes')
}


//----- Commitment ----- //
function Commitment_Yes(){
//Shows appropriate div if first aid is yes
	hideElement('divCommitment_No')
}


function Commitment_No(){
//Shows appropriate div if first aid is yes
	showElementBlock('divCommitment_No')
}




function showDiv(getDiv){
//Displays element and scrolls to top	
	divID = document.getElementById(getDiv);
	
	divID.style.display = "block"
	divID.scrollIntoView();
}

function hideDiv(getDiv){
//Displays element and scrolls to top	
	divID = document.getElementById(getDiv);
	
	divID.style.display = "none"
}
