function showItem(module, id) {   
 var node = document.getElementById(module).childNodes[3];
 var length2 = node.childNodes.length;
 var modulo = 2;
 var modulo1 = 1;
 var modulo2 = (length2 + 1)/2;
 var modulo3 = 2;    

  var length = node.childNodes.length;
      
  for(var i=0; i<length; i++) {
   var currentNode = node.childNodes[i];
   if(i == (id * modulo) + modulo1) {
     currentNode.style.display = 'block'; 
   } else if(currentNode.nodeName == 'DIV') {
     currentNode.style.display = 'none'; 
   } else if(i == (id * modulo3) + modulo2) {     
     currentNode.className = "active"; 
   } else if(currentNode.nodeName == 'A') {
     currentNode.className = "";
   }      
  }  
}

function confirmDelete()
{
    return confirm("Are you sure you wish to delete this entry?");
}

function show(id) {
  var node = document.getElementById(id);
  node.style.display = 'block';
}

function hide(id) {
  var node = document.getElementById(id);
  node.style.display = 'none';
}

function showInline(element) {
   $(".secblock").hide();
   $("select[name='IdSection']").attr('disabled','disabled');
   $("#section" + element.value).show();
   $("#ssection" + element.value).removeAttr('disabled');
}

function logon()
{
	f = document.user;
	f.submit();
}

function login(element,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	{
	   document.user.submit();
	   return false;
	}


	else
	   return true;
}

function set_price()
{
	f = document.subscribe_form;
	elInfo = document.getElementById('SubsInfo');
	elPrice = document.getElementById('Price');
	SubsId = f.SubsType.options[f.SubsType.selectedIndex].value;
	elInfo.innerHTML = SubsTypes[SubsId];
	elPrice.innerHTML = SubsPriceText[SubsId];
	f.amount.value = SubsCosts[SubsId];
}

function show_subscr_alert(msg)
{
    $('#bubble p:first-child').html(msg);
    $('#bubble').css('top', ($('#submit_button').offset().top-$('#bubble').height())+'px' );
    $('#bubble').css('left', ($('#submit_button').offset().left+15)+'px' );
    $('#bubble').fadeIn();
}
function hide_subscr_alert()
{
    $('#bubble').hide();
}
function form_submit()
{
	if ( $.trim( $("input[name='Password']").val() ) == "")
    return show_subscr_alert("Please enter a valid password.");

  if ( $("input[name='Password2']").val() != $("input[name='Password']").val())
    return show_subscr_alert("Password confirmation do not match.");
		
  if(!$("input[name='subscription']:checked").val())
		return show_subscr_alert("Please select your subscription type.");
  
	if ( $("input[name='Name']").val() == "First Name" || $.trim( $("input[name='Name']").val() ) == "" )
    return show_subscr_alert("Please enter a value for the 'Name' field.");

	if ( $("input[name='Surname']").val() == "Surname" || $.trim( $("input[name='Surname']").val() ) == "" )
    return show_subscr_alert("Please enter a value for the 'Surname' field.");

	if ( $("input[name='Company']").val() == "Company" || $.trim( $("input[name='Company']").val() ) == "" )
    return show_subscr_alert("Please enter a value for the 'Company' field.");

	var re = /^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/;
	if (!re.test( $("input[name='Email']").val() ))
    return show_subscr_alert("Please enter a valid email address.");

	var re = /^[0-9\s-]{6,20}$/;
	if (!re.test( $("input[name='Phone']").val() ))
    return show_subscr_alert("Please enter a valid phone number.");

	if ( $("input[name='Address1']").val() == "Address 1" || $.trim( $("input[name='Address1']").val() ) == "" )
    return show_subscr_alert("Please enter a value for the 'Address 1' field.");

	if ( $("input[name='City']").val() == "Town/City" || $.trim( $("input[name='City']").val() ) == "" )
    return show_subscr_alert("Please enter a value for the 'City' field.");

	if ( $("#country").attr("selectedIndex") == 0)
    return show_subscr_alert("Please enter a country.");

	if ( $("input[name='Postcode']").val() == "Postalcode/Zip" || $.trim( $("input[name='Postcode']").val() ) == "" )
    return show_subscr_alert("Please enter a valid post code.");
  
  if ( $("input[name='recaptcha_response_field']").val() == '')
    return show_subscr_alert("Please enter a security code.");
  
  if ( $('#tccheckbox:checked').val() != '1')
    return show_subscr_alert("Please confirm that you have read and agree to the Terms & Conditions.");

  $("#subscribe_form").submit();
}

function job_submit(nosalary)
{
	f = document.job_form;

	if (f.jobtitle.value == '') {
		alert("Please enter a value for Title");
		return (false);
	}
	if (nosalary == 1){
  	if (f.salary.value == '') {
  		alert("Please enter a value for Salary");
  		return (false);
  	}
  }
	if (f.location.value == '') {
		alert("Please enter a value for Location");
		return (false);
	}
	
	var re = /^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/;
	if (!re.test(f.email.value))
	{
		alert("Please enter a valid email address.");
		return (false);
	}

	var re = /^[0-9\s-]{6,20}$/;
	if (!re.test(f.phone.value))
	{
		alert("Please enter a valid phone number.");
		return (false);
	}	

    f.submit();
}

function item_submit()
{
	f = document.item_form;

	if (f.Title.value == '' || f.Title.value == 'Article Title') {
		alert("Please enter a value for Title");
		return (false);
	}
	/*if (f.Header.value == '') {
		alert("Please enter a value for Headline");
		return (false);
	}
	if (f.Body.value == '') {
		alert("Please enter a value for Content");
		return (false);
	}	*/

    f.submit();
}

function issue_submit()
{
	f = document.issue_form;

	if (f.Title.value == '' || f.Title.value == 'Issue Title') {
		alert("Please enter a value for Title");
		return (false);
	}
	/*if (f.Summary.value == '') {
		alert("Please enter a value for Summary");
		return (false);
	}*/
    f.submit();
}

function SortableTable (tableEl) {
 
	this.tbody = tableEl.getElementsByTagName('tbody');
	this.thead = tableEl.getElementsByTagName('thead');
	this.tfoot = tableEl.getElementsByTagName('tfoot');
 
	this.getInnerText = function (el) {
		if (typeof(el.textContent) != 'undefined') return el.textContent;
		if (typeof(el.innerText) != 'undefined') return el.innerText;
		if (typeof(el.innerHTML) == 'string') return el.innerHTML.replace(/<[^<>]+>/g,'');
	}
 
	this.getParent = function (el, pTagName) {
		if (el == null) return null;
		else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
			return el;
		else
			return this.getParent(el.parentNode, pTagName);
	}
 
	this.sort = function (cell) {
 
	    var column = cell.cellIndex;
	    var itm = this.getInnerText(this.tbody[0].rows[1].cells[column]);
		var sortfn = this.sortCaseInsensitive;
 
		if (itm.match(/\d\d[-]+\d\d[-]+\d\d\d\d/)) sortfn = this.sortDate; // date format mm-dd-yyyy
		if (itm.replace(/^\s+|\s+$/g,"").match(/^[\d\.]+$/)) sortfn = this.sortNumeric;
 
		this.sortColumnIndex = column;
 
	    var newRows = new Array();
	    for (j = 0; j < this.tbody[0].rows.length; j++) {
			newRows[j] = this.tbody[0].rows[j];
		}
 
		newRows.sort(sortfn);
 
		if (cell.getAttribute("sortdir") == 'down') {
			newRows.reverse();
			cell.setAttribute('sortdir','up');
		} else {
			cell.setAttribute('sortdir','down');
		}
 
		for (i=0;i<newRows.length;i++) {
			this.tbody[0].appendChild(newRows[i]);
		}
 
	}
 
	this.sortCaseInsensitive = function(a,b) {
		aa = thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]).toLowerCase();
		bb = thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]).toLowerCase();
		if (aa==bb) return 0;
		if (aa<bb) return -1;
		return 1;
	}
 
	this.sortDate = function(a,b) {
		aa = thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]);
		bb = thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]);
		date1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
		date2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
		if (date1==date2) return 0;
		if (date1<date2) return -1;
		return 1;
	}
 
	this.sortNumeric = function(a,b) {
		aa = parseFloat(thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]));
		if (isNaN(aa)) aa = 0;
		bb = parseFloat(thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]));
		if (isNaN(bb)) bb = 0;
		return aa-bb;
	}
 
	// define variables
	var thisObject = this;
	var sortSection = this.thead;
 
	// constructor actions
	if (!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length > 0)) return;
 
	if (sortSection && sortSection[0].rows && sortSection[0].rows.length > 0) {
		var sortRow = sortSection[0].rows[0];
	} else {
		return;
	}
 
	for (var i=0; i<sortRow.cells.length; i++) {
		sortRow.cells[i].sTable = this;
		sortRow.cells[i].onclick = function () {
			this.sTable.sort(this);
			return false;
		}
	}
 
}
function toggleFrontArticle(prefix, id){
  $("."+prefix+":visible").hide();
  $("#"+prefix+id).show();
}

function addBookmark(Id, Section){
    $.ajax({  url: "index.php?func=AddBookmark&Id="+Id+"&Section="+Section, 
              success: function(data) {
                  alert(data);
              }
    });
}
