//
// Javascript Lib of castogo (http://castogo.com)
//
// Copyright (C) 2008 Rahlfs+Ross Multimedia GmbH <info@digital-worx.de>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//


//------------------------------------------------
// *** Trail Vote start ***
//------------------------------------------------

function SetRate(rate_val, trail_id, div, rate_it)
				{
					ajax_do("ajax/set_rate.php?rating="+rate_val+"&trail_id="+trail_id+"&rate_it="+rate_it, div);
				}

				//SetRate(0, document.frm1.trail_id.value, document.getElementById('sp_rate1'),2);

				function previewStar(num,trail_id) {
					resetStars(trail_id);
					for(i=1; i<=num; i++){
						document.getElementById('s'+i+'_'+trail_id).src='images/fullstar.gif';
					}

				}
				function previewStar2(num,trail_id) {
					//resetStars(trail_id);
					for(i=1; i<=num; i++){
						document.getElementById('s'+i+'_'+trail_id).src='images/fullstar2.gif';
					}

				}

				function showDefaultStars(){
				// you will have to set this value based on the current rating
					previewStar(3);
				}

				function resetStars(trail_id) {
					for(i=1; i<=5; i++){
						document.getElementById('s'+i+'_'+trail_id).src='images/emptystar.gif';
						//eval('document.getElementById(\'s'+i+'\').src="images/emptystar.gif"');
					}
				}


//------------------------------------------------
// *** Mouse over Map Effect on Container ***
//------------------------------------------------


				function MM_findObj(n, d) { //v4.0
  					var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  						if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  							for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  								if(!x && document.getElementById) x=document.getElementById(n); return x;
				}

				function MM_showHideLayers() { //v3.0
  					var i,p,v,obj,args=MM_showHideLayers.arguments;
  						for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    					if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    				obj.visibility=v; }
				}

//------------------------------------------------
// *** AJAX Engine ***
//------------------------------------------------

function ajax_do(url, div_content)
{
	var arg = url;
	//url = "content.php?q=" + url;
	var http_request = false;

	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();

		if (http_request.overrideMimeType)
		{
		//http_request.overrideMimeType('text/xml');
		// See note below about this line
		}
	}
	else if (window.ActiveXObject)
	{ // IE
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}

	if (!http_request)
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function() { alertContents(http_request, div_content); };
	http_request.open('GET', url, true);
	http_request.send(null);
}


function alertContents(http_request, div_content)
{
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{
			//document.getElementById("content").innerHTML=http_request.responseText;
			div_content.innerHTML=http_request.responseText;
		}
		else
		{
			alert('There was a problem with the request.');
		}
	}
}

 /* -------------------------------------- */
 /* Calculate GPS Values to Decimal Values */
 /* -------------------------------------- */

function flaenge()
	{
		with(document.frm)
		{
    	var dLaenge1=parseFloat(gps_n_dec.value);
		var dLaenge2=parseFloat(gps_n_min.value);
   		var dLaenge3=parseFloat(gps_n_sec.value);
		var dErgebnisLaenge=dLaenge1+dLaenge2/60+dLaenge3/3600;
   		trailpoint_lat.value=dErgebnisLaenge;
   		}
	}

function fbreite()
	{
		with(document.frm)
		{
    	var dBreite1=parseFloat(gps_e_dec.value);
		var dBreite2=parseFloat(gps_e_min.value);
   		var dBreite3=parseFloat(gps_e_sec.value);
		var dErgebnisBreite=dBreite1+dBreite2/60+dBreite3/3600;
   		trailpoint_long.value=dErgebnisBreite;
   		}
	}



 /* -------------------------------------- */
 /* Show and Hide Progress Layers	       */
 /* -------------------------------------- */

function DisplayLayer()
		{
			if(document.getElementById("photo").value != '' || document.getElementById("media").value != '' )
				document.getElementById("lb_layer1").style.visibility='visible';
				document.getElementById("theLayer_pf").style.visibility='visible';
			//alert('aaaa');
			//document.frm_edit_email.title.value = document.back_form.ad_title.value;
		}

function show(aa,bb,cc)
		{
			if(document.getElementById(aa).style.display=='none')
			{
			document.getElementById(bb).innerHTML='-';
			document.getElementById(aa).style.display='inline';
			}
		else
			{
			document.getElementById(bb).innerHTML='+';
			document.getElementById(aa).style.display='none';
			}
		}



 /* -------------------------------------- */
 /* Count Chars on Form Inputs  	       */
 /* -------------------------------------- */

var formfeld="";
var maxlang=5000;

function zaehle(feld, counter, maxlang){

		if (feld.value.length>maxlang){
			feld.value=formfeld;
			return;
		}
		else{
			formfeld=feld.value;
			document.frm[counter].value=maxlang-feld.value.length;
		}
}
