// CHATLOG
function updateMessage(message, name, acceptable) {
	if (message.value.length > 255) {
		message.value = message.value.substring(0, 256);
	} else if (message.value.length > 0 && name.value.length > 0) {
		acceptable.innerHTML = 'ACCEPTABLE';
		acceptable.className = 'green';
	} else if (message.value.length == 0 || name.value.length == 0) {
		acceptable.innerHTML = 'UNACCEPTABLE';
		acceptable.className = 'red';
	}
}


// CLOCK
function init ( )
{
 timeDisplay = document.createTextNode ( "" );
 document.getElementById("clock").appendChild ( timeDisplay );
}

function updateClock ( ) {
var time = new Date ( );
var currentHours = time.getHours ( );
var currentMinutes = time.getMinutes ( );
var currentSeconds = time.getSeconds ( );
currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
currentHours = ( currentHours == 0 ) ? 12 : currentHours;
var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}

// FADE IN - TOP FUNCTION
function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
function shiftOpacity(id, millisec) {
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 



function contactMe() {
	document.getElementById('bg_h').style.visibility='visible';
	opacity('bg_h', 0, 70, 1500);
	
	document.getElementById('cm_div').style.visibility='visible';
	var x = setTimeout('opacity("cm_div", 0, 100, 1500)', 1500);
}

function contactMeClose() {
	opacity("cm_div", 100, 0, 1500);
	var x = setTimeout("document.getElementById('cm_div').style.visibility='hidden';", 1500);
	
	var y = setTimeout('opacity("bg_h", 70, 0, 1500)', 1500);
	setTimeout("document.getElementById('bg_h').style.visibility='hidden';", 3000);
}

function autoloadImages() {
	barImageOne = new Image(); barImageOne.src = 'http://sonorinato.com/static/images/icons3/ally.png';
	barImageTwo = new Image(); barImageTwo.src = 'http://sonorinato.com/static/images/icons3/work.png';
	barImageThree = new Image(); barImageThree.src = 'http://sonorinato.com/static/images/icons3/home.png';
	barImageFour = new Image(); barImageFour.src = 'http://sonorinato.com/static/images/icons3/chat.png';
}