﻿

/*****************************************************************************************
									Load Page
*****************************************************************************************/
function setCssJs(filename, filetype){
	    loadjscssfile(filename, filetype);
}


function setDivContent(pageUrl, divid, params){
	var my_element = document.getElementById(divid);
	my_element.className = divid;
	loadPage(pageUrl, divid, params);
}


function loadPage(page,divid, params){
         // Set up request varible
         try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
         //Show page is loading
         document.getElementById(divid).innerHTML = '<center><br><br>Loading Page...</center>';
		 setFlashHeight(divid, 120, "yes");
		 
         //send data
         xmlhttp.onreadystatechange = function(){
                 //Check page is completed and there were no problems.
                 if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
                        //Write data returned to page
						clearGrowBox();
                        document.getElementById(divid).innerHTML = xmlhttp.responseText;
                        setBoxHeight();
						newH = document.getElementById("b_content").offsetHeight;
						setFlashHeight(divid, newH, "yes");
					
                 }
         }
		 var myparams = params;
         xmlhttp.open("GET", page+"?"+myparams);
         xmlhttp.send(null);
         //Stop any link loading normaly
         return false;
}

function setBoxHeight(){
		bkgd1 = document.getElementById("bkgd_1").offsetHeight;
		bkgd2 = document.getElementById("bkgd_2").offsetHeight;
		
		if(bkgd1> bkgd2){
			bkgdHeight = bkgd1;
		}else{
			bkgdHeight = bkgd2;
		}
		
		 document.getElementById("bkgd_1").style.height = bkgdHeight + "px";
		 document.getElementById("bkgd_2").style.height = bkgdHeight + "px";
}

/*****************************************************************************************
									Clear Div Content
*****************************************************************************************/

function clearDivContent(parent, childDiv){
	
	if (document.getElementById("b_content")) {     
        var child = document.getElementById("b_content");
    	var parent = document.getElementById(parent);
    	parent.removeChild(child);
		document.getElementById("w_bottom").style.height = "0px";
		document.getElementById("w_bottom").className = "w_bottom_remove";
		document.getElementById("flashid").style.height = "600px";
		
     }
}


/*****************************************************************************************
										Resize Page (DIV)
*****************************************************************************************/

var h = 0;

function setFlashHeight(divid, newH, animation){
	
	var mydiv = document.getElementById(divid);
	
	if(animation == "yes"){
		h = document.getElementById(divid).offsetHeight;
		
		var current_div = "growBX("+ divid + ","+ newH + ")"
		myinterval = setInterval(current_div , 20);
	}else{
		mydiv.style.height = newH + "px"
	}
}


function growBX(divid, newH){
	document.getElementById("flashid").style.height = "584px";
	document.getElementById("main_container").style.paddingBottom = "16px";
	
	
	if(newH > h){
		h += 10;
		document.getElementById("w_bottom").style.height = h +'px';
	}else{
		clearGrowBox();
		document.getElementById("w_bottom").style.height = newH  +'px';
	}


}

function clearGrowBox(){
	clearInterval(myinterval);
}

function smoothScroll(){
	window.scrollTo(0,600);
}
/*****************************************************************************************
										Set Page Anchor
*****************************************************************************************/

//top of page anchor - flash link clicked
function callTag(){
	window.scrollTo(0,0);

};


/*****************************************************************************************
										Page BKGD color
*****************************************************************************************/

//Changes Wrapper BKGD Color
function changeBackground(color) { 
		document.getElementById("main_container").style.padding = "0px";
		document.getElementById("main_container").style.height ="auto";
		
	if(color == "white"){
		document.getElementById("main_container").style.backgroundColor = "#FFFFFF";
	}else if(color == "green"){
		document.getElementById("main_container").style.backgroundColor = "#D5E29D";
	}
	
}



//Javascript to flash function
function callExternalInterface() {
    thisMovie("externalInterfaceExample").goHome();
}


/*****************************************************************************************
							loading an external JavaScript or CSS 
*****************************************************************************************/

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", filename);
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


function removejscssfile(filename, filetype){
 var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
 var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
 var allsuspects=document.getElementsByTagName(targetelement)
 for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
  if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
   allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
 }
}

//loadjscssfile("weightloss/css/weightloss.css", "css");
/*****************************************************************************************
							      Checks OS (Mac or Window)
*****************************************************************************************/


function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
