function dexGetURLParameter(name, url) {

	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( url );

	if(results == null) {
		return "";
	} else {
		return results[1];
	}

} // end function



function dexRedirectAlbum(album_id) {

	window.location = "http://" + location.hostname + "/gallery/album/" + album_id;
	return false;

} // end function



function dexRefreshScreen() {

	window.location.reload();
	return false;

} // end function



function dexDeleteImage(div_id) {

	var answer = confirm ("Dzēst bildi?");
	if (!answer) { return; }

	document.getElementById(div_id).style.display = "none";

 	with (new dexAjax()) {

 		url = "http://" + location.hostname + "/modules/gallery/functions.php";
 		params = "ma=deleteimage&id="+div_id;
 		doRequest();

	} // end with

} // end function



function dexDeleteAlbum(div_id) {

	var answer = confirm ("Dzēst albumu un visas bildes tajā?");
	if (!answer) { return; }


	document.getElementById(div_id).style.display = "none";

	with (new dexAjax()) {

		url = "http://" + location.hostname + "/modules/gallery/functions.php";
		params = "ma=deletealbum&id="+div_id;
		doRequest();
	}

} // end function



function dexChangeGalleryType(form) {

	var val_type = form.gallery_type.options[form.gallery_type.options.selectedIndex].value;
	//alert(val_type);

	var type_gallery_div = document.getElementById('gallery');
	var type_users_div = document.getElementById('users');
	var step3_div = document.getElementById('step3');

	var type_active_div = document.getElementById(val_type);

	type_gallery_div.style.display = 'none';
	type_users_div.style.display = 'none';
	step3_div.style.display = 'none';

	if(type_active_div) {
		type_active_div.style.display = 'block';
	}

} // end function



function dexShowStep3(form) {

	var album_id = form.album.options[form.album.options.selectedIndex].value;
	var step3 = document.getElementById('step3');
	step3.style.display = 'block';

	var upload_link = document.getElementById('upload_link');
	upload_link.href="http://" + location.hostname + "/modules/gallery/tools/swfupload/image_uploader.php?id=" + album_id +"&keepThis=false&TB_iframe=true&height=500&width=800";
	//document.getElementById('upload_link').onclick = "dexRedirectAlbum(" + album_id + ");";

	upload_link.onclick = function() {
		};

} // end function



function dexShowGallerySelect(form) {

	var album_id = form.album.options[form.album.options.selectedIndex].value;
	var gallery_select_div = document.getElementById('gallery_select');
	var album_type_input = document.getElementById('album_type');
	
	
	if(gallery_select_div.style.display == 'none') {

		gallery_select_div.style.display = 'block';
		album_type_input.value = 'gallery';


	} else {

		gallery_select_div.style.display = 'none';
		album_type_input.value = 'user';

	}

} // end function



function dexReload(form) {

	var val_type = form.gallery_type.options[form.gallery_type.options.selectedIndex].value;
	var val_gallery = form.gallery_id.options[form.gallery_id.options.selectedIndex].value;
	var val_album = form.album_id.options[form.album_id.options.selectedIndex].value;

	self.location='?type=' + val;

} // end function
