function changeImage ( id, src, width, height ) {
	var oImage = $( id );
	oImage.src = src;
	oImage.style.width = width;
	oImage.style.height = height;
	return false;
	
}

function over( id ) {
	var i_s = $( id ).src.split('.');
	var f = i_s.length-2;
	var regex = /_ov$/;

	if( i_s[f].match( regex ) ) {
		i_s[f] = i_s[f].replace( regex, '' );
	} else {
		i_s[f] = i_s[f] + '_ov';
	}
	
	var n_i_s = i_s.join( '.' );
	
	try {
		$( id ).src = n_i_s;
	} catch( error ) {
		// Error
	}
}

function showPopupText ( text_id ) {
	var oPopup = $( "popup" );
	var oPopupText = $( "popup_text" );
	var oText = $( text_id );
	
	oPopupText.innerHTML = oText.innerHTML;
	
	
	oPopup.style.display = 'block';
		
	popup( oPopup );
		
	return false;
}

function showPopupTextPrint ( text_id, item_id ) {
	var oPopup = $( "popup" );
	
	var oPopupTextPrint = $( "popup_text_print_m" );
	
	var oPopupId = $( "popup_id_m" );
	var oText = $( text_id );
	
	oPopupTextPrint.innerHTML = oText.innerHTML;
	oPopupId.value = item_id;
	

	oPopup.style.display = 'block';
		
	popup( oPopup );
		
	return false;
}

function showHideQuestionText ( id ) {
	var oText = $( id );
	
	if( oText.style.display == 'none' ) {
		oText.style.display = 'block';
	}else {
		oText.style.display = 'none';
	}
	
	return false;
}

function showGalleryImage( id ) {
	
	if( id != image_page_id ) {
		var oControl = $( id );
		var oImage = $( 'image' );
		var count_images = images['count'];
		
		var s_i = id.split('_');
		var i_n = s_i.length-1;
		
		oImage.src = images[s_i[i_n] - 1]['url'];
		oImage.style.width = images[s_i[i_n] - 1]['width'] + "px";
		oImage.style.height = images[s_i[i_n] - 1]['height'] + "px";
		oImage.alt = images[s_i[i_n] - 1]['name'];
		oControl.className = 'active';
		
		$( image_page_id ).className = '';
		image_page_id = id;
		
		this.showHideArrows( s_i[i_n] );
	}
	
	return false;
	
}

function showNextGalleryImage(){
	
	var oImage = $( 'image' );
	$( image_page_id ).className = '';
	var s_i = image_page_id.split('_');
	var i_n = s_i.length-1;
	var new_id = ++s_i[i_n];
	
	var oControl = $( 'image_' + new_id );
	
	oImage.src = images[s_i[i_n]-1]['url'];
	oImage.style.width = images[s_i[i_n]-1]['width'] + "px";
	oImage.style.height = images[s_i[i_n]-1]['height'] + "px";
	oImage.alt = images[s_i[i_n]-1]['name'];
	oControl.className = 'active';
	image_page_id = "image_" + new_id;
	
	this.showHideArrows( new_id );
	return false;
	
}

function showPrevGalleryImage(){
	
	var oImage = $( 'image' );
	$( image_page_id ).className = '';
	var s_i = image_page_id.split('_');
	var i_n = s_i.length-1;
	var new_id = --s_i[i_n];
	
	var oControl = $( 'image_' + new_id );
	
	oImage.src = images[s_i[i_n]-1]['url'];
	oImage.style.width = images[s_i[i_n]-1]['width'] + "px";
	oImage.style.height = images[s_i[i_n]-1]['height'] + "px";
	oImage.alt = images[s_i[i_n]-1]['name'];
	oControl.className = 'active';
	image_page_id = "image_" + new_id;
	
	this.showHideArrows( new_id );
	return false;
	
}

function showHideArrows( new_id ) {

	if( new_id == 1 ) {
		$( 'prev_arrow' ).style.display = 'none';
	}else {
		$( 'prev_arrow' ).style.display = 'block';
	}
	
	if( new_id == images_count ) {
		$( 'next_arrow' ).style.display = 'none';
	}else {
		$( 'next_arrow' ).style.display = 'block';
	}
	
	return false;
	
}

/* popup */
function popup( id ) {

	var p = $( id );
	
	var m_top = p.offsetHeight / 2 + 'px';
	var m_left = p.offsetWidth / 2 + 'px';
	
	p.style.margin = '-' + m_top + ' 0 0 -' + m_left;

}
/* popup */


function showPrintPopup( id, url ) {

	var popup_id = "popup_id_"+id;
	var text_id = "popup_text_print_"+id;

	var oPrintId = $( popup_id ).value;

	oPrintId = oPrintId > 0 ? oPrintId : print_item_id;
	
	var oPrintText = $( text_id );



	var link = url + '&item_id='+oPrintId;

	var oConfig = {
		'width' 	: 700,
		'height' 	: 600,
		'menubar'	: true,
		'resize'	: true,
		'url'		: link
	}
	
	
	createWindow( oConfig );
};

function leaseCalcCheckValue( iid, eid, fid ) {
	
	var value = j( iid ).attr( 'value' );
	
	if ( value.strlen == 0 ) {
		
		return leaseCalcShowError( eid );
	}
	
	value = parseInt( value );
	
	if ( isNaN( value ) ) {
		
		return leaseCalcShowError( eid );
	}
	
	if ( value <= 0 ) {
		
		return leaseCalcShowError( eid );
	}
	
	j( eid ).hide();
	j( fid ).submit();
	
	return false;
}

function leaseCalcShowError( eid ) {
	
	j( eid ).show();
	if ( j('.first_text') ) {
		j('.first_text').addClass('error');
	}
	
	return false;
}

function leaseCalcCheckValueAjax( iid, eid, bid, fid ) {
	
	var value = j( iid ).attr( 'value' );
	
	if ( value.strlen == 0 ) {
		
		return j( eid ).addClass( 'error' );
	}
	
	value = parseInt( value );
	
	if ( isNaN( value ) ) {
		
		return j( eid ).addClass( 'error' );
	}
	
	if ( value <= 0 ) {
		
		return j( eid ).addClass( 'error' );
	}
	
	j( eid ).removeClass( 'error' );
	
	var form_url = j( fid ).attr( 'action' );
	
	j.ajax({
		url: form_url,
		type: 'POST',
		data: ( { lt : value, ajax : '1' }),
		dataType: "html",
		success: function( msg ){
			j( bid ).html( msg );
		}
	}
	);
	
	return false;
}