//********************************
// G O O G L E     M A P S    F U N C T I O N S
//    F O R    I M A G E S AND V I D E O S 
// author: Gursch Markus
// August 2008
/////////////////////////////////*

///////// GLOBAL VARS /////////////


///////// FUNCTIONS /////////////
var fileCount = 0;
/**
 * generates the Text for the images tab
 */
function generateTab4Text(details, katID)
{
	var tab4Text = "";
	
	tab4Text += "<div id='tab4'>";
	tab4Text += "<div id='tab4Page1'>";
	tab4Text += generateTab4TextStart(details);
	tab4Text += "</div>";
	
	tab4Text += "<div id='tab4Page2'>";
	tab4Text += generateTab4TextNew(details["name"], details["instID"]);
	tab4Text += "</div>";
	
	return tab4Text;
}

/**
 * creates the html content for the list view of all images 
 */
function generateTab4TextStart(details)
{
	var tab4Text = "<p class='title'>Fotos von " + details["name"] + "</p>";
	tab4Text += "<br /><a href='javascript:void(0);' onclick='changeTab4Page2()'>&raquo; Fotos hinzuf&uuml;gen</a>";
	
	tab4Text += "<div id='fotos'>";
	for (var x = details["foto"].length-1; x >= 0 ; x--)
	{	
		//tab4Text += "<tr><td><img src='http://www.vulkanland.at/upload/maps/fotos/" + details["foto"][x]["pfad"] + "'></td>";
		tab4Text += "<div id='fotoText'>" + details["foto"][x]["titel"] + "</div>";
		tab4Text += "<div id='fotoTable'>";
		
		if (details["foto"][x]["portalFoto"] == 0 ) 
		{
			tab4Text += "<a href='http://www.vulkanland.at/upload/maps/fotos/big" + details["foto"][x]["pfad"] + "' target='_blank'>";
			tab4Text += "<img src='http://www.vulkanland.at/upload/maps/fotos/" + details["foto"][x]["pfad"] + "'></a></div>";
		}
		else
		{
			tab4Text += "<a href='" + details["foto"][x]["fotoID"] + "' target='_blank'>";
			tab4Text += "<img src='" + details["foto"][x]["pfad"] + "'></a></div>";
		}
		//tab4Text += "<a href='http://localhost/vulkanland/maps/images/fotos/big" + details["foto"][x]["pfad"] + "' target='_blank'>";
		//tab4Text += "<img src='http://localhost/vulkanland/maps/images/fotos/" + details["foto"][x]["pfad"] + "'></a></td>";	
	}
	tab4Text += "</div>";
	
	return tab4Text;
}

/**
 * creates the hmlt content to upload a new image
 */
function generateTab4TextNew(name, instID)
{
	fileCount = 0;
	var tab4Text = "";
	
	tab4Text += '<div id="newImage">';
	tab4Text += "Ein neues Foto hinzuf&uuml;gen (jpg, gif, png)<br />";
	tab4Text += '<form action="' + hostFiller + '/includes/upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >';                     
	tab4Text += '<p id="f1_upload_process" style="visibility:hidden">Loading...<br/><img src="' + hostFiller + '/images/loader.gif" /><br/></p><p id="f1_upload_form" align="left"><br/>';
	tab4Text += '<label>Titel &nbsp;&nbsp;<input name="title" type="text" size="40" /></label><br />';
	tab4Text += "<input type='hidden' name='instID' value=" + instID + " />";
	tab4Text += '<label>Datei <input name="myfile" type="file" size="40" /></label>';
	tab4Text += '<label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /></label></p>';
	tab4Text += '<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>';
	tab4Text += '</form></div>';
	tab4Text += '<input type="button" onclick="changeTab4Page1();" value="zur&uuml;ck" />';
	return tab4Text;
}

/**
 * sets the divs visible and invisible at uploading an image
 */
function startUpload(){

      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}

/**
 * method is called if upload has been finished
 */
function stopUpload(success, instID, titel, foto){

      var result = '';

      if (success == 1){
         result = '<span class="msg">Erfolgreich hochgeladen!<\/span><br/><br/>';
      }
      else {
         result = '<span class="emsg">Es ist ein Fehler aufgetreten!<\/span><br/><br/>';
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '<label>Titel &nbsp;&nbsp;<input name="title" type="text" size="40" /></label><br /><input type="hidden" name="instID" value=' + instID + ' /><label>Datei <input name="myfile" type="file" size="40" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      document.getElementById('f1_upload_form').style.visibility = 'visible'; 
    
      if (success == 1)
      	reloadTab4(titel, foto);
      return true;   
}

/**
 * adds the new uploaded image to the listview
 */
function reloadTab4(titel, foto)
{
	var tab = document.getElementById("fotos");
	
	var text = tab.innerHTML;
	
	tab.innerHTML = "";
	tab.innerHTML += "<div id='fotoText'>" + titel + "</div>";
	tab.innerHTML += "<div id='fotoTable'><a href='http://www.vulkanland.at/upload/maps/fotos/big" + foto + "' target='_blank'><img src='http://www.vulkanland.at/upload/maps/fotos/" + foto + "' /></a></div>";
	
	//tab.innerHTML = "<tr><td class='fotoTable'><a href='http://localhost/vulkanland/maps/images/fotos/big" + foto + "' target='_blank'><img src='http://localhost/vulkanland/maps/images/fotos/" + foto + "'></a></td><td>" + titel + "</td></tr>";
	tab.innerHTML += text;
	
	changeTab4Page1();
}

/**
 * changes the view
 */
function changeTab4Page1()
{
	toggle("unfold", "tab4Page1");
	toggle("fold", "tab4Page2");
}

/**
 * changes the view
 */
function changeTab4Page2()
{
	toggle("fold", "tab4Page1");
	toggle("unfold", "tab4Page2");
}

/** 
 * folds page 2 and page 3 for startup
 */
function foldTab4Pages()
{
	toggle("unfold", "tab4Page1");
	toggle("fold", "tab4Page2");
}