var lastSubmitTime=0;

function showHide(id){
	ID = document.getElementById(id);

	if(ID.style.display == "")
	ID.style.display = "none";
	else
	ID.style.display = "";
}

function ConfirmMsg(newurl,message) {
	if (confirm( message ) )
	{
		parent.location=newurl;

	}

}

function doLinkConfirm( oObj, message ) {
	if ( !oObj.getAttribute('o_href') ) {
		var oAttr = document.createAttribute("o_href");
		oAttr.value = oObj.href;
		oObj.setAttributeNode(oAttr);
		oObj.href = '#';
	}

	if ( !message ) {
		message = 'Kustuta ?';
	}

	if ( confirm(message) ) {
		var oAttr = oObj.getAttribute('o_href');
		window.location.href = oAttr;
	}
	return false;
}

function findForm ( oObj ) {
	var notFound = true;
	var oForm = null;
	while ( notFound ) {
		if ( !oObj ) {
			notFound = false;
			continue;
		}

		if ( !oObj.parentNode ) {
			notFound = false;
			continue;
		}

		if ( oObj.tagName.toLowerCase() == 'form' ) {
			oForm = oObj;
			notFound = false;
			continue;
		}
		oObj = oObj.parentNode;
	}

	return oForm;
}


function submitForm ( oImage, sSubmitUrl ) {

	/**
	*
	* Double click trapping
	*/

	var tDate = new Date;
	var localTrapTime = tDate.valueOf();

	if (lastSubmitTime>0 && (localTrapTime - lastSubmitTime) < (1 * 1000)) {

	}
	else {
		lastSubmitTime=localTrapTime;
		var oForm = findForm ( oImage );

		if ( oForm == null ) {
			return false;
		}

		if ( sSubmitUrl && sSubmitUrl.length ) {
			oForm.action = sSubmitUrl;
		}

		if ( oForm.onsubmit ) {
			oForm.onsubmit();
		}

		oForm.submit();
		return true;
	}
}


function toggleRowsOn(tableId, start, end){

	tbl = document.getElementById(tableId);

	var vStyle = "";

	for(i=start ; i< end; i++){
		if (tbl.rows[i]) tbl.rows[i].style.display = vStyle;
	}
}

function toggleRowsOff(tableId, start, end){

	tbl = document.getElementById(tableId);

	var vStyle = "none";

	for(i=start ; i< end; i++){
		if (tbl.rows[i]) tbl.rows[i].style.display = vStyle;
	}

}

function get_selected(object){
	for (var i = 0; i < object.length; i++) {
		if (object[i].selected) return(object[i].value);
	}
}

function openPopup( link, name, width, height ) {
	if ( !width ) { width = 510; }
	if ( !height ) { height = 510; }
	
	
	var left = Math.floor( screen.availWidth / 2 ) - Math.floor( width / 2 );
	var top = Math.floor( screen.availHeight / 2 ) - Math.floor( height / 2 );
	prop = 'toolbar=0,directories=0,menubar=0,status=yes,resizable=1,location=0,scrollbars=1,copyhistory=0'

	var win = window.open( link, name, 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',' + prop );
		
	if ( win ) win.focus();
	
	return win;
}


