// JavaScript Document
var errorElement = '.x-err-msg';
Ext.BLANK_IMAGE_URL = '/common/images/s.gif';

function goto(page)
{
	window.location.href=page;
}

function hideError()
{
	$(errorElement).slideUp('fast');
}

function showError()
{	
	$(errorElement).slideDown('fast');
	setTimeout('hideError()',5000);
}

function login()
{
	var f = document.loginForm;
	var auth = false;
	
	if(f.logon.value=="")
	{
		showError();
		return false;
	}
	if(f.password.value=="")
	{
		showError();
		return false;
	}
	
	Ext.Ajax.request({
		 url: '/common/cfx/member.login.cfm',
		 method: 'POST',
		 form: 'loginForm',
		 success: function(r)
		 {
			 var result = eval('(' + r.responseText + ')');
			 if(result.status)
			 {
				 window.location.href='/personal';
			 }
			 else
			 {
				 showError();
				 return;
			 }
		 }
	});
	
}


function CountSelectedItems(oForm,oField)
{
	var f = document.forms[oForm];
	var count = 0;
	for(i = 0; i < f.elements.length; i++)
	{
		if( (f.elements[i].type=="checkbox") && (f.elements[i].name==oField) )
		{
			if(f.elements[i].checked==true)
			{
				count++;
			}
		}
	}
	return count;
}


function AddItem(oForm)
{
	var f = document.forms[oForm];
	// reset list
	var newList = "";
	for(i = 0; i < f.elements.length; i++)
	{
		if( (f.elements[i].type=="checkbox") && (f.elements[i].name=="id") )
		{
			if(f.elements[i].checked==true)
			{
				newList += f.elements[i].value + ",";
			}
		}		
	}
	if(newList.length > 0)
	{
		newList = newList.substring(0,newList.length-1);
	}
	
	f.items.value =  newList;	
}


function checkAll(oForm)
{
	var f = document.forms[oForm];
	var itemList = "";
	for(i = 0; i < f.elements.length; i++)
	{
		if( (f.elements[i].type=="checkbox") && (f.elements[i].name=="id") )
		{
			f.elements[i].checked=true;
			itemList += f.elements[i].value + ",";
		}
	}
	
	if(itemList.length > 0)
	{
		itemList = itemList.substring(0,itemList.length-1);
	}
	
	f.items.value=itemList;
	
}

function uncheckAll(oForm)
{
	var f = document.forms[oForm];
	for(i = 0; i < f.elements.length; i++)
	{
		if( (f.elements[i].type=="checkbox") && (f.elements[i].name=="id") )
		{
			f.elements[i].checked=false;
		}
	}
}


var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable,status=1';
	win = window.open(mypage,myname,settings);
	if(window.focus)
	{
		win.focus();
	}
}


function toggle(elem)
{
	var el;
	switch(elem)
	{
		case "folder":
			el = "#px-folder";
			break;
		case "gallery":
			el = "#px-gallery";
			break;
	}
	
	if( $(el).css("display") == "none" ? $(el).slideDown("fast") : $(el).slideUp("fast") );
}

function clearForm(form)
{
	document.forms[form].reset();
}



