
// BROWSER SNIFFING FOR CSS USE ____________________________________________________
// Author: Rafael Lima (http://rafael.adm.br)

var css_browser_selector = function()
{
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=( !(/opera|webtv/i.test(ua)) && /msie (\d)/.test(ua) )? ('ie ie'+RegExp.$1):
			is('gecko/')? 'gecko':
				is('opera/9')? 'opera opera9':
					/opera (\d)/.test(ua)? 'opera opera'+RegExp.$1:
						is('konqueror')? 'konqueror':
							is('applewebkit/')? 'webkit safari':
								is('mozilla/')? 'gecko':'',
		os=( is('x11')||is('linux') )? ' linux':
			is('mac')? ' mac':
				is('win')? ' win':
					'';
	var c=b+os+' js';
	
	h.className += h.className?' '+c:c;
}();



function checkLogInForm() {

	errors = '';

	if (document.logInForm.username.value.length == 0 || document.logInForm.username.value=='Username')
		errors += '- Username\n';
	if (document.logInForm.password.value.length == 0 || document.logInForm.password.value=='Password')
		errors += '- Password\n';

	if (errors != '') {
		errors = 'Please complete the following:\n\n'+errors;
		window.alert(errors);
		return false;
	} else {
		return true;
	}

}

//

function checkImageUploadForm() {

	errors = '';
	
	return true;

}

//

function checkRegisterForm() {

	errors = '';

	if (document.registerForm.firstName.value.length == 0)
		errors += '- First Name\n';
	if (document.registerForm.lastName.value.length == 0)
		errors += '- Last Name\n';
	
	if (document.registerForm.username.value.length == 0)
		errors += '- Username\n';
	
	if (checkEmail(document.registerForm.email.value)==false)
		errors += '- Email Address\n';
		
	if (document.registerForm.confirmEmail.value != document.registerForm.email.value) {
		errors += '- Email Addresses did not match\n';
		document.registerForm.checkEmail.value = '';	
	} else if (document.registerForm.confirmEmail.value.length == 0)
		errors += '- Confirmation Email Address\n';

	if (document.registerForm.password.value.length < 6)
		errors += '- Password\n';

	if (document.registerForm.confirmPassword.value.length < 6 || document.registerForm.confirmPassword.value != document.registerForm.password.value)
		errors += '- Confirm Password\n';

	if (errors == '') {
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}

}

//

function checkProfileForm() {

	errors = '';

	if (checkEmail(document.profileForm.email.value)==false)
		errors += '- Email address\n';

	if (document.profileForm.password.value.length > 0 && (document.profileForm.password.value.length < 6 || document.profileForm.password.value.length > 30))
		errors += '- Password must be between 6 and 30 characters';
	else if (document.profileForm.password.value.length > 0 && document.profileForm.password.value != document.profileForm.confirmPassword.value)
		errors += '- Passwords do not match\n';

	if (errors=='') {
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}

}

//

function checkEmail(emailAddress) {
	
	var str = emailAddress;
	if ((str.indexOf(".") > 0) && (str.indexOf("@") > 0) == true) {
		return true;
	} else {
		//window.alert('Please enter a valid email address');
		return false;
	}
}

//

function checkCommentForm() {

	errors = '';
	
	if (document.commentForm.commentTitle.value.length == 0)
		errors += '- Comment Title\n';
	if (document.commentForm.commentText.value.length == 0)
		errors += '- Comment Text\n';
		
	if (errors == '') {
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}

}

//------------------------------------------------------------------------------

var noContent = '';
var liveReq = false;
var liveReqLast = '';
var liveReqDestination = '';

if (window.XMLHttpRequest) {
	liveReq = new XMLHttpRequest();
}

function loadContent(destination, uri) {
	
	liveReqDestination = destination;

	if (liveReqLast != liveReqDestination && liveReqDestination != '') {
	
		if (window.XMLHttpRequest) {
		} else if (window.ActiveXObject) {
			liveReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
	
		liveReq.onreadystatechange = liveReqProcessReqChange;
		liveReq.open('GET', uri);
		liveReq.send(null);

	}

}

function liveReqProcessReqChange() {

	if (liveReq.readyState == 4) {
		document.getElementById(liveReqDestination).innerHTML = liveReq.responseText;
	}
}


function openMediaPlayer() {

	winprops = 'height=434,width=310,scrollbars=no,resizable=no';
	mypage = webroot+'/player/?articleID='+articleID+'&section='+section+'&trackID='+trackID;
	myname = 'scriptPlayer';

	win = window.open(mypage, myname, winprops);
	win.focus();

}