var dom=GetId;

function GetId(Id){
	return document.getElementById(Id);
	}


function refreshBrowser() {
	actual_url = document.location.href;
	window.location = actual_url;
}

function getAbsoluteLeft(objectId) {
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            
	while(o.offsetParent!=null) {   
		oParent = o.offsetParent
		oLeft += oParent.offsetLeft
		o = oParent
	}
	
	return oLeft
}

function getAbsoluteTop(objectId) {
	o = document.getElementById(objectId)
	oTop = o.offsetTop            
	while(o.offsetParent!=null) { 
		oParent = o.offsetParent
		oTop += oParent.offsetTop
		o = oParent
	}

	return oTop
}

function posicionar(objectId,parentTabId,paramLeft,top){//adaptar
oDrop=document.getElementById(objectId);
oDrop.style.left=getAbsoluteLeft(parentTabId) + paramLeft + 'px';
oDrop.style.top=getAbsoluteTop(parentTabId) -top+ 'px';
}

/* ACTUALIZAMOS FUNCIONES DE USUARIOS PARA EL ENGINE DE IMAGENES */ 


function trySignIn(frmId){
	goAJAX(frmId,'engines/users/users.ajax.php','controller=trySignIn&frmId='+ frmId + '&' + akiSfrm(frmId), 'refreshBrowser()');
	return false;
}


/* FIN */

function showImage(actual, id_img, id_gal, caption, width) {
	//alert(id);
	image = GetId('image_show');
	image.innerHTML = '<img src="../imgs/images_engine/'+id_gal+'/'+id_img+'_med.jpg" width="'+width+'" hspace="4" border="0" align="absmiddle" /><br><p class="caption">'+caption+'</p>';
	campo = GetId('actual');
	campo.value = actual;
}

function nextImage(id_gal, width) {
	if (parseInt(GetId('actual').value)<(images.length-1)) {
		
		GetId('actual').value = parseInt(GetId('actual').value)+1;
		
		id_img = GetId('actual').value;
		
		image = GetId('image_show');	
		image.innerHTML = '<img src="../imgs/images_engine/'+id_gal+'/'+images[id_img]+'_med.jpg" width="'+width+'" hspace="4" border="0" align="absmiddle" /><br><p class="caption">'+caption[id_img]+'</p>';
	}
	
}

function prevImage(id_gal, width) {
	if (parseInt(GetId('actual').value)>0) {
		
		GetId('actual').value = parseInt(GetId('actual').value)-1;
		
		id_img = GetId('actual').value;

		image = GetId('image_show');		
		image.innerHTML = '<img src="../imgs/images_engine/'+id_gal+'/'+images[id_img]+'_med.jpg" width="'+width+'" hspace="4" border="0" align="absmiddle" /><br><p class="caption">'+caption[id_img]+'</p>';
	}
}

function displaySort() {
	divSort = GetId('sort');
	if (divSort.style.display=="none") {		
		divSort.style.display="";
		if(navigator.appName == "Microsoft Internet Explorer") {
			posicionar('sort','userMenu', 295, 8);
		}
	} else {
		divSort.style.display="none";
	}
}

function IEdisplayCategories() {
	divCategories = GetId('ie_categories');
	if (divCategories.style.display=="none") {		
		divCategories.style.display="";	
		if(navigator.appName == "Microsoft Internet Explorer") {
			posicionar('ie_categories','userMenu', 295, 8);
		}
	} else {
		divCategories.style.display="none";
	}
}

function displaySearch() {
	divSearch = GetId('search');
	if (divSearch.style.display=="none") {		
		divSearch.style.display="";
		if(navigator.appName == "Microsoft Internet Explorer") {
			posicionar('search','userMenu', 295, 8);
		}
	} else {
		divSearch.style.display="none";
	}
}

function displayGalleryTools() {
	divSearch = GetId('galleryTools');
	if (divSearch.style.display=="none") {		
		divSearch.style.display="";
		if(navigator.appName == "Microsoft Internet Explorer") {
			posicionar('galleryTools','galMenu', 298, -21);
		}
	} else {
		divSearch.style.display="none";
	}
}

function IE_displayUserMenu() {
	divSort = GetId('IE_UserMenu');
	if (divSort.style.display=="none") {		
		divSort.style.display="";
		if(navigator.appName == "Microsoft Internet Explorer") {
			posicionar('IE_UserMenu','userMenu', 368, 8);
		}
	} else {
		divSort.style.display="none";
	}
}

function navigateCategories(catId) {
	window.location = "imagesGalleries.php?category="+catId;
}

function navigateSort(type) {
	window.location = "imagesGalleries.php?sort="+type;
}

function navigateSearch() {
	SearchKey = GetId('gal_name').value;
	if (GetId('categorySearch').value != 0) {
		SearchCat = "&categorySearch="+GetId('categorySearch').value;
	} else {
		SearchCat = "";
	}
	window.location = "imagesGalleries.php?action=search&searchkey="+SearchKey+SearchCat;
}



function showRate(gal_id) {
	displayGalleryTools();

	putIn('winTit250','Rate this gallery')
	showWindow('win250');	
	goAJAX('winCont250','engines/images_engine/ajax/rate.php','gal_id='+gal_id, 'centerDivWindow(\'win250\');');
	return false;
}

function showAddFavorite(user_id, gal_id) {
	displayGalleryTools();
	if (user_id != "XX") {
		goAJAX('winCont250', 'engines/images_engine/ajax/favoriteAdd.php', 'user_id='+user_id+'&gal_id='+gal_id+'&photo_id='+images[0]);
		alert("This gallery has been added to your favorites.");
	} else {
		alert("You must sing in first.");
	}
}

function deleteFavorite(id) {
	goAJAX('winCont250', 'engines/images_engine/ajax/favoriteAdd.php', 'favorite_id='+id);
	alert("This gallery has been deleted to your favorites.");
	actual_url = document.location.href;
	window.location = actual_url;
}

function showEmailPhoto(gal_id) {
	displayGalleryTools();
	id_img = GetId('actual').value;
	
	putIn('winTit400','Email this Gallery')
	showWindow('win400');	
	goAJAX('winCont400','engines/images_engine/ajax/emailPhoto.php','gal_id='+gal_id+'&photo_id='+images[0], 'centerDivWindow(\'win400\');');
	return false;
}

function showEmailUser(id_usr) {
	displayGalleryTools();
	id_img = GetId('actual').value;
	
	putIn('winTit350','Email to this User')
	showWindow('win350');	
	goAJAX('winCont350','engines/images_engine/ajax/emailUser.php','id_usr='+id_usr, 'centerDivWindow(\'win350\');');
	return false;
}

function rateIt(gal_id) {
	goAJAX('winCont250', 'engines/images_engine/ajax/rate.php', 'rate='+GetId('rating_value').value+'&gal_id='+gal_id);
}

function emailPhoto() {
	gal_id = GetId('gal_id').value;
	photo_id = GetId('photo_id').value;
	to = GetId('to').value;
	email = GetId('email').value;
	name = GetId('name').value;
	comment = GetId('comment').value;
	goAJAX('winCont400', 'engines/images_engine/ajax/emailPhoto.php', 'gal_id='+gal_id+'&photo_id='+photo_id+'&to='+to+'&email='+email+'&name='+name+'&comment='+comment);
}

function navigateSameUser(user_id) {
	window.location = "imagesGalleries.php?usr_id="+user_id;
}

function navigateMyGalleries(user_id) {
	window.location = "/imagesGalleries.php?usr_id="+user_id+"&my=true";
}

function emailUser() {
	id_usr = GetId('id_usr').value;
	email = GetId('email').value;
	name = GetId('name').value;
	subject = GetId('subject').value;
	message = GetId('message').value;
	goAJAX('winCont350', 'engines/images_engine/ajax/emailUser.php', 'id_usr='+id_usr+'email='+email+'&name='+name+'&subject='+subject+'&message='+message);
}

function navigateMyFavorites(user_id) {
	window.location = "imagesGalleries.php?action=favorites&usr_id="+user_id;
}

function navigateAddGallery() {
	window.location = "imagesGalleries.php?action=addGallery";
}

function navigateEditGallery(id) {
	window.location = "imagesGalleries.php?action=editGallery&id_gallery="+id;
}

function navigateViewPhotos(id) {
	window.location = "imagesGalleries.php?action=viewPhotos&gal_id="+id;
}

function navigateDeleteGallery(id) {
	si = confirm("Are you sure?");
	if (si == true) {
		goAJAX('', 'engines/images_engine/ajax/deleteGallery.php', 'id_gallery='+id, 'refreshBrowser()', '', '0', '0');
	}
	

}

function addGallery(id_usr) {
	if (GetId('name').value != "") {
	name = GetId('name').value;
	category = GetId('category').value;
	goAJAX('addResult', 'engines/images_engine/ajax/addGallery.php', 'name='+name+'&category='+category+'&id_usr='+id_usr);
	GetId('name').value = "";
	GetId('addResult').style.display="";
	} else {
		alert("Complete all fields.");
	}
	
}

function editGallery(id_usr) {
	name = GetId('name_frm').value;
	category = GetId('category_frm').value;
	gal_id = GetId('gal_id_frm').value;
	goAJAX('addResult', 'engines/images_engine/ajax/editGallery.php', 'name='+name+'&category='+category+'&gal_id='+gal_id+'&id_usr='+id_usr);
	GetId('addResult').style.display="";
}

function showUploadPhotos(gal_id) {
	putIn('winTit500','Upload Photos')
	showWindow('win500');	
	goAJAX('winCont500','engines/images_engine/ajax/uploadPhotos.php', 'gal_id='+gal_id, 'centerDivWindow(\'win500\');');
	return false;
}

function savePhotoInfo(id) {
	order = GetId('order'+id).value;
	caption = GetId('caption'+id).value;
	goAJAX('result'+id, 'engines/images_engine/ajax/editPhoto.php', 'order='+order+'&caption='+caption+'&photo_id='+id, 'refreshBrowser()');
}

function deletePhotoInfo(id) {
	goAJAX('result'+id, 'engines/images_engine/ajax/deletePhoto.php', 'photo_id='+id, 'getId(\'showPhoto_'+id+'\').style.display = \'none\';');
}

function closeWindow(divWindow){
	GetId(divWindow).style.display='none';
	refreshBrowser();
	return false;
}

