var current_page=1;
var current_cat=0;
var current_img=0;

function getThumbs(cat, page, catname)
{	
	OpenCloseDiv('loadicon',1);
	var randomID =  Math.random(0, 1000) + "_" + Math.random(0, 1000);
	current_page=page;
	current_cat=cat;
	var newRequest = "json.loadThumbs.php?c=" + cat+ "&page="+ page +"&catname="+ escape(catname)+ "&guid=" + randomID;
	ajaxGet(newRequest);	
}

function getThumbsByPage(page)
{	
	OpenCloseDiv('loadicon',1);
	alert(page);
	current_page=page;
	var randomID =  Math.random(0, 1000) + "_" + Math.random(0, 1000);
	var newRequest = "json.loadThumbs.php?c=" + current_cat + "&page="+ page +"&guid=" + randomID + "&bypage=true";
	ajaxGet(newRequest);	
}

function getImageDetails(imgid)
{	
	OpenCloseDiv('loadicon',1);
	current_img= imgid;
	var randomID =  Math.random(0, 1000) + "_" + Math.random(0, 1000);
	var newRequest = "json.loadDetails.php?c=" + current_cat+ "&page="+ current_page + "&guid=" + randomID + "&imgid="+ imgid;
	ajaxGet(newRequest);	
}

function goToImage(imgid, page)
{
	if (page!=current_page)
	{ 
		getThumbsByPage(page);
	}//refresh thumbs, update current
	getImageDetails(imgid);
}

function FormError(message)
{
	updateDiv('formError', message);
}

function SelectDefaultGallery()
{
	//document.galleryCategory.gal_select_list.selectedIndex=1;
	//var catID= document.galleryCategory.default_id.value;
	//var catName= document.galleryCategory.default_name.value;
	//getThumbs(catID, 1, catName);
	//getImageDetails(1);
	document.galleryCategory.gal_select_list.selectedIndex=2;
	var catID= 999;
	var catName= "All Photos...";
	getThumbs(catID, 1, catName);
	getImageDetails(1);
}

function SelectDefaultGallery(id)
{
	//var selectedindex=document.galleryCategory.gal_select_list.selectedIndex;
	//var catID= document.galleryCategory.default_id.value;
	//var catName= document.galleryCategory.default_name.value;
	//getThumbs(catID, 1, catName);
	//getImageDetails(1);
	//var selectedindex=document.galleryCategory.gal_select_list.selectedIndex;
	document.galleryCategory.gal_select_list.selectedIndex=1;
	var catID= 999;
	var catName= "All Photos...";
	getThumbs(999, 1, catName);
	getImageDetails(1);
}

function validateProfileForm()
{
errormessage="";
email=document.form1.email.value;
password=document.form1.password.value;
password2=document.form1.password2.value;

if (email=="") errormessage=errormessage + "E-mail is required ! \n";
if (password=="") errormessage=errormessage + "Password is required ! \n";

if (password==password2)
{}
else
{
errormessage=errormessage + "Please re-type your password ! \n";
}


if (errormessage=="")
	{
	document.form1.submit();
	}
	else
	{
	FormError(errormessage);
	}
}
