// Common JavaScript

<!--//SHOW HIDE CODE
function showhide(layer_ref){
	state = document.getElementById(layer_ref).style.display;
	if (state == 'none') {
			state = ''; 
	} else {
			state = 'none';
	}
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = state; 
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.display = state; 
	}
}
//-->

<!--//SWAP contents of a tag
function swap(me,main,alt) {
	me.innerHTML = (me.innerHTML == main) ? alt : main;
}
//-->

<!--// Pop-up windows
var popUpWin=0;
function popup(URLStr, width, height){
  if(width == ''){
	  width = 700;
  }
  if(height == ''){
	  height = 600;
  }
  if(popUpWin){
    if(!popUpWin.closed){
		popUpWin.close();
	}
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+'px,height='+height+'px,left=100px, top=100px,screenX=100px,screenY=100px');
}
//-->


<!--// Add link to browser favourites
var popUpWin=0;
function addtofavourites(url, title){
	if (window.sidebar) // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	else if( window.external ) // IE Favorite
		window.external.AddFavorite( url, title);
	else if(window.opera && window.print) // Opera Hotlist
		return true;
}
//-->

<!--// Image Resizing in popup
function toggleimgstretch(layer_ref){
	size = document.getElementById(layer_ref).style.width;
	if (size == 'auto') {
			size = '95%'; 
			windowwidth = 300;
			windowheight = 350;
			windowposx = 100;
			windowposy = 100;
	} else {
			size = 'auto';
			windowwidth = screen.width;
			windowheight = screen.height;
			windowposx = 0;
			windowposy = 0;
	}
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.width = size");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].width = size; 
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.width = size; 
	}
	self.resizeTo(windowwidth, windowheight);
	self.moveTo(windowposx, windowposy);
}
//-->

<!--// Add File include to textarea
function addfiletopost(file){
	document.post_form.body.value += ' <img src="post_files/'+file+'" />';
	document.post_form.body.focus();
}
//-->

<!--// Add specified text to textarea
function addtexttopost(text){
	document.post_form.body.value += text;
	document.post_form.body.focus();
}
//-->

<!--// Add link to textarea
function addlinktopost(){
	var link_url = prompt("Link URL?", "http://");
	var link_text = prompt("Link Text?");
	if(link_text == '' || link_text == null){
		text = '(<a href="'+link_url+'" target="_blank">link</a>)';
	} else {
		text = '<a href="'+link_url+'" target="_blank">'+link_text+'</a>';
	}
	document.post_form.body.value += text;
	document.post_form.body.focus();
}
//-->

<!--// Add youTube embed to textarea
function addyoutubetopost(){
	var youtube_url = prompt("Link URL?", "http://");
	var full_link = confirm("Was that the full url?");
	if(full_link)
		youtube_code = youtube_url.substr(31);
	else
		youtube_code = youtube_url;
	text = '<object type="application/x-shockwave-flash"  data="http://www.youtube.com/v/'+youtube_code+'" width="300" height="247" class="floatright"><param name="movie" value="http://www.youtube.com/v/'+youtube_code+'"></param><param name="quality" value="best" /><param name="wmode" value="transparent"></param></object>';
	document.post_form.body.value += text;
	document.post_form.body.focus();
}
//-->

<!--// Ajax Comment Form Submit
function submit_form(postid){
	/* submit form */
	$.post("0-common/scripts/add_comment.php",{ 
		name: $("#name_"+postid).val(),
		email: $("#email_"+postid).val(),
		notify: $("#notify_"+postid).val(),
		bodytext: $("#body_"+postid).val(), 
		list: $("#list_"+postid).val(),
		post_id: $("#post_id_"+postid).val()
	}, function(msg) {
		/* callback function to deal with post request */
		alert(msg);
		if(msg == 'Comment saved. Thanks!'){
			/* use ajax to bring new comment into div immediately */
			var now = new Date();
			$("#comments_"+postid+" .style_comments").prepend("<div id=\"NEWCOMMENT\"></div>");
			$("#NEWCOMMENT").hide().append("<p class=\"comment_name\"><span class=\"comment_date\">"+now.toGMTString()+"</span>"+$("#name_"+postid).attr("value")+"</p><p>"+$("#body_"+postid).attr("value")+"</p>").SlideInUp(500);
			/* update number of comments text */
			var numcomments = $("#num_comments_"+postid).attr("value");
			numcomments++;
			if(numcomments == 1)
				$("#comment_link_"+postid).text("1 Comment");
			else
				$("#comment_link_"+postid).text(numcomments+" Comments");
			/* clear form if successful */
			$("#name_"+postid).attr("value","");
			$("#email_"+postid).attr("value","");
			$("#body_"+postid).attr("value","");
		}
		/* enable submit button again */
		$("#submit_"+postid).removeAttr("disabled");
		$("#submit_"+postid).attr("value","Save Comment");	
	});
};
//-->

<!--// Ajax Share Post by Email Form Submit
function share_email(postid){
	/* submit form */
	$.post("0-common/scripts/share_email.php",{ 
		name: $("#email_name_"+postid).val(),
		toemail: $("#email_toemail_"+postid).val(),
		body: $("#email_body_"+postid).val(), 
		post_id: $("#email_post_id_"+postid).val()
	}, function(msg) {
		/* callback function to deal with post request */
		alert(msg);
		if(msg == 'E-mail sent. Thanks!'){
			/* clear form if successful */
			$("#name_"+postid).attr("value","Your Name");
			$("#toemail_"+postid).attr("value","Send To (seperate with a comma)");
			$("#body_"+postid).attr("value","[ Optional Message ]");
		}
		/* enable submit button again */
		$("#submit_email_"+postid).removeAttr("disabled");
		$("#submit_email_"+postid).attr("value","Send");	
	});
};
//-->

<!--// Site style cookie set
function setStyle(style) {
	document.cookie = "style="+style+"; expires=Fri, 31-Dec-2010 23:59:59; path=/";
	window.location.href=window.location.href;
}
//-->

<!--// Basic / Advanced link on search page
function searchmode() {
	showhide('advanced_search');
	document.getElementById('case').checked = 0;
	document.getElementById('mode').selectedIndex = 0;
	swap(document.getElementById('advancedlink'),'Basic Search','Advanced Search');
}
//-->