$(document).ready(function() {
   $('a[rel*=lightbox]').lightBox();
});
// set password to MD5() password
function userSubmit(code){
	
	var md5_passw;
	var md5_code;

	md5_passw = hex_md5(document.getElementById('password').value);
	md5_code = hex_md5(md5_passw + code);
	
	document.getElementById('md5_passw').value = md5_code;

	return true;
}


// check if only one radio button selected in group
function isOneRadioButtonSelected(rb_group) {
	
	var rb_group_node_count = rb_group.length;
	var selected = 0;

	for(i = 0; i < rb_group_node_count; i++) {
		
		if(rb_group[i].checked) {
			selected = selected + 1;
			if(selected > 1) {
				return false;
			}
		}
	}
	
	return (selected == 1);
}


// reset radio button group
function resetRadioButtonGroup(rb_group) {
	var rb_group_node_count = rb_group.length;
	var selected = 0;

	for(i = 0; i < rb_group_node_count; i++) {		
		rb_group[i].checked = false;
	}
}



function isAnyCheckboxSelected(cb_group, alert_text) {

	var cb_count;
	var cb_group_element;

	cb_group_element = document.getElementsByName(cb_group);

	cb_count = cb_group_element.length;

	for(i = 0; i < cb_count; i++) {
		if(cb_group_element[i].checked) {
			return true;			
		}
	}

	alert(alert_text);

	return false;
}

function DraugiemSay( title, url, titlePrefix, text ){
  window.open(
   'http://www.draugiem.lv/say/ext/add.php?title=' + encodeURIComponent( title ) +
   '&link=' + encodeURIComponent( url ) +
   ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ) +
   ( text ? '&text='+ encodeURIComponent(text) : ''),
   '',
   'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
  );
  return false;
 }
 
 function toggleSimpleDiv(element){
      if(document.getElementById(element).style.display == 'none')
      {
        document.getElementById(element).style.display = 'block';
      }
      else if(document.getElementById(element).style.display == 'block')
      {
        document.getElementById(element).style.display = 'none';
      }
}

function addBookmark(){
  if(navigator.appName == 'Microsoft Internet Explorer' || (navigator.appName == 'Netscape' && navigator.appVersion.indexOf('Chrome') == -1 )){
    if(document.all){
      window.external.AddFavorite(location.href,document.title);}
    else if(window.sidebar){
      window.sidebar.addPanel(document.title,location.href,'');
    }
  }else{
    alert('If you see an error message, then your browser does not support automatic bookmarking script. You can manually add to your favourites by depressing keys \'\'CTRL\'\' & \'\'D\'\' at the same time!');
  }
}

function scrollFirstPageImages() {
  var imagesCount = $("#slide-images li").size();    
  var currentImage = $("#slide-images li:visible").attr('id');  
  if(imagesCount > 1) {  
    var nextimage = 1+parseFloat(currentImage);    
    if(nextimage > imagesCount) {
      var nextimage = 1;
    } 
    $("#slide-images li#"+currentImage).fadeOut(1000, '', function() {
      $("#slide-images li#"+nextimage).fadeIn(1000);
    });                   
  }  
}
