// JavaScript Document
function check_chars(msg,counter,maxchars) { 
	var str = document.getElementById(msg).value;
	
	if (str.length > maxchars) {
		document.getElementById(msg).value = str.substring(0,maxchars);
	} else {		
		document.getElementById(counter).innerHTML = maxchars - document.getElementById(msg).value.length + " characters remaining.";
		//document.getElementById("counter").value = maxchars - document.getElementById("msg").value.length;
	}
}

	//function trim(txt) {		
	//	tmp = (txt.replace(/^\W+/,'')).replace(/\W+$/,'');
	//	return tmp;
	//}
	function trim(str) {
        return str.replace(/^\s+|\s+$/g,"");
    }
	
	function validate_reg_form(rf) {
		var fullname = trim(rf.fullname.value);
		var email = trim(rf.email.value);
		var mail_valid = document.getElementById("v_mail").innerHTML;
		var pwd = rf.pwd.value;
		var cpwd = rf.cpwd.value;
			
		if (fullname.length == 0) {
			alert("Please enter your fullname.");
		} else if (email.length == 0) {
			alert("Please enter your e-mail address.");
		} else if (mail_valid.length > 1) {
			alert("Please enter a valid e-mail address.");
		} else if ((pwd.length == 0) || (cpwd.length ==0)) {
			alert("Please enter your desired password and confirm it.");
		} else if (pwd != cpwd) {
			alert("You confirmation password does not match your password.");
		} else {			
			return true;
		}
		return false;
	}
	
	function validate_contact_form()
	{
		var name = trim(window.document.contact_form.name.value);
		var email = trim(window.document.contact_form.email.value);
		var msg = trim(window.document.contact_form.msg.value);	
		var vmail = document.getElementById("v_mail").innerHTML;
		
		if (email.length == 0) {
			alert("Plese enter your e-mail address.");
		}else if (vmail.length > 1) {
			alert("Please enter a valid e-mail address.");
		} else if (name.length == 0) {
			alert("Please enter your name.");			
		} else if (msg.length == 0) {
			alert("Please type a message on the message text box.");		
		} else {
			return true;
		} 
		return false;
	}
	
	

function showPic(mypic)
{
	document.getElementById("bigpic").src = "images/gallery/" + mypic.id;
	
}


//main fader object ====================================

function fader(id) {
	this.mouseout = false;
	this.id = id;
	this.step = 0;
	this.inout = 0;
	this.timer = 0;

	var me = this;
	function loopMethod() {
		me.fade_it();
	}
	
	this.show = function () 
	{
		this.mouseout = false;
		this.step = 5;
		this.inout = 1;
		clearInterval(this.timer);
		this.timer = setInterval(loopMethod, 20);
	}

	this.hide = function () 
	{
		this.mouseout = true;
		this.step = -5;
		this.inout = 0;
		clearInterval(this.timer);
		this.timer = setInterval(loopMethod, 20);
	}

	this.fade_it = function ()
		{
			
			var tmp = document.getElementById(this.id);
			var op = 0;
			if (document.all) {
				//ie		
				if (tmp.filters[0].opacity != null) op = tmp.filters[0].opacity;			
			} else {
				//firefox		
				op = tmp.style.opacity * 100;
			}
			
			if (!this.mouseout) tmp.style.display = "block";
			
			if (this.inout == 1) {
				if ((op < 100) && (!this.mouseout)) {
					op += this.step;
					tmp.style.opacity = op / 100;
					tmp.style.filter = "alpha(opacity=" + op + ")";
				}
				if (op >= 100) clearInterval(this.timer);
			}
			else {
				if ((op > 1) && (this.mouseout)) {
					op += this.step;
					tmp.style.opacity = op / 100;
					tmp.style.filter = "alpha(opacity=" + op + ")";
				}
				if (op < 2 && this.mouseout)  {
					tmp.style.display = "none";
					clearInterval(this.timer);
				}
			}
		}
		
}

var fade1 = new fader("promos");
var fade2 = new fader("about");
var fade3 = new fader("pro_menu");
