var single;
var preLoadPic;

// loading needed images etc. into cache
function preLoad( ) {
	
}

// show's a pic on rollover, if it's the same - nothing
function showPic(docID, width) {
   var tmpsrc = "/servlet/com.kapelan.kcom.servlets.dms.DocumentImage?imgWidth=" + width + "&docID=" + docID + "&dbpool=gwdb";
   var tmpvar2 = window.document.images["mainPic"].src;
   if( tmpvar2 != tmpsrc ) {
	// set up load-picture
	window.document.images["mainPic"].src = "";
	// set up the new car-picture
	window.document.images["mainPic"].src = "/servlet/com.kapelan.kcom.servlets.dms.DocumentImage?imgWidth=" + width + "&docID=" + docID + "&dbpool=gwdb";
	// Server-angabe dynamisch verändern!!! TODO !!
       // alert("Not same: " + tmpsrc + " --- " + tmpvar2);
   }
   // else alert("is the same");
   if( window.document.picSize ) {
	window.document.picSize.docID.value = docID
   }
   if( window.document.druckdetails ) {
	window.document.druckdetails.docID.value = docID
   }
}
// open a single popup window
function openSingle(fahrzeugID, fahrzeugCode ) {
	single = window.open("/servlet/engine/gw/misc/document/doc_singlesite.html?fahrzeugID=" + fahrzeugID + "&fahrzeugCode=" + fahrzeugCode + "&width=250&blank=1", "SingleDoc","width=350,height=325,left=150,top=150,location=no,resizable=yes,status=no,menubar=no,toolbar=no,dependent=yes");
	single.title = "Angebot " + fahrzeugCode;
	single.focus();
}

function openMinMax(fahrzeugID, fahrzeugCode ) {
	single = window.open("/servlet/engine/gw/misc/document/doc_minmax.html?fahrzeugID=" + fahrzeugID + "&fahrzeugCode=" + fahrzeugCode + "&width=250&blank=1", "SingleDoc","width=350,height=425,left=10,top=10,location=no,resizable=yes,status=no,menubar=no,toolbar=no,dependent=yes");
	single.focus();

}
function openHelp( psite ) {
	single = window.open("/servlet/engine" + psite, "SingleHelp","width=150,height=150,left=400,top=400,location=no,resizable=no,status=no,menubar=no,toolbar=no,dependent=yes");
	single.focus();

}
function resizeHelp(width, height) {
	if( navigator.userAgent.indexOf("MSIE") > 0 ) {
    	height = height - 20; 
    } 
    else if( navigator.userAgent.indexOf("Firefox") > 0 ) {
    	height = height + 20;
    }
	window.resizeTo( width,height );
} 
function resizeMe(width, height, thumbcnt) {
	// je nach Bildanzahl was zur Hoehe dazuaddieren	
	if( thumbcnt < 2 ) {
	  thumbcnt = 0;
	}
	else if( thumbcnt == 2 || thumbcnt == 3 ) {
	  thumbcnt = 110;
	}
	else if( thumbcnt >= 4 || thumbcnt <= 6 ) {
	  thumbcnt = 175;
	}
	else if( thumbcnt >= 7 || thumbcnt <= 9 ) {
	  thumbcnt = 250;
	}
	// wenn GROSSES Bild gewaehlt, neue breite setzten
	if( width == 320 ) {	
		width = width + 70;
		height = height + 55;
	}
	// wenn zu klein
	if( width < 249 ) {	
		width = 250;
		//height = height - 70;
	}
	window.resizeTo( (width + 110), (height + 100 + thumbcnt) );
	//alert( (width + 100) + ":" +  (height + 100 + thumbcnt) );
}

function emptyOffer( ) {
   window.document.angebotsNummer.offercode.value = '';
}

function explain( ) {
	window.status = 'Der Händler ist nicht an das Angebot gebunden!';
}
function clearstatus( ) {
	window.status = 'Export und Anzeige der Gebrauchtfahrzeug erstellt durch car2sale 3.0';
}
function checkJS( ) {
	document.jsPic.src = "/gw/images/empty.gif";
}


function preSelect( isSel, oind, oadd ) {
	if( document.mtSimple ) {		
		for(i=0; i<document.mtSimple.elements[oind].length; i++) {
			if( document.mtSimple.elements[oind].options[i].text == isSel + oadd ) {
				document.mtSimple.elements[oind].options[i].selected = true;
				break;
			}
			else document.mtSimple.elements[oind].options[0].selected = true;
		}
	}
}
function preSelectPrice( isSel, oind ) {
	isSel = isSel + " EUR";
	if( document.mtSimple ) {		
		for(i=0; i<11; i++) {
			if( document.mtSimple.elements[oind].options[i].text == isSel ) {
				document.mtSimple.elements[oind].options[i].selected = true;
				break;
			}
			else document.mtSimple.elements[oind].options[0].selected = true;
		}
	}
}
function moveover(picname){
	if (document.images) {   
		document.images[picname.name].src = document.images[picname.name].src.replace(".gif", "_over.gif");
	}
}
function moveout(picname){
   	if (document.images) {
		document.images[picname.name].src = document.images[picname.name].src.replace("_over.gif", ".gif");
   	}
}
function imoveover(fname, eid){
alert( "A" + fname);
	pruefen( fname );

	alert( "B" + document.forms[fname.name].name );

	//alert( "A" + document.forms[fname.name].name );
	//alert( "B" + document.forms[fname].elements[0].type );	
	// alert( "C" + document.forms[fname.name].elements[eid].name );	
	if (document.forms) {   
		document.forms[fname.name].elements[1].src = document.forms["coview"].elements["ue1"].src.replace(".", "_over.");
	}
	/*if (document.forms) {   
		document.forms[fname.name].elements[eid.name].src = document.forms[fname.name].elements[eid.name].src.replace(".", "_over.");
	}*/
}
function imoveout(picname){
   	if (document.images) {
		document.images[picname.name].src = document.images[picname.name].src.replace("_over.", ".");
   	}
}

function pruefen(f){ //Formular wird als Parameter übergeben
	alert( f.name + " LENGTH: " + f.elements.length );  
	var fehler = "" //Variable für die Fehlermeldung
   var i //Enthält das jeweilige Formularelement
   for (var j=0; j<f.elements.length; j++){
alert( j );      
i = f.elements[j];
      alert( j + " NAME: " + i.name );
   }
   return true
}

