// JavaScript Document
<!--

/*************************************************************************
  Set height of iframe
  
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 15 + "px";
  }
}

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;   
    return false;
  }
  else return true;
}

function getQueryString(query,obj) {
                qs = window.location.search.substring(1);
                qss = qs.split("&");
                for (i=0;i<qss.length;i++) {
                                //alert(qss[i]);
                                q = qss[i].split("=");
                                if (q[0] == query)
                                 { obj.value=unescape(q[1]); }
                }
}



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_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_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 mailpage()
{
mail_str = "mailto:?subject=Check out the " + document.title;
mail_str += "&body=I thought you might be interested in the " + document.title;
mail_str += ". You can view it at, " + location.href;
location.href = mail_str;
}

function getUrl()
{	return parent.location;}

function getPageTitle()
{	return document.title;}


function setValueAsURL(objID,qs)
{
	var o = document.getElementById(objID);
	o.value=getUrl() + qs;
	//alert(objID + "\n" + o.value);
}	

function setValueAsPageTitle(objID)
{
	var o = document.getElementById(objID);
	o.value=getPageTitle();
}	


function redirectWithURLandTitle(baseUrl)
{
	var myUrl = baseUrl; 
	var currUrl = getUrl().toString().replace(/#/,'');
	if(myUrl.indexOf("?") < 0)
	{myUrl+='?rurl=' + currUrl + '&rtitle=' + getPageTitle() }
	else
	{myUrl+='&rurl=' + currUrl + '&rtitle=' + getPageTitle()}
	window.location = myUrl;
}


function setValueAsURLPhysicalPath(objID,qs)
{
	var o = document.getElementById(objID);
	o.value=contertUrlToPhysical(getUrl()) ;
	//o.value=getUrl()
	//alert(objID + "\n" + o.value);
}	

function contertUrlToPhysical(inURL)
{
	//alert(inURL.toString());
	var myURL = inURL.toString();
	return myURL.replace(/http:\/\/www.csu.edu.au\//i,'/local/WWW/');
}

function redirectToCourseBrochure()
{
	var myURL = window.location.href;
	myURL = myURL.substring(0,myURL.indexOf("print.html"));
	window.location = myURL;
}


function printpage()
{
	window.print();
}



/*--- TESTIMONIALS ---*/

var isIE = false;
var req;

var imgBaseURL = "../../testimonials/"

function testimonial()
{
	this.imgSrc = "";
	this.imgAlt = "";
	this.imgWidth = 0;
	this.imgHeight = 0;
	this.comment = "";
	this.student = "";
	this.course = "";
}

function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			getRandomTestimonial(req);
         } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
         }
    }
}



function getRandomTestimonial(request)
{
			var xmlDoc=request.responseXML;
			var a = xmlDoc.getElementsByTagName('testimonial');
				var i=Math.floor(Math.random() * a.length) ; 
				
				var t = new testimonial();
				

				t.comment = a[i].getElementsByTagName('comment')[0].firstChild.data;
				t.student =  a[i].getElementsByTagName('student')[0].firstChild.data;
				t.course = a[i].getElementsByTagName('course')[0].firstChild.data;

				t.imgSrc = a[i].getElementsByTagName('image')[0].firstChild.data;
				t.imgAlt = t.student + " - " + t.course;
				
				getTestimonial(t);
}






function getTestimonial(t){
	window.onload = function (evt) {
		getImage(t);
		getComment(t);
	}
}

function getImage(t){
	if (t.imgSrc=="")
		return false;
		
    var img = document.createElement('img');
    img.onload = function (evt) {
		document.getElementById('commentscsuimgholder').appendChild(img);
    }
    img.src = imgBaseURL + t.imgSrc;
	img.alt = t.imgAlt;
    return false;
}

function getComment(t){
	var say = document.createElement('h2');
	say.innerHTML = "Our students say..." 
	
    var comm = document.createElement('p');
    comm.innerHTML = t.comment + "<br /><strong>" + t.student + "<br />" + t.course + "</strong>";
	
	document.getElementById('commentscsu').appendChild(say);
	document.getElementById('commentscsu').appendChild(comm);
    return false;
}


function loadTestimonial()
{
	loadXMLDoc('../testimonials/testimonials.xml')
}

// new button script for application detail page

var btn = {
    init : function() {
        if (!document.getElementById || !document.createElement || !document.appendChild) return false;
        as = btn.getElementsByClassName('btn(.*)');
        for (i=0; i<as.length; i++) {
            if ( as[i].tagName == "INPUT" && ( as[i].type.toLowerCase() == "submit" || as[i].type.toLowerCase() == "button" ) ) {
                var a1 = document.createElement("a");
                a1.appendChild(document.createTextNode(as[i].value));
                a1.className = as[i].className;
                a1.id = as[i].id;
                as[i] = as[i].parentNode.replaceChild(a1, as[i]);
                as[i] = a1;
                as[i].style.cursor = "pointer";
            }
            else if (as[i].tagName == "A") {
                var tt = as[i].childNodes;
            }
            else { return false };
            var i1 = document.createElement('i');
            var i2 = document.createElement('i');
            var s1 = document.createElement('span');
            var s2 = document.createElement('span');
            s1.appendChild(i1);
            s1.appendChild(s2);
            while (as[i].firstChild) {
              s1.appendChild(as[i].firstChild);
            }
            as[i].appendChild(s1);
            as[i] = as[i].insertBefore(i2, s1);
        }


    },
    findForm : function(f) {
        while(f.tagName != "FORM") {
            f = f.parentNode;
        }
        return f;
    },
    addEvent : function(obj, type, fn) {
        if (obj.addEventListener) {
            obj.addEventListener(type, fn, false);
        }
        else if (obj.attachEvent) {
            obj["e"+type+fn] = fn;
            obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
            obj.attachEvent("on"+type, obj[type+fn]);
        }
    },
    getElementsByClassName : function(className, tag, elm) {
        var testClass = new RegExp("(^|\s)" + className + "(\s|$)");
        var tag = tag || "*";
        var elm = elm || document;
        var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
        var returnElements = [];
        var current;
        var length = elements.length;
        for(var i=0; i<length; i++){
            current = elements[i];
            if(testClass.test(current.className)){
                returnElements.push(current);
            }
        }
        return returnElements;
    }
}

btn.addEvent(window,'load', function() { btn.init();} );


//-->