function resetwidth() {
  var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	
	var e = document.getElementById('main');
	if (e) {
		var test = e.style.width.replace(/[a-z]+/,'');
		if (test < myWidth) {
			e.style.width = (myWidth + 'px');
		}
	}
}

function shownav(sel) {
	if (!sel) sel = 'nav';
	navs = new Array('nav','nav_special');
	for (i=0;i<2;i++) {
		id=navs[i];
		if ((id == sel) && ($('#'+id).css('display') == 'none')) {
			$('#'+id).slideDown(500);
		} else {
			$('#'+id).slideUp(500);
		}
	}
	return false;
}

function showcomments(id) {
	hid = '#comments_'+id;
	if ($(hid).length) {
		if ($(hid).css('display') == 'none') {
			$.post('/blog.php', {"comments":id}, function(data) {
													  data = data.split("<split>");
													  $('#comments_'+data[0]).html(data[1]);
													  });
			$(hid).slideDown(500);
		} else {
			$(hid).hide();
		}
	}
}

function showhideCountryList() {
	if ($('#countries ul').css('display') == 'none') {
		$('#countries ul').slideDown(500);
	} else {
		$('#countries ul').slideUp(500);
	}
}

function savecomment() {
	$('#comment_author').each(function(index) { $(this).css('border-color','black'); });
	$('#commentform textarea').each(function(index) { $(this).css('border-color','black'); });
	$.post('/comment.php',
		   {	"author":$('#comment_author').val(),
				"comment":$('#comment_comment').val(),
				"email":$('#comment_email').val(),
				"auth":$('#comment_auth').val(),
				"r":$('#comment_r').val(),
				"i":$('#comment_i').val()
		   }, function(data) {
			   switch(data) {
				   case "error":	alert('Oops, an error occurred.');	break;
				   case "success":	$('#commentform').html('<p>Thank you for your comment.  It should appear on the site shortly.</p>');			break;
				   default: 
				   	if ($('#comment_' + data).length) {
						$('#comment_' + data).css('border-color','red');
					} else {
						alert(data);
					}
			   }
		   }
		   );
	return false;
}

window.onload = resetwidth;
window.onresize = resetwidth;
