// JavaScript Document

function LoadSwf(sHost) {
	// HOME
	var myFlash1;
	myFlash1 = new SWFObject('/images/flash/velovirus_intro.swf', 'velovirus_intro', 560, 240, 8);
	myFlash1.addVariable('dom', sHost);
	myFlash1.addParam("wmode", "transparent");
	myFlash1.write('divIntro');
}

function LoadBrands() {
	var oBrandFlash;
	oBrandFlash = new SWFObject('/images/flash/hersteller.swf', 'velovirus_brands', 162, 60, 8);
	oBrandFlash.addParam("wmode", "transparent");
	oBrandFlash.write('divMenuBottom');
}

//Funktion zum Öffnen eines Popup
function openWin(sPage, sWindow, width, height) {
  if (!width) width = 845;
  if (!height) height = 600;  
  if (!sWindow) sWindow = "";
  var winRef = window.open(sPage,sWindow,'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
  winRef.focus();
}

// Check ob Suche eingeschränkt wird
function checkForm(form) {
	if (form.optType.value == 0  && form.optBrand.value == 0 && form.txtKeyword.value.length == 0) {
		alert('Bitte geben Sie mindestens ein Suchkriterium ein.');
		return false;
	}
	else {return true;}
}

// postback mit anderen Dropdowns für Suche
function changeSearchItem(ID) {
	document.frmSearch.hdnAction.value = '';
	document.frmSearch.submit();
	document.frmSearch.action = '/search.asp?ID=' + ID;
}

// =============================================
// Checkt die 3 Formularfelder auf Ihre Eingaben
// Übergabe: form, zu überprüfendes Rootform
function checkFormVals(form) {
	
	var eleName = form.elements.Name;
	var eleFirstname = form.elements.Vorname;
	var eleMail = form.elements.Email;

	if (eleName.value.length != 0) {
		if (eleFirstname.value.length != 0) {
			if (eleMail.value.length != 0) {
				var bMail = isMailAdr(eleMail.value); 
				if (!bMail) { 
					alert('Die eingegebene E-mail-Adresse ist ungültig.'); eleMail.focus(); eleMail.select();
				}
				else {return true;}
			}
			else { alert('Das Feld "E-mail" darf nicht leer sein.'); eleMail.focus(); }
		}
		else { alert('Das Feld "Vorname" darf nicht leer sein.'); eleFirstname.focus(); }
		
	}
	else { alert('Das Feld "Name" darf nicht leer sein.'); eleName.focus(); }
	
	return false;
}
// =============================================

// =============================================
// isMailAdr: checkt ein String auf seine 
// gültigkeit bezüglich mailadresse
// Übergabe: String
// Rückgabe: boolean
function isMailAdr(str) {
	// check ob @ vorhanden
	var nIndex = str.indexOf('@');
	if (nIndex != -1) {
		var sDomain = str.substr(nIndex + 1);
		var nPointPos = sDomain.indexOf('.');
		if (nPointPos > 0) {
			if (sDomain.substr(nPointPos + 1).length >= 1) {return true};
		}
	}
	return false;
}
// =============================================

function resetForm(form) {
	var fEle = form.elements;
	var fEleIndex = fEle.length;
	for (var i = 0; i < fEleIndex; i++) {
		// Ele-Typ bestimmen
		var fEleTyp = fEle[i].type;
		switch (fEleTyp) {
			case 'text':
				fEle[i].value = '';
				break;
			case 'select-one':
				fEle[i].selectedIndex = 0;
				break;
			case 'textarea':
				fEle[i].value = '';
				break;
			case 'checkbox':
				fEle[i].checked = false;
				break;
			default:
				break;
		}
	}
}

function imageView(sImg) {
  // neues Imgobjekt instanzieren
  var imgUrl = '/images/' + sImg;
  var imgObj = new Image();
  imgObj.src = imgUrl;
  // höhe und breite definieren
  var nHeight = imgObj.height;
  var nWidth = imgObj.width;
  var nMargin = 20;
  var nWinH = nHeight + 2*nMargin;
  var nWinW = nWidth + 2*nMargin;
  var winRef = window.open(imgUrl,'Bildansicht','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=' + nWinW + ',height=' + nWinH);
  winRef.focus();
}

function RequestHandler(oForm,sVal){
	var sUrl = "requesthandler.asp?do=" + sVal;
	oForm.action = sUrl; oForm.submit();
}

function resetCombo(oForm,oCombo) {
	if (oForm && oCombo) {
		oCombo.selectedIndex = 0;
		oForm.submit();
	}
}

function getMonthRate(n,p) {
	$.ajax({
		type: "GET",
		url: "/getCreditNowRate.asp?R="+n+"&P="+p,
		success: function(data){
			$("#spanCN_Rate").html(data);
			$("#divCN_RateResulte").show("fast");
		}
	});
}

function SetView(nView) { LoadOccPage("vw="+nView); }

function LoadOccPage(sParam) {
	
	$("#OccLoadingState").css({'visibility' : 'visible'});
	
	$.ajax({
		cache: false,
		data: $('#frmOcc').serialize(),
		type: "POST",
		url: "occloadlist.asp?"+sParam,
		success: function(msg){
			$("#divOccItemsContent").html(msg);
		},
		complete: function(){
			$("#OccLoadingState").css({'visibility' : 'hidden'});
		}
	});
}

function SetFilter() {
	LoadOccPage("");
}


function SetFilterBak() {
	var s = "";
	var o = document.forms.frmOccViewFilter.elements.chkOccTyp;
	var n = o.length;
	for (var i = 0; i < n; i++) {
		if (o[i].checked) { if (s.length > 0) { s += ","; }; s += o[i].value };
	}
	// letzte Deselektion mit "RESET" lösen
	if (s.length == 0) { s = "reset"; }
	LoadOccPage("ts="+s);
}

function ResetFilter(sParam) {
	resetForm(document.forms.frmOcc);
	LoadOccPage(sParam);
}
