  	

//############################################
// UCA Javascript for MySource Matrix
// @author: Tim Everist
//############################################

var currenturl= unescape(window.location.pathname);


//############################################
// Common UCA JS Functions
//############################################


function uca_replaceChars(entry, pattern, replace) {
entry = uca_rightTrim(entry);
out = pattern; // replace this
add = replace; // with this
temp = "" + entry; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + 
temp.substring((pos + out.length), temp.length));
}
return temp;
}

function uca_stripHTML(oldString) {

   var newString = "";
   var inTag = false;

   for(var i = 0; i < oldString.length; i++) {   

        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              inTag = false;
              i++;
        }  

        if(!inTag) newString += oldString.charAt(i);
  }
   return newString;

}

function uca_closeWindow()
{
opener.uca_refreshPage();
self.close();
}

function uca_addFacilityImage(assetid, lineage)
{   
   url = rooturl+'/facilities_and_services_/add_image/?assetid='+assetid+'&SQ_DESIGN_NAME=ax';
   addFileWindow = window.open(url, 'addFileWindow','resizable=yes,scrollbars=yes,height=500,width=750');
   
	if (this.focus) 
   {
     addFileWindow.focus();
   }   
}


function uca_addPage(assetid, lineage)
{   
   url = rooturl+'/add_page/?assetid='+assetid+'&SQ_DESIGN_NAME=ax';
   editFileWindow = window.open(url, 'editFileWindow','resizable=yes,scrollbars=yes,height=500,width=750');
   
	if (this.focus) 
   {
     editFileWindow.focus();
   }   
}

function uca_rollon(imgid, imgsrc)
{
	document[imgid].src = imgsrc;

}

function uca_rolloff(imgid, imgsrc)
{
	document[imgid].src = imgsrc;	
}


function uca_rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
{
	sString = sString.substring(0,sString.length-1);
}
	return sString;
}

function uca_trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

function uca_setUsername(field, input, usernameid) {

var usernamefield = document.getElementById(usernameid);

if (field == 'firstname')
{
firstname = input.value; 
firstname = uca_trimAll(firstname);
}
else if (field == 'lastname')
{
lastname = input.value;
lastname = uca_trimAll(lastname);
}
usernamefield.value = 'hrs.' + firstname + '.' + lastname; 
usernamefield.value = usernamefield.value.toLowerCase();

}

function uca_randPassword(passwordid) {
var passone = document.getElementById(passwordid+'_one');
var passtwo = document.getElementById(passwordid+'_two');
var password = Math.random();

passone.value = password;
passtwo.value = password;

}

function replaceChars(entry, prefix) {
entry = uca_rightTrim(entry);
out = " "; // replace this
add = "."; // with this
temp = "" + entry; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + 
temp.substring((pos + out.length), temp.length));
}
var temp2 = "";
temp2 = prefix + temp;
document.getElementById('username').value = temp2;
}

function uca_newSave()
{

var save = document.getElementById('sq_commit_button');

if (save != null)
{
save.onclick = new Function("uca_toggleDIV('grayload'); uca_grayOut(1);if (submit_form) {submit_form(this.form); } else { this.form.submit(); this.disabled = 'disabled'; }");
}

   
}

function uca_editPage() 
{
   this.location.href = currenturl+'/_edit?ignore_frames=1';
}


function uca_admin() 
{
   this.location.href = currenturl+'/_admin';
}

function uca_logout() 
{
   this.location.href = currenturl+'/?SQ_ACTION=logout';
}


function uca_deleteAsset(assetid, assetname, type) 
{
   if(confirm('Are you sure you want to delete '+assetname+'?')==true)
   {
        var url = this.location.href = this.location.href+'?a='+assetid+'&delete=yes';
        url2 = uca_replaceChars(url, '_edit', '');
        this.location.href = url2+'?a='+assetid+'&delete=yes';
        

if (type == 'page')
{
this.location.href = url2;
}
else
{
uca_refreshPage();
}
        
   }     
   
}

function uca_editFile(assetid)
{   
   url = rooturl+'/edit/_edit?limbo_assetid='+assetid+'&ignore_frames=1';
   editFileWindow = window.open(url, 'editFileWindow','resizable=yes,scrollbars=yes,height=600,width=750');
   
	if (this.focus) 
   {
     editFileWindow.focus();
   }   
}

function uca_refreshPage() 
{
   uca_grayOut(1);
   uca_toggleDIV('grayload');
   this.location.href = currenturl;

}

function uca_toggleDIV( whichLayer )
{
   var elem, vis;
   if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
   else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
   else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
   vis = elem.style;
   // if the style.display value is blank we try to figure it out here
   if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
   vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}




//############################################
// Common AJAX send function
//
// Parameters;
//	## URL
//	## Result Div Control
//############################################
function uca_axSend(url, result) 
{
	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange = function(){if(http_request.readyState==4){xhrHandler(http_request,result)}};
	http_request.open('GET', url, true);
	http_request.send(null);
}

function xhrHandler(xhr, resultid)
{
	var e = document.getElementById(resultid);
	if (e) {
		e.innerHTML = xhr.responseText;
	}
}

function ur_axAssetid(assetid, div)
{
  uca_axSend(rooturl+'/ax?a='+assetid,div);
}

function uca_grayOut(vis, options)
{
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis && dark.style.display != 'block') {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}



function uca_addLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

//uca_addLoadEvent(setTimeout("ur_randomResource()",10000));
//uca_addLoadEvent(setTimeout("uca_newSave()",3000));


//############################################
// Uniting Care Functions
//############################################  	

function uca_showvideo(url) {
document.getElementById('video').style.display = 'block';
document.getElementById('outervideo').style.display = 'block';
document.getElementById('videoimg').style.display = 'none';
document.getElementById('video').focus();

flashembed("video", 
	
		/* 
			first argument supplies standard Flash parameters. See full list:
			http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701
		*/
		{
			src:'http://www.withoutfearorfavour.org.au/__data/assets/file/0018/34047/FlowPlayerLight.swf',
			width: 640, 
			height: 388
		},
		
		/*
			second argument is Flowplayer specific configuration. See full list:
			http://flowplayer.org/player/configuration.html
		*/
		{config: {   
			autoPlay: true,
			autoBuffering: false,
			controlBarBackgroundColor:'0xB23427',
			initialScale: 'scale',
                        showFullScreenButton: false,
                        showMenu: false,
                        googleAnalyticsPrefix: 'flowplayer',
                        loop: false,
			videoFile: url
		}} 
	);

}

function uca_closevideo() {
document.getElementById('video').style.display = 'none';
document.getElementById('video').innerHTML = '';
document.getElementById('outervideo').style.display = 'none';
document.getElementById('videoimg').style.display = 'block';
}


