// var curtaal = "NL";
function XkiesTaal(welke) {
 var d = document.getElementById("lang_"+welke);
 var e = document.getElementById("lang_"+curtaal);
 e.className = "tk-taal";
 d.className = "tk-taal-active";
 curtaal = welke;
}

/*
var p_lang = "NL"; // standaard taal filter
var p_sex = "D"; // standaard geslacht filter
var p_jaar = ""; // standaard age filter
var p_snap = "medium"; // standaard snapshot grootte
var pager_offset = 0;
*/

var p_other = "";

function kiesTaal(welke) {
 var d = document.getElementById("lang_"+welke);
 if (d.className == "tk-taal-active") {
	d.className = "tk-taal";
 } else {
	d.className = "tk-taal-active"
 }

 var w = "";
 if (document.getElementById("lang_NL").className == "tk-taal-active") w+="NL";
 if (document.getElementById("lang_IT").className == "tk-taal-active") w+="IT";
 if (document.getElementById("lang_FR").className == "tk-taal-active") w+="FR";
 if (document.getElementById("lang_DE").className == "tk-taal-active") w+="DE";
 if (document.getElementById("lang_ES").className == "tk-taal-active") w+="ES";
 if (document.getElementById("lang_EN").className == "tk-taal-active") w+="EN";
 if (document.getElementById("lang_TU").className == "tk-taal-active") w+="TU";
 p_lang = w;
 pager_offset = 0;
 getCams();
}


function kiesSex(welke) {
 var d = document.getElementById("sex_"+welke);
 if (d.className == "tk-taal-active") {
	d.className = "tk-taal";
 } else {
	d.className = "tk-taal-active"
 }
 var w = "";
 if (document.getElementById("sex_Dames").className == "tk-taal-active") w+="D";
 if (document.getElementById("sex_Koppels").className == "tk-taal-active") w+="K";
 if (document.getElementById("sex_Heren").className == "tk-taal-active") w+="H";
 if (document.getElementById("sex_Shemales").className == "tk-taal-active") w+="S";

 p_sex = w;
 pager_offset = 0;
 getCams();
}

function kiesJaar(welke) {
 var d = document.getElementById("jaar_"+welke);
 if (d.className == "tk-taal-active") {
	d.className = "tk-taal";
 } else {
	d.className = "tk-taal-active"
 }
 var w = "";
 if (document.getElementById("jaar_18").className == "tk-taal-active") w+="18";
 if (document.getElementById("jaar_25").className == "tk-taal-active") w+="25";
 if (document.getElementById("jaar_35").className == "tk-taal-active") w+="35";
 if (document.getElementById("jaar_45").className == "tk-taal-active") w+="45";
 if (document.getElementById("jaar_55").className == "tk-taal-active") w+="55";
 if (w=="1825354555") w="";
 p_jaar = w;
 pager_offset = 0;
 getCams();
}

function setSnap(wat) {
 p_snap=wat;
 getCams();
}

function getCams() {
	var req = new Request.HTML({url:'getcams_request.php?lang='+p_lang+"&sex="+p_sex+"&age="+p_jaar+"&snap="+p_snap+(pager_offset!=0?"&pager_offset="+pager_offset:"")+p_other, 
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('leftkol').set('text', '');
			//Inject the new DOM elements into the results div.
			$('leftkol').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('leftkol').set('text', 'Er is een fout opgetreden.');
		}
	});
	req.send();
	return false;
}







var s_opt_toys = "";
var s_opt_pierce = "";
var s_opt_tats = "";
var s_opt_online = "";
var s_opt_one = "";

function searchOpt(welke) {
 var d = document.getElementById("search_"+welke);
 var v = "";
 if (d.className == "tk-taal-active") {
	d.className = "tk-taal";
	v = "";
 } else {
	d.className = "tk-taal-active"
	v = "1";
 }
 if (welke == "toys") s_opt_toys = v;
 if (welke == "pierce") s_opt_pierce = v;
 if (welke == "tats") s_opt_tats = v;
 if (welke == "online") s_opt_online = v;
 if (welke == "one") s_opt_one = v;
}



function search() {
 var d = 0;
 var p = new Array;
 var s = "";

 // safety first
 $("search_nickname").value = $("search_nickname").value.replace("|", "");
 $("search_nickname").value = $("search_nickname").value.replace(";", "");
 $("search_nickname").value = $("search_nickname").value.replace("\"", "");
 $("search_nickname").value = $("search_nickname").value.replace("'", "");
 $("search_nickname").value = $("search_nickname").value.replace("?", "");
 $("search_nickname").value = $("search_nickname").value.replace("&", "");

 if ($("search_nickname").value!="") p[d++] = "nick|"+$("search_nickname").value;
 if ($("search_language").value!="") p[d++] = "taal|"+$("search_language").value;
 if ($("search_category").value!="") p[d++] = "sex|"+$("search_category").value;
 if ($("search_age").value!="")      p[d++] = "age|"+$("search_age").value;
 if ($("search_type").value!="")     p[d++] = "type|"+$("search_type").value;
 if ($("search_sign").value!="")     p[d++] = "sign|"+$("search_sign").value;
 if ($("search_hair").value!="")     p[d++] = "haar|"+$("search_hair").value;
 if ($("search_sex").value!="")      p[d++] = "aard|"+$("search_sex").value;
 if ($("search_cup").value!="")      p[d++] = "cup|"+$("search_cup").value;
 if ($("search_figure").value!="")   p[d++] = "figuur|"+$("search_figure").value;

 if (s_opt_toys+s_opt_pierce+s_opt_tats+s_opt_online+s_opt_one!="") {
  if (s_opt_toys!="")   p[d++] = "toys|1";
  if (s_opt_pierce!="") p[d++] = "pierce|1";
  if (s_opt_tats!="")   p[d++] = "tats|1";
  if (s_opt_online!="") p[d++] = "online|1";
  if (s_opt_one!="")    p[d++] = "one|1";
 }

 s = p.join(";");

 // alert(s);
 getSearch(s,0);
}




var oldparams = "";
function getSearch(params,offset) {
 oldparams=params;
	var req = new Request.HTML({url:'getcams_request.php?search='+params+(offset!=0?"&pager_offset="+offset:""), 
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('search_results').set('text', '');
			//Inject the new DOM elements into the results div.
			$('search_results').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('search_results').set('text', 'Er is een fout opgetreden.');
		}
	});
	req.send();
	return false;
}



function getPage(wat) {
 pager_offset = wat;
 getCams();
}

function getSearchPage(wat) {
 getSearch(oldparams,wat);
}







function changeFav() {
	var req = new Request.HTML({url:'getcams_fav.php', 
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('favcontent').set('text', '');
			//Inject the new DOM elements into the results div.
			$('favcontent').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('favcontent').set('text', 'Er is een fout opgetreden.');
		}
	});
	req.send();
	return false;
}





function addFav(wie) {
 var curCook = Cookie.read('favs');
 var s = "";
 if (curCook) {
  s = curCook+"|";
 }
 if (s.indexOf(wie)>=0) {
  alert("Deze cam staat al in jouw favorieten");
  return false;
 }
 s = s + wie;
 var myCookie = Cookie.write('favs', s, {duration: 14} );
// alert(wie+"***"+s);
 changeFav();
}

function delFav(wie) {
 var curCook = Cookie.read('favs');
 var a = curCook.split("|");
 var b = new Array();
 var c = 0;

 var s = "";
 var i = 0;
 for (i=0; i<a.length; i++) {
  if (a[i]!=wie && a[i]!="") b[c++] = a[i];
 }
 s = b.join("|");

 var myCookie = Cookie.write('favs', s, {duration: 14} );
// alert(wie+"***"+s);
 changeFav();
}


function resetLang() {
 document.getElementById("lang_NL").className = "tk-taal";
 document.getElementById("lang_IT").className = "tk-taal";
 document.getElementById("lang_FR").className = "tk-taal";
 document.getElementById("lang_DE").className = "tk-taal";
 document.getElementById("lang_ES").className = "tk-taal";
 document.getElementById("lang_EN").className = "tk-taal";
 document.getElementById("lang_TU").className = "tk-taal";
 p_lang = "";
}

function resetSex() {
 document.getElementById("sex_Dames").className = "tk-taal";
 document.getElementById("sex_Koppels").className = "tk-taal";
 document.getElementById("sex_Heren").className = "tk-taal";
 document.getElementById("sex_Shemales").className = "tk-taal";
 p_sex = "";
}

function resetAge() {
 document.getElementById("jaar_18").className = "tk-taal-active";
 document.getElementById("jaar_25").className = "tk-taal-active";
 document.getElementById("jaar_35").className = "tk-taal-active";
 document.getElementById("jaar_45").className = "tk-taal-active";
 document.getElementById("jaar_55").className = "tk-taal-active";
 p_jaar = "";
}

function resetAgeBack() {
 document.getElementById("jaar_18").className = "tk-taal";
 document.getElementById("jaar_25").className = "tk-taal";
 document.getElementById("jaar_35").className = "tk-taal";
 document.getElementById("jaar_45").className = "tk-taal";
 document.getElementById("jaar_55").className = "tk-taal";
 p_jaar = "";
}

function getSubCams(wat) {
 p_other = "";
 pager_offset = 0;

 switch (wat) {
  case 1:
	// vrouwen
	resetLang();
	resetSex();
	resetAge();

	document.getElementById("sex_Dames").className = "tk-taal-active";
	p_sex = "D";
	getCams();
	break;
  case 2:
	// Hollands
	resetLang();
	resetSex();
	resetAge();

	document.getElementById("lang_NL").className = "tk-taal-active";
	p_lang = "NL";
	getCams();
	break;
  case 3:
	// English
	resetLang();
	resetSex();
	resetAge();

	document.getElementById("lang_EN").className = "tk-taal-active";
	p_lang = "EN";
	getCams();
	break;
  case 4:
	// mannen
	resetLang();
	resetSex();
	resetAge();

	document.getElementById("sex_Heren").className = "tk-taal-active";
	p_sex = "H";
	getCams();
	break;
  case 5:
	// shemales
	resetLang();
	resetSex();
	resetAge();

	document.getElementById("sex_Shemales").className = "tk-taal-active";
	p_sex = "S";
	getCams();
	break;






  case 6:
	// stellen
	resetLang();
	resetSex();
	resetAge();

	document.getElementById("sex_Koppels").className = "tk-taal-active";
	p_sex = "K";
	getCams();
	break;

  case 7:
	// 18+
	resetLang();
	resetSex();
	resetAgeBack();

	document.getElementById("sex_Dames").className = "tk-taal-active";
	p_sex = "D";

	document.getElementById("jaar_18").className = "tk-taal-active";
	p_jaar = "18";
	getCams();
	break;

  case 8:
	// Rijp
	resetLang();
	resetSex();
	resetAgeBack();

	document.getElementById("jaar_35").className = "tk-taal-active";
	document.getElementById("jaar_45").className = "tk-taal-active";
	document.getElementById("jaar_55").className = "tk-taal-active";
	p_jaar = "354555";
	getCams();
	break;

  case 9:
	// one2one
	resetLang();
	resetSex();
	resetAge();
	p_other = "&one2one=Y";

	getCams();
	break;

  case 10:
	// HD live
	resetLang();
	resetSex();
	resetAge();
	p_other = "&hdlive=Y";

	getCams();
	break;


  default:
	// Alle cams
	resetLang();
	resetSex();
	resetAge();

	getCams();
 }
 return false;
}


function clear() {
 $("search_nickname").value = "";
 $("search_language").value = "";
 $("search_category").value="";
 $("search_age").value="";
 $("search_type").value="";
 $("search_sign").value="";
 $("search_hair").value="";
 $("search_sex").value="";
 $("search_cup").value="";
 $("search_figure").value="";
 s_opt_toys="";
 s_opt_pierce="";
 s_opt_tats="";
 s_opt_online="";
 s_opt_one="";
 $("search_toys").className="tk-taal";
 $("search_pierce").className="tk-taal";
 $("search_tats").className="tk-taal";
 $("search_online").className="tk-taal";
 $("search_one").className="tk-taal";
 $('search_results').set('text', '');
}