function openwindow(rec_id)
{
	window.open("includes/view_rec_details.php?rec_id=" + rec_id,"my_new_window" + rec_id, "scrollbars=yes,resizable,height=400,width=600,top=0,left=0");
	return false;
}
function openreport(rec_id)
{
	window.open("includes/report.php?rec_id=" + rec_id,"my_new_window" + rec_id, "scrollbars=yes,height=400,width=600,top=0,left=0")
}
function show_help(url)
{
	window.open(url, "Help", "scrollbars=yes,height=400,width=600,top=0,left=0")
}
function sure()
{
	var answer=confirm("Are you sure to delete this Recommendation?");
	if (answer) {
		 return true;
	} else {
		return false;
	}
}
function chkFormular(preview)
{
 if(document.rec_input.category_id.value == "0") {
   alert("You have to choose a category!");
   document.rec_input.category_id.focus();
   return false;
  }
 if(document.rec_input.title.value == "")  {
   alert("Please enter a title!");
   document.rec_input.title.focus();
   return false;
  }
 if(document.rec_input.author.value == "") {
   alert("Please enter an author name!");
   document.rec_input.author.focus();
   return false;
  }
 if(document.rec_input.author_url.value != "") {
 	var str = document.rec_input.author_url.value;
 	if (str.length < 14 || str.indexOf ('.',0) == -1 || str.indexOf ('http://', 0) == -1) {
 		alert("You have to enter a valid Author's URL!");
  		document.rec_input.author_url.focus()
  		return false;
 	}
 }
 var str = document.rec_input.location.value;
 if (str.length < 14 || str.indexOf ('.',0) == -1 || str.indexOf ('http://', 0) == -1) {
 	alert("You have to enter a valid URL for Location!");
  	document.rec_input.location.focus()
  	return false;
 }
 if(document.rec_input.alt1_location.value != "") {
 	var str = document.rec_input.alt1_location.value;
 	if (str.length < 14 || str.indexOf ('.',0) == -1 || str.indexOf ('http://', 0) == -1) {
 		alert("You have to enter a valid Alternate Location1(URL)!");
  		document.rec_input.alt1_location.focus()
  		return false;
 	}
 }
 if(document.rec_input.alt2_location.value != "") {
 	var str = document.rec_input.alt2_location.value;
 	if (str.length < 14 || str.indexOf ('.',0) == -1 || str.indexOf ('http://', 0) == -1) {
 		alert("You have to enter a valid Alternate Location2(URL)!");
  		document.rec_input.alt2_location.focus()
  		return false;
 	}
 }
 if(document.rec_input.alt3_location.value != "") {
 	var str = document.rec_input.alt3_location.value;
 	if (str.length < 14 || str.indexOf ('.',0) == -1 || str.indexOf ('http://', 0) == -1) {
 		alert("You have to enter a valid Alternate Location3(URL)!");
  		document.rec_input.alt3_location.focus()
  		return false;
 	}
 }
 var sal = document.rec_input.words.value; var chkZ = 1;
 for(i=0;i<sal.length;++i)
 	if(sal.charAt(i) < "0" || sal.charAt(i) > "9")  chkZ = -1;
    	if(chkZ == -1) {
    		alert("The field words can be numbers only!");
    		document.rec_input.words.focus()
  			return false;
		}
 if(document.rec_input.words.value == "0") {
   alert("A fic with 0 words is no fic at all!");
   document.rec_input.words.focus();
   return false;
  }
 var sal = document.rec_input.chapters.value; var chkZ = 1;
 for(i=0;i<sal.length;++i)
 	if(sal.charAt(i) < "0" || sal.charAt(i) > "9")  chkZ = -1;
    	if(chkZ == -1) {
    		alert("The field Chapters can be numbers only!");
    		document.rec_input.chapters.focus()
  			return false;
		}
 if(document.rec_input.chapters.value == "0") {
   alert("A fic with 0 chapters is no fic at all!");
   document.rec_input.chapters.focus();
   return false;
  }
 if(document.rec_input.is_oneshot.checked == true && document.rec_input.chapters.value != "1") {
   alert("A one-shot can only contain 1 chapter!");
   document.rec_input.is_oneshot.focus();
   return false;
  }
 if (document.rec_input.series) {
 	var sal = document.rec_input.series.value; var chkZ = 1;
 	for(i=0;i<sal.length;++i)
 		if(sal.charAt(i) < "0" || sal.charAt(i) > "9")  chkZ = -1;
 	    if(chkZ == -1) {
 	   		alert("The field Series can be integer numbers only!");
    		document.rec_input.series.focus()
  			return false;
		}
 }
 if (preview == "1") {
 	var getstr = "?category_id=" + document.rec_input.category_id.value;
 	getstr = getstr + "&title=" + document.rec_input.title.value;
 	getstr = getstr + "&author=" + document.rec_input.author.value;
 	getstr = getstr + "&author_url=" + document.rec_input.author_url.value;
 	getstr = getstr + "&rating=" + document.rec_input.rating.value;
 	getstr = getstr + "&ships=" + document.rec_input.ships.value;
 	getstr = getstr + "&based=" + document.rec_input.based.value;
 	getstr = getstr + "&genre1=" + document.rec_input.genre1.value;
 	getstr = getstr + "&genre2=" + document.rec_input.genre2.value;
	getstr = getstr + "&status=" + document.rec_input.status.value;
 	getstr = getstr + "&location=" + document.rec_input.location.value;
 	getstr = getstr + "&alt1_location=" + document.rec_input.alt1_location.value;
 	getstr = getstr + "&alt2_location=" + document.rec_input.alt2_location.value;
 	getstr = getstr + "&alt3_location=" + document.rec_input.alt3_location.value;
	if(document.rec_input.is_oneshot.checked == true) {
	 	getstr = getstr + "&is_oneshot=" + document.rec_input.is_oneshot.value;
	}
	if(document.rec_input.cat_hhr.checked == true) {
	 	getstr = getstr + "&cat_hhr=on";
	}
	if(document.rec_input.cat_dg.checked == true) {
	 	getstr = getstr + "&cat_dg=on";
	}
	if(document.rec_input.cat_jl.checked == true) {
	 	getstr = getstr + "&cat_jl=on";
	}
	if(document.rec_input.cat_rll.checked == true) {
	 	getstr = getstr + "&cat_rll=on";
	}
	getstr = getstr + "&words=" + document.rec_input.words.value;
 	getstr = getstr + "&chapters=" + document.rec_input.chapters.value;
 	getstr = getstr + "&warnings=" + document.rec_input.warnings.value;
 	getstr = getstr + "&summary=" + document.rec_input.summary.value;
 	getstr = getstr + "&comments=" + document.rec_input.comments.value;
 	var location = "includes/preview_rec_details.php" + getstr;
 	window.open(location, "my_new_window", "scrollbars=yes,height=400,width=600,top=0,left=0")
 }
}

function check_title()
{
	var title = trim(document.rec_input.title.value);
 	var location = "myrec.php?order=post_date&direction=DESC&view=&submit=sort&title=1&keyword=" + title;
 	window.open(location, "newwindow", "scrollbars=yes,height=600,width=800");

}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function multi_page_jump( url_bit, total_posts, per_page )
{
	pages = 1; cur_st = parseInt(""); cur_page  = 1;
	if ( total_posts % per_page == 0 ) { pages = total_posts / per_page; }
	else { pages = Math.ceil( total_posts / per_page ); }
	msg = "Please enter a page number to jump to between 1 and" + " " + pages;
	if ( cur_st > 0 ) { cur_page = cur_st / per_page; cur_page = cur_page -1; }
	show_page = 1;
	if ( cur_page < pages )  { show_page = cur_page + 1; }
	if ( cur_page >= pages ) { show_page = cur_page - 1; }
	else { show_page = cur_page + 1; }
	userPage = prompt( msg, show_page );
	if ( userPage > 0  ) {
		if ( userPage < 1 )     {    userPage = 1;  }
		if ( userPage > pages ) { userPage = pages; }
		if ( userPage == 1 )    {     start = 0;    }
		else { start = (userPage - 1) * per_page; }
		window.location = url_bit + start;
	}
}

function showtr()
{
	if (document.getElementById('mylink1').style.display =="inline") {
		document.getElementById('mylink1').style.display = "none";
		document.getElementById('mylink2').style.display = "inline";
		document.search.advanced.value ="1";
	} else {
		document.getElementById('mylink1').style.display = "inline";
		document.getElementById('mylink2').style.display = "none";
		document.search.advanced.value ="0";
	}
	if (document.getElementById('myrow').style.display =="") {
		document.getElementById('myrow').style.display = "none";
	} else {
		document.getElementById('myrow').style.display = "";
	}
	myswitch();
}

function myswitch()
{
	if ( document.search.category_id.value =="0" ) {
	    document.getElementById('hhrdif_and').style.display = "inline";
	    document.getElementById('hhrdif_or').style.display = "inline";
	 	document.getElementById('dgdif_and').style.display = "inline";
	 	document.getElementById('dgdif_or').style.display = "inline";
	 	document.getElementById('jldif_and').style.display = "inline";
	 	document.getElementById('jldif_or').style.display = "inline";
	 	document.getElementById('rlldif_and').style.display = "inline";
	 	document.getElementById('rlldif_or').style.display = "inline";
	}
	if ( document.search.category_id.value =="1" ) {
	    document.getElementById('hhrdif_and').style.display = "none";
	    document.getElementById('hhrdif_or').style.display = "inline";
	 	document.getElementById('dgdif_and').style.display = "inline";
	 	document.getElementById('dgdif_or').style.display = "inline";
	 	document.getElementById('jldif_and').style.display = "inline";
	 	document.getElementById('jldif_or').style.display = "inline";
	 	document.getElementById('rlldif_and').style.display = "inline";
	 	document.getElementById('rlldif_or').style.display = "inline";
	}
	if ( document.search.category_id.value =="2" ) {
	    document.getElementById('hhrdif_and').style.display = "inline";
	    document.getElementById('hhrdif_or').style.display = "inline";
	 	document.getElementById('dgdif_and').style.display = "none";
	 	document.getElementById('dgdif_or').style.display = "inline";
	 	document.getElementById('jldif_and').style.display = "inline";
	 	document.getElementById('jldif_or').style.display = "inline";
	 	document.getElementById('rlldif_and').style.display = "inline";
	 	document.getElementById('rlldif_or').style.display = "inline";
	}
	if ( document.search.category_id.value =="3" ) {
	    document.getElementById('hhrdif_and').style.display = "inline";
	    document.getElementById('hhrdif_or').style.display = "inline";
	 	document.getElementById('dgdif_and').style.display = "inline";
	 	document.getElementById('dgdif_or').style.display = "inline";
	 	document.getElementById('jldif_and').style.display = "none";
	 	document.getElementById('jldif_or').style.display = "inline";
	 	document.getElementById('rlldif_and').style.display = "inline";
	 	document.getElementById('rlldif_or').style.display = "inline";
	}
	if ( document.search.category_id.value =="4" ) {
	    document.getElementById('hhrdif_and').style.display = "inline";
	    document.getElementById('hhrdif_or').style.display = "inline";
	 	document.getElementById('dgdif_and').style.display = "inline";
	 	document.getElementById('dgdif_or').style.display = "inline";
	 	document.getElementById('jldif_and').style.display = "inline";
	 	document.getElementById('jldif_or').style.display = "inline";
	 	document.getElementById('rlldif_and').style.display = "none";
	 	document.getElementById('rlldif_or').style.display = "inline";
	}
	if ( document.search.category_id.value =="5" ) {
	    document.getElementById('hhrdif_and').style.display = "none";
	    document.getElementById('hhrdif_or').style.display = "none";
	 	document.getElementById('dgdif_and').style.display = "none";
	 	document.getElementById('dgdif_or').style.display = "none";
	 	document.getElementById('jldif_and').style.display = "none";
	 	document.getElementById('jldif_or').style.display = "none";
	 	document.getElementById('rlldif_and').style.display = "none";
	 	document.getElementById('rlldif_or').style.display = "none";
		document.getElementById('mylink1').style.display = "inline";
		document.getElementById('mylink2').style.display = "none";
		document.search.advanced.value ="0";
		document.getElementById('myrow').style.display = "none";
	}
}

function myswitch2()
{
	if ( document.rec_input.category_id.value == "0" ) {
	    document.getElementById('hhrdif').style.display = "none";
	 	document.getElementById('dgdif').style.display = "none";
	 	document.getElementById('jldif').style.display = "none";
	 	document.getElementById('rlldif').style.display = "none";
	 	document.rec_input.cat_hhr.checked = false;
	 	document.rec_input.cat_dg.checked = false;
	 	document.rec_input.cat_jl.checked = false;
	 	document.rec_input.cat_rll.checked = false;
	}
	if ( document.rec_input.category_id.value == "1" ) {
	    document.getElementById('hhrdif').style.display = "none";
	 	document.getElementById('dgdif').style.display = "inline";
	 	document.getElementById('jldif').style.display = "inline";
	 	document.getElementById('rlldif').style.display = "inline";
	 	document.rec_input.cat_hhr.checked = false;
	}
	if ( document.rec_input.category_id.value == "2" ) {
	    document.getElementById('hhrdif').style.display = "inline";
	 	document.getElementById('dgdif').style.display = "none";
	 	document.getElementById('jldif').style.display = "inline";
	 	document.getElementById('rlldif').style.display = "inline";
	 	document.rec_input.cat_dg.checked = false;
	}
	if ( document.rec_input.category_id.value == "3" ) {
	    document.getElementById('hhrdif').style.display = "inline";
	 	document.getElementById('dgdif').style.display = "inline";
	 	document.getElementById('jldif').style.display = "none";
	 	document.getElementById('rlldif').style.display = "inline";
	 	document.rec_input.cat_jl.checked = false;
	}
	if ( document.rec_input.category_id.value == "4" ) {
	    document.getElementById('hhrdif').style.display = "inline";
	 	document.getElementById('dgdif').style.display = "inline";
	 	document.getElementById('jldif').style.display = "inline";
	 	document.getElementById('rlldif').style.display = "none";
	 	document.rec_input.cat_rll.checked = false;
	}
	if ( document.rec_input.category_id.value == "5" ) {
	    document.getElementById('hhrdif').style.display = "none";
	 	document.getElementById('dgdif').style.display = "none";
	 	document.getElementById('jldif').style.display = "none";
	 	document.getElementById('rlldif').style.display = "none";
	 	document.rec_input.cat_hhr.checked = false;
	 	document.rec_input.cat_dg.checked = false;
	 	document.rec_input.cat_jl.checked = false;
	 	document.rec_input.cat_rll.checked = false;
	}
}

function show_search()
{
	if (document.search.mem_name.value == "") {
		alert("You can't leave this field empty!");
	} else {
		var title = trim(document.search.mem_name.value);
	 	var location = "includes/search_member.php?mem_name=" + title;
	 	window.open(location, "newwindow", "left="+ ((screen.width / 2)-150) + ",top=" + ((screen.height / 2)-50) + "),scrollbars=yes,height=100,width=300");
	}

}