function MM_preloadImages() { //v3.0
	
	var d=document;
	
	if(d.images){
		if(!d.MM_p){
			d.MM_p=new Array();
		
		
			var i
			var j=d.MM_p.length
			var 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
	var	x
	var 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.0
	var p
	var i
	var 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 && document.getElementById)
    	x=document.getElementById(n);
    	
    return x;
}

function MM_swapImage() { //v3.0
	var i
	var j=0
	var x
	var 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 MyOfficeHoursSubmit( step, day, index )
{
	if( step == "delOH" ){
		if( confirm( "Are you sure you want to delete this office hour?" ) ){
			document.forms[0].action.value = step
			document.forms[0].addOHDay.value = day
			document.forms[0].editOHID.value = index
			document.forms[0].submit()
		}
	}else{
		document.forms[0].action.value = step
		document.forms[0].addOHDay.value = day
		document.forms[0].editOHID.value = index
		document.forms[0].submit()
	}
		
	return true;
}

function MyAdminSelectAllPeople( selectType, select )
{
	for( i=0; i<document.forms[0].elements.length; i++ ){
		if( document.forms[0].elements[ i ].type == "checkbox" ){
			value = document.forms[0].elements[ i ].value
			offset = value.indexOf( "t" ) + 1
			personType = value.charAt( offset )
			if( personType == selectType ){
				if( select == 1 ){
					document.forms[0].elements[ i ].checked = true
				}else{
					document.forms[0].elements[ i ].checked = false
				}
			}
		}
		
	}
}

function MyAdminAddPerson( type )
{
	document.forms[0].action.value = "addPerson"
	document.forms[0].step.value = "edit"
	document.forms[0].type.value = type
	document.forms[0].submit()
}

function MyAdminNewPassword( type )
{
	var alphabet = "abcdefghjkmnpqrstuvwxyz23456789";
	var length = alphabet.length;
	var password = "", letter = "", i, index, randomNum
	
	for( i=0; i<8; i++ ){
		index = Math.random() * length;
		letter = alphabet.charAt( index )
		randomNum = Math.round( Math.random() )
		if(  randomNum == 0 ){
			letter = letter.toUpperCase()
		}
		password += letter
	}
	document.forms[0].pwd.value = password
	document.forms[0].pwd.focus()
}




function StartTimer()
{
	running = true
	now = new Date()
	now = now.getTime()
	endTime = now + (1000 * 60)
	ShowCountDown()
}

function ShowCountDown()
{
	var now = new Date()
	now = now.getTime()
	if( endTime - now <= 0 ){
		Redirect()
	}else{
		var delta = new Date( endTime - now )
		var theMin = delta.getMinutes()
		var theSec = delta.getSeconds()
		var theTime = theMin
		theTime += ((theSec < 10) ? ":0" : ":" ) + theSec
		document.forms[ 0 ].timerDisplay.value = theTime
		if( running ){
			timerID = setTimeout( "ShowCountDown()", 1000 )
		}
	}
}


function Redirect()
{
	clearTimeout( timerID )
	running = false
	document.forms[ 0 ].timerDisplay.value = "0:00"
	if( document.forms[0].refer.checked ){
		pageURL += "&showRefer=1"
	}
	location = pageURL
}

function fix(num, dec) {
	
	var number = num
	if( number.toFixed ){
		alert( number.toFixed(dec) )
		return number.toFixed(dec)
	}else{
		var numStr = num.toString()
		var decPointPassed = false
		var endStr=""
		for (var i = 0; i < numStr.length; i++) {
			var oneChar = numStr.charAt(i)
			if ((oneChar==".")&&(i==0)) {
				endStr += 0
			}
			if (oneChar == ".") {
				var decPlaces = 0
				decPointPassed = true
			}
			if (decPointPassed) {
				decPlaces++
			}
			if (decPlaces>dec) {
				if(numStr.charAt(i+1)>=5) {
					oneChar=parseFloat(oneChar)
					oneChar+=1
				}else{
					oneChar=oneChar
				}
				endStr+=oneChar
				break
			}
			endStr += oneChar
		}
		return endStr
	}
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}



function doOrderPurposeMenuSelection( prodIndex ) {

	form = document.orderForm;

	menuName = "prodType" + prodIndex;
	
	for( i=0; i<form.elements.length; i++ ){
		if( form.elements[ i ].name == menuName ){
			typeText = form.elements[ i ].options[ form.elements[ i ].selectedIndex ].text;
			if( typeText == "----------" ){
				for( j=0; j<form.elements[ i ].length; j++ ){
					if( form.elements[ i ].options[ j ].text == "Please choose..." ){
						form.elements[ i ].options[ j ].selected = true;
						break;
					}
				}
			}
		}
	}
}


function copyName() {
	if( document.orderForm.piClaim.checked == true /*&& document.orderForm.name.value != ""*/ ){
		document.orderForm.piName.value = document.orderForm.name.value;
		document.orderForm.piName.value = document.orderForm.name.value;
		document.orderForm.piName.value = document.orderForm.name.value;
	}
	if( document.orderForm.piClaim.checked == true /*&& document.orderForm.email.value != ""*/ ){
		document.orderForm.piEmail.value = document.orderForm.email.value;
		document.orderForm.piEmail.value = document.orderForm.email.value;
		document.orderForm.piEmail.value = document.orderForm.email.value;
	}
}

function startList() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("navmenu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
				node.onclick=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
	
