var a1;
$(function() { 
  	var toggleMinus = '/img/icons/system/bullet_toggle_minus.png';
    var togglePlus = '/img/icons/system/bullet_toggle_plus.png';
		
		var tbId = null;
  	var $subHead = $('tbody.collapse tr.trhead td:first-child');
    $subHead.prepend('<img src="' + togglePlus + '" alt="Collapse/expand" class="left-align toggle" />');

	 	$('img', $subHead).addClass('clickable')
		.click(function() {
			tbId=$(this).parents('tbody').attr('id');
			var toggleSrc = $(this).attr('src');
      if ( toggleSrc == toggleMinus ) {
				$.cookie('expandstatus'+tbId, togglePlus)
        $(this).attr('src', togglePlus)
        .parents('tr').siblings('tr.collapsetr').fadeOut('fast')
      } else{
				$.cookie('expandstatus'+tbId, toggleMinus)
        $(this).attr('src', toggleMinus)
        .parents('tr').siblings('tr.collapsetr').fadeIn('fast')
      };
			//alert(tbId);
    })
		.each(function(i) {
				//Create tbody IDs
				if($(this).parents('tbody').attr('id')==''){
					$(this).parents('tbody').attr('id', 'tbodyId'+i);
					//Reset all cookies
					//$.cookie('expandstatus'+tbId, null);
					tbId=$(this).parents('tbody').attr('id');
					if ((($(this).parents('tbody').attr('class').indexOf("initexpanded")>0)&&($.cookie('expandstatus'+tbId)==null))||($.cookie('expandstatus'+tbId)==toggleMinus)){
						$(this).attr('src', toggleMinus);
					}else{
						$(this).parents('tr').siblings('tr.collapsetr').hide();
					}
				}else{
					$(this).parents('tr').siblings('tr.collapsetr').hide();
				}
				
    });

	
});	
	


function confirmDelete(){
	if (confirm('Please note! This action can NOT be undone. Are you sure you want to delete?')){
		return true;
	}else{
		return false;
	}
}

function validatePwd(formObj){
	if(!isValidEmail(formObj.newemail.value)){
		alert('Valid email address is mandatory!');
		formObj.newemail.focus();
		return false;
	}
	if(formObj.pwd.value != formObj.pwd2.value){
		alert('Password fields dont match!');
		formObj.pwd.focus();
		return false;
	}
	return true;
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


function printCase(pUrl){
	window.open(pUrl, "TeethRusCase", "height=700,width=990,titelbar=0,channelmode=0,screenX=0,left=30,screenY=0,top=30,hotkeys=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=1,resizable=1,scrollbars=1,status=0,toolbar=0");
	return false;
}
