
// Toggle function
function toggle(id)
{	
	var md = document.getElementById(id);		
	if (md !== null) 
	{
		if (md.style.display == 'none' || md.style.display == '') {
			md.style.display = 'block';
		}
		else if (md.style.display == 'block') {
			md.style.display = 'none';
		}
	}	
}



function remove_confirmation(obj)
{
	res = confirm("Delete this entry?");
	return res;
}


function reset_confirmation(obj)
{
	res = confirm("Continuing will cause all changes to be lost.");
	return res;
}

// Confirm if the user really want to logout the session
function logout_confirmation(obj)
{
	msg = "Are you sure to logout?";
	return confirm(msg);
}


// Search functions

function doSearch(formid)
{
	obj = document.getElementById( formid );
	if (obj.offset)
	{
		obj.offset.value = "0";
	}
	if (obj.submit)
	{
		obj.submit();
	}
}


// Paging utilities

function goPage(offset, rowsperpage, formid)
{
	obj = document.getElementById( formid );
	obj = document.getElementById( "rowsperpage" );
	if (obj!=null)
	{
		obj.value = rowsperpage;
	}

	obj = document.getElementById( "offset" );
	if (obj!=null)
	{
		obj.value = offset;
	}
	
	obj = document.getElementById( formid );
	if (obj!=null)
	{
		obj.submit();
	}
	return;
}

// This function allows to toggle div visibility
function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none'){
	  document.getElementById(divid).style.display = 'block';
	}else{
	  document.getElementById(divid).style.display = 'none';
	}
}

function customFocus(id)
{
	obj = document.getElementById('searchValue');
	if (obj!=null)
	{
		obj.focus();
	}
}


function remove_item(formid, table, id)
{
	obj = document.getElementById(formid);
	if (obj!=null)
	{
		obj.removeid.value = id;
		obj.table.value = table;
		obj.submit();
	}
}

function validatePhoneNumber(el) {
	// strip all dashes from el.value
	el.value = el.value.replace(/[-]+/g, '');
}
function submitEditForm() {
	validatePhoneNumber(document.editform.phone);			
	validatePhoneNumber(document.editform.fax);
}
