// JavaScript Document

function expand(e){

	/*
	function:	expand
	purpose:	to change the visible style of the div id(e) to the opposite of what it currently is
	*/

	var el
	
	el = document.getElementById(e);
	
	//if(!el){alert('There was an error with expand(e);');return false;}
	
	if(!el){return false;}
		
	if(el.style.display=='none'){
		el.style.width = 'auto';
		el.style.height = 'auto';
		el.style.display = 'inline';
	} else {
		el.style.width = '0px';
		el.style.height = '0px';
		el.style.display = 'none';
	}
	
}

function boolExpand(e,blExpand){
	// same as abobe but with a definate expand / collapse action based on a boolean argument
	var el
	el = document.getElementById(e);
	if(!el){return false;}
	if(blExpand==true){
		/*for(i=0;i<1000;i++){  // sort out some animation!!!
			el.style.width = i + 'px';
			el.style.height = i + 'px';
		}*/
		el.style.width = 'auto';
		el.style.height = 'auto';
		el.style.display = 'inline';	
	} else {
		el.style.width = '0px';
		el.style.height = '0px';
		el.style.display = 'none';
	}
}

function wipe(m){
	/* 	function:	wipe
		purpose:	puts message in status bar, used to cover confusing urls */
	window.status = m;
}
	
function isNumeric(strX){
	//Emulates the vbscript isNumeric() function
	//returns TRUE if strX is a number
	
	var ValidChars = "0123456789.";
	var Char, blResult;
	
	blResult = true;
	
	for (i = 0; i < strX.length; i++) {
		Char = strX.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			blResult = false;
		}
	}
	return blResult;
}

function zerofy(strIn, intLen){
	/*
		functions:		zerofy
		purpose:		makes a string longer by adding 0's to the front of it
		arguments:		strIn:	string:		the string to play around with
						intLen:	integer:	the length to make it
		returns:		strIn with a bunch of zeros on the front
		created:		15/10/05
	*/
	
	if(!isNumeric(intLen)){return false;}	
	while(strIn.length<intLen){strIn = '0' + strIn + '';}
	return strIn;
	
}


	
function eStyle(e,strStyle,strValue,getOrSet){

	var el
	
	el = document.getElementById(e);
	
	if(el!=null){
		var sty, value
		sty = camelCase(strStyle)
		
		if(getOrSet=="get"){
			value = el.style[sty]
			return value
		}else{
			el.style[sty] = strValue;
		}
	}

}
	
function camelCase(strInput,strSplit) {
	/** camelCase(strInput)
	 * Converts string input to a camel cased version of itself.
	 * For example:
	 * camelCase("z-index","-"); // returns zIndex
	 * camelCase("border bottom style", " "); // returns borderBottomStyle.
	 */

    var oStringList = strInput.split(strSplit);
    if(oStringList.length == 1)    
        return oStringList[0];
    var ret = strInput.indexOf(strSplit) == 0 ? 
    	oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}

function resource(strType, strNumber){

	strNumber = '' + strNumber + "";
	
	while(strNumber.length < 3){
		strNumber = '0' + strNumber;
	}
		
	//var strPath = "assets/_" + strType + "s/" + strNumber + ".pdf";
	
	var strPath = "assets/pdf/" + strNumber + ".pdf";
	
	window.location = strPath;
	
}

function expand_user(e){

	/*
	function:	expand_user
	purpose:	expand/collapse the user pane in the admin section
	*/

	var el
	
	el = document.getElementById(String(e) + '_details');
	
	elParent = document.getElementById(String(e));
	
	//if(!el){alert('There was an error with expand(e);');return false;}
	
	if(!el){return false;}
		
	if(el.style.display=='none'){
		el.style.width = 'auto';
		el.style.height = 'auto';
		el.style.display = 'inline';
	} else {
		el.style.width = '0px';
		el.style.height = '0px';
		el.style.display = 'none';
	}
	
	elParent.style.height = 'auto';
	
}
