var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;
function change_lang(languange){
	document.main_form.lang.value=languange;
	document.main_form.submit();
	return;
	
}
function changeContent(id,shtml) {
   if (document.getElementById || document.all) {
      var el = document.getElementById? document.getElementById(id): document.all[id];
      if (el && typeof el.innerHTML != "undefined") el.innerHTML = shtml;
   }
}

function modify_photo(photo_id, back_page){
	if (document.main_form.admin_page)
		document.main_form.admin_page.value="upload";
	//document.main_form.back_url.value=back_page;
	//document.main_form.
	document.main_form.photo_id.value=photo_id;
	document.main_form.submit();
	return;
}
function animate(){
	var elem = document.getElementById('progress');
	if(elem != null) {
		if (pos==0) len += dir;
		if (len>32 || pos>79) pos += dir;
		if (pos>79) len -= dir;
		if (pos>79 && len==0) pos=0;
		elem.style.left = pos;
		elem.style.width = len;
	}
}
function remove_loading() {
	this.clearInterval(t_id);
	var targelem = document.getElementById('loader_container');
	//targelem.style.display='none';
	targelem.style.visibility='hidden';
}
function add_loading() {
	this.setInterval(animate,20);
	var targelem = document.getElementById('loader_container');
	//targelem.style.display='true';
	targelem.style.visibility='visible';
}
function handlePoint (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		if (field.name == "password")
			document.part.submit();
		else{
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		}
	} 
	else
		return true;
}      
function send_login(){	
// 	document.main_form.username.value=document.partI.uname.value;
// 	document.partI.uname.value="";	
// 	document.main_form.password.value=document.partII.passwd.value;
// 	document.partII.passwd.value="";
	//alert(document.part.username.value);
	document.part.submit();
	return;
}
function change_section(section_name, default_page){
	if (document.main_form.section.value!=section_name)
		document.main_form.page.value=default_page;
		
	document.main_form.section.value=section_name;
	if (document.main_form.admin_page)
		document.main_form.admin_page.value="";
	document.main_form.submit();
}
function open_win(url,name, w,h){
	var win=null;
	//w=screen.width;
	//h=400;
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
// 	if (
// 	TopPosition=230;
// 	LeftPosition=0;
	win=window.open(url,name,'top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+w+',height='+h+'');
	if(win.focus)
		win.focus();
}
function popup_photo(photo_id, add_to_fields){
	open_win("popup_photo.php?photo_id="+photo_id+"&add_to_fields="+add_to_fields,"photo"+photo_id, 200,200);
}
function change_page(page_name, old_page, admin){
	if (admin){
		change_admin_page(page_name);
		return;
	}
	document.main_form.page.value=page_name;
	if (document.main_form.admin_page)
		document.main_form.admin_page.value="";
	//document.main_form.back_url.value=old_page;
	document.main_form.play_videos.value=0;
//	alert(page_name)
	document.main_form.submit();
}
function change_admin_page(page_name){
	document.main_form.admin_page.value=page_name;
	
	document.main_form.submit();
}
function show_photo(photo_id, back_url){
// 	i=0;
// 	j=0;
// 	while (document.forms[i].elements[j]){
// 		while (document.forms[i].elements[j]){
// 			alert(document.forms[i].elements[j].name);
// 			j++;
// 		}
// 		i++;
// 	}
// 	document.main_form.photo_path.value=path;
// 	document.main_form.img_width.value=img_width;
// 	document.main_form.img_height.value=img_height;
// 	document.main_form.photo_type.value=photo_type;
	
	//document.main_form.back_url.value=back_url;
	document.main_form.save_page.value='show_photo';
	//document.main_form.page.value='show_photo';
	//document.main_form.admin_page.value="";
	document.main_form.photo_id.value=photo_id;
	
	//document.main_form.section.value='fotografia';
	document.main_form.submit();
}
function reload_page(){	
	document.add_photo.submit();
}

function reload_main_page(){	
	document.main_form.submit();
}
function set_lightbox(photo_id){
	document.main_form.photo_lightbox.value=photo_id;
	document.main_form.photo_id.value=photo_id;
	document.main_form.submit();
}
function set_lightbox_show(photo_id){
	document.main_form.photo_lightbox.value=photo_id;
	document.main_form.photo_id.value=photo_id;
	show_photo(photo_id, 0);
}
