
var http_dlp = (("https:" == window.location.protocol) ? "https://" : "http://") + window.location.hostname;

function trim (zeichenkette) {
	  // Erst führende, dann Abschließende Whitespaces entfernen
	  // und das Ergebnis dieser Operationen zurückliefern
	  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
	}

function $$(k){
	return document.getElementById(k);
}

function actNewsletterPre(E, err){
	if (checkEnter(E)){
		actNewsletter(err);
	}
}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode// literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
	e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	return (characterCode == 13);
	
}

//http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
//http://de.wikipedia.org/wiki/Top-Level-Domain
function chkEmail(s){
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function'){
		var b = new RegExp('abc');
		if(b.test('abc') == true){a = true;}
	}
	
	if(a == true){
		reg = new RegExp('^([a-z0-9\\-\\.\\_]+)'+
		'(\\@)([a-z0-9\\-\\.]+)'+
		'(\\.)([a-z]{2}|arpa|aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel)$');
		res = (reg.test(s));
	}	else {
		res = (s.search('@') >= 1 &&
		s.lastIndexOf('.') > s.search('@') &&
		s.lastIndexOf('.') >= s.length-6)
	}

	if (res==false){
		return false;
	} else {
		return true;
	}
} 

function clearme(i, v) {
	if ($$(i).value == v)
		$$(i).value = '';
}

function fillme(i, v) {
	if ($$(i).value == '')
		$$(i).value = v;
}

function navigate(n){
	window.location.href = http_dlp + n;
}


function nextimage(v, u, c, a, s, vo, it){
	var i = $$(v);	
	http_dlp_ = (("https:" == window.location.protocol) ? "https://" : "http://") + "www.bookson.de";
	i.src= http_dlp_ + u + allimages[c];
	thisimage = c;

	var l = $$(v + '_links');	
	var r = $$(v + '_rechts');	
	if ( thisimage == maximage){
		l.src= http_dlp + a + 'blick_ins_buch_links_aktiv.png';
		r.src= http_dlp + a + 'blick_ins_buch_rechts.png';
	} else if ( thisimage == 0){
		l.src= http_dlp + a + 'blick_ins_buch_links.png';
		r.src= http_dlp + a + 'blick_ins_buch_rechts_aktiv.png';
	} else {
		l.src= http_dlp + a + 'blick_ins_buch_links_aktiv.png';
		r.src= http_dlp + a + 'blick_ins_buch_rechts_aktiv.png';
	}		
	
	tmp1 = maximage + 1;
	tmp2 = thisimage + 1;
	var itm = $$(it);	
	itm.innerHTML = tmp2 + ' ' + vo + ' ' + tmp1 + ' ' + s;
}

/* function nextimage_start(scr_id, img_url, a_id, a_href){
	var i = $$(scr_id);	
	http_dlp_ = (("https:" == window.location.protocol) ? "https://" : "http://") + "www.bookson.cdo";
	i.src= http_dlp_ + img_url;
	var t = $$(a_id);	
	t.href= http_dlp_ + a_href;
} */


function changeimage(v, u, t, a, s, vo, i){
	
	if (t == 'next'){
		if (thisimage < maximage){
			thisimage++;
			nextimage(v, u, thisimage, a, s, vo, i);
		}
	} else if (t == 'last') {
		if (thisimage > 0){
			thisimage--;
			nextimage(v, u, thisimage, a, s, vo, i);
		}
	}
	
}


//document.getElementById wird ersetzt durch: $$

function reader_download(){
	$("#dialog").dialog({modal:true,width:700,height:500});
	$("#dialog").dialog("open");
}

function registercheck(){
  var k = false;
  if($$("agb").checked == false){
		$("#agbaccept").dialog({modal:true});
		$("#agbaccept").dialog("open");
		k = false;
  } else {
		k = true;
  }
  
  var p1 = trim($$("register_email").value);
  var p2 = trim($$("register_email2").value);
  
  if((p1 != p2) && k){
		$("#emailcheck").dialog({modal:true});
		$("#emailcheck").dialog("open");
		k = false;
  }
  return k;
}

function passaendern(){
  var k = false;
  var p1 = trim($$("passwort_neu").value);
  var p2 = trim($$("passwort_neu2").value);
  
  if((p1 != p2) && k){
		$("#passcheck").dialog({modal:true});
		$("#passcheck").dialog("open");
		k = false;
  }
  return k;
}

function passeingabe(){
	if($$("passwort").value == ""){
		alert("Bitte Passwort eingeben! Sofort");
		return false;
	}
	else{
		alert("es geht");
		return true;
	}
}


function showpassword(){
	$("#showpassword").dialog({modal:true,width:400,resizable:false});
	$("#showpassword").dialog("open");
}



function showagb(){
	$("#showagb").dialog({modal:true,width:700,height:500});
	$("#showagb").dialog("open");
}

/* function slider(){
	$(document).ready(function(){	
	$("#slider").easySlider();
});

} */


function setRadio(id){
	if (id == "CC")
		$$("formzahlung").action = cc_form_url;
	else
		$$("formzahlung").action = be_re_form_url;
	$$(id).checked = true;	
}




function getSubcategory(blank){
	var cat = $$('search_category');
	var scat = $$('search_subcategory');
	var val = 0;
	
  for (i = 0; i < cat.length; i++)
    if (cat.options[i].selected  == true)
      val = cat.options[i].value;	
   
	var t = scat.length;

  for (i = 0; i < t; i++)
		scat.options[0] = null;	

	var newelement = new Option(blank, "0", false, false);
	scat.options[scat.length] = newelement;
		
 	if (val > 0){

	  	var allelements = allsubcat[val].split("|");
	  	if (allelements.length > 1)
		  	for (i = 0; i < allelements.length; i++){
					var item = allelements[i].split(";");
		  		var newelement = new Option(item[1], item[0], false, false);
		  		scat.options[scat.length] = newelement;
		  	}
 		
 	}
	
}


function actSearch(itemid, searchid, itemtype, redir, path){

	var df = $$(itemid);
	var val = "";

	for (i = 0; i < df.length; i++)
	if (df.options[i].selected  == true)
	val = df.options[i].value;
	window.location.href = http_dlp + "/" + path + "?" + redir + "=1&id=" + searchid + "&seite=0&sort=" + val;

}

/* if(options.continuous){
				$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
				$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
				$("ul", obj).css('width',(s+1)*w);
			};s	 */

/* function adjust_kat(){
		$("#unterkategorie").css("margin-left",-580);
		$$("bu").style.display = "inline";
		$$("ba").style.display = "none";
		
		$("#prevBtn").click(function(){		
			$("#unterkategorie").animate({marginLeft: "50px"},800 );
	});
} */

function animation()
{
	$$("img_wait").style.display = "none";
	$$("img_wait2").style.display = "block";
	return true;
}
	
function setLandingpage(i){
	$.ajax({
		url: http_dlp + "/js/index.cfm?fuseaction=landingpage&books=" + i ,
			success: function(transport){
				$('#landingpage').html(transport);
			}
	});	
}
