emptyCursor = "/portal/as-images/as/empty.cur";

// To disable double submits
function disableFormAfterSubmit(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
		var tempobj = theform.elements[i];
		if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
			tempobj.disabled = true;
		}
		// setTimeout('alert("Your form has been submitted.  Notice how the submit and reset buttons were disabled upon submission.")', 2000);
		return true;
		// return false;
	} else {
		// alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
		return false;
   }
}

// Cookie Hack
function WertHolen() {
 var Wert = "";
 if(document.cookie) {
  var Wertstart = document.cookie.indexOf("=") + 1;
  var Wertende = document.cookie.indexOf(";");
  if (Wertende == -1)
   Wertende = document.cookie.length;
  Wert = document.cookie.substring(Wertstart,Wertende);
 } else {
  Wert = Math.floor(10000000000 * Math.random());
 }
 return Wert;
}

function initcookie(domainName) {
	if (document.cookie) {
		tmp = "JSESSIONID=" + WertHolen() + ";path=/portal;domain=" + domainName + ";";
		document.cookie = tmp;
	}
}

// Double click trap - was form_tools
var submitted = false;
var popupWidth = 300;
var popupHeight = 300;

function submitFormAndDontTrapDoubleClick(myForm, command, param)
{
        myForm.cmd.value = command;
        myForm.cmdParam.value = param;
        submitted = true;
        myForm.submit();
        // if (submitted == false)
        // {
        //      myForm.cmd.value = command;
        //      myForm.cmdParam.value = param;
        //      submitted = true;
        //      myForm.submit();
        // }
        // else
        // {
        //      alert("Ein Klick reicht aus. Der Server sollte sofort antworten.\n\n\nBitte klicken Sie auf \"OK\".");
        // }
        return false;
}

function showImage(bild)
{
	var x=0;
	var y=0;
	var w;
	if (window.event || document.layers) {
        x = event.screenX - popupWidth;
	    y = event.screenY;
		if (x < 0) { x = 0; }			
		w = window.open("","BildPreview","width=" + popupWidth + ",height=" + popupHeight + ",screenY=" + y + ",screenX=" + x + ",top=" + y + ",left=" + x + ",menubar=no,resizable=yes,scrollbars=auto,status=no,toolbar=no");
	} else {
		w = window.open("","BildPreview","width=" + popupWidth + ",height=" + popupHeight + ",top=" + ((screen.height-popupHeight)/2) + ",left=" + ((screen.width-popupWidth)/2) + ",menubar=no,resizable=yes,scrollbars=auto,status=no,toolbar=no");
	}
    with (w.document) {
	    open();
    	writeln('<html><head><title>Bildvorschau</title></head>');
        writeln('<body>');
	    writeln('<img src="/documents/etravelshop/' + bild + '" /><br />');
    	writeln('<input type="button" name="Close" value="Schlie&szlig;en" onclick="window.close();"/>');
        writeln('</body></html>');
	    close();
    }	
}


// bump it / shake it / move it - from list - tools

	sortitems = 1; 
	
	/**
	 * select all items of a select box
	 */ 
	function selectAll( tbox ) 
	{ 
		for( var i=0; i<tbox.options.length; i++ ) 
		{ 
			tbox.options[i].selected = true;
		} 
	} 
	
	/**
	 * select all items of a select box
	 */ 
	function deselectAll( tbox ) 
	{ 
		for( var i=0; i<tbox.options.length; i++ ) 
		{ 
			tbox.options[i].selected = false;
		} 
	} 
		
	/**
	 * change the position of an item in a select box
	 * @param select the select box
	 * @param index direction and steps (e.g. -1: one position up, 2: two positions down)
	 */
	function moveIt( select, index ) 
	{ 
		if( select.length >= 2 ) 
		{ 
			var item	= select.selectedIndex; 
			if ((item+index < 0) || (item+index >= select.length))
			{
				return;
			}
			var value	= select[item+index].value; 
			var text	= select[item+index].text; 
	 
			select[item + index].value = select[item].value; 
			select[item + index].text  = select[item].text; 
			select[item].value         = value; 
			select[item].text          = text; 
			select.selectedIndex      += index; 
		} 
		else 
		{ 
			alert( "You need at least two items, so you can change their order." ); 
		} 
	} 
	 
	/**
	 * move an item from a select box to another
	 *
	 * @param fbox move item from this box
	 * @param tbox move item to this box
	 */
	function swapIt( fbox, tbox ) 
	{ 
		for( var i=0; i<fbox.options.length; i++ ) 
		{ 
			if( fbox.options[i].selected && fbox.options[i].value != "" ) 
			{ 
				var no = new Option(); 
				no.value = fbox.options[i].value; 
				no.text = fbox.options[i].text; 
				tbox.options[tbox.options.length] = no; 
				fbox.options[i].value = ""; 
				fbox.options[i].text = ""; 
			} 
		} 
		
		bumpUp( fbox );
		deselectAll( fbox); 
		
		if ( sortitems ) 
		{ 
			sortIt( tbox ); 
		} 
	} 
	
	/**
	 * DOCUMENT_ME
	 */ 
	function bumpUp( box )  
	{ 
		for( var i=0; i<box.options.length; i++ ) 
		{ 
			if( box.options[i].value == "" )  
			{ 
				for( var j=i; j<box.options.length-1; j++ )  
				{ 
					box.options[j].value = box.options[j+1].value; 
					box.options[j].text  = box.options[j+1].text; 
				} 
				var ln = i; 
				break; 
			} 
		} 
		
		if( ln < box.options.length )  
		{ 
			box.options.length -= 1; 
			bumpUp( box ); 
		} 
	} 
	
	/**
	 * sort the items in a select box
	 */ 
	function sortIt( box )  
	{ 
		var temp_opts = new Array(); 
		var temp = new Object(); 
		
		for( var i=0; i<box.options.length; i++ )  
		{ 
			temp_opts[i] = box.options[i]; 
		} 
		
		for( var x=0; x<temp_opts.length-1; x++ )  
		{ 
			for( var y=(x+1); y<temp_opts.length; y++ )  
			{ 
				if( temp_opts[x].text > temp_opts[y].text )  
				{ 
					temp = temp_opts[x].text; 
					temp_opts[x].text = temp_opts[y].text; 
					temp_opts[y].text = temp; 
				} 
			} 
		} 
		
		for( var i=0; i<box.options.length; i++ )  
		{ 
			box.options[i].value = temp_opts[i].value; 
			box.options[i].text = temp_opts[i].text; 
		} 
	} 

// Sandclock fix - from menu.js
var imgArrayOn = new Array();
var imgArrayOff = new Array();

function preloadNavImages(imgPath, menuArray) {
	for(i=0; i<menuArray.length; i++){
		imgArrayOn[menuArray[i]] = new Image();
		imgArrayOn[menuArray[i]].src = imgPath + "bg_mainnav_" + menuArray[i] + "_on_" + lang + ".gif";
		imgArrayOff[menuArray[i]] = new Image();
		imgArrayOff[menuArray[i]].src = imgPath + "bg_mainnav_" + menuArray[i] + "_off_" + lang + ".gif";
	}
	// emptyCursor = imgPath + "empty.cur";
}

function highlight(what) {
	if(imgArrayOn[what])
	{
		if (document.images[what])
		{ 
			if (document.getElementById(what)) 
			{
				document.getElementById(what).style.cursor="url("+emptyCursor+")";
			}
			document.images[what].src= imgArrayOn[what].src;
			if (document.getElementById(what)) 
			{
				document.getElementById(what).style.cursor="hand";
				document.getElementById(what).style.cursor="pointer"; // see http://www.drweb.de/trickkiste/tricks175.shtml
			}
		} else {
			alert("highlight: No image with name " + what);
		}
	}
}

function darken(what) {
	if(imgArrayOff[what])
	{
		if (document.images[what])
		{ 
			if (document.getElementById(what)) 
			{
				document.getElementById(what).style.cursor="url("+emptyCursor+")";
			}
			document.images[what].src= imgArrayOff[what].src;
			if (document.getElementById(what)) 
			{
				document.getElementById(what).style.cursor="auto";
			}
		} else {
			alert("darken: No image with name " + what);
		}
	}
}

function menuImgSrcOff(what) {
	if(imgArrayOff[what])
		return imgArrayOff[what].src;
	else
		return "/unknown.gif";
}

function showAllMenuImg()
{
	for (var imgName in imgArrayOff)
	{
		if (document.images[imgName]) 
		{
			document.images[imgName].src= imgArrayOff[imgName].src;
		} 
	}
}

function deselectRadios(nameOfRadioFields){
	
	var radios = document.getElementsByName(nameOfRadioFields);
	if (radios) {
		for(var i=0; i<radios.length; i++) {
			radios[i].checked = false;
		}
	}
}

// Derived from http://javascript.internet.com/navigation/links-list.html
// Use like this in jsp:
// <% de.autostadt.vap.control.SuperTracker.track(request); %>
// <body onload="appendParameterToLinks('SuperIndex=<%= request.getAttribute(de.autostadt.vap.control.SuperTracker.HISTORY_INDEX_REQUEST_ATTRIBUTE) %>');">

function appendParameterToLinks(parameters) {
    var myHref;
    for (i=0; i<document.links.length; i++) {
      myHref = document.links[i].href;
      if (myHref.indexOf('javascript:') == -1) {
        if (myHref.indexOf('?') == -1) {
          // myHref = myHref + '?' + trackingParam + "=" + trackingValue;
      	  document.links[i].href = myHref + '?' + parameters;
        } else {
          // myHref = myHref + '&' + trackingParam + "=" + trackingValue;
      	  document.links[i].href= myHref + '&' + parameters;
        }
      }
	}
}

function appendParameterToCertainLinks(urlSubString, parameters) {
    var myHref;
    for (i=0; i<document.links.length; i++) {
      myHref = document.links[i].href;
      if (myHref.indexOf(urlSubString) > -1) {
        if (myHref.indexOf('?') == -1) {
      	  document.links[i].href = myHref + '?' + parameters;
        } else {
      	  document.links[i].href= myHref + '&' + parameters;
        }
      }
	}
}

function setChanged() {
    var field = document.getElementById("formChanged");
    if (field) {
        field.value = "true";
    }
}

function hasChanged() {
    var field = document.getElementById("formChanged");
    if (field) {
	if (field.value == "true") return true; else return false;
    } else return false;
}   
