function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld == "") {
        error = "You didn't enter a username.";
    } else if ((fld.length < 5) || (fld.length > 15)) {
        error = "The username is the wrong length.";
    } else if (illegalChars.test(fld)) {
        error = "The username contains illegal characters.";
    } else {
    }
    return error;
}

function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld == "") {
        error = "You didn't enter a password.\n";
    } else if ((fld.length < 4) || (fld.length > 15)) {
        error = "The password is the wrong length. \n";
    } else if (illegalChars.test(fld)) {
        error = "The password contains illegal characters.\n";
    } else if (!((fld.search(/(a-z)+/)) && (fld.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
    } else {
    }
   return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld);                        // value of field with whitespace trimmed off
    var emailFilter = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-z]{2,7}$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld == "") {
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        error = "Please enter a valid email address.\n";
    } else if (fld.match(illegalChars)) {
        error = "The email address contains illegal characters.\n";
    } else {
    }
    return error;
}

function inappr_wrap_close() {
	$('.inappr-wrap').hide();
	$('.flag-wrap').show();
}



//rotating thumb functions
var changing_thumbs = new Array();
function changeThumb(index, i, pict1, pict2, pict3)
{
	var count = 0;
	if(pict1 != '') count++;
	if(pict2 != '') count++;
	if(pict3 != '') count++;
	if (changing_thumbs[index])
	{
		if(i == 1) document.getElementById(index).src = '/video/thumbs/' + pict1;
		if(i == 2) document.getElementById(index).src = '/video/thumbs/' + pict2;
		if(i == 3) document.getElementById(index).src = '/video/thumbs/' + pict3;

		i++;
		if(i > count) i = 1;
		changing_thumbs[index] = setTimeout("changeThumb('" + index + "'," + i + ", '" + pict1 + "', '" + pict2 + "', '" + pict3 + "')", 600);
	}
}



function changePics(index, pict1, pict2, pict3)
{

	changing_thumbs[index] = true;
	changeThumb(index, 1, pict1, pict2, pict3);
}



function unchangePics(index, pict1)
{
	clearTimeout(changing_thumbs[index]);
	document.getElementById(index).src = '/video/thumbs/' + pict1;
}
