// JavaScript Document
var gl_request = {}

function validate(type)	{
	switch (type)	{
		case 'login':
			if (document.getElementById('username').value == '')	{
				alert('Username required.'); return false;
			}
			if (document.getElementById('password').value == '')	{
				alert('Password required.'); return false;
			}
			break;
		case 'user': return validate('login'); break;
		case 'sample':
			if (document.getElementById('sample_name').value == '')	{
				alert('Sample name required.'); return false;
			}
			if (document.getElementById('sample_description').value == '')	{
				alert('Sample description required.'); return false;
			}
			break;
		case 'upload':
			if (document.getElementById('upload_name').value == '')	{
				alert('Upload name required.'); return false;
			}
			if (document.getElementById('upload_description').value == '')	{
				alert('Upload description required.'); return false;
			}
			if (document.getElementById('upload_file').value == '')	{
				alert('Upload file required.'); return false;
			}
			break;
	}
	return true;
}
function updateSampleNav(type) {
	var t = ['site', 'code', 'fla'];
	for (var x in t)	{
		var nav = document.getElementById('sample_nav_'+t[x]);
		if (t[x] == type) { 
			nav.className = 'sample_nav_btn sample_nav_btn_down'; 
			nav.onmouseout = null;
			nav.onmouseover = null;
		}
		else { 
			nav.className = 'sample_nav_btn'; 
			nav.onmouseout = 'this.className=\'sample_nav_btn\';';
			nav.onmouseover = 'this.className+=\' sample_nav_btn_over\';';	
		}		
	}
	gl_request.callback = 'update_target';
	gl_request.target = 'sample_win';
	sendRequest('?goto=samples&async&sub='+type, '', 'GET');
}
function getContent(type, ref) {
	gl_request.callback = 'update_target';
	gl_request.target = 'sample_win';
	sendRequest('?goto=samples&async&sub='+type+'&ref='+ref, '', 'GET');	
}
function imagePreview(path)	{
	if (!get('preview_win'))	{
		var win = create('div');
		win.id ='preview_win';
		win.height = '175';
		win.width = '150';
		win.className = 'preview_win';
		//i.setAttribute('style', 'position:absolute; top:255px; left:15px; background-color:#CCCCCC');		
		document.body.appendChild(win); 	
		var img = create('img');
		img.id = 'preview_img';
		img.width = 200;
		img.height = 170;
		img.border = 0;
		win.appendChild(img);	
	}	
	get('preview_win').style.display = '';
	get('preview_img').src = path;
}
function hideImagePreview()	{
	get('preview_win').style.display = 'none';
	get('preview_img').src = '';
}
function fixMenuHeight()	{
	var h = getElementHeight('content_win');
	get('content_nav').setAttribute('style', 'height:'+h+'px');
}
